diff --git a/src/sys/ubixfsv2/device.h b/src/sys/ubixfsv2/device.h index 09bd9b3..6d81bc1 100644 --- a/src/sys/ubixfsv2/device.h +++ b/src/sys/ubixfsv2/device.h @@ -49,7 +49,7 @@ typedef struct device_t { int major; void *info; - uInt32 size; + uInt32 sectors; int (*read)(device_t *,void *,uInt32,uInt32); int (*write)(device_t *,void *,uInt32,uInt32); int (*reset)(void *); @@ -64,6 +64,11 @@ /*** $Log$ + Revision 1.2 2004/09/11 22:05:59 flameshadow + chg: modified UbixFS::vfs_format() to properly init the device + chg: modified UbixFS::vfs_init() to verify that it's a ubixfs partition + add: added BAT blockRun in the superBlock + Revision 1.1 2004/09/11 12:43:42 flameshadow add: device.h, types.h. Temporarily moved custom ubix typedefs to types.h ( supercedes this file when this code is included into diff --git a/src/sys/ubixfsv2/main.cpp b/src/sys/ubixfsv2/main.cpp index c76b28a..8b05e17 100644 --- a/src/sys/ubixfsv2/main.cpp +++ b/src/sys/ubixfsv2/main.cpp @@ -4,11 +4,13 @@ #include "vfs.h" #include "btree.h" #include "ubixfs.h" - +#include "device.h" +#include "ramdrive.h" using namespace std; int main(void) { +#if 0 int i = 0; ubixfsInode * inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); memset(inode, 0, sizeof(ubixfsInode)); @@ -48,5 +50,6 @@ tree->Save("tree.dat"); free(inode); delete tree; +#endif return 0; } diff --git a/src/sys/ubixfsv2/ramdrive.cpp b/src/sys/ubixfsv2/ramdrive.cpp index b5c3e4d..7308d31 100644 --- a/src/sys/ubixfsv2/ramdrive.cpp +++ b/src/sys/ubixfsv2/ramdrive.cpp @@ -36,24 +36,30 @@ static char *ram_data = 0x0; +#define RAM_DRIVE_SIZE 1024*1024*512 -static int ramDrive_read(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { +static +int +ramDrive_read(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { char *data = ram_data + offset; memcpy(ptr,data,length * 512); return(length); - } +} -static int ramDrive_write(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { +static +int +ramDrive_write(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { char *data = ram_data + offset; memcpy(data,ptr,length * 512); return(length); - } +} -device_t *dev_ramDrive() { +device_t * +dev_ramDrive(void) { device_t *ramDrive = 0x0; FILE *ramDisk; @@ -62,38 +68,45 @@ ramDrive = (device_t *)malloc(sizeof(device_t)); - ram_data = (char *)malloc(1024 * 1024 * 40); + ram_data = (char *)malloc(RAM_DRIVE_SIZE); if (ramDisk != 0x0) { printf("Loaded Ram Disk\n"); - fread(ram_data,1024 * 1024 * 40,1,ramDisk); + fread(ram_data,RAM_DRIVE_SIZE,1,ramDisk); fclose(ramDisk); } ramDrive->major = 0x1; + ramDrive->sectors = RAM_DRIVE_SIZE / 512; ramDrive->read = ramDrive_read; ramDrive->write = ramDrive_write; return(ramDrive); - } +} // dev_ramDrive -int dev_ramDestroy() { +int +dev_ramDestroy(void) { FILE *ramDisk; ramDisk = fopen("./ram.dsk","wb"); - fwrite(ram_data,1024 * 1024 * 40,1,ramDisk); + fwrite(ram_data, RAM_DRIVE_SIZE ,1,ramDisk); fclose(ramDisk); printf("Saved Ram Disk\n"); return(0x0); - } +} // dev_ramDestroy /*** $Log$ + Revision 1.1 2004/09/13 14:37:49 flameshadow + add: ramdrive.cpp + chg: added ramdrive to the makefile + chg: finished root dir inode initialization and saving in UbixFS::format() + Revision 1.8 2004/08/30 13:29:08 reddawg Fixed ramdisk to write/read 512 blocks diff --git a/src/sys/ubixfsv2/ramdrive.h b/src/sys/ubixfsv2/ramdrive.h new file mode 100644 index 0000000..e56488b --- /dev/null +++ b/src/sys/ubixfsv2/ramdrive.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef __RAMDRIVE_H_ +#define __RAMDRIVE_H_ + +#include + +int dev_ramDestroy(); +device_t *dev_ramDrive(); + +#endif + +/*** + $Log$ + Revision 1.1 2004/08/13 21:47:49 reddawg + Fixed + + END + ***/ + diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 51f714f..77e70d9 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -22,7 +22,7 @@ if (superBlock == NULL) return -1; // read in the superBlock. It's always the last block on the partition - device->read(device, superBlock, device->size-1, 1); + device->read(device, superBlock, device->sectors-1, 1); assert(superBlock->magic1 == UBIXFS_MAGIC1); assert(superBlock->magic2 == UBIXFS_MAGIC2); @@ -245,7 +245,7 @@ memset(§or, 0, sizeof(sector)); // fill the drive in with zeroed out sectors - for (unsigned int i = 0; i < dev->size; i++) { + for (unsigned int i = 0; i < dev->sectors; i++) { dev->write(dev, §or, i, 1); } // for i @@ -255,10 +255,10 @@ if (sb == NULL) return -1; memset(sb, 0, sizeof(diskSuperBlock)); - // dev->size is the size of the device in 512 byte sectors + // dev->sectors is the number of 512 byte sectors - blocks = (dev->size-1) / 8; // 4k blocks - batSize = (dev->size-1) % 8; // remainder + blocks = (dev->sectors-1) / 8; // 4k blocks + batSize = (dev->sectors-1) % 8; // remainder // compute the BAT size @@ -308,7 +308,7 @@ sb->rootDir.len = 1; // write out the superBlock - dev->write(dev, sb, dev->size-1, 1); + dev->write(dev, sb, dev->sectors-1, 1); // mark the first two 4k blocks used sector[0] = (1 << 7) | (1 << 6); @@ -370,6 +370,7 @@ dev->write(dev, inode, 0, superBlock->inodeSize / 512); // write out the "root" dir dev->write(dev, bth, 1, superBlock->blockSize / 512); + delete inode; free(bth); delete sb; return 0;