Added bash script for testing during makefile test
This commit is contained in:
parent
4fcd64ea81
commit
81647a3100
2
.gitignore
vendored
2
.gitignore
vendored
@ -50,3 +50,5 @@ modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
*.test
|
||||
*.sh
|
||||
|
2
Makefile
2
Makefile
@ -27,7 +27,9 @@ testLink:
|
||||
|
||||
testExec:
|
||||
./bin/test.out
|
||||
test/testfs.sh
|
||||
|
||||
clean:
|
||||
rm build/*.o
|
||||
rm bin/*.out
|
||||
rm test/fakefs.test
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef FUSE_H
|
||||
#define FUSE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define DEFAULTINODEMAX 128
|
||||
#define DEFAULTBLOCKSIZE 512 // Size in bytes
|
||||
|
||||
@ -27,13 +29,15 @@ typedef struct BlockStruct
|
||||
|
||||
typedef struct InodeStruct
|
||||
{
|
||||
BlockStruct* dataBlock;
|
||||
char filePath[256];
|
||||
off_t fileSize;
|
||||
BlockStruct dataBlock;
|
||||
} InodeStruct;
|
||||
|
||||
typedef struct SuperBlockStruct
|
||||
{
|
||||
int blockCount;
|
||||
int blockSize;
|
||||
blksize_t blockSize;
|
||||
blkcnt_t blockCount;
|
||||
} SuperBlockStruct;
|
||||
|
||||
typedef struct FBLStruct
|
||||
@ -44,7 +48,7 @@ typedef struct FBLStruct
|
||||
typedef struct FileSystemStruct
|
||||
{
|
||||
SuperBlockStruct superBlock;
|
||||
FBLStruct freeList;
|
||||
FBLStruct fbl;
|
||||
InodeStruct inodes[DEFAULTINODEMAX];
|
||||
} FileSystemStruct;
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
void MapFS(FileSystemStruct* fs, int fd);
|
||||
void UnmapFS(FileSystemStruct* fs);
|
||||
void FormatFS();
|
||||
void LoadFS();
|
||||
void ListFS();
|
||||
void AddFileToFS(char* fname);
|
||||
void RemoveFileFromFS(char* fname);
|
||||
void ExtractFileFromFS(char* fname);
|
||||
void FormatFS(FileSystemStruct* fs);
|
||||
void LoadFS(FileSystemStruct* fs);
|
||||
void ListFS(FileSystemStruct* fs);
|
||||
void AddFileToFS(FileSystemStruct* fs, char* fname);
|
||||
void RemoveFileFromFS(FileSystemStruct* fs, char* fname);
|
||||
void ExtractFileFromFS(FileSystemStruct* fs, char* fname);
|
||||
|
||||
#endif
|
12
src/fuse.c
12
src/fuse.c
@ -77,16 +77,16 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
||||
}
|
||||
MapFS(&fileSystem, fuseArgs->fd);
|
||||
if (fuseArgs->newfs)
|
||||
FormatFS();
|
||||
LoadFS();
|
||||
FormatFS(&fileSystem);
|
||||
LoadFS(&fileSystem);
|
||||
if (fuseArgs->add)
|
||||
AddFileToFS(fuseArgs->toAdd);
|
||||
AddFileToFS(&fileSystem, fuseArgs->toAdd);
|
||||
if (fuseArgs->remove)
|
||||
RemoveFileFromFS(fuseArgs->toRemove);
|
||||
RemoveFileFromFS(&fileSystem, fuseArgs->toRemove);
|
||||
if (fuseArgs->extract)
|
||||
ExtractFileFromFS(fuseArgs->toExtract);
|
||||
ExtractFileFromFS(&fileSystem, fuseArgs->toExtract);
|
||||
if(fuseArgs->list)
|
||||
ListFS();
|
||||
ListFS(&fileSystem);
|
||||
UnmapFS(&fileSystem);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
#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"
|
||||
|
||||
void MapFS(FileSystemStruct* fs, int fd)
|
||||
@ -19,32 +23,59 @@ void UnmapFS(FileSystemStruct* fs)
|
||||
munmap(fs, FSSIZE);
|
||||
}
|
||||
|
||||
void FormatFS(void)
|
||||
void FormatFS(FileSystemStruct* fs)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
fs->fbl.freeList[i] = 0;
|
||||
}
|
||||
|
||||
void LoadFS(void)
|
||||
void LoadFS(FileSystemStruct* fs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ListFS(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AddFileToFS(char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RemoveFileFromFS(char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExtractFileFromFS(char* fname)
|
||||
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);
|
||||
}
|
||||
|
||||
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
BIN
test/fakefs
BIN
test/fakefs
Binary file not shown.
1
test/files/test1.txt
Normal file
1
test/files/test1.txt
Normal file
@ -0,0 +1 @@
|
||||
easy
|
1
test/files/test2.txt
Normal file
1
test/files/test2.txt
Normal file
@ -0,0 +1 @@
|
||||
wind
|
1
test/files/test3.txt
Normal file
1
test/files/test3.txt
Normal file
@ -0,0 +1 @@
|
||||
chocolate
|
Loading…
Reference in New Issue
Block a user