Found issue relying within the next listing of the program causing issues

This commit is contained in:
TriantaTV 2022-12-06 20:25:22 -06:00
parent 5bfa0a79e4
commit ee19c23ea8
3 changed files with 31 additions and 29 deletions

View File

@ -13,8 +13,9 @@ ino_t GetFreeInodeNumber(Inode inodes[]);
ino_t GetFreeBlockNumber(int fbl[], unsigned short size);
int FindEmptyBitPosition(int number);
int FindNextDirectory(char* fname);
int IsDirectorySetup(Inode inode, ino_t* inodePosition, char* directoryName);
int FindDirectory(Inode inode, char* directoryName);
void SetFileSystemDefaults(FileSystem* fs);
void SetupRootDirectory(FileSystem* fs);
void SetupDirectoryBlock(DirectBlock* newBlock, ino_t inode);
#endif

View File

@ -45,21 +45,18 @@ void AddFileToFS(FileSystem* fs, char* fname)
// Third: get a free inode number
// Fourth: set info for direct block
tempname = strndup(fname, splitLocation);
if (!IsDirectorySetup(fs->inodes[currentInode], &currentInode, tempname))
newInode = FindDirectory(fs->inodes[currentInode], tempname);
if (newInode == -1)
{
for (int i = 0; i < 4; i++)
tempfbl[i] = (currentInode*4) + i;
newDirectBlock = GetFreeBlockNumber(tempfbl, 4);
newInode = GetFreeInodeNumber(fs->inodes);
printf("Name held: |%s|\n", tempname);
printf("Block: |%i|\n", newDirectBlock);
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, tempname);
free(tempname);
fs->inodes[currentInode].blocks[newDirectBlock].isValid = 1;
fs->inodes[currentInode].blocks[newDirectBlock].isDirectory = 1;
fs->inodes[currentInode].blocks[newDirectBlock].inode = newInode;
SetupDirectoryBlock(&(fs->inodes[currentInode].blocks[newDirectBlock]), newInode);
fs->inodes[newInode].isValid = 1;
currentInode = newInode;
fs->inodes[currentInode].isValid = 1;
}
fname = fname + splitLocation + 1;
splitLocation = FindNextDirectory(fname);
@ -70,22 +67,15 @@ void AddFileToFS(FileSystem* fs, char* fname)
fs->inodes[currentInode].blocks[newDirectBlock].isValid = 1;
fs->inodes[currentInode].blocks[newDirectBlock].size = tempstat.st_size;
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, fname);
printf("%s\n", fs->inodes[0].blocks[0].name);
return;
}
// List path names of all used inodes
void ListFS(FileSystem* fs)
{
Inode* fsRoot = &(fs->inodes[0]);
printf("/\n");
for (int i = 0; i < fs->superBlock.inodeCount; i++)
{
if (!(fsRoot->blocks[i].isValid))
continue;
printf("%s\n", fsRoot->blocks[i].name);
if (fsRoot->blocks[i].isDirectory)
_ListFS_(fs, fsRoot->blocks[i].inode, 1);
}
_ListFS_(fs, 0, 0);
return;
}
@ -165,8 +155,8 @@ int FindNextDirectory(char* fname)
return -1;
}
// Bool function checks if directory is setup. If it is, then sets the inode
int IsDirectorySetup(Inode inode, ino_t* inodePosition, char* directoryName)
// Function checks if directory is setup. If it is, then returns the inode
int FindDirectory(Inode inode, char* directoryName)
{
for (int i = 0; i < 128; i++)
{
@ -175,12 +165,9 @@ int IsDirectorySetup(Inode inode, ino_t* inodePosition, char* directoryName)
if (!(inode.blocks[i].isDirectory))
continue;
if (strcmp(inode.blocks[i].name, directoryName) == 0)
{
*inodePosition = i;
return 1;
}
return i;
}
return 0;
return -1;
}
// Function for setting all defaults of filesystem
@ -202,3 +189,11 @@ void SetupRootDirectory(FileSystem* fs)
fs->inodes[0].isValid = 1;
return;
}
void SetupDirectoryBlock(DirectBlock* newBlock, ino_t inode)
{
newBlock->isValid = 1;
newBlock->isDirectory = 1;
newBlock->inode = inode;
return;
}

View File

@ -64,18 +64,24 @@ void Test_FileSystem_Should_AddFile(void)
argv[1] = "-a";
GetArguments(argc, argv, &dummyFuse);
RunFuse(fakefs, &dummyFuse);
argv[2] = "test/files/test2.txt";
GetArguments(argc, argv, &dummyFuse);
RunFuse(fakefs, &dummyFuse);
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
}
void Test_FileSystem_Should_ListContents(void)
{
Fuse(argc, argv);
printf("%s\n", fakefs->inodes[0].blocks[0].name);
TEST_IGNORE_MESSAGE("This only runs the list operation. Check info yourself.");
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
TEST_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
TEST_MESSAGE("This only runs the list operation. Check info yourself.");
}
int main(void)