getting inode number using freeList is breaking program, will fix later

This commit is contained in:
2022-11-25 23:51:27 -06:00
parent 81647a3100
commit 1c237c1bcc
5 changed files with 75 additions and 43 deletions
+39 -9
View File
@@ -51,7 +51,7 @@ void FuseGetArgs(int argc, char* argv[], fuseArgStruct* fuseArgs)
// Given code for default functionality
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
{
FileSystemStruct fileSystem;
FileSystemStruct* fsptr;
if (!fuseArgs->filefsname)
FuseUsageError(programPath);
fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
@@ -75,19 +75,19 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
exit(EXIT_FAILURE);
}
}
MapFS(&fileSystem, fuseArgs->fd);
MapFS(fsptr, fuseArgs->fd);
if (fuseArgs->newfs)
FormatFS(&fileSystem);
LoadFS(&fileSystem);
FormatFS(fsptr);
LoadFS(fsptr);
if (fuseArgs->add)
AddFileToFS(&fileSystem, fuseArgs->toAdd);
AddFileToFS(fsptr, fuseArgs->toAdd);
if (fuseArgs->remove)
RemoveFileFromFS(&fileSystem, fuseArgs->toRemove);
RemoveFileFromFS(fsptr, fuseArgs->toRemove);
if (fuseArgs->extract)
ExtractFileFromFS(&fileSystem, fuseArgs->toExtract);
ExtractFileFromFS(fsptr, fuseArgs->toExtract);
if(fuseArgs->list)
ListFS(&fileSystem);
UnmapFS(&fileSystem);
ListFS(fsptr);
UnmapFS(fsptr);
}
// Initialize entire fuseStruct
@@ -134,3 +134,33 @@ int FindEmptyBitPosition(int number)
return -1;
}
ino_t GetFreeInodeNumber(int* fbl)
{
int bitPosition;
for (int i = 0; i < (DEFAULTINODEMAX/32); i++)
{
bitPosition = FindEmptyBitPosition(fbl[i]);
if (bitPosition >= 0)
{
fbl[i] = (fbl[i] | (1 << bitPosition));
return ((i*32) + bitPosition);
}
}
return -1;
}
void SetFileSystemDefaults(FileSystemStruct* fs)
{
fs->superBlock->blockSize = DEFAULTBLOCKSIZE;
fs->superBlock->blockCount = DEFAULTINODEMAX;
for (int i = 0; i < 4; i++)
fs->fbl->freeList[i] = 0;
printf("fdsfd%i\n", fs->fbl->freeList[0]);
for (int i = 0; i < DEFAULTINODEMAX; i++)
{
*fs->inodes[i].filePath = NULL;
fs->inodes[i].fileSize = 0;
*fs->inodes[i].dataBlock.byte = NULL;
}
return;
}
+14 -17
View File
@@ -8,55 +8,52 @@
#include <sys/stat.h>
#include "fuseactions.h"
unsigned char* tempfs;
void MapFS(FileSystemStruct* fs, int fd)
{
fs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (fs == NULL)
{
perror("mmap failed");
exit(EXIT_FAILURE);
}
return;
}
void UnmapFS(FileSystemStruct* fs)
{
munmap(fs, FSSIZE);
return;
}
void FormatFS(FileSystemStruct* fs)
{
for (int i = 0; i < 4; i++)
fs->fbl.freeList[i] = 0;
fs->superBlock = (SuperBlockStruct*) tempfs;
fs->fbl = (FBLStruct*) (tempfs + sizeof(SuperBlockStruct));
fs->inodes = (InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct));
SetFileSystemDefaults(fs);
return;
}
void LoadFS(FileSystemStruct* fs)
{
}
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))
if ((fs->fbl->freeList[i] & (1 << j)) == (1 << j))
printf("%s\n", fs->inodes[i*32 + j].filePath);
return;
}
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);
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl->freeList);
strcpy(fs->inodes[inodeNumber].filePath, fname);
stat(fname, &statBuffer);
fs->inodes[inodeNumber].fileSize = statBuffer.st_size;