diff --git a/.cproject b/.cproject index 04b8d6f..202d010 100644 --- a/.cproject +++ b/.cproject @@ -5,7 +5,6 @@ - @@ -17,8 +16,8 @@ - - + + @@ -44,6 +43,9 @@ + + + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 076bf00..1650089 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,10 +5,6 @@ - - - - diff --git a/sys/fs/ubixfsv2/btree.cpp b/sys/fs/ubixfsv2/btree.cpp index 114018d..c24a051 100644 --- a/sys/fs/ubixfsv2/btree.cpp +++ b/sys/fs/ubixfsv2/btree.cpp @@ -1,4 +1,7 @@ // http://www.cs.msstate.edu/~cs2314/global/BTreeAnimation/algorithm.html + +/* + #include #include #include @@ -37,7 +40,7 @@ } // bTree::bTree bTree::bTree(const char * key, ubixfsInode * inode) { -/* once the FS and the bTree are interfaced, this should go away */ +// once the FS and the bTree are interfaced, this should go away root = NULL; tag = 0; header = new bTreeHeader; @@ -114,9 +117,8 @@ // cout << "Insert(" << key << ")" << endl; //Info(bnode); ++header->treeLeafCount; - /* - * Find the leaf node the inode goes into - */ + //Find the leaf node the inode goes into + assert(bnode->used); // cout << "---Inserting " << inode->name << " @ " << inode << endl; while (bnode != NULL && !bnode->leaf) { @@ -136,9 +138,6 @@ } } // while - /* - * - */ assert(bnode); if (bnode->leaf != true) cout << "leafnode!=true" << endl; @@ -161,9 +160,7 @@ if (tmpInode == NULL) { - /* - * This is the first node in this leaf - */ + // This is the first node in this leaf bnode->head[curSlot].iPtr = bnode->tail[curSlot].iPtr = inode; bnode->present[curSlot] = true; @@ -185,9 +182,8 @@ } // else } else { - /* - * Add node to leaf page. Scan through to find where it goes. - */ + // Add node to leaf page. Scan through to find where it goes. + if (strcmp(key, bnode->head[curSlot].iPtr->name) < 0) { @@ -405,11 +401,12 @@ if (strcmp(key, node->keys[curSlot]) < 0) break; } // for - /* + + *//* * note that there is one more item for everything but keys * So, make the shift count +1 and just subtract it from the key shift * later - */ + *//* int shift = node->used - curSlot +1; memmove(&node->head[curSlot+1], @@ -543,14 +540,15 @@ ubixfsInode * bTree::Find(const char * key) { -/* + +*//* ubixfsInode * tmp = GetFirstNode(); while (tmp!=NULL) { if (strcmp(tmp->name, key) == 0) return tmp; tmp = tmp->next.iPtr; } return NULL; -*/ +*//* return treeSearch(root, key); } // bTree::Find @@ -765,3 +763,5 @@ cout << "tree width: " << header->treeWidth << endl; cout << "tree leaf count: " << header->treeLeafCount << endl; } // bTree::~bTree + +*/ diff --git a/sys/fs/ubixfsv2/btree.h b/sys/fs/ubixfsv2/btree.h index edd28ee..591ba26 100644 --- a/sys/fs/ubixfsv2/btree.h +++ b/sys/fs/ubixfsv2/btree.h @@ -1,3 +1,4 @@ +/* #ifndef BTREE_H #define BTREE_H @@ -68,3 +69,4 @@ friend class UbixFS; }; // bTree #endif // !BTREE_H +*/ diff --git a/sys/fs/ubixfsv2/btreeheader.h b/sys/fs/ubixfsv2/btreeheader.h index be72012..9f0e1fb 100644 --- a/sys/fs/ubixfsv2/btreeheader.h +++ b/sys/fs/ubixfsv2/btreeheader.h @@ -1,4 +1,4 @@ -#ifndef BTREEHEADER_H +/*#ifndef BTREEHEADER_H #define BTREEHEADER_H typedef struct bTreeHeader { @@ -10,4 +10,4 @@ char paddington[4068]; } bTreeHeader; // bTreeHeader -#endif /* !BTREEHEADER_H */ +#endif*/ /* !BTREEHEADER_H */ diff --git a/sys/fs/ubixfsv2/device.h b/sys/fs/ubixfsv2/device.h index fe3d82f..007d187 100644 --- a/sys/fs/ubixfsv2/device.h +++ b/sys/fs/ubixfsv2/device.h @@ -26,7 +26,7 @@ $Id: device.h 54 2016-01-11 01:29:55Z reddawg $ *****************************************************************************************/ - +/* #ifndef _DEVICE_H #define _DEVICE_H @@ -62,7 +62,7 @@ }; #endif - +*/ /*** $Log: device.h,v $ Revision 1.1.1.1 2006/06/01 12:46:15 reddawg diff --git a/sys/fs/ubixfsv2/file.h b/sys/fs/ubixfsv2/file.h index 7d8f1f3..d03e2d3 100644 --- a/sys/fs/ubixfsv2/file.h +++ b/sys/fs/ubixfsv2/file.h @@ -1,3 +1,4 @@ +/* #ifndef FILE_H #define FILE_H @@ -11,4 +12,4 @@ size_t size; } fileDescriptor; -#endif /* !FILE_H */ +#endif *//* !FILE_H */ diff --git a/sys/fs/ubixfsv2/fsAbstract.h b/sys/fs/ubixfsv2/fsAbstract.h index 9658881..4f1bf80 100644 --- a/sys/fs/ubixfsv2/fsAbstract.h +++ b/sys/fs/ubixfsv2/fsAbstract.h @@ -1,4 +1,4 @@ -#ifndef FSABSTRACT_H +/*#ifndef FSABSTRACT_H #define FSABSTRACT_H #include @@ -13,7 +13,7 @@ vfs_abstract * next; device_t * device; public: - /* File I/O */ + // File I/O virtual int vfs_open(const char *, fileDescriptor *,int,...) { return -1; }; virtual int vfs_close(fileDescriptor *) { return -1; }; virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t) @@ -21,14 +21,14 @@ virtual size_t vfs_write(fileDescriptor *, void *, off_t, size_t) { return 0; }; - /* Dir I/O */ + // Dir I/O virtual int vfs_opendir(DIR *,const char *) { return -1; }; virtual int vfs_closedir(DIR *) { return -1; }; virtual int vfs_mkdir(const char *, mode_t) { return -1; }; virtual int vfs_rmdir(const char *) { return -1; }; virtual int vfs_readdir(DIR *,struct dirent *) { return -1; }; - /* FS Functions */ + // FS Functions virtual int vfs_init(void) { return -1; }; virtual int vfs_format(device_t *) { return -1; }; virtual void * vfs_mknod(const char *, mode_t) { return NULL; }; @@ -36,11 +36,11 @@ virtual int vfs_stop(void) { return -1; }; virtual int vfs_sync(void) { return -1; }; - /* Misc Functions */ + // Misc Functions virtual int vfs_unlink(const char *) { return -1; }; virtual int vfs_rename(const char *,const char *) { return -1; }; virtual ~vfs_abstract(void) { }; }; // vfs_FS -#endif // !FSABSTRACT_H +#endif*/ // !FSABSTRACT_H diff --git a/sys/fs/ubixfsv2/main.cpp b/sys/fs/ubixfsv2/main.cpp index 8bdff45..5c14a12 100644 --- a/sys/fs/ubixfsv2/main.cpp +++ b/sys/fs/ubixfsv2/main.cpp @@ -1,4 +1,5 @@ -#include +/* + #include #include #include #include "vfs.h" @@ -63,3 +64,4 @@ cout << "sizeof(bTreeHeader): " << sizeof(struct bTreeHeader) << endl; return 0; } +*/ diff --git a/sys/fs/ubixfsv2/ramdrive.cpp b/sys/fs/ubixfsv2/ramdrive.cpp index 2ecc2d7..3a189bb 100644 --- a/sys/fs/ubixfsv2/ramdrive.cpp +++ b/sys/fs/ubixfsv2/ramdrive.cpp @@ -26,7 +26,7 @@ $Id: ramdrive.cpp 54 2016-01-11 01:29:55Z reddawg $ *****************************************************************************************/ - +/* #include #include #include @@ -106,7 +106,7 @@ return(0x0); } // dev_ramDestroy - +*/ /*** $Log: ramdrive.cpp,v $ Revision 1.1.1.1 2006/06/01 12:46:15 reddawg diff --git a/sys/fs/ubixfsv2/ramdrive.h b/sys/fs/ubixfsv2/ramdrive.h index 647969e..c7e9914 100644 --- a/sys/fs/ubixfsv2/ramdrive.h +++ b/sys/fs/ubixfsv2/ramdrive.h @@ -26,7 +26,7 @@ $Id: ramdrive.h 54 2016-01-11 01:29:55Z reddawg $ *****************************************************************************************/ - +/* #ifndef __RAMDRIVE_H_ #define __RAMDRIVE_H_ @@ -36,6 +36,7 @@ device_t *dev_ramDrive(); #endif +*/ /*** $Log: ramdrive.h,v $ diff --git a/sys/fs/ubixfsv2/types.h b/sys/fs/ubixfsv2/types.h index 0cad845..1bea2a5 100644 --- a/sys/fs/ubixfsv2/types.h +++ b/sys/fs/ubixfsv2/types.h @@ -1,3 +1,4 @@ +/* #ifndef TYPES_H #define TYPES_H @@ -8,4 +9,4 @@ typedef unsigned long long uInt64; typedef signed long long int64; -#endif /* !TYPES_H */ +#endif *//* !TYPES_H */ diff --git a/sys/fs/ubixfsv2/ubixfs.cpp b/sys/fs/ubixfsv2/ubixfs.cpp index f938ddb..55b7964 100644 --- a/sys/fs/ubixfsv2/ubixfs.cpp +++ b/sys/fs/ubixfsv2/ubixfs.cpp @@ -1,4 +1,4 @@ -#include +/*#include #include #include #include @@ -106,7 +106,7 @@ ubixfsInode * rootInode = static_cast(root->inode); assert(rootInode); - /* the bTree constructor now loads in the header */ + //the bTree constructor now loads in the header rootInode->data.btPtr = new bTree(this, root); rootInode->data.btPtr->Info(); @@ -209,7 +209,7 @@ dev->write(dev, §or, (batSect)+i, 1); } // for i - /* allocate part of the root dir */ + // allocate part of the root dir // sanity checks assert(sb->blockSize); @@ -225,7 +225,7 @@ bth->treeWidth = 0; bth->treeLeafCount = 0; - /* create the root dir inode here */ + // create the root dir inode here ubixfsInode * inode = new ubixfsInode; assert(inode); @@ -244,7 +244,7 @@ inode->parent.iAddr.start = 0; inode->parent.iAddr.len = 0; - /* this is part of the root dir structure (the bTreeHeader) */ + // this is part of the root dir structure (the bTreeHeader) inode->blocks.direct[0].AG = 0; inode->blocks.direct[0].start = 1; inode->blocks.direct[0].len = 1; @@ -267,11 +267,11 @@ inode->inodeSize = sb->inodeSize; - /* + *//* * next and prev are used in memory to hold pointers to the next/prev * inodes in this dir. On disk they may have another value, but for * now they should be set to null. - */ + *//* inode->next.offset = 0; inode->prev.offset = 0; @@ -342,9 +342,9 @@ while (size > 0) { - /* + *//* * place check here to see which set of blocks we're looking through - */ + *//* // scan through direct blocks do { @@ -422,11 +422,11 @@ } if (EORPos > maxRange) { - /* + *//* * The offset+size is greater than the size of the file, so we need to * extend out the file. Scan through the direct blocks (FIX LATER) * to find out where we need to extend - */ + *//* switch (whichBlocks) { case 0: while (i < NUM_DIRECT_BLOCKS && inode->blocks.direct[i].len != 0) ++i; @@ -440,18 +440,18 @@ assert(false); // sanity check } // switch - /* + *//* * NOTE: it's possible that if we scan through to find where the * run goes, we might be able to extend the previous block extent. * This will require that we set up br.start to be where we'd like to * start looking through the free block list, and then modifying * getFreeBlock() to honour that. - */ + *//* br.AG = inode->inodeNum.AG; // request a sane allocation group br.start = 0; // getFreeBlock() will ignore this - /* + *//* * The length that we need is determined by how much extra slack we * already have in the pre-allocated blocks. * e.g. (assumes 4k blocks) @@ -473,7 +473,7 @@ * ((3000 + 4000) - 4096 + (4095)) / 4096 == 1 (rounded down) * And then we expand it by a little extra so we don't have to keep * looking for more blocks. Currently we use 32k of slack (or 8 blocks) - */ + *//* br.len = ((EORPos - maxRange + (bSize-1)) / bSize); @@ -509,9 +509,8 @@ while (size > 0) { - /* - * place check here to see which set of blocks we're looking through - */ + / place check here to see which set of blocks we're looking through + // scan through direct blocks do { @@ -576,10 +575,10 @@ superBlock = NULL; root = NULL; - /* + *//* * The device isn't null at this point, allowing for people to restart * the mount point. Or, alternatively, to blow things up. - */ + *//* return 0; } // UbixFS::vfs_stop @@ -628,22 +627,22 @@ if (ibr.len > superBlock->numBlocks) return obr; if (ibr.len == 1) return getFreeBlock(ibr.AG); - /* + *//* * count is the block from the base of the list. * Since we're given a specific AG to look through, we start the count at * AG << AGShift, where AGShift is the shift value of the number of blocks * in an AG - */ + *//* count = (ibr.AG << superBlock->AGShift); - /* + *//* * The freeBlockList is a bit map of the free/used blocks. * Used = on bit * Unused = off bit * There are 8 bits per byte (hopefully) and so we have to divide the count * by 8 to get our starting byte offset to look from - */ + *//* ptr = freeBlockList + (count >> 3); @@ -706,22 +705,22 @@ // Are there any blocks available? if (superBlock->numBlocks == superBlock->usedBlocks) return br; - /* + *//* * count is the block from the base of the list. * Since we're given a specific AG to look through, we start the count at * AG << AGShift, where AGShift is the shift value of the number of blocks * in an AG - */ + *//* count = (AG << superBlock->AGShift); - /* + *//* * The freeBlockList is a bit map of the free/used blocks. * Used = on bit * Unused = off bit * There are 8 bits per byte (hopefully) and so we have to divide the count * by 8 to get our starting byte offset to look from - */ + *//* ptr = freeBlockList + (count >> 3); @@ -767,11 +766,11 @@ } // UbixFS::getNextAG -/* +*//* * UbixFS::getFreeBlock(void) * upon success returns a free block based on the next AG after the lastUsedAG * failure returns -1 - */ + *//* blockRun UbixFS::getFreeBlock(void) { @@ -795,12 +794,12 @@ // Are there any blocks available? if (superBlock->usedBlocks+8 > superBlock->numBlocks) return br; - /* + *//* * count is the block from the base of the list. * Since we're given a specific AG to look through, we start the count at * AG << AGShift, where AGShift is the shift value of the number of blocks * in an AG - */ + *//* count = (AG << superBlock->AGShift); @@ -842,11 +841,11 @@ inode->magic1 = UBIXFS_INODE_MAGIC; - /* + *//* * in retrospect.. I'm not sure why parent would be null.. only the * root directory would have a null parent, but that's manually allocated * in vfs_format() - */ + *//* if (parent == NULL) { inode->inodeNum = getFreeBlock(); @@ -874,11 +873,11 @@ // inode->type - /* + *//* * next and prev are used in memory to hold pointers to the next/prev * inodes in this dir. On disk they may have another value, but for * now they should be set to null. - */ + *//* inode->next.offset = 0; inode->prev.offset = 0; @@ -913,24 +912,24 @@ assert(path[nameStart] != '/'); // bad input: mkdir /a// - /* + *//* * we're guaranteed by the assert() above that there is * at least one "/" before our location. If you remove the assert * you might need to make sure nameStart stays above 0 in the following * while - */ + *//* while (path[nameStart] != '/') --nameStart; ++nameStart; assert(len - nameStart > 0); - /* e.g. + *//* e.g. * v--------------------- start * v------------------ end * v------ nameStart * /usr/local/data/dirname/ <--- ignores trailing / * <---------23----------> len - */ + *//* start = end = 1; // skip leading / while (end < nameStart) { @@ -949,13 +948,13 @@ strncpy(name, &path[nameStart], len - nameStart); inode = (ubixfsInode *)mknod(name, dir, mode | INODE_DIRECTORY); - /* + *//* * keep in mind that the reason for passing in the name is because * we thought about allowing key names to be different from inode * names. In retrospect, I don't think that's a good idea since a dir * listing will print the actual dir name instead of . and .. * Thus: the first parameter of btPtr->Insert() may go away. - */ + *//* assert(dir->data.btPtr->Insert(inode->name, inode)); @@ -987,3 +986,4 @@ delete [] freeBlockList; return; } +*/ diff --git a/sys/fs/ubixfsv2/ubixfs.h b/sys/fs/ubixfsv2/ubixfs.h index 595e6f4..15d40a2 100644 --- a/sys/fs/ubixfsv2/ubixfs.h +++ b/sys/fs/ubixfsv2/ubixfs.h @@ -1,4 +1,4 @@ -#ifndef UBIXFS_H +/*#ifndef UBIXFS_H #define UBIXFS_H #include @@ -25,11 +25,11 @@ #define UBIXFS_MAGIC3 0xC0C0C0C #define UBIXFS_INODE_MAGIC 0x3bbe0ad9 -/* befs magic numbers +*//* befs magic numbers #define SUPER_BLOCK_MAGIC1 0x42465331 // BFS1 #define SUPER_BLOCK_MAGIC2 0xdd121031 #define SUPER_BLOCK_MAGIC3 0x15b6830e - */ + *//* #define UBIXFS_CLEAN 0x434C454E // CLEN #define UBIXFS_DIRTY 0x44495254 // DIRT @@ -161,3 +161,4 @@ }; // UbixFS #endif // !UBIXFS_H +*/ diff --git a/sys/fs/ubixfsv2/vfs.cpp b/sys/fs/ubixfsv2/vfs.cpp index daa28a7..1cf4a45 100644 --- a/sys/fs/ubixfsv2/vfs.cpp +++ b/sys/fs/ubixfsv2/vfs.cpp @@ -1,4 +1,4 @@ -#include +/*#include #include "vfs.h" DiskFS::DiskFS(const char * filename) { @@ -20,3 +20,4 @@ fread(data, size, 1, diskFile); return 0; } // DiskFS::read +*/ diff --git a/sys/fs/ubixfsv2/vfs.h b/sys/fs/ubixfsv2/vfs.h index 68548e9..dc78084 100644 --- a/sys/fs/ubixfsv2/vfs.h +++ b/sys/fs/ubixfsv2/vfs.h @@ -1,4 +1,4 @@ -#ifndef VFS_H +/*#ifndef VFS_H #define VFS_H #include @@ -23,3 +23,4 @@ }; // DiskFS #endif // !VFS_H +*/ diff --git a/sys/fs/ufs/ufs.c b/sys/fs/ufs/ufs.c index 4bb26ab..e91b2cf 100644 --- a/sys/fs/ufs/ufs.c +++ b/sys/fs/ufs/ufs.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -48,9 +49,9 @@ (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK)) #define INO_TO_VBO(ipervblk, x) ((x) % ipervblk) -static int dskread(void *buf, u_int64_t block, size_t count, fileDescriptor *fd) { - fd->mp->device->devInfo->read(fd->mp->device->devInfo->info, buf, block, count); - return (0x0); +static int dskread(void *buf, uint64_t block, size_t count, fileDescriptor *fd) { + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info, buf, block, count); + return (0x0); } //struct dmadat { @@ -74,216 +75,221 @@ #endif static ssize_t fsread(ino_t inode, void *buf, size_t nbyte, fileDescriptor *fd) { - #ifndef UFS2_ONLY +#ifndef UFS2_ONLY static struct ufs1_dinode dp1; - #endif - #ifndef UFS1_ONLY +#endif +#ifndef UFS1_ONLY static struct ufs2_dinode dp2; - #endif - static ino_t inomap; - char *blkbuf; - void *indbuf; - struct fs *fs; - char *s; - size_t n, nb, size, off, vboff; - ufs_lbn_t lbn; - ufs2_daddr_t addr, vbaddr; - static ufs2_daddr_t blkmap, indmap; - u_int u; +#endif + static ino_t inomap; + char *blkbuf; + void *indbuf; + struct fs *fs; + char *s; + size_t n, nb, size, off, vboff; + ufs_lbn_t lbn; + ufs2_daddr_t addr, vbaddr; + static ufs2_daddr_t blkmap, indmap; + u_int u; - blkbuf = fd->dmadat->blkbuf; - indbuf = fd->dmadat->indbuf; - fs = (struct fs *) fd->dmadat->sbbuf; + blkbuf = fd->dmadat->blkbuf; + indbuf = fd->dmadat->indbuf; + fs = (struct fs *) fd->dmadat->sbbuf; - if (!fd->dsk_meta) { - inomap = 0; - for (n = 0; sblock_try[n] != -1; n++) { - if (dskread(fs, sblock_try[n] / DEV_BSIZE, 16, fd)) - return -1; - if (( + if (!fd->dsk_meta) { + inomap = 0; + for (n = 0; sblock_try[n] != -1; n++) { + if (dskread(fs, sblock_try[n] / DEV_BSIZE, 16, fd)) + return -1; + if (( #if defined(UFS1_ONLY) - fs->fs_magic == FS_UFS1_MAGIC + fs->fs_magic == FS_UFS1_MAGIC #elif defined(UFS2_ONLY) (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc == sblock_try[n]) #else fs->fs_magic == FS_UFS1_MAGIC || (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc == sblock_try[n]) #endif ) && fs->fs_bsize <= MAXBSIZE && fs->fs_bsize >= sizeof(struct fs)) - break; + break; //MrOlsen 2017-12-14 this was for debugging kprintf("Finding SBlock: [%s][0x%X][%i - %i]\n", fs->fs_fsmnt, fs->fs_magic, sblock_try[n], sblock_try[n] / DEV_BSIZE); - } - if (sblock_try[n] == -1) { - kprintf("Not ufs\n"); - return -1; - } - fd->dsk_meta++; - } + } + if (sblock_try[n] == -1) { + kprintf("Not ufs\n"); + return -1; + } + fd->dsk_meta++; + } - if (!inode) - return (0x0); + if (!inode) + return (0x0); - if (inomap != inode) { - n = IPERVBLK(fs); - if (dskread(blkbuf, INO_TO_VBA(fs, n, inode), DBPERVBLK, fd)) - return -1; - n = INO_TO_VBO(n, inode); + if (inomap != inode) { + n = IPERVBLK(fs); + if (dskread(blkbuf, INO_TO_VBA(fs, n, inode), DBPERVBLK, fd)) + return -1; + n = INO_TO_VBO(n, inode); #if defined(UFS1_ONLY) - dp1 = ((struct ufs1_dinode *)blkbuf)[n]; + dp1 = ((struct ufs1_dinode *)blkbuf)[n]; + memcpy(fd->inode.ufs1, dp1, sizeof(struct ufs1_dinode)); #elif defined(UFS2_ONLY) - dp2 = ((struct ufs2_dinode *)blkbuf)[n]; + dp2 = ((struct ufs2_dinode *)blkbuf)[n]; + memcpy(fd->inode.ufs2, dp2, sizeof(struct ufs2_dinode)); #else - if (fs->fs_magic == FS_UFS1_MAGIC) - dp1 = ((struct ufs1_dinode *) blkbuf)[n]; - else - dp2 = ((struct ufs2_dinode *) blkbuf)[n]; + if (fs->fs_magic == FS_UFS1_MAGIC) { + dp1 = ((struct ufs1_dinode *) blkbuf)[n]; + memcpy(fd->inode.ufs1, dp1, sizeof(struct ufs1_dinode)); + } + else{ + dp2 = ((struct ufs2_dinode *) blkbuf)[n]; + memcpy(fd->inode.ufs2, dp2, sizeof(struct ufs2_dinode)); + } #endif - inomap = inode; - fd->offset = 0; - blkmap = indmap = 0; - } + inomap = inode; + fd->offset = 0; + blkmap = indmap = 0; + } - s = buf; - size = DIP(di_size); - fd->size = size; - n = size - fd->offset; - //Why? - if (n < 0) - return (0x0); - if (nbyte > n) - nbyte = n; - nb = nbyte; - while (nb) { - lbn = lblkno(fs, fd->offset); - off = blkoff(fs, fd->offset); - if (lbn < NDADDR) { - addr = DIP(di_db[lbn]); - } else if (lbn < NDADDR + NINDIR(fs)) { - n = INDIRPERVBLK(fs); - addr = DIP(di_ib[0]); - u = (u_int) (lbn - NDADDR) / (n * DBPERVBLK); - vbaddr = fsbtodb(fs, addr) + u; - if (indmap != vbaddr) { - if (dskread(indbuf, vbaddr, DBPERVBLK, fd)) - return -1; - indmap = vbaddr; - } - n = (lbn - NDADDR) & (n - 1); + s = buf; + size = DIP(di_size); + fd->size = size; + n = size - fd->offset; + //Why? + if (n < 0) + return (0x0); + if (nbyte > n) + nbyte = n; + nb = nbyte; + while (nb) { + lbn = lblkno(fs, fd->offset); + off = blkoff(fs, fd->offset); + if (lbn < NDADDR) { + addr = DIP(di_db[lbn]); + } else if (lbn < NDADDR + NINDIR(fs)) { + n = INDIRPERVBLK(fs); + addr = DIP(di_ib[0]); + u = (u_int) (lbn - NDADDR) / (n * DBPERVBLK); + vbaddr = fsbtodb(fs, addr) + u; + if (indmap != vbaddr) { + if (dskread(indbuf, vbaddr, DBPERVBLK, fd)) + return -1; + indmap = vbaddr; + } + n = (lbn - NDADDR) & (n - 1); #if defined(UFS1_ONLY) - addr = ((ufs1_daddr_t *)indbuf)[n]; + addr = ((ufs1_daddr_t *)indbuf)[n]; #elif defined(UFS2_ONLY) - addr = ((ufs2_daddr_t *)indbuf)[n]; + addr = ((ufs2_daddr_t *)indbuf)[n]; #else - if (fs->fs_magic == FS_UFS1_MAGIC) - addr = ((ufs1_daddr_t *) indbuf)[n]; - else - addr = ((ufs2_daddr_t *) indbuf)[n]; + if (fs->fs_magic == FS_UFS1_MAGIC) + addr = ((ufs1_daddr_t *) indbuf)[n]; + else + addr = ((ufs2_daddr_t *) indbuf)[n]; #endif - } else { - return -1; - } - vbaddr = fsbtodb(fs, addr) + (off >> VBLKSHIFT) * DBPERVBLK; - vboff = off & VBLKMASK; - n = sblksize(fs, size, lbn) - (off & ~VBLKMASK); - if (n > VBLKSIZE) - n = VBLKSIZE; - if (blkmap != vbaddr) { - if (dskread(blkbuf, vbaddr, n >> DEV_BSHIFT, fd)) - return -1; - blkmap = vbaddr; - } - n -= vboff; - if (n > nb) - n = nb; - memcpy(s, blkbuf + vboff, n); - s += n; - fd->offset += n; - nb -= n; - } - return nbyte; + } else { + return -1; + } + vbaddr = fsbtodb(fs, addr) + (off >> VBLKSHIFT) * DBPERVBLK; + vboff = off & VBLKMASK; + n = sblksize(fs, size, lbn) - (off & ~VBLKMASK); + if (n > VBLKSIZE) + n = VBLKSIZE; + if (blkmap != vbaddr) { + if (dskread(blkbuf, vbaddr, n >> DEV_BSHIFT, fd)) + return -1; + blkmap = vbaddr; + } + n -= vboff; + if (n > nb) + n = nb; + memcpy(s, blkbuf + vboff, n); + s += n; + fd->offset += n; + nb -= n; + } + return nbyte; } static __inline int fsfind(const char *name, ino_t * ino, fileDescriptor *fd) { - char buf[DEV_BSIZE]; - struct dirent *d; - char *s; - ssize_t n; + char buf[DEV_BSIZE]; + struct dirent *d; + char *s; + ssize_t n; - fd->offset = 0; - while ((n = fsread(*ino, buf, DEV_BSIZE, fd)) > 0) - for (s = buf; s < buf + DEV_BSIZE;) { - d = (void *) s; - if (!strcmp(name, d->d_name)) { - *ino = d->d_fileno; - return d->d_type; - } - s += d->d_reclen; - } - //if (n != -1 && ls) - //kprintf("\n"); - return 0; + fd->offset = 0; + while ((n = fsread(*ino, buf, DEV_BSIZE, fd)) > 0) + for (s = buf; s < buf + DEV_BSIZE;) { + d = (void *) s; + if (!strcmp(name, d->d_name)) { + *ino = d->d_fileno; + return d->d_type; + } + s += d->d_reclen; + } + + return 0; } static ino_t lookup(const char *path, fileDescriptor *fd) { - char name[MAXNAMLEN + 1]; - const char *s; - ino_t ino; - ssize_t n; - int dt; + char name[MAXNAMLEN + 1]; + const char *s; + ino_t ino; + ssize_t n; + int dt; - ino = ROOTINO; - dt = DT_DIR; - name[0] = '/'; - name[1] = '\0'; - for (;;) { - if (*path == '/') - path++; - if (!*path) - break; - for (s = path; *s && *s != '/'; s++) - ; - if ((n = s - path) > MAXNAMLEN) - return 0; - //ls = *path == '?' && n == 1 && !*s; - memcpy(name, path, n); - name[n] = 0; - if (dt != DT_DIR) { - kprintf("%s: not a directory.\n", name); - return (0); - } - if ((dt = fsfind(name, &ino, fd)) <= 0) - break; - path = s; - } + ino = ROOTINO; + dt = DT_DIR; + name[0] = '/'; + name[1] = '\0'; + for (;;) { + if (*path == '/') + path++; + if (!*path) + break; + for (s = path; *s && *s != '/'; s++) + ; + if ((n = s - path) > MAXNAMLEN) + return 0; + //ls = *path == '?' && n == 1 && !*s; + memcpy(name, path, n); + name[n] = 0; + if (dt != DT_DIR) { + kprintf("%s: not a directory.\n", name); + return (0); + } + if ((dt = fsfind(name, &ino, fd)) <= 0) + break; + path = s; + } - return dt == DT_REG ? ino : 0; + return dt == DT_REG ? ino : 0; } static int ufs_openFile(const char *file, fileDescriptor *fd) { - char tmp[2]; - int ino = 0; - fd->dmadat = (struct dmadat *) kmalloc(sizeof(struct dmadat)); - ino = lookup(file, fd); - fd->offset = 0x0; - fd->ino = ino; - if (ino == 0x0) { - return (-1); - } + char tmp[2]; + int ino = 0; + fd->dmadat = (struct dmadat *) kmalloc(sizeof(struct dmadat)); + ino = lookup(file, fd); + fd->offset = 0x0; + fd->ino = ino; + if (ino == 0x0) { + return (-1); + } - /* Quick Hack for file size */ - fsread(fd->ino, &tmp, 1, fd); - fd->offset = 0; - /* Return */ - fd->perms = 0x1; - return (0x1); + /* Quick Hack for file size */ + fsread(fd->ino, &tmp, 1, fd); + fd->offset = 0; + /* Return */ + fd->perms = 0x1; + return (0x1); } int ufs_readFile(fileDescriptor *fd, char *data, uInt32 offset, long size) { - return (fsread(fd->ino, data, size, fd)); + return (fsread(fd->ino, data, size, fd)); } int ufs_writeFile(fileDescriptor *fd, char *data, uInt32 offset, long size) { - kprintf("Writing :)\n"); - return (0x0); + kprintf("Writing :)\n"); + return (0x0); } /***************************************************************************************** @@ -296,32 +302,32 @@ *****************************************************************************************/ int ufs_initialize(struct vfs_mountPoint *mp) { - /* Return */ - return (0x1); + /* Return */ + return (0x1); } int ufs_init() { - /* Build our ufs struct */ - struct fileSystem ufs = { NULL, /* prev */ - NULL, /* next */ - (void *) ufs_initialize, /* vfsInitFS */ - (void *) ufs_readFile, /* vfsRead */ - (void *) ufs_writeFile, /* vfsWrite */ - (void *) ufs_openFile, /* vfsOpenFile */ - NULL, /* vfsUnlink */ - NULL, /* vfsMakeDir */ - NULL, /* vfsRemDir */ - NULL, /* vfsSync */ - 0xAA, /* vfsType */ - }; /* UFS */ + /* Build our ufs struct */ + struct fileSystem ufs = { NULL, /* prev */ + NULL, /* next */ + (void *) ufs_initialize, /* vfsInitFS */ + (void *) ufs_readFile, /* vfsRead */ + (void *) ufs_writeFile, /* vfsWrite */ + (void *) ufs_openFile, /* vfsOpenFile */ + NULL, /* vfsUnlink */ + NULL, /* vfsMakeDir */ + NULL, /* vfsRemDir */ + NULL, /* vfsSync */ + 0xAA, /* vfsType */ + }; /* UFS */ - if (vfsRegisterFS(ufs) != 0x0) { - kpanic("Unable To Enable UFS"); - return (0x1); - } - //dmadat = (struct dmadat *)kmalloc(sizeof(struct dmadat)); - /* Return */ - return (0x0); + if (vfsRegisterFS(ufs) != 0x0) { + kpanic("Unable To Enable UFS"); + return (0x1); + } + //dmadat = (struct dmadat *)kmalloc(sizeof(struct dmadat)); + /* Return */ + return (0x0); } /*** diff --git a/sys/fs/vfs/stat.c b/sys/fs/vfs/stat.c index 026c797..3403547 100644 --- a/sys/fs/vfs/stat.c +++ b/sys/fs/vfs/stat.c @@ -8,7 +8,7 @@ //NOTE: Should we verify that the memory is writable? kprintf("SYS_STAT {%s}", path); - +/* switch (flags) { case STAT_LSTAT: error = namei(path, NULL, STAT_NO_FOLLOW, &inode); @@ -30,15 +30,27 @@ error = -1; break; } +*/ + fileDescriptor *fd = fopen(path, "r"); - sb->st_dev = 0x5E; - sb->st_ino = 0x3003; - sb->st_mode = 0x41FF; - sb->st_nlink = 0x2; - sb->st_uid = 0x0; - sb->st_gid = 0x0; - sb->st_rdev = 0x7FF3; - sb->st_size = 0xFFFFEB70; + if (fd == 0) { + error -1; + } + else { + sb->st_dev = 0xDEADBEEF; + sb->st_ino = fd->ino; + sb->st_mode = fd->inode.ufs2->di_mode; + sb->st_nlink = fd->inode.ufs2->di_nlink; + sb->st_uid = fd->inode.ufs2->di_uid; + sb->st_gid = fd->inode.ufs2->di_gid; + sb->st_rdev = 0xBEEFDEAD; + sb->st_size = fd->inode.ufs2->di_size; + sb->st_atime = fd->inode.ufs2->di_atime; + sb->st_mtime = fd->inode.ufs2->di_mtime; + sb->st_ctime = fd->inode.ufs2->di_ctime; + kprintf("LSTAT(%i): st_ino 0x%X, st_mode: 0x%X, st_uid %i, st_gid %i, st_size: 0x%X", error, sb->st_ino, sb->st_mode, sb->st_uid, sb->st_gid, sb->st_size); + fclose(fd); + } return(error); } diff --git a/sys/include/vfs/file.h b/sys/include/vfs/file.h index 4d4df02..149ef73 100644 --- a/sys/include/vfs/file.h +++ b/sys/include/vfs/file.h @@ -53,26 +53,30 @@ struct fileDescriptorStruct *prev; struct fileDescriptorStruct *next; struct vfs_mountPoint *mp; - uInt16 status; - uInt16 mode; - uInt32 offset; - uInt32 size; - uInt16 length; - uInt32 start; + uint16_t status; + uint16_t mode; + uint32_t offset; + uint32_t size; + uint16_t length; + uint32_t start; char fileName[512]; char *buffer; - uInt32 ino; + uint32_t ino; struct cacheNode *cacheNode; - uInt32 perms; + uint32_t perms; struct dmadat *dmadat; int dsk_meta; - uInt32 resid; + uint32_t resid; + union { + struct ufs1_dinode ufs1; + struct ufs2_dinode ufs2; + } inode; } fileDescriptor; typedef struct userFileDescriptorStruct { struct fileDescriptorStruct *fd; - uInt32 fdSize; + uint32_t fdSize; } userFileDescriptor; extern fileDescriptor *fdTable;