Split given fuse function into pieces
This commit is contained in:
parent
565832e1ee
commit
86622536d6
1
.gitignore
vendored
1
.gitignore
vendored
@ -52,3 +52,4 @@ Mkfile.old
|
||||
dkms.conf
|
||||
*.test
|
||||
*.sh
|
||||
*.swp
|
||||
|
@ -38,6 +38,8 @@ typedef struct BlockStruct
|
||||
char byte[DEFAULTBLOCKSIZE];
|
||||
} BlockStruct;
|
||||
|
||||
// TODO: Adjust Inodes to be 128 inodes with 128 direct block references *each*
|
||||
// Slides exist for inode structure
|
||||
typedef struct InodeStruct
|
||||
{
|
||||
char filePath[256];
|
||||
@ -53,7 +55,11 @@ typedef struct FileSystemStruct
|
||||
} FileSystemStruct;
|
||||
|
||||
void Fuse(int argc, char* argv[]);
|
||||
void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs);
|
||||
void GetArguments(int argc, char* argv[], fuseArgStruct* fuseArgs);
|
||||
void OpenFS(fuseArgStruct* fuseArgs, char* programPath);
|
||||
FileSystemStruct* SetupFS(fuseArgStruct* fuseArgs);
|
||||
void RunFuse(FileSystemStruct* fs, fuseArgStruct* fuseArgs);
|
||||
void TearDownFS(void);
|
||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath);
|
||||
void FuseStructInit(fuseArgStruct* fuseStruct);
|
||||
void FuseUsageError(char* programPath);
|
||||
|
@ -10,10 +10,10 @@ extern unsigned char* tempfs;
|
||||
void MapFS(int fd);
|
||||
void UnmapFS(void);
|
||||
void FormatFS(FileSystemStruct* fs);
|
||||
void LoadFS(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
|
||||
#endif
|
||||
|
92
src/fuse.c
92
src/fuse.c
@ -13,13 +13,19 @@
|
||||
// Main handler for Fuse
|
||||
void Fuse(int argc, char* argv[])
|
||||
{
|
||||
FileSystemStruct* fsptr;
|
||||
fuseArgStruct fuseArgs;
|
||||
FuseGetArgs(argc, argv, &fuseArgs);
|
||||
FuseGivenTest(&fuseArgs, argv[0]);
|
||||
GetArguments(argc, argv, &fuseArgs);
|
||||
OpenFS(&fuseArgs, argv[0]);
|
||||
fsptr = SetupFS(&fuseArgs);
|
||||
RunFuse(fsptr, &fuseArgs);
|
||||
TearDownFS();
|
||||
// FuseGivenTest(&fuseArgs, argv[0]);
|
||||
}
|
||||
|
||||
// Gets command line arguments and puts information into fuseArgs
|
||||
// New method for getting arguments
|
||||
void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
||||
void GetArguments(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
||||
{
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
@ -48,10 +54,8 @@ void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
||||
}
|
||||
}
|
||||
|
||||
// Given code for default functionality
|
||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
void OpenFS(fuseArgStruct* fuseArgs, char* programPath)
|
||||
{
|
||||
FileSystemStruct* fsptr;
|
||||
if (!fuseArgs->filefsname)
|
||||
FuseUsageError(programPath);
|
||||
fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
@ -75,21 +79,79 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystemStruct* SetupFS(fuseArgStruct* fuseArgs)
|
||||
{
|
||||
FileSystemStruct* fs;
|
||||
MapFS(fuseArgs->fd);
|
||||
LoadFS(&fs);
|
||||
if (fuseArgs->newfs)
|
||||
FormatFS(fsptr);
|
||||
fsptr = (FileSystemStruct*) tempfs;
|
||||
// LoadFS(fsptr);
|
||||
printf("first free list:%i\n", fsptr->fbl.freeList[0]);
|
||||
FormatFS(fs);
|
||||
return fs;
|
||||
}
|
||||
|
||||
void RunFuse(FileSystemStruct* fs, fuseArgStruct* fuseArgs)
|
||||
{
|
||||
if (fuseArgs->add)
|
||||
AddFileToFS(fsptr, fuseArgs->toAdd);
|
||||
AddFileToFS(fs, fuseArgs->toAdd);
|
||||
if (fuseArgs->remove)
|
||||
RemoveFileFromFS(fsptr, fuseArgs->toRemove);
|
||||
RemoveFileFromFS(fs, fuseArgs->toRemove);
|
||||
if (fuseArgs->extract)
|
||||
ExtractFileFromFS(fsptr, fuseArgs->toExtract);
|
||||
ExtractFileFromFS(fs, fuseArgs->toExtract);
|
||||
if(fuseArgs->list)
|
||||
ListFS(fsptr);
|
||||
ListFS(fs);
|
||||
return;
|
||||
}
|
||||
|
||||
void TearDownFS(void)
|
||||
{
|
||||
UnmapFS();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Given code for default functionality
|
||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
{
|
||||
// FileSystemStruct* fsptr;
|
||||
// if (!fuseArgs->filefsname)
|
||||
// FuseUsageError(programPath);
|
||||
// fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
// if (fuseArgs->fd == -1)
|
||||
// {
|
||||
// perror("open failed");
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
// if (zerosize(fuseArgs->fd))
|
||||
// fuseArgs->newfs = 1;
|
||||
// if (fuseArgs->newfs)
|
||||
// {
|
||||
// if (lseek(fuseArgs->fd, FSSIZE-1, SEEK_SET) == -1)
|
||||
// {
|
||||
// perror("seek failed");
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
// if (write(fuseArgs->fd, "\0", 1) == -1)
|
||||
// {
|
||||
// perror("write failed");
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
// }
|
||||
// MapFS(fuseArgs->fd);
|
||||
// if (fuseArgs->newfs)
|
||||
// FormatFS();
|
||||
// LoadFS(&fsptr);
|
||||
// if (fuseArgs->add)
|
||||
// AddFileToFS(fsptr, fuseArgs->toAdd);
|
||||
// if (fuseArgs->remove)
|
||||
// RemoveFileFromFS(fsptr, fuseArgs->toRemove);
|
||||
// if (fuseArgs->extract)
|
||||
// ExtractFileFromFS(fsptr, fuseArgs->toExtract);
|
||||
// if(fuseArgs->list)
|
||||
// ListFS(fsptr);
|
||||
// UnmapFS();
|
||||
}
|
||||
|
||||
// Initialize entire fuseStruct
|
||||
@ -136,6 +198,7 @@ int FindEmptyBitPosition(int number)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Gets next free inode number and returns it
|
||||
ino_t GetFreeInodeNumber(int fbl[])
|
||||
{
|
||||
int bitPosition;
|
||||
@ -151,6 +214,7 @@ ino_t GetFreeInodeNumber(int fbl[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Function for setting all defaults of filesystem
|
||||
void SetFileSystemDefaults(FileSystemStruct* fs)
|
||||
{
|
||||
fs->superBlock.blockSize = DEFAULTBLOCKSIZE;
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
unsigned char* tempfs;
|
||||
|
||||
// Map filesystem to memory
|
||||
void MapFS(int fd)
|
||||
{
|
||||
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
@ -18,32 +19,33 @@ void MapFS(int fd)
|
||||
perror("mmap failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unmap filesystem from memory
|
||||
void UnmapFS(void)
|
||||
{
|
||||
munmap(tempfs, FSSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sets defaults of a new filesystem
|
||||
void FormatFS(FileSystemStruct* fs)
|
||||
{
|
||||
SetFileSystemDefaults(tempfs);
|
||||
// fs->superBlock = (FileSystemStruct*) tempfs->superBlock;
|
||||
// fs->fbl = (FileSystemStruct*) tempfs->fbl;
|
||||
// fs->inodes = (FileSystemStruct*) tempfs->inodes;
|
||||
// for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
// fs->inodes[i] = *(InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct) + sizeof(InodeStruct) * i);
|
||||
SetFileSystemDefaults(fs);
|
||||
return;
|
||||
}
|
||||
|
||||
void LoadFS(FileSystemStruct* fs)
|
||||
// Load existing filesystem
|
||||
// Depreciated Function
|
||||
void LoadFS(FileSystemStruct** fs)
|
||||
{
|
||||
fs = (FileSystemStruct*) tempfs;
|
||||
*fs = (FileSystemStruct*) (tempfs);
|
||||
return;
|
||||
}
|
||||
|
||||
// List path names of all used inodes
|
||||
void ListFS(FileSystemStruct* fs)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
@ -53,11 +55,10 @@ void ListFS(FileSystemStruct* fs)
|
||||
return;
|
||||
}
|
||||
|
||||
// Adds a file to the filesystem
|
||||
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
struct stat statBuffer;
|
||||
printf("Check\n");
|
||||
printf("Bit: %i\n", fs->fbl.freeList[0]);
|
||||
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl.freeList);
|
||||
strcpy(fs->inodes[inodeNumber].filePath, fname);
|
||||
stat(fname, &statBuffer);
|
||||
@ -72,11 +73,13 @@ void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
// Remove a file from the filesystem
|
||||
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Extract a file from the filesystem
|
||||
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
|
||||
|
@ -26,16 +26,16 @@ void tearDown(void)
|
||||
|
||||
void Test_FuseGetArgs_Should_SetDummyArgs(void)
|
||||
{
|
||||
FuseGetArgs(argc, argv, &dummyFuse);
|
||||
GetArguments(argc, argv, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(1, dummyFuse.list);
|
||||
argv[1] = "-a";
|
||||
FuseGetArgs(argc, argv, &dummyFuse);
|
||||
GetArguments(argc, argv, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(1, dummyFuse.add);
|
||||
argv[1] = "-r";
|
||||
FuseGetArgs(argc, argv, &dummyFuse);
|
||||
GetArguments(argc, argv, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(1, dummyFuse.remove);
|
||||
argv[1] = "-e";
|
||||
FuseGetArgs(argc, argv, &dummyFuse);
|
||||
GetArguments(argc, argv, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(1, dummyFuse.extract);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user