Extraction works now, but it broke listing the directories for some reason
This commit is contained in:
parent
6a7068d22a
commit
4444defd27
@ -9,19 +9,15 @@
|
||||
#include "fsactions.h"
|
||||
#include "fusestructs.h"
|
||||
|
||||
/* Things to set for directory:
|
||||
* Name, isValid, inode, isDirectory=1
|
||||
*/
|
||||
|
||||
/* Things to set for file:
|
||||
* Name, size, isValid, inode, isDirectory=0
|
||||
*/
|
||||
|
||||
// Adds a file to the filesystem
|
||||
// TODO: Fix implementation to add starting at Inode 0
|
||||
void AddFileToFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
int inputfd = open(fname, O_RDONLY);
|
||||
if (inputfd == -1)
|
||||
{
|
||||
fprintf(stderr, "Failed opening input file\n");
|
||||
exit(1);
|
||||
}
|
||||
struct stat tempstat;
|
||||
ino_t currentInode = 0;
|
||||
ino_t newInode;
|
||||
@ -61,6 +57,7 @@ void AddFileToFS(FileSystem* fs, char* fname)
|
||||
strcpy(fs->inodes[currentInode].blocks[newDirectBlock].name, fname);
|
||||
fs->inodes[currentInode].blocks[newDirectBlock].inode = newInode;
|
||||
read(inputfd, &(fs->dataBlocks[newInode].byte), tempstat.st_size);
|
||||
close(inputfd);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,10 +117,45 @@ int _RemoveFileFromFS_(FileSystem* fs, ino_t inodeNumber, char* fname)
|
||||
}
|
||||
|
||||
// Extract a file from the filesystem
|
||||
// TODO: Fix function so that it adds directories, then the file after
|
||||
void ExtractFileFromFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
|
||||
|
||||
ino_t currentInode = 0;
|
||||
ino_t newInode;
|
||||
char* tempname;
|
||||
// Get first directory, labelled by 0 to splitLocation-1,
|
||||
// assuming splitLocation not 0;
|
||||
int splitLocation = FindNextDirectory(fname);
|
||||
if (splitLocation == 0)
|
||||
{
|
||||
fname = fname + 1;
|
||||
splitLocation = FindNextDirectory(fname);
|
||||
}
|
||||
// While there is a '/', make a new inode out of left and keep right side
|
||||
while (splitLocation > -1)
|
||||
{
|
||||
tempname = strndup(fname, splitLocation);
|
||||
newInode = FindDirectory(fs->inodes[currentInode], tempname);
|
||||
if (newInode == -1)
|
||||
{
|
||||
fprintf(stderr, "Error extracting file due to path\n");
|
||||
exit(1);
|
||||
}
|
||||
currentInode = newInode;
|
||||
fname = fname + splitLocation + 1;
|
||||
splitLocation = FindNextDirectory(fname);
|
||||
}
|
||||
for (int i = 0; i < DEFAULTINODEMAX; i++)
|
||||
{
|
||||
if (strcmp(fs->inodes[currentInode].blocks[i].name, fname) == 0)
|
||||
{
|
||||
newInode = fs->inodes[currentInode].blocks[i].inode;
|
||||
off_t size = fs->inodes[currentInode].blocks[i].size;
|
||||
write(STDOUT_FILENO, fs->dataBlocks[newInode].byte, size);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
1
test/files/output.txt
Normal file
1
test/files/output.txt
Normal file
@ -0,0 +1 @@
|
||||
wind
|
Loading…
Reference in New Issue
Block a user