Setup FS structure and set fs to point to struct
This commit is contained in:
		
							parent
							
								
									0b9eb0be9a
								
							
						
					
					
						commit
						4fcd64ea81
					
				| @ -1,6 +1,9 @@ | ||||
| #ifndef FUSE_H | ||||
| #define FUSE_H | ||||
| 
 | ||||
| #define DEFAULTINODEMAX 128 | ||||
| #define DEFAULTBLOCKSIZE 512 // Size in bytes
 | ||||
| 
 | ||||
| typedef struct fuseArgStruct | ||||
| { | ||||
|     int create; | ||||
| @ -17,12 +20,40 @@ typedef struct fuseArgStruct | ||||
|     int filefsname; | ||||
| } fuseArgStruct; | ||||
| 
 | ||||
| typedef struct BlockStruct | ||||
| { | ||||
|     char byte[DEFAULTBLOCKSIZE]; | ||||
| } BlockStruct; | ||||
| 
 | ||||
| typedef struct InodeStruct | ||||
| { | ||||
|     BlockStruct* dataBlock; | ||||
| } InodeStruct; | ||||
| 
 | ||||
| typedef struct SuperBlockStruct | ||||
| { | ||||
|     int blockCount; | ||||
|     int blockSize; | ||||
| } SuperBlockStruct; | ||||
| 
 | ||||
| typedef struct FBLStruct | ||||
| { | ||||
|     int freeList[DEFAULTINODEMAX/32]; | ||||
| } FBLStruct; | ||||
| 
 | ||||
| typedef struct FileSystemStruct | ||||
| { | ||||
|     SuperBlockStruct superBlock; | ||||
|     FBLStruct freeList; | ||||
|     InodeStruct inodes[DEFAULTINODEMAX]; | ||||
| } FileSystemStruct; | ||||
| 
 | ||||
| void Fuse(int argc, char* argv[]); | ||||
| void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs); | ||||
| void FuseCheckArgs(int argc, char* argv[], fuseArgStruct* fuseArgs); | ||||
| void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath); | ||||
| void FuseStructInit(fuseArgStruct* fuseStruct); | ||||
| void FuseUsageError(char* programPath); | ||||
| int zerosize(int fd); | ||||
| int FindEmptyBitPosition(int number); | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| #ifndef FUSEACTIONS_H | ||||
| #define FUSEACTIONS_H | ||||
| 
 | ||||
| #include "fuse.h" | ||||
| 
 | ||||
| #define FSSIZE 10000000 | ||||
| 
 | ||||
| extern unsigned char* fs; | ||||
| 
 | ||||
| void MapFS(int fd); | ||||
| void UnmapFS(); | ||||
| void MapFS(FileSystemStruct* fs, int fd); | ||||
| void UnmapFS(FileSystemStruct* fs); | ||||
| void FormatFS(); | ||||
| void LoadFS(); | ||||
| void ListFS(); | ||||
|  | ||||
							
								
								
									
										15
									
								
								src/fuse.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/fuse.c
									
									
									
									
									
								
							| @ -51,6 +51,7 @@ void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs) | ||||
| // Given code for default functionality
 | ||||
| void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath) | ||||
| { | ||||
|     FileSystemStruct fileSystem; | ||||
|     if (!fuseArgs->filefsname) | ||||
|         FuseUsageError(programPath); | ||||
|     fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); | ||||
| @ -74,7 +75,7 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath) | ||||
|             exit(EXIT_FAILURE); | ||||
|         } | ||||
|     } | ||||
|     MapFS(fuseArgs->fd); | ||||
|     MapFS(&fileSystem, fuseArgs->fd); | ||||
|     if (fuseArgs->newfs) | ||||
|         FormatFS(); | ||||
|     LoadFS(); | ||||
| @ -86,7 +87,7 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath) | ||||
|         ExtractFileFromFS(fuseArgs->toExtract); | ||||
|     if(fuseArgs->list) | ||||
|         ListFS(); | ||||
|     UnmapFS(); | ||||
|     UnmapFS(&fileSystem); | ||||
| } | ||||
| 
 | ||||
| // Initialize entire fuseStruct
 | ||||
| @ -123,3 +124,13 @@ int zerosize(int fd) | ||||
|         return 1; | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| // Finds next empty bit in Free Block List
 | ||||
| int FindEmptyBitPosition(int number) | ||||
| { | ||||
|     for (int i = 0; i < 32; i++) | ||||
|         if ((~number & (1 << i)) == (1 << i)) | ||||
|             return i; | ||||
|     return -1; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -4,9 +4,7 @@ | ||||
| #include <sys/mman.h> | ||||
| #include "fuseactions.h" | ||||
| 
 | ||||
| unsigned char* fs; | ||||
| 
 | ||||
| void MapFS(int fd) | ||||
| void MapFS(FileSystemStruct* fs, int fd) | ||||
| { | ||||
|     fs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||||
|     if (fs == NULL) | ||||
| @ -16,22 +14,22 @@ void MapFS(int fd) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void UnmapFS() | ||||
| void UnmapFS(FileSystemStruct* fs) | ||||
| { | ||||
|     munmap(fs, FSSIZE); | ||||
| } | ||||
| 
 | ||||
| void FormatFS() | ||||
| void FormatFS(void) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void LoadFS() | ||||
| void LoadFS(void) | ||||
| { | ||||
|      | ||||
| } | ||||
| 
 | ||||
| void ListFS() | ||||
| void ListFS(void) | ||||
| { | ||||
|      | ||||
| } | ||||
|  | ||||
							
								
								
									
										10
									
								
								test/test.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								test/test.c
									
									
									
									
									
								
							| @ -39,9 +39,19 @@ void Test_FuseGetArgs_Should_SetDummyArgs(void) | ||||
|     TEST_ASSERT_EQUAL(1, dummyFuse.extract); | ||||
| } | ||||
| 
 | ||||
| void Test_FindEmptyBitPosition_Should_ReturnPosition(void) | ||||
| { | ||||
|     TEST_ASSERT_EQUAL(3, FindEmptyBitPosition(7)); | ||||
|     TEST_ASSERT_EQUAL(1, FindEmptyBitPosition(29)); | ||||
|     TEST_ASSERT_EQUAL(5, FindEmptyBitPosition(95)); | ||||
|     TEST_ASSERT_EQUAL(31, FindEmptyBitPosition(2147483647)); | ||||
|     TEST_ASSERT_EQUAL(-1, FindEmptyBitPosition(4294967295)); | ||||
| } | ||||
| 
 | ||||
| int main(void) | ||||
| { | ||||
|     UNITY_BEGIN(); | ||||
|     RUN_TEST(Test_FuseGetArgs_Should_SetDummyArgs); | ||||
|     RUN_TEST(Test_FindEmptyBitPosition_Should_ReturnPosition); | ||||
|     return UNITY_END(); | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user