getting inode number using freeList is breaking program, will fix later
This commit is contained in:
parent
81647a3100
commit
1c237c1bcc
7
Makefile
7
Makefile
@ -1,5 +1,6 @@
|
||||
UNITYPATH = test/unity
|
||||
INC := -I include
|
||||
WARNINGS := -m64 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
|
||||
UNITY := -I $(UNITYPATH)
|
||||
|
||||
all: compile link
|
||||
@ -16,9 +17,9 @@ test: testCompile testLink testExec
|
||||
|
||||
testCompile:
|
||||
gcc $(INC) $(UNITY) -g -c -o build/unity.o $(UNITYPATH)/unity.c
|
||||
gcc $(INC) -c -o build/main.o src/main.c
|
||||
gcc $(INC) -c -o build/fuse.o src/fuse.c
|
||||
gcc $(INC) -c -o build/fuseactions.o src/fuseactions.c
|
||||
gcc $(INC) $(WARNINGS) -c -o build/main.o src/main.c
|
||||
gcc $(INC) $(WARNINGS) -c -o build/fuse.o src/fuse.c
|
||||
gcc $(INC) $(WARNINGS) -c -o build/fuseactions.o src/fuseactions.c
|
||||
gcc $(INC) -g -c -o build/test.o test/test.c
|
||||
|
||||
testLink:
|
||||
|
@ -22,6 +22,17 @@ typedef struct fuseArgStruct
|
||||
int filefsname;
|
||||
} fuseArgStruct;
|
||||
|
||||
typedef struct SuperBlockStruct
|
||||
{
|
||||
blksize_t blockSize;
|
||||
blkcnt_t blockCount;
|
||||
} SuperBlockStruct;
|
||||
|
||||
typedef struct FBLStruct
|
||||
{
|
||||
int freeList[DEFAULTINODEMAX/32];
|
||||
} FBLStruct;
|
||||
|
||||
typedef struct BlockStruct
|
||||
{
|
||||
char byte[DEFAULTBLOCKSIZE];
|
||||
@ -34,22 +45,11 @@ typedef struct InodeStruct
|
||||
BlockStruct dataBlock;
|
||||
} InodeStruct;
|
||||
|
||||
typedef struct SuperBlockStruct
|
||||
{
|
||||
blksize_t blockSize;
|
||||
blkcnt_t blockCount;
|
||||
} SuperBlockStruct;
|
||||
|
||||
typedef struct FBLStruct
|
||||
{
|
||||
int freeList[DEFAULTINODEMAX/32];
|
||||
} FBLStruct;
|
||||
|
||||
typedef struct FileSystemStruct
|
||||
{
|
||||
SuperBlockStruct superBlock;
|
||||
FBLStruct fbl;
|
||||
InodeStruct inodes[DEFAULTINODEMAX];
|
||||
SuperBlockStruct* superBlock;
|
||||
FBLStruct* fbl;
|
||||
InodeStruct* inodes;
|
||||
} FileSystemStruct;
|
||||
|
||||
void Fuse(int argc, char* argv[]);
|
||||
@ -59,5 +59,7 @@ void FuseStructInit(fuseArgStruct* fuseStruct);
|
||||
void FuseUsageError(char* programPath);
|
||||
int zerosize(int fd);
|
||||
int FindEmptyBitPosition(int number);
|
||||
ino_t GetFreeInodeNumber(int* fbl);
|
||||
void SetFileSystemDefaults(FileSystemStruct* fs);
|
||||
|
||||
#endif
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#define FSSIZE 10000000
|
||||
|
||||
extern unsigned char* tempfs;
|
||||
|
||||
void MapFS(FileSystemStruct* fs, int fd);
|
||||
void UnmapFS(FileSystemStruct* fs);
|
||||
void FormatFS(FileSystemStruct* fs);
|
||||
|
48
src/fuse.c
48
src/fuse.c
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user