fuse/src/fuseactions.c

79 lines
1.7 KiB
C
Raw Normal View History

2022-11-14 21:46:44 -06:00
#include <errno.h>
#include <fcntl.h>
2022-11-14 21:46:44 -06:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
2022-11-14 21:46:44 -06:00
#include <sys/mman.h>
#include <sys/stat.h>
2022-11-14 21:46:44 -06:00
#include "fuseactions.h"
unsigned char* tempfs;
void MapFS(FileSystemStruct* fs, int fd)
2022-11-14 21:46:44 -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);
}
return;
2022-11-14 21:46:44 -06:00
}
void UnmapFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
munmap(fs, FSSIZE);
return;
2022-11-14 21:46:44 -06:00
}
void FormatFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -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
}
void LoadFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
2022-11-14 21:46:44 -06:00
}
void ListFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 32; j++)
if ((fs->fbl->freeList[i] & (1 << j)) == (1 << j))
printf("%s\n", fs->inodes[i*32 + j].filePath);
return;
2022-11-14 21:46:44 -06:00
}
void AddFileToFS(FileSystemStruct* fs, char* fname)
2022-11-14 21:46:44 -06:00
{
struct stat statBuffer;
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl->freeList);
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
}
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
2022-11-14 21:46:44 -06:00
{
}
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
2022-11-14 21:46:44 -06:00
{
}