Setup default files, test files next
This commit is contained in:
parent
cd31743229
commit
3df863d285
11
Makefile
11
Makefile
@ -6,22 +6,23 @@ all: compile link
|
||||
|
||||
compile:
|
||||
gcc $(INC) -c -o build/main.o src/main.c
|
||||
gcc $(INC) -c -o build/stuffy.o src/stuffy.c
|
||||
gcc $(INC) -c -o build/fuse.o src/fuse.c
|
||||
gcc $(INC) -c -o build/fuseactions.o src/fuseactions.c
|
||||
|
||||
link:
|
||||
gcc -o bin/stuffy.out build/stuffy.o build/main.o
|
||||
gcc -o bin/fuse.out build/fuseactions.o build/fuse.o build/main.o
|
||||
|
||||
test: testCompile testLink testExec
|
||||
|
||||
testCompile:
|
||||
gcc $(INC) $(UNITY) -g -c -o build/unity.o $(UNITYPATH)/unity.c
|
||||
gcc $(INC) -c -o build/main.o src/main.c
|
||||
gcc $(INC) -g -c -o build/stuffy.o src/stuffy.c
|
||||
gcc $(INC) -g -c -o build/fuse.o src/fuse.c
|
||||
gcc $(INC) -g -c -o build/test.o test/test.c
|
||||
|
||||
testLink:
|
||||
gcc -g -o bin/test.out build/stuffy.o build/test.o build/unity.o
|
||||
gcc -o bin/stuffy.out build/stuffy.o build/main.o
|
||||
gcc -g -o bin/test.out build/fuse.o build/test.o build/unity.o
|
||||
gcc -o bin/fuse.out build/fuse.o build/main.o
|
||||
|
||||
testExec:
|
||||
./bin/test.out
|
||||
|
27
include/fuse.h
Normal file
27
include/fuse.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef FUSE_H
|
||||
#define FUSE_H
|
||||
|
||||
typedef struct fuseArgStruct
|
||||
{
|
||||
int create;
|
||||
int list;
|
||||
int add;
|
||||
int remove;
|
||||
int extract;
|
||||
char* toAdd;
|
||||
char* toRemove;
|
||||
char* toExtract;
|
||||
char* fsname;
|
||||
int fd;
|
||||
int newfs;
|
||||
int filefsname;
|
||||
} fuseArgStruct;
|
||||
|
||||
void Fuse(int argc, char* argv[]);
|
||||
void FuseCheckArgs(int argc, char* argv[], fuseArgStruct* fuseArgs);
|
||||
void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath);
|
||||
void FuseStructInit(fuseArgStruct* fuseStruct);
|
||||
void FuseUsageError(char* programPath);
|
||||
int zerosize(int fd);
|
||||
|
||||
#endif
|
17
include/fuseactions.h
Normal file
17
include/fuseactions.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef FUSEACTIONS_H
|
||||
#define FUSEACTIONS_H
|
||||
|
||||
#define FSSIZE 10000000
|
||||
|
||||
extern unsigned char* fs;
|
||||
|
||||
void mapfs(int fd);
|
||||
void unmapfs();
|
||||
void formatfs();
|
||||
void loadfs();
|
||||
void lsfs();
|
||||
void addfilefs(char* fname);
|
||||
void removefilefs(char* fname);
|
||||
void extractfilefs(char* fname);
|
||||
|
||||
#endif
|
124
src/fuse.c
124
src/fuse.c
@ -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;
|
||||
}
|
52
src/fuseactions.c
Normal file
52
src/fuseactions.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user