Fixed structure of inodes, setup testing for opening and adding fs
This commit is contained in:
+35
-13
@@ -10,10 +10,21 @@
|
||||
#include "fuse.h"
|
||||
#include "fuseactions.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[])
|
||||
{
|
||||
FileSystemStruct* fsptr;
|
||||
FileSystem* fsptr;
|
||||
fuseArgStruct fuseArgs;
|
||||
GetArguments(argc, argv, &fuseArgs);
|
||||
OpenFS(&fuseArgs, argv[0]);
|
||||
@@ -23,7 +34,6 @@ void Fuse(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// Gets command line arguments and puts information into fuseArgs
|
||||
// New method for getting arguments
|
||||
void GetArguments(int argc, char* argv[], fuseArgStruct* fuseArgs)
|
||||
{
|
||||
for (int i = 0; i < argc; i++)
|
||||
@@ -81,9 +91,9 @@ void OpenFS(fuseArgStruct* fuseArgs, char* programPath)
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystemStruct* SetupFS(fuseArgStruct* fuseArgs)
|
||||
FileSystem* SetupFS(fuseArgStruct* fuseArgs)
|
||||
{
|
||||
FileSystemStruct* fs;
|
||||
FileSystem* fs;
|
||||
MapFS(fuseArgs->fd);
|
||||
LoadFS(&fs);
|
||||
if (fuseArgs->newfs)
|
||||
@@ -91,7 +101,7 @@ FileSystemStruct* SetupFS(fuseArgStruct* fuseArgs)
|
||||
return fs;
|
||||
}
|
||||
|
||||
void RunFuse(FileSystemStruct* fs, fuseArgStruct* fuseArgs)
|
||||
void RunFuse(FileSystem* fs, fuseArgStruct* fuseArgs)
|
||||
{
|
||||
if (fuseArgs->add)
|
||||
AddFileToFS(fs, fuseArgs->toAdd);
|
||||
@@ -155,7 +165,7 @@ int FindEmptyBitPosition(int number)
|
||||
}
|
||||
|
||||
// Gets next free inode number and returns it
|
||||
ino_t GetFreeInodeNumber(int fbl[])
|
||||
ino_t GetFreeBlockNumber(int fbl[])
|
||||
{
|
||||
int bitPosition;
|
||||
for (int i = 0; i < (DEFAULTINODEMAX/32); i++)
|
||||
@@ -170,18 +180,30 @@ ino_t GetFreeInodeNumber(int fbl[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
ino_t GetFreeInodeNumber(Inode inodes[])
|
||||
{
|
||||
for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
if (!(inodes[i].isValid))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Function for setting all defaults of filesystem
|
||||
void SetFileSystemDefaults(FileSystemStruct* fs)
|
||||
void SetFileSystemDefaults(FileSystem* fs)
|
||||
{
|
||||
fs->superBlock.blockSize = DEFAULTBLOCKSIZE;
|
||||
fs->superBlock.blockCount = DEFAULTINODEMAX;
|
||||
fs->superBlock.blockCount = DEFAULTBLOCKMAX;
|
||||
fs->superBlock.inodeCount = DEFAULTINODEMAX;
|
||||
for (int i = 0; i < 4; i++)
|
||||
fs->fbl.freeList[i] = 0;
|
||||
for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
{
|
||||
strcpy(fs->inodes[i].filePath, "\0");
|
||||
fs->inodes[i].fileSize = 0;
|
||||
strcpy(fs->inodes[i].dataBlock.byte, "\0");
|
||||
}
|
||||
fs->inodes[i].isValid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void SetupRootDirectory(FileSystem* fs)
|
||||
{
|
||||
fs->inodes[0].isValid = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+65
-24
@@ -31,56 +31,97 @@ void UnmapFS(void)
|
||||
}
|
||||
|
||||
// Sets defaults of a new filesystem
|
||||
void FormatFS(FileSystemStruct* fs)
|
||||
void FormatFS(FileSystem* fs)
|
||||
{
|
||||
SetFileSystemDefaults(fs);
|
||||
SetupRootDirectory(fs);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load existing filesystem
|
||||
// Depreciated Function
|
||||
void LoadFS(FileSystemStruct** fs)
|
||||
// Redirect global pointer to structured local pointer
|
||||
void LoadFS(FileSystem** fs)
|
||||
{
|
||||
*fs = (FileSystemStruct*) (tempfs);
|
||||
*fs = (FileSystem*) (tempfs);
|
||||
return;
|
||||
}
|
||||
|
||||
// List path names of all used inodes
|
||||
void ListFS(FileSystemStruct* fs)
|
||||
// TODO: Fix implementation to print starting at Inode 0
|
||||
void ListFS(FileSystem* 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);
|
||||
Inode* fsRoot = &(fs->inodes[0]);
|
||||
printf("/\n");
|
||||
for (int i = 0; i < fs->superBlock.inodeCount; i++)
|
||||
{
|
||||
if (!(fsRoot->inodeBlocks[i].isValid))
|
||||
continue;
|
||||
printf("%s\n", fsRoot->inodeBlocks[i].name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Depreciated due to new structure method
|
||||
void _RecursivePrintFS_(FileSystem* fs, ino_t inodePosition)
|
||||
{
|
||||
// for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
// {
|
||||
// if (!(fs->inodes[inodePosition].inodeBlocks[i].info.isValid))
|
||||
// continue;
|
||||
// printf("%s\n", fs->inodes[inodePosition].inodeBlocks[i].info.filePath);
|
||||
// if (fs->inodes[inodePosition].inodeBlocks[i].info.isDirectory)
|
||||
// _RecursivePrintFS_(fs, fs->inodes[inodePosition].inodeBlocks[i].info.inode);
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
int FindNextDirectory(char* fname)
|
||||
{
|
||||
int i = 0;
|
||||
while (fname[i] != '\0')
|
||||
{
|
||||
if (fname[i] == '/')
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Adds a file to the filesystem
|
||||
void AddFileToFS(FileSystemStruct* fs, char* fname)
|
||||
// TODO: Fix implementation to add starting at Inode 0
|
||||
void AddFileToFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
struct stat statBuffer;
|
||||
ino_t inodeNumber = GetFreeInodeNumber(fs->fbl.freeList);
|
||||
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);
|
||||
// strcpy(fs->inodes[inodeNumber].info.filePath, fname);
|
||||
// stat(fname, &statBuffer);
|
||||
// fs->inodes[inodeNumber].info.fileSize = statBuffer.st_size;
|
||||
// int fd = open(fname, O_RDONLY);
|
||||
// if (fd < 0)
|
||||
// {
|
||||
// perror(fname);
|
||||
// exit(1);
|
||||
// }
|
||||
// read(fd, fs->inodes[inodeNumber].dataBlocks.byte, sizeof(BlockStruct));
|
||||
// close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
// Depreciated due to new structure method
|
||||
void _RecursiveAddFS_(FileSystem* fs, char* fname)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove a file from the filesystem
|
||||
void RemoveFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
// TODO: Fix function so that it adds directories, then the file after
|
||||
void RemoveFileFromFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Extract a file from the filesystem
|
||||
void ExtractFileFromFS(FileSystemStruct* fs, char* fname)
|
||||
// TODO: Fix function so that it adds directories, then the file after
|
||||
void ExtractFileFromFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user