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
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
*.test
|
||||||
|
*.sh
|
||||||
|
2
Makefile
2
Makefile
@ -27,7 +27,9 @@ testLink:
|
|||||||
|
|
||||||
testExec:
|
testExec:
|
||||||
./bin/test.out
|
./bin/test.out
|
||||||
|
test/testfs.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm build/*.o
|
rm build/*.o
|
||||||
rm bin/*.out
|
rm bin/*.out
|
||||||
|
rm test/fakefs.test
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef FUSE_H
|
#ifndef FUSE_H
|
||||||
#define FUSE_H
|
#define FUSE_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define DEFAULTINODEMAX 128
|
#define DEFAULTINODEMAX 128
|
||||||
#define DEFAULTBLOCKSIZE 512 // Size in bytes
|
#define DEFAULTBLOCKSIZE 512 // Size in bytes
|
||||||
|
|
||||||
@ -27,13 +29,15 @@ typedef struct BlockStruct
|
|||||||
|
|
||||||
typedef struct InodeStruct
|
typedef struct InodeStruct
|
||||||
{
|
{
|
||||||
BlockStruct* dataBlock;
|
char filePath[256];
|
||||||
|
off_t fileSize;
|
||||||
|
BlockStruct dataBlock;
|
||||||
} InodeStruct;
|
} InodeStruct;
|
||||||
|
|
||||||
typedef struct SuperBlockStruct
|
typedef struct SuperBlockStruct
|
||||||
{
|
{
|
||||||
int blockCount;
|
blksize_t blockSize;
|
||||||
int blockSize;
|
blkcnt_t blockCount;
|
||||||
} SuperBlockStruct;
|
} SuperBlockStruct;
|
||||||
|
|
||||||
typedef struct FBLStruct
|
typedef struct FBLStruct
|
||||||
@ -44,7 +48,7 @@ typedef struct FBLStruct
|
|||||||
typedef struct FileSystemStruct
|
typedef struct FileSystemStruct
|
||||||
{
|
{
|
||||||
SuperBlockStruct superBlock;
|
SuperBlockStruct superBlock;
|
||||||
FBLStruct freeList;
|
FBLStruct fbl;
|
||||||
InodeStruct inodes[DEFAULTINODEMAX];
|
InodeStruct inodes[DEFAULTINODEMAX];
|
||||||
} FileSystemStruct;
|
} FileSystemStruct;
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
void MapFS(FileSystemStruct* fs, int fd);
|
void MapFS(FileSystemStruct* fs, int fd);
|
||||||
void UnmapFS(FileSystemStruct* fs);
|
void UnmapFS(FileSystemStruct* fs);
|
||||||
void FormatFS();
|
void FormatFS(FileSystemStruct* fs);
|
||||||
void LoadFS();
|
void LoadFS(FileSystemStruct* fs);
|
||||||
void ListFS();
|
void ListFS(FileSystemStruct* fs);
|
||||||
void AddFileToFS(char* fname);
|
void AddFileToFS(FileSystemStruct* fs, char* fname);
|
||||||
void RemoveFileFromFS(char* fname);
|
void RemoveFileFromFS(FileSystemStruct* fs, char* fname);
|
||||||
void ExtractFileFromFS(char* fname);
|
void ExtractFileFromFS(FileSystemStruct* fs, char* fname);
|
||||||
|
|
||||||
#endif
|
#endif
|
12
src/fuse.c
12
src/fuse.c
@ -77,16 +77,16 @@ void FuseGivenTest(fuseArgStruct* fuseArgs, char* programPath)
|
|||||||
}
|
}
|
||||||
MapFS(&fileSystem, fuseArgs->fd);
|
MapFS(&fileSystem, fuseArgs->fd);
|
||||||
if (fuseArgs->newfs)
|
if (fuseArgs->newfs)
|
||||||
FormatFS();
|
FormatFS(&fileSystem);
|
||||||
LoadFS();
|
LoadFS(&fileSystem);
|
||||||
if (fuseArgs->add)
|
if (fuseArgs->add)
|
||||||
AddFileToFS(fuseArgs->toAdd);
|
AddFileToFS(&fileSystem, fuseArgs->toAdd);
|
||||||
if (fuseArgs->remove)
|
if (fuseArgs->remove)
|
||||||
RemoveFileFromFS(fuseArgs->toRemove);
|
RemoveFileFromFS(&fileSystem, fuseArgs->toRemove);
|
||||||
if (fuseArgs->extract)
|
if (fuseArgs->extract)
|
||||||
ExtractFileFromFS(fuseArgs->toExtract);
|
ExtractFileFromFS(&fileSystem, fuseArgs->toExtract);
|
||||||
if(fuseArgs->list)
|
if(fuseArgs->list)
|
||||||
ListFS();
|
ListFS(&fileSystem);
|
||||||
UnmapFS(&fileSystem);
|
UnmapFS(&fileSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "fuseactions.h"
|
#include "fuseactions.h"
|
||||||
|
|
||||||
void MapFS(FileSystemStruct* fs, int fd)
|
void MapFS(FileSystemStruct* fs, int fd)
|
||||||
@ -19,32 +23,59 @@ void UnmapFS(FileSystemStruct* fs)
|
|||||||
munmap(fs, FSSIZE);
|
munmap(fs, FSSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormatFS(void)
|
void FormatFS(FileSystemStruct* fs)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
fs->fbl.freeList[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadFS(FileSystemStruct* fs)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadFS(void)
|
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 ListFS(void)
|
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddFileToFS(char* fname)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveFileFromFS(char* fname)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExtractFileFromFS(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