2022-11-14 21:46:44 -06:00
|
|
|
#include <errno.h>
|
2022-11-25 20:55:43 -06:00
|
|
|
#include <fcntl.h>
|
2022-11-14 21:46:44 -06:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2022-11-25 20:55:43 -06:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2022-11-14 21:46:44 -06:00
|
|
|
#include <sys/mman.h>
|
2022-11-25 20:55:43 -06:00
|
|
|
#include <sys/stat.h>
|
2022-11-14 21:46:44 -06:00
|
|
|
#include "fuseactions.h"
|
|
|
|
|
2022-11-25 23:51:27 -06:00
|
|
|
unsigned char* tempfs;
|
|
|
|
|
2022-11-25 18:03:45 -06:00
|
|
|
void MapFS(FileSystemStruct* fs, int fd)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
2022-11-25 23:51:27 -06:00
|
|
|
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
2022-11-14 21:46:44 -06:00
|
|
|
if (fs == NULL)
|
|
|
|
{
|
|
|
|
perror("mmap failed");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2022-11-25 23:51:27 -06:00
|
|
|
return;
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 18:03:45 -06:00
|
|
|
void UnmapFS(FileSystemStruct* fs)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
|
|
|
munmap(fs, FSSIZE);
|
2022-11-25 23:51:27 -06:00
|
|
|
return;
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void FormatFS(FileSystemStruct* fs)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
2022-11-25 23:51:27 -06:00
|
|
|
fs->superBlock = (SuperBlockStruct*) tempfs;
|
|
|
|
fs->fbl = (FBLStruct*) (tempfs + sizeof(SuperBlockStruct));
|
|
|
|
fs->inodes = (InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct));
|
|
|
|
SetFileSystemDefaults(fs);
|
|
|
|
return;
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void LoadFS(FileSystemStruct* fs)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
2022-11-25 23:51:27 -06:00
|
|
|
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void ListFS(FileSystemStruct* fs)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
2022-11-25 20:55:43 -06:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 32; j++)
|
2022-11-25 23:51:27 -06:00
|
|
|
if ((fs->fbl->freeList[i] & (1 << j)) == (1 << j))
|
2022-11-25 20:55:43 -06:00
|
|
|
printf("%s\n", fs->inodes[i*32 + j].filePath);
|
2022-11-25 23:51:27 -06:00
|
|
|
return;
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
2022-11-25 20:55:43 -06:00
|
|
|
struct stat statBuffer;
|
2022-11-25 23:51:27 -06:00
|
|
|
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl->freeList);
|
2022-11-25 20:55:43 -06:00
|
|
|
strcpy(fs->inodes[inodeNumber].filePath, fname);
|
|
|
|
stat(fname, &statBuffer);
|
|
|
|
fs->inodes[inodeNumber].fileSize = statBuffer.st_size;
|
|
|
|
int fd = open(fname, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
perror(fname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
read(fd, fs->inodes[inodeNumber].dataBlock.byte, sizeof(BlockStruct));
|
|
|
|
close(fd);
|
2022-11-14 21:46:44 -06:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-25 20:55:43 -06:00
|
|
|
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
2022-11-14 21:46:44 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|