fuse/src/fuseactions.c

84 lines
1.9 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(int fd)
2022-11-14 21:46:44 -06:00
{
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (tempfs == NULL)
2022-11-14 21:46:44 -06:00
{
perror("mmap failed");
exit(EXIT_FAILURE);
}
return;
2022-11-14 21:46:44 -06:00
}
void UnmapFS(void)
2022-11-14 21:46:44 -06:00
{
munmap(tempfs, FSSIZE);
return;
2022-11-14 21:46:44 -06:00
}
void FormatFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
SetFileSystemDefaults(tempfs);
// fs->superBlock = (FileSystemStruct*) tempfs->superBlock;
// fs->fbl = (FileSystemStruct*) tempfs->fbl;
// fs->inodes = (FileSystemStruct*) tempfs->inodes;
// for (int i = 0; i < DEFAULTINODEMAX; i++)
// fs->inodes[i] = *(InodeStruct*) (tempfs + sizeof(SuperBlockStruct) + sizeof(FBLStruct) + sizeof(InodeStruct) * i);
return;
2022-11-14 21:46:44 -06:00
}
void LoadFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
fs = (FileSystemStruct*) tempfs;
return;
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;
printf("Check\n");
printf("Bit: %i\n", fs->fbl.freeList[0]);
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
{
}