106 lines
2.7 KiB
C
106 lines
2.7 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 <sys/types.h>
|
|
#include "fuse.h"
|
|
#include "fsactions.h"
|
|
#include "fsinterface.h"
|
|
|
|
/*
|
|
* Steps to formatting inodes:
|
|
* 1) Check if file exists already in directory
|
|
* 2) If file does not exist in directory, provide new inode
|
|
* 3) Inodes are placed inside of inodes that are directories
|
|
*
|
|
*/
|
|
|
|
// TODO: Take BlockStruct out of InodeStruct
|
|
// Make a method for turning names into Inodes
|
|
|
|
// Main handler for Fuse
|
|
void Fuse(int argc, char* argv[])
|
|
{
|
|
FileSystem* fsptr;
|
|
fuseArgStruct fuseArgs;
|
|
GetArguments(argc, argv, &fuseArgs);
|
|
OpenFS(&fuseArgs, argv[0]);
|
|
fsptr = SetupFS(&fuseArgs);
|
|
RunFuse(fsptr, &fuseArgs);
|
|
TearDownFS();
|
|
}
|
|
|
|
// Gets command line arguments and puts information into fuseArgs
|
|
void GetArguments(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
|
{
|
|
for (int i = 0; i < argc; i++)
|
|
{
|
|
if (argv[i][0] == '-' && argv[i][1] == 'l')
|
|
fuseArgs->list = 1;
|
|
if (argv[i][0] == '-' && argv[i][1] == 'a')
|
|
{
|
|
fuseArgs->add = 1;
|
|
fuseArgs->toAdd = strdup(argv[i+1]);
|
|
}
|
|
if (argv[i][0] == '-' && argv[i][1] == 'r')
|
|
{
|
|
fuseArgs->remove = 1;
|
|
fuseArgs->toRemove = strdup(argv[i+1]);
|
|
}
|
|
if (argv[i][0] == '-' && argv[i][1] == 'e')
|
|
{
|
|
fuseArgs->extract = 1;
|
|
fuseArgs->toExtract = strdup(argv[i+1]);
|
|
}
|
|
if (argv[i][0] == '-' && argv[i][1] == 'f')
|
|
{
|
|
fuseArgs->filefsname = 1;
|
|
fuseArgs->fsname = strdup(argv[i+1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Runs the fuse functions that were previously marked
|
|
void RunFuse(FileSystem* fs, fuseArgStruct* fuseArgs)
|
|
{
|
|
if (fuseArgs->add)
|
|
AddFileToFS(fs, fuseArgs->toAdd);
|
|
if (fuseArgs->remove)
|
|
RemoveFileFromFS(fs, fuseArgs->toRemove);
|
|
if (fuseArgs->extract)
|
|
ExtractFileFromFS(fs, fuseArgs->toExtract);
|
|
if(fuseArgs->list)
|
|
ListFS(fs);
|
|
return;
|
|
}
|
|
|
|
// Initialize entire fuseStruct
|
|
void FuseStructInit(fuseArgStruct* fuseStruct)
|
|
{
|
|
fuseStruct->create = 0;
|
|
fuseStruct->list = 0;
|
|
fuseStruct->add = 0;
|
|
fuseStruct->remove = 0;
|
|
fuseStruct->extract = 0;
|
|
fuseStruct->toAdd = NULL;
|
|
fuseStruct->toRemove = NULL;
|
|
fuseStruct->toExtract = NULL;
|
|
fuseStruct->fsname = NULL;
|
|
fuseStruct->fd = -1;
|
|
fuseStruct->newfs = 0;
|
|
fuseStruct->filefsname = 0;
|
|
return;
|
|
}
|
|
|
|
// Print error if usage is wrong
|
|
void FuseUsageError(char* programPath)
|
|
{
|
|
fprintf(stderr, "Usage %s [-l] [-a path] [-e path] [-r path] -f name\n",
|
|
programPath);
|
|
exit(EXIT_FAILURE);
|
|
}
|