fuse/src/fuseactions.c

82 lines
1.8 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"
void MapFS(FileSystemStruct* fs, int fd)
2022-11-14 21:46:44 -06:00
{
fs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (fs == NULL)
{
perror("mmap failed");
exit(EXIT_FAILURE);
}
}
void UnmapFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
munmap(fs, FSSIZE);
}
void FormatFS(FileSystemStruct* fs)
2022-11-14 21:46:44 -06:00
{
for (int i = 0; i < 4; i++)
fs->fbl.freeList[i] = 0;
2022-11-14 21:46:44 -06:00
}
void LoadFS(FileSystemStruct* fs)
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);
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;
int inodeNumber = -1;
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);
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
{
}