84 lines
1.9 KiB
C
84 lines
1.9 KiB
C
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include "fuseactions.h"
|
|
|
|
unsigned char* tempfs;
|
|
|
|
void MapFS(int fd)
|
|
{
|
|
tempfs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
if (tempfs == NULL)
|
|
{
|
|
perror("mmap failed");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
return;
|
|
}
|
|
|
|
void UnmapFS(void)
|
|
{
|
|
munmap(tempfs, FSSIZE);
|
|
return;
|
|
}
|
|
|
|
void FormatFS(FileSystemStruct* fs)
|
|
{
|
|
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;
|
|
}
|
|
|
|
void LoadFS(FileSystemStruct* fs)
|
|
{
|
|
fs = (FileSystemStruct*) tempfs;
|
|
return;
|
|
}
|
|
|
|
void ListFS(FileSystemStruct* fs)
|
|
{
|
|
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;
|
|
}
|
|
|
|
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
|
{
|
|
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);
|
|
}
|
|
|
|
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
|
|
{
|
|
|
|
}
|
|
|
|
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
|
{
|
|
|
|
}
|