Found issue relying within the next listing of the program causing issues
This commit is contained in:
parent
5bfa0a79e4
commit
ee19c23ea8
@ -13,8 +13,9 @@ ino_t GetFreeInodeNumber(Inode inodes[]);
|
|||||||
ino_t GetFreeBlockNumber(int fbl[], unsigned short size);
|
ino_t GetFreeBlockNumber(int fbl[], unsigned short size);
|
||||||
int FindEmptyBitPosition(int number);
|
int FindEmptyBitPosition(int number);
|
||||||
int FindNextDirectory(char* fname);
|
int FindNextDirectory(char* fname);
|
||||||
int IsDirectorySetup(Inode inode, ino_t* inodePosition, char* directoryName);
|
int FindDirectory(Inode inode, char* directoryName);
|
||||||
void SetFileSystemDefaults(FileSystem* fs);
|
void SetFileSystemDefaults(FileSystem* fs);
|
||||||
void SetupRootDirectory(FileSystem* fs);
|
void SetupRootDirectory(FileSystem* fs);
|
||||||
|
void SetupDirectoryBlock(DirectBlock* newBlock, ino_t inode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,21 +45,18 @@ void AddFileToFS(FileSystem* fs, char* fname)
|
|||||||
// Third: get a free inode number
|
// Third: get a free inode number
|
||||||
// Fourth: set info for direct block
|
// Fourth: set info for direct block
|
||||||
tempname = strndup(fname, splitLocation);
|
tempname = strndup(fname, splitLocation);
|
||||||
if (!IsDirectorySetup(fs->inodes[currentInode], ¤tInode, tempname))
|
newInode = FindDirectory(fs->inodes[currentInode], tempname);
|
||||||
|
if (newInode == -1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
tempfbl[i] = (currentInode*4) + i;
|
tempfbl[i] = (currentInode*4) + i;
|
||||||
newDirectBlock = GetFreeBlockNumber(tempfbl, 4);
|
newDirectBlock = GetFreeBlockNumber(tempfbl, 4);
|
||||||
newInode = GetFreeInodeNumber(fs->inodes);
|
newInode = GetFreeInodeNumber(fs->inodes);
|
||||||
printf("Name held: |%s|\n", tempname);
|
|
||||||
printf("Block: |%i|\n", newDirectBlock);
|
|
||||||
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, tempname);
|
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, tempname);
|
||||||
free(tempname);
|
free(tempname);
|
||||||
fs->inodes[currentInode].blocks[newDirectBlock].isValid = 1;
|
SetupDirectoryBlock(&(fs->inodes[currentInode].blocks[newDirectBlock]), newInode);
|
||||||
fs->inodes[currentInode].blocks[newDirectBlock].isDirectory = 1;
|
fs->inodes[newInode].isValid = 1;
|
||||||
fs->inodes[currentInode].blocks[newDirectBlock].inode = newInode;
|
|
||||||
currentInode = newInode;
|
currentInode = newInode;
|
||||||
fs->inodes[currentInode].isValid = 1;
|
|
||||||
}
|
}
|
||||||
fname = fname + splitLocation + 1;
|
fname = fname + splitLocation + 1;
|
||||||
splitLocation = FindNextDirectory(fname);
|
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].isValid = 1;
|
||||||
fs->inodes[currentInode].blocks[newDirectBlock].size = tempstat.st_size;
|
fs->inodes[currentInode].blocks[newDirectBlock].size = tempstat.st_size;
|
||||||
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, fname);
|
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, fname);
|
||||||
|
printf("%s\n", fs->inodes[0].blocks[0].name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List path names of all used inodes
|
// List path names of all used inodes
|
||||||
void ListFS(FileSystem* fs)
|
void ListFS(FileSystem* fs)
|
||||||
{
|
{
|
||||||
Inode* fsRoot = &(fs->inodes[0]);
|
|
||||||
printf("/\n");
|
printf("/\n");
|
||||||
for (int i = 0; i < fs->superBlock.inodeCount; i++)
|
_ListFS_(fs, 0, 0);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +155,8 @@ int FindNextDirectory(char* fname)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool function checks if directory is setup. If it is, then sets the inode
|
// Function checks if directory is setup. If it is, then returns the inode
|
||||||
int IsDirectorySetup(Inode inode, ino_t* inodePosition, char* directoryName)
|
int FindDirectory(Inode inode, char* directoryName)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 128; i++)
|
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))
|
if (!(inode.blocks[i].isDirectory))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(inode.blocks[i].name, directoryName) == 0)
|
if (strcmp(inode.blocks[i].name, directoryName) == 0)
|
||||||
{
|
return i;
|
||||||
*inodePosition = i;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function for setting all defaults of filesystem
|
// Function for setting all defaults of filesystem
|
||||||
@ -202,3 +189,11 @@ void SetupRootDirectory(FileSystem* fs)
|
|||||||
fs->inodes[0].isValid = 1;
|
fs->inodes[0].isValid = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupDirectoryBlock(DirectBlock* newBlock, ino_t inode)
|
||||||
|
{
|
||||||
|
newBlock->isValid = 1;
|
||||||
|
newBlock->isDirectory = 1;
|
||||||
|
newBlock->inode = inode;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
16
test/test.c
16
test/test.c
@ -64,18 +64,24 @@ void Test_FileSystem_Should_AddFile(void)
|
|||||||
argv[1] = "-a";
|
argv[1] = "-a";
|
||||||
GetArguments(argc, argv, &dummyFuse);
|
GetArguments(argc, argv, &dummyFuse);
|
||||||
RunFuse(fakefs, &dummyFuse);
|
RunFuse(fakefs, &dummyFuse);
|
||||||
argv[2] = "test/files/test2.txt";
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
||||||
GetArguments(argc, argv, &dummyFuse);
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
|
||||||
RunFuse(fakefs, &dummyFuse);
|
|
||||||
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
|
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_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_FileSystem_Should_ListContents(void)
|
void Test_FileSystem_Should_ListContents(void)
|
||||||
{
|
{
|
||||||
Fuse(argc, argv);
|
Fuse(argc, argv);
|
||||||
printf("%s\n", fakefs->inodes[0].blocks[0].name);
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
||||||
TEST_IGNORE_MESSAGE("This only runs the list operation. Check info yourself.");
|
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)
|
int main(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user