Setup default files, test files next
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
#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 "fuseactions.h"
|
||||
|
||||
// Main handler for Fuse
|
||||
void Fuse(int argc, char* argv[])
|
||||
{
|
||||
fuseArgStruct fuseArgs;
|
||||
FuseCheckArgs(argc, argv, &fuseArgs);
|
||||
FuseGivenTest(&fuseArgs, argv[0]);
|
||||
}
|
||||
|
||||
// Originally given method for getting arguments
|
||||
void FuseCheckArgs(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
||||
{
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "la:r:e:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'l':
|
||||
fuseArgs->list = 1;
|
||||
break;
|
||||
case 'a':
|
||||
fuseArgs->add = 1;
|
||||
fuseArgs->toAdd = strdup(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
fuseArgs->remove = 1;
|
||||
fuseArgs->toRemove = strdup(optarg);
|
||||
break;
|
||||
case 'e':
|
||||
fuseArgs->extract = 1;
|
||||
fuseArgs->toExtract = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
FuseUsageError(argv[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Given code for default functionality
|
||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
{
|
||||
if (!fuseArgs->filefsname)
|
||||
FuseUsageError(programPath);
|
||||
fuseArgs->fd = open(fuseArgs->fsname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fuseArgs->fd == -1)
|
||||
{
|
||||
perror("open failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (zerosize(fuseArgs->fd))
|
||||
fuseArgs->newfs = 1;
|
||||
if (fuseArgs->newfs)
|
||||
{
|
||||
if (lseek(fuseArgs->fd, FSSIZE-1, SEEK_SET) == -1)
|
||||
{
|
||||
perror("seek failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (write(fuseArgs->fd, "\0", 1) == -1)
|
||||
{
|
||||
perror("write failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
mapfs(fuseArgs->fd);
|
||||
if (fuseArgs->newfs)
|
||||
formatfs();
|
||||
loadfs();
|
||||
if (fuseArgs->add)
|
||||
addfilefs(fuseArgs->toAdd);
|
||||
if (fuseArgs->remove)
|
||||
removefilefs(fuseArgs->toRemove);
|
||||
if (fuseArgs->extract)
|
||||
extractfilefs(fuseArgs->toExtract);
|
||||
if(fuseArgs->list)
|
||||
lsfs();
|
||||
unmapfs();
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Return bool of if the size is 0
|
||||
int zerosize(int fd)
|
||||
{
|
||||
struct stat stats;
|
||||
fstat(fd, &stats);
|
||||
if(stats.st_size == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include "fuseactions.h"
|
||||
|
||||
unsigned char* fs;
|
||||
|
||||
void mapfs(int fd)
|
||||
{
|
||||
fs = mmap(NULL, FSSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (fs == NULL)
|
||||
{
|
||||
perror("mmap failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void unmapfs()
|
||||
{
|
||||
munmap(fs, FSSIZE);
|
||||
}
|
||||
|
||||
void formatfs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void loadfs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void lsfs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void addfilefs(char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void removefilefs(char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void extractfilefs(char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "fuse.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Fuse(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user