2022-11-14 21:46:44 -06:00
|
|
|
#ifndef FUSE_H
|
|
|
|
#define FUSE_H
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2022-11-25 18:03:45 -06:00
|
|
|
#define DEFAULTINODEMAX 128
|
|
|
|
#define DEFAULTBLOCKSIZE 512 // Size in bytes
|
2022-12-03 18:35:51 -06:00
|
|
|
#define DEFAULTBLOCKMAX 16384
|
2022-11-25 18:03:45 -06:00
|
|
|
|
2022-11-14 21:46:44 -06:00
|
|
|
typedef struct fuseArgStruct
|
|
|
|
{
|
|
|
|
int create;
|
|
|
|
int list;
|
|
|
|
int add;
|
|
|
|
int remove;
|
|
|
|
int extract;
|
|
|
|
char* toAdd;
|
|
|
|
char* toRemove;
|
|
|
|
char* toExtract;
|
|
|
|
char* fsname;
|
|
|
|
int fd;
|
|
|
|
int newfs;
|
|
|
|
int filefsname;
|
|
|
|
} fuseArgStruct;
|
|
|
|
|
2022-12-03 18:35:51 -06:00
|
|
|
typedef struct SuperBlock
|
2022-11-25 23:51:27 -06:00
|
|
|
{
|
|
|
|
blksize_t blockSize;
|
|
|
|
blkcnt_t blockCount;
|
2022-12-03 18:35:51 -06:00
|
|
|
unsigned long inodeCount;
|
|
|
|
} SuperBlock;
|
2022-11-25 23:51:27 -06:00
|
|
|
|
2022-12-03 18:35:51 -06:00
|
|
|
typedef struct FreeBlockList
|
2022-11-25 23:51:27 -06:00
|
|
|
{
|
|
|
|
int freeList[DEFAULTINODEMAX/32];
|
2022-12-03 18:35:51 -06:00
|
|
|
} FreeBlockList;
|
2022-11-25 23:51:27 -06:00
|
|
|
|
2022-12-03 18:35:51 -06:00
|
|
|
// 128 Blocks
|
|
|
|
typedef struct DataBlock
|
2022-11-25 18:03:45 -06:00
|
|
|
{
|
|
|
|
char byte[DEFAULTBLOCKSIZE];
|
2022-12-03 18:35:51 -06:00
|
|
|
} DataBlock;
|
2022-11-25 18:03:45 -06:00
|
|
|
|
2022-12-03 18:35:51 -06:00
|
|
|
// typedef struct InodeInfo
|
|
|
|
// {
|
|
|
|
// // char filePath[256];
|
|
|
|
// // off_t fileSize;
|
|
|
|
// ino_t inode;
|
|
|
|
// unsigned int isDirectory : 1;
|
|
|
|
// unsigned int isPrinted : 1;
|
|
|
|
// unsigned int isValid : 1;
|
|
|
|
// } InodeInfo;
|
|
|
|
|
|
|
|
// Inode * 128 + number
|
|
|
|
// Directblock == Files/Directories inside an inode?
|
|
|
|
typedef struct DirectBlock
|
|
|
|
{
|
|
|
|
unsigned int isValid : 1;
|
|
|
|
unsigned int isDirectory : 1;
|
|
|
|
char name[256];
|
|
|
|
ino_t inode;
|
|
|
|
off_t size;
|
|
|
|
} DirectBlock;
|
|
|
|
|
|
|
|
// Inode 0 is root
|
|
|
|
// Inode * 128
|
|
|
|
typedef struct Inode
|
2022-11-25 18:03:45 -06:00
|
|
|
{
|
2022-12-03 18:35:51 -06:00
|
|
|
unsigned int isValid : 1;
|
|
|
|
DirectBlock inodeBlocks[DEFAULTINODEMAX];
|
|
|
|
} Inode;
|
2022-11-25 18:03:45 -06:00
|
|
|
|
2022-12-03 18:35:51 -06:00
|
|
|
typedef struct FileSystem
|
2022-11-25 18:03:45 -06:00
|
|
|
{
|
2022-12-03 18:35:51 -06:00
|
|
|
SuperBlock superBlock;
|
|
|
|
FreeBlockList fbl;
|
|
|
|
Inode inodes[DEFAULTINODEMAX];
|
|
|
|
DataBlock dataBlocks[DEFAULTBLOCKMAX];
|
|
|
|
} FileSystem;
|
2022-11-25 18:03:45 -06:00
|
|
|
|
2022-11-14 21:46:44 -06:00
|
|
|
void Fuse(int argc, char* argv[]);
|
2022-12-02 13:35:38 -06:00
|
|
|
void GetArguments(int argc, char* argv[], fuseArgStruct* fuseArgs);
|
|
|
|
void OpenFS(fuseArgStruct* fuseArgs, char* programPath);
|
2022-12-03 18:35:51 -06:00
|
|
|
FileSystem* SetupFS(fuseArgStruct* fuseArgs);
|
|
|
|
void RunFuse(FileSystem* fs, fuseArgStruct* fuseArgs);
|
2022-12-02 13:35:38 -06:00
|
|
|
void TearDownFS(void);
|
2022-11-14 21:46:44 -06:00
|
|
|
void FuseStructInit(fuseArgStruct* fuseStruct);
|
|
|
|
void FuseUsageError(char* programPath);
|
|
|
|
int zerosize(int fd);
|
2022-11-25 18:03:45 -06:00
|
|
|
int FindEmptyBitPosition(int number);
|
2022-12-03 18:35:51 -06:00
|
|
|
ino_t GetFreeInodeNumber(Inode inodes[]);
|
|
|
|
ino_t GetFreeBlockNumber(int fbl[]);
|
|
|
|
void SetFileSystemDefaults(FileSystem* fs);
|
|
|
|
void SetupRootDirectory(FileSystem* fs);
|
2022-11-14 21:46:44 -06:00
|
|
|
|
|
|
|
#endif
|