From 99f723c4cb6d37ee934ea6b785f44d663d2d809a Mon Sep 17 00:00:00 2001 From: Hitmonrocker Date: Thu, 26 Apr 2018 23:53:40 -0400 Subject: [PATCH 1/3] Add files via upload --- sfs.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- structures.h | 19 ++++++++++--------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/sfs.c b/sfs.c index 2633159..d13d5e1 100644 --- a/sfs.c +++ b/sfs.c @@ -273,8 +273,52 @@ int sfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offse struct fuse_file_info *fi) { int retstat = 0; + log_msg("\nreaddir has begun\n"); + if(strcmp(path,"/") != 0 ) + { + return -1; + } - + filler(buf,".",NULL,0); + filler(buf,"..",NULL,0); + + char* disk = SFS_DATA->diskfile; + char buffer[512]; + + bufferlock_read(0,buffer); + superblock* sb = (superblock*)buffer; + + int rootD = sb->start_of_data_block; + + block_read(rootD,buffer); + inode* rootDir = (inode*)buffer; + + + //Search through all the direct map ptrs + int i=1; + for(i;i<15;i++) { + log_msg("\nreaddir: inside first for loop\n"); + //block num referenced by ptr + int blocknum = rootDir->blocks[i]; + log_msg("entered 1st for loop"); + //if valid ptr + if(blocknum > 0) { + + //read in inode + char buffer2[512]; + block_read(blocknum,buffer2); + inode* tempNode=(inode*)buffer2; + log_msg("\npath=\"%s\"\n",tempNode->path); + //Compares paths for match + + if (filler(buf, tempNode->path, NULL, 0) != 0){ + log_msg("\nerror returned: ENOMEM. When inserting file with path:\"%s\"\n",tempNode->path); + return -ENOMEM; + + log_msg("\npath=\"%s\"\n",tempNode->path); + } + } + } return retstat; } diff --git a/structures.h b/structures.h index 10500ff..b4b230c 100644 --- a/structures.h +++ b/structures.h @@ -3,15 +3,16 @@ // File descriptor (i-node) typedef struct _inode { - short int num; - char filename[16]; - uint32_t size; - char permissions[3]; - uint32_t blocks[15]; - /* - indirection ptrs, worry about it later - * void* single_indir_ptr; - * void* double_indir_ptr; - * */ + int16_t num; + int16_t isOpen; + char filename[16]; + uint32_t parent; + uint32_t size; + uint32_t blocks[15]; + /* - indirection ptrs, worry about it later + * void* single_indir_ptr; + * void* double_indir_ptr; + * */ }inode; // LL for free blocks From c61c5300d2ec8d8544096cd8917a209c5c56b850 Mon Sep 17 00:00:00 2001 From: Hitmonrocker Date: Fri, 27 Apr 2018 00:28:36 -0400 Subject: [PATCH 2/3] Add files via upload --- sfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/sfs.c b/sfs.c index d13d5e1..76d4efe 100644 --- a/sfs.c +++ b/sfs.c @@ -183,6 +183,52 @@ int sfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse log_msg("\nsfs_read(path=\"%s\", buf=0x%08x, size=%d, offset=%lld, fi=0x%08x)\n", path, buf, size, offset, fi); + int x = 1; + int amountReadIN = 0; + for (; x < ; x++) + { + char buffer[512]; + block_read(u,buffer); + inode* currentBlock = (inode*) buffer; + + if(strcmp(current->path,path+1) == 0) + { + int numBlocksToRead = ((offset%512+size)-1+512)/512; + + int firstBlock = offset/512; + + int lastBlock = firstBlock+numBlocksToRead; + + int i = firstBlock; + + for(i;i<=lastBlock;i++) { + + if(i<15) { + char buffering[512]; + + //initialize + if(current->blocks[i]==-1) { + return amountRead; + } + + block_read(current->dblocks[i], buffering); + + if(i==firstBlock) { + + memcpy(buf+amountRead,buffer3+offset%512,512-offset%512); + amountRead+=512-offset%512; + } else if (i==lastBlock) { + memcpy(buf+amountRead,buffer3,size-amountRead); + amountRead+=size-amountRead; + } + else { + memcpy(buf+amountRead,buffer3,512); + amountRead+=512-offset%512; + } + } + + } + } return retstat; } From 46ebcb633566a20d3e93f4fedcb06f95bede8d40 Mon Sep 17 00:00:00 2001 From: Hitmonrocker Date: Fri, 27 Apr 2018 00:34:08 -0400 Subject: [PATCH 3/3] Update sfs.c --- sfs.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sfs.c b/sfs.c index 76d4efe..1bbb0b4 100644 --- a/sfs.c +++ b/sfs.c @@ -182,10 +182,14 @@ int sfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse int retstat = 0; log_msg("\nsfs_read(path=\"%s\", buf=0x%08x, size=%d, offset=%lld, fi=0x%08x)\n", path, buf, size, offset, fi); + char buffers[512]; + bufferlock_read(0,buffers); + superblock* sb = (superblock*)buffers; + int x = 1; int amountReadIN = 0; - for (; x < ; x++) + for (; x num_of_data_blocks; x++) { char buffer[512]; block_read(u,buffer); @@ -208,22 +212,22 @@ int sfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse //initialize if(current->blocks[i]==-1) { - return amountRead; + return amountReadIN; } - block_read(current->dblocks[i], buffering); + block_read(current->blocks[i], buffering); if(i==firstBlock) { - memcpy(buf+amountRead,buffer3+offset%512,512-offset%512); - amountRead+=512-offset%512; + memcpy(buf+amountReadIN,buffering+offset%512,512-offset%512); + amountReadIN+=512-offset%512; } else if (i==lastBlock) { - memcpy(buf+amountRead,buffer3,size-amountRead); - amountRead+=size-amountRead; + memcpy(buf+amountReadIN,buffering,size-amountReadIN); + amountReadIN+=size-amountReadIN; } else { - memcpy(buf+amountRead,buffer3,512); - amountRead+=512-offset%512; + memcpy(buf+amountReadIN,buffering,512); + amountReadIN+=512-offset%512; } }