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
|
UNITYPATH = test/unity
|
||||||
INC := -I include
|
INC := -I include
|
||||||
|
WARNINGS := -m64 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
|
||||||
UNITY := -I $(UNITYPATH)
|
UNITY := -I $(UNITYPATH)
|
||||||
|
|
||||||
all: compile link
|
all: compile link
|
||||||
@ -16,9 +17,9 @@ test: testCompile testLink testExec
|
|||||||
|
|
||||||
testCompile:
|
testCompile:
|
||||||
gcc $(INC) $(UNITY) -g -c -o build/unity.o $(UNITYPATH)/unity.c
|
gcc $(INC) $(UNITY) -g -c -o build/unity.o $(UNITYPATH)/unity.c
|
||||||
gcc $(INC) -c -o build/main.o src/main.c
|
gcc $(INC) $(WARNINGS) -c -o build/main.o src/main.c
|
||||||
gcc $(INC) -c -o build/fuse.o src/fuse.c
|
gcc $(INC) $(WARNINGS) -c -o build/fuse.o src/fuse.c
|
||||||
gcc $(INC) -c -o build/fuseactions.o src/fuseactions.c
|
gcc $(INC) $(WARNINGS) -c -o build/fuseactions.o src/fuseactions.c
|
||||||
gcc $(INC) -g -c -o build/test.o test/test.c
|
gcc $(INC) -g -c -o build/test.o test/test.c
|
||||||
|
|
||||||
testLink:
|
testLink:
|
||||||
|
@ -22,6 +22,17 @@ typedef struct fuseArgStruct
|
|||||||
int filefsname;
|
int filefsname;
|
||||||
} fuseArgStruct;
|
} fuseArgStruct;
|
||||||
|
|
||||||
|
typedef struct SuperBlockStruct
|
||||||
|
{
|
||||||
|
blksize_t blockSize;
|
||||||
|
blkcnt_t blockCount;
|
||||||
|
} SuperBlockStruct;
|
||||||
|
|
||||||
|
typedef struct FBLStruct
|
||||||
|
{
|
||||||
|
int freeList[DEFAULTINODEMAX/32];
|
||||||
|
} FBLStruct;
|
||||||
|
|
||||||
typedef struct BlockStruct
|
typedef struct BlockStruct
|
||||||
{
|
{
|
||||||
char byte[DEFAULTBLOCKSIZE];
|
char byte[DEFAULTBLOCKSIZE];
|
||||||
@ -34,22 +45,11 @@ typedef struct InodeStruct
|
|||||||
BlockStruct dataBlock;
|
BlockStruct dataBlock;
|
||||||
} InodeStruct;
|
} InodeStruct;
|
||||||
|
|
||||||
typedef struct SuperBlockStruct
|
|
||||||
{
|
|
||||||
blksize_t blockSize;
|
|
||||||
blkcnt_t blockCount;
|
|
||||||
} SuperBlockStruct;
|
|
||||||
|
|
||||||
typedef struct FBLStruct
|
|
||||||
{
|
|
||||||
int freeList[DEFAULTINODEMAX/32];
|
|
||||||
} FBLStruct;
|
|
||||||
|
|
||||||
typedef struct FileSystemStruct
|
typedef struct FileSystemStruct
|
||||||
{
|
{
|
||||||
SuperBlockStruct superBlock;
|
SuperBlockStruct* superBlock;
|
||||||
FBLStruct fbl;
|
FBLStruct* fbl;
|
||||||
InodeStruct inodes[DEFAULTINODEMAX];
|
InodeStruct* inodes;
|
||||||
} FileSystemStruct;
|
} FileSystemStruct;
|
||||||
|
|
||||||
void Fuse(int argc, char* argv[]);
|
void Fuse(int argc, char* argv[]);
|
||||||
@ -59,5 +59,7 @@ void FuseStructInit(fuseArgStruct* fuseStruct);
|
|||||||
void FuseUsageError(char* programPath);
|
void FuseUsageError(char* programPath);
|
||||||
int zerosize(int fd);
|
int zerosize(int fd);
|
||||||
int FindEmptyBitPosition(int number);
|
int FindEmptyBitPosition(int number);
|
||||||
|
ino_t GetFreeInodeNumber(int* fbl);
|
||||||
|
void SetFileSystemDefaults(FileSystemStruct* fs);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#define FSSIZE 10000000
|
#define FSSIZE 10000000
|
||||||
|
|
||||||
|
extern unsigned char* tempfs;
|
||||||
|
|
||||||
void MapFS(FileSystemStruct* fs, int fd);
|
void MapFS(FileSystemStruct* fs, int fd);
|
||||||
void UnmapFS(FileSystemStruct* fs);
|
void UnmapFS(FileSystemStruct* fs);
|
||||||
void FormatFS(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
|
// Given code for default functionality
|
||||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||||
{
|
{
|
||||||
FileSystemStruct fileSystem;
|
FileSystemStruct* fsptr;
|
||||||
if (!fuseArgs->filefsname)
|
if (!fuseArgs->filefsname)
|
||||||
FuseUsageError(programPath);
|
FuseUsageError(programPath);
|
||||||
fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
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);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MapFS(&fileSystem, fuseArgs->fd);
|
MapFS(fsptr, fuseArgs->fd);
|
||||||
if (fuseArgs->newfs)
|
if (fuseArgs->newfs)
|
||||||
FormatFS(&fileSystem);
|
FormatFS(fsptr);
|
||||||
LoadFS(&fileSystem);
|
LoadFS(fsptr);
|
||||||
if (fuseArgs->add)
|
if (fuseArgs->add)
|
||||||
AddFileToFS(&fileSystem, fuseArgs->toAdd);
|
AddFileToFS(fsptr, fuseArgs->toAdd);
|
||||||
if (fuseArgs->remove)
|
if (fuseArgs->remove)
|
||||||
RemoveFileFromFS(&fileSystem, fuseArgs->toRemove);
|
RemoveFileFromFS(fsptr, fuseArgs->toRemove);
|
||||||
if (fuseArgs->extract)
|
if (fuseArgs->extract)
|
||||||
ExtractFileFromFS(&fileSystem, fuseArgs->toExtract);
|
ExtractFileFromFS(fsptr, fuseArgs->toExtract);
|
||||||
if(fuseArgs->list)
|
if(fuseArgs->list)
|
||||||
ListFS(&fileSystem);
|
ListFS(fsptr);
|
||||||
UnmapFS(&fileSystem);
|
UnmapFS(fsptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize entire fuseStruct
|
// Initialize entire fuseStruct
|
||||||
@ -134,3 +134,33 @@ int FindEmptyBitPosition(int number)
|
|||||||
return -1;
|
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,25 +8,32 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "fuseactions.h"
|
#include "fuseactions.h"
|
||||||
|
|
||||||
|
unsigned char* tempfs;
|
||||||
|
|
||||||
void MapFS(FileSystemStruct* fs, int fd)
|
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)
|
if (fs == NULL)
|
||||||
{
|
{
|
||||||
perror("mmap failed");
|
perror("mmap failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnmapFS(FileSystemStruct* fs)
|
void UnmapFS(FileSystemStruct* fs)
|
||||||
{
|
{
|
||||||
munmap(fs, FSSIZE);
|
munmap(fs, FSSIZE);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormatFS(FileSystemStruct* fs)
|
void FormatFS(FileSystemStruct* fs)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
fs->superBlock = (SuperBlockStruct*) tempfs;
|
||||||
fs->fbl.freeList[i] = 0;
|
fs->fbl = (FBLStruct*) (tempfs + sizeof(SuperBlockStruct));
|
||||||
|
fs->inodes = (InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct));
|
||||||
|
SetFileSystemDefaults(fs);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadFS(FileSystemStruct* fs)
|
void LoadFS(FileSystemStruct* fs)
|
||||||
@ -38,25 +45,15 @@ void ListFS(FileSystemStruct* fs)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
for (int j = 0; j < 32; j++)
|
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);
|
printf("%s\n", fs->inodes[i*32 + j].filePath);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||||
{
|
{
|
||||||
struct stat statBuffer;
|
struct stat statBuffer;
|
||||||
int inodeNumber = -1;
|
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl->freeList);
|
||||||
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);
|
|
||||||
strcpy(fs->inodes[inodeNumber].filePath, fname);
|
strcpy(fs->inodes[inodeNumber].filePath, fname);
|
||||||
stat(fname, &statBuffer);
|
stat(fname, &statBuffer);
|
||||||
fs->inodes[inodeNumber].fileSize = statBuffer.st_size;
|
fs->inodes[inodeNumber].fileSize = statBuffer.st_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user