diff --git a/.gitignore b/.gitignore index c6127b3..0b731e8 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ modules.order Module.symvers Mkfile.old dkms.conf +*.test +*.sh diff --git a/Makefile b/Makefile index 1abb6b3..ba3ce96 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,9 @@ testLink: testExec: ./bin/test.out + test/testfs.sh clean: rm build/*.o rm bin/*.out + rm test/fakefs.test diff --git a/include/fuse.h b/include/fuse.h index 47f1ef5..bb9dca8 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -1,6 +1,8 @@ #ifndef FUSE_H #define FUSE_H +#include + #define DEFAULTINODEMAX 128 #define DEFAULTBLOCKSIZE 512 // Size in bytes @@ -27,13 +29,15 @@ typedef struct BlockStruct typedef struct InodeStruct { - BlockStruct* dataBlock; + char filePath[256]; + off_t fileSize; + BlockStruct dataBlock; } InodeStruct; typedef struct SuperBlockStruct { - int blockCount; - int blockSize; + blksize_t blockSize; + blkcnt_t blockCount; } SuperBlockStruct; typedef struct FBLStruct @@ -44,7 +48,7 @@ typedef struct FBLStruct typedef struct FileSystemStruct { SuperBlockStruct superBlock; - FBLStruct freeList; + FBLStruct fbl; InodeStruct inodes[DEFAULTINODEMAX]; } FileSystemStruct; diff --git a/include/fuseactions.h b/include/fuseactions.h index c8e2c10..4d346c0 100644 --- a/include/fuseactions.h +++ b/include/fuseactions.h @@ -7,11 +7,11 @@ void MapFS(FileSystemStruct* fs, int fd); void UnmapFS(FileSystemStruct* fs); -void FormatFS(); -void LoadFS(); -void ListFS(); -void AddFileToFS(char* fname); -void RemoveFileFromFS(char* fname); -void ExtractFileFromFS(char* fname); +void FormatFS(FileSystemStruct* fs); +void LoadFS(FileSystemStruct* fs); +void ListFS(FileSystemStruct* fs); +void AddFileToFS(FileSystemStruct* fs, char* fname); +void RemoveFileFromFS(FileSystemStruct* fs, char* fname); +void ExtractFileFromFS(FileSystemStruct* fs, char* fname); #endif \ No newline at end of file diff --git a/src/fuse.c b/src/fuse.c index 924116c..9b02b6c 100644 --- a/src/fuse.c +++ b/src/fuse.c @@ -77,16 +77,16 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath) } MapFS(&fileSystem, fuseArgs->fd); if (fuseArgs->newfs) - FormatFS(); - LoadFS(); + FormatFS(&fileSystem); + LoadFS(&fileSystem); if (fuseArgs->add) - AddFileToFS(fuseArgs->toAdd); + AddFileToFS(&fileSystem, fuseArgs->toAdd); if (fuseArgs->remove) - RemoveFileFromFS(fuseArgs->toRemove); + RemoveFileFromFS(&fileSystem, fuseArgs->toRemove); if (fuseArgs->extract) - ExtractFileFromFS(fuseArgs->toExtract); + ExtractFileFromFS(&fileSystem, fuseArgs->toExtract); if(fuseArgs->list) - ListFS(); + ListFS(&fileSystem); UnmapFS(&fileSystem); } diff --git a/src/fuseactions.c b/src/fuseactions.c index 0dd6a12..ec75743 100644 --- a/src/fuseactions.c +++ b/src/fuseactions.c @@ -1,7 +1,11 @@ #include +#include #include #include +#include +#include #include +#include #include "fuseactions.h" void MapFS(FileSystemStruct* fs, int fd) @@ -19,32 +23,59 @@ void UnmapFS(FileSystemStruct* fs) munmap(fs, FSSIZE); } -void FormatFS(void) +void FormatFS(FileSystemStruct* fs) { - + for (int i = 0; i < 4; i++) + fs->fbl.freeList[i] = 0; } -void LoadFS(void) +void LoadFS(FileSystemStruct* fs) { } -void ListFS(void) -{ - -} - -void AddFileToFS(char* fname) -{ - -} - -void RemoveFileFromFS(char* fname) -{ - -} - -void ExtractFileFromFS(char* fname) +void ListFS(FileSystemStruct* fs) +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 32; j++) + if ((fs->fbl.freeList[i] & (1 << j)) == (1 << j)) + printf("%s\n", fs->inodes[i*32 + j].filePath); +} + +void AddFileToFS(FileSystemStruct* fs, char* fname) +{ + struct stat statBuffer; + int inodeNumber = -1; + int i = -1; + while ((inodeNumber < 0) && (i < 4)) + { + i++; + inodeNumber = FindEmptyBitPosition(fs->fbl.freeList[i]); + } + fs->fbl.freeList[i] = (fs->fbl.freeList[i]) | (1 << inodeNumber); + printf("FBL: %i\n", fs->fbl.freeList[i]); + inodeNumber = (i * 32) + inodeNumber; + printf("Inode location: %i\n", inodeNumber); + printf("Filename: %s\n", fname); + strcpy(fs->inodes[inodeNumber].filePath, fname); + stat(fname, &statBuffer); + fs->inodes[inodeNumber].fileSize = statBuffer.st_size; + int fd = open(fname, O_RDONLY); + if (fd < 0) + { + perror(fname); + exit(1); + } + read(fd, fs->inodes[inodeNumber].dataBlock.byte, sizeof(BlockStruct)); + close(fd); +} + +void RemoveFileFromFS(FileSystemStruct* fs, char* fname) +{ + +} + +void ExtractFileFromFS(FileSystemStruct* fs, char* fname) { } diff --git a/test/fakefs b/test/fakefs deleted file mode 100644 index 5630165..0000000 Binary files a/test/fakefs and /dev/null differ diff --git a/test/files/test1.txt b/test/files/test1.txt new file mode 100644 index 0000000..ec00b37 --- /dev/null +++ b/test/files/test1.txt @@ -0,0 +1 @@ +easy diff --git a/test/files/test2.txt b/test/files/test2.txt new file mode 100644 index 0000000..1ac88df --- /dev/null +++ b/test/files/test2.txt @@ -0,0 +1 @@ +wind diff --git a/test/files/test3.txt b/test/files/test3.txt new file mode 100644 index 0000000..9f04455 --- /dev/null +++ b/test/files/test3.txt @@ -0,0 +1 @@ +chocolate