Stopped segfaults by moving casting a step out of a function
This commit is contained in:
parent
1c237c1bcc
commit
565832e1ee
@ -47,9 +47,9 @@ typedef struct InodeStruct
|
||||
|
||||
typedef struct FileSystemStruct
|
||||
{
|
||||
SuperBlockStruct* superBlock;
|
||||
FBLStruct* fbl;
|
||||
InodeStruct* inodes;
|
||||
SuperBlockStruct superBlock;
|
||||
FBLStruct fbl;
|
||||
InodeStruct inodes[DEFAULTINODEMAX];
|
||||
} FileSystemStruct;
|
||||
|
||||
void Fuse(int argc, char* argv[]);
|
||||
@ -59,7 +59,7 @@ void FuseStructInit(fuseArgStruct* fuseStruct);
|
||||
void FuseUsageError(char* programPath);
|
||||
int zerosize(int fd);
|
||||
int FindEmptyBitPosition(int number);
|
||||
ino_t GetFreeInodeNumber(int* fbl);
|
||||
ino_t GetFreeInodeNumber(int fbl[]);
|
||||
void SetFileSystemDefaults(FileSystemStruct* fs);
|
||||
|
||||
#endif
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
extern unsigned char* tempfs;
|
||||
|
||||
void MapFS(FileSystemStruct* fs, int fd);
|
||||
void UnmapFS(FileSystemStruct* fs);
|
||||
void MapFS(int fd);
|
||||
void UnmapFS(void);
|
||||
void FormatFS(FileSystemStruct* fs);
|
||||
void LoadFS(FileSystemStruct* fs);
|
||||
void ListFS(FileSystemStruct* fs);
|
||||
|
21
src/fuse.c
21
src/fuse.c
@ -75,10 +75,12 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
MapFS(fsptr, fuseArgs->fd);
|
||||
MapFS(fuseArgs->fd);
|
||||
if (fuseArgs->newfs)
|
||||
FormatFS(fsptr);
|
||||
LoadFS(fsptr);
|
||||
fsptr = (FileSystemStruct*) tempfs;
|
||||
// LoadFS(fsptr);
|
||||
printf("first free list:%i\n", fsptr->fbl.freeList[0]);
|
||||
if (fuseArgs->add)
|
||||
AddFileToFS(fsptr, fuseArgs->toAdd);
|
||||
if (fuseArgs->remove)
|
||||
@ -87,7 +89,7 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
ExtractFileFromFS(fsptr, fuseArgs->toExtract);
|
||||
if(fuseArgs->list)
|
||||
ListFS(fsptr);
|
||||
UnmapFS(fsptr);
|
||||
UnmapFS();
|
||||
}
|
||||
|
||||
// Initialize entire fuseStruct
|
||||
@ -134,7 +136,7 @@ int FindEmptyBitPosition(int number)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ino_t GetFreeInodeNumber(int* fbl)
|
||||
ino_t GetFreeInodeNumber(int fbl[])
|
||||
{
|
||||
int bitPosition;
|
||||
for (int i = 0; i < (DEFAULTINODEMAX/32); i++)
|
||||
@ -151,16 +153,15 @@ ino_t GetFreeInodeNumber(int* fbl)
|
||||
|
||||
void SetFileSystemDefaults(FileSystemStruct* fs)
|
||||
{
|
||||
fs->superBlock->blockSize = DEFAULTBLOCKSIZE;
|
||||
fs->superBlock->blockCount = DEFAULTINODEMAX;
|
||||
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]);
|
||||
fs->fbl.freeList[i] = 0;
|
||||
for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
{
|
||||
*fs->inodes[i].filePath = NULL;
|
||||
strcpy(fs->inodes[i].filePath, "\0");
|
||||
fs->inodes[i].fileSize = 0;
|
||||
*fs->inodes[i].dataBlock.byte = NULL;
|
||||
strcpy(fs->inodes[i].dataBlock.byte, "\0");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
unsigned char* tempfs;
|
||||
|
||||
void MapFS(FileSystemStruct* fs, int fd)
|
||||
void MapFS(int fd)
|
||||
{
|
||||
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (fs == NULL)
|
||||
if (tempfs == NULL)
|
||||
{
|
||||
perror("mmap failed");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -21,31 +21,34 @@ void MapFS(FileSystemStruct* fs, int fd)
|
||||
return;
|
||||
}
|
||||
|
||||
void UnmapFS(FileSystemStruct* fs)
|
||||
void UnmapFS(void)
|
||||
{
|
||||
munmap(fs, FSSIZE);
|
||||
munmap(tempfs, FSSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
void FormatFS(FileSystemStruct* fs)
|
||||
{
|
||||
fs->superBlock = (SuperBlockStruct*) tempfs;
|
||||
fs->fbl = (FBLStruct*) (tempfs + sizeof(SuperBlockStruct));
|
||||
fs->inodes = (InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct));
|
||||
SetFileSystemDefaults(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);
|
||||
return;
|
||||
}
|
||||
|
||||
void LoadFS(FileSystemStruct* fs)
|
||||
{
|
||||
|
||||
fs = (FileSystemStruct*) tempfs;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -53,7 +56,9 @@ void ListFS(FileSystemStruct* fs)
|
||||
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
struct stat statBuffer;
|
||||
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl->freeList);
|
||||
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);
|
||||
fs->inodes[inodeNumber].fileSize = statBuffer.st_size;
|
||||
|
Loading…
Reference in New Issue
Block a user