Skip to content

Commit

Permalink
load sould be done
Browse files Browse the repository at this point in the history
  • Loading branch information
Azoam committed Apr 6, 2018
1 parent b443567 commit 31f4760
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 19 deletions.
68 changes: 52 additions & 16 deletions Asst3/src/sfs.c
Expand Up @@ -26,7 +26,7 @@
#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
#define MAX_INODES 300
#define MAX_INODES 1530
#include "log.h"
#include "util.h"
///////////////////////////////////////////////////////////////////////
Expand All @@ -50,32 +50,34 @@ int ceil_bytes(int numBytes)
//Loaf the File System from Disk
int loadFS()
{
int totalSize = ceil_bytes(MAX_INODES * BLOCK_SIZE + 1 + 4 + 4);
char buffer[totalSize];
int ret = block_read(totalSize,buffer);
else if(ret < 0)
char buffer[BLOCK_SIZE];
int init = block_read(0,buffer);
if(init < 0)
{
return ret;
return init;
}
FT = malloc(osizeof(FileTable*));
if(ret == 0)
FT = malloc(sizeof(FileTable*));
if(init == 0)
{
FT->num_free_inodes = totalsize/BLOCK_SIZE;
FT->size = totalsize/BLOCK_SIZE;
FT->num_free_inodes = MAX_INODES;
FT->size = MAX_INODES;
}
else
{
FT->num_free_inodes = (int)buffer[1];
FT->size = (int)buffer[5];
ret = block_read(BLOCK_SIZE,buffer);
}
FT->files = malloc(FT->num_free_inodes*sizeof(FileTable*));
FT->files = malloc(FT->num_free_inodes*sizeof(Inode*));
int i;
for(i=0; FT->num_free_inodes;i++)
int blockCount = 0;
int blockCurr = 1;
for(i=0; FT->size;i++)
{
Inode * file = FT->files[i];
FT->files[i]=malloc(sizeof(Inode));
FT->files[i]->fd = i*BLOCK_SIZE;
if(ret == 0)
file=malloc(sizeof(Inode));
file -> fd = i*BLOCK_SIZE;
if(init == 0)
{
file->permissions = -1;
file->file_type = 0;
Expand All @@ -86,7 +88,41 @@ int loadFS()
}
else
{

Inode * temp = (struct dummyInode)buffer[blockCount*sizeof(struct dummyInode)];
file->permissions = temp->permissions;
file->file_type = temp->file_type;
file->spaceleft = temp->spaceleft;
file->next = temp-> is_init = temp->is_init

blockCount+=1;
if(blockCount == (int)(BLOCK_SIZE/sizeof(struct dummyInode))+1)
{
blockCount = 0;
blockCurr++;
ret = block_read(BLOCK_SIZE*blockCurr,buffer);
if(ret == 0 || ret < 0)
{
return -99;
}
}
}
}
//blockCurr doesnt increment on the last one to move on to the file paths so we increment after the for loop
blockCurr++;
ret = block_read(BLOCK_SIZE*blockCurr,buffer);
//Going through path blocks now
for(i = 0; FT->size;i++)
{
Inode * file = FT->file[i];
if(init != 0)
{
mempcy(file->path,buffer,BLOCK_SIZE);
blockCurr++;
ret = block_read(BLOCK_SIZE*blockCurr,buffer);
if(ret == 0 || ret < 0)
{
return -99;
}
}
}
}
Expand Down
37 changes: 34 additions & 3 deletions Asst3/src/util.h
Expand Up @@ -21,7 +21,7 @@ typedef struct Inode
char file_type;

//path
char *path;
char path[512];
//timestamp
time_t timestamp;
//above is what we only care about in the frist thing in the chain
Expand All @@ -34,8 +34,37 @@ typedef struct Inode
short linkcount;

}Inode;



typedef struct dummyInode
{

//we only care aboyt the positon for the first inode in the chain
int file_position;
int fd;
//permissions the file was created with
int permissions;
//permssions the file currently using
int file_mode;
//is this a file or folder
char file_type;
//path
//timestamp
time_t timestamp;
//above is what we only care about in the frist thing in the chain
//space left in INODE
short spaceleft;
//pointer to next inode in the chain
struct Inode * next;
struct Inode *prev;
bool is_init;
short linkcount;

}dummyInode;







/*
Expand All @@ -52,3 +81,5 @@ FileTable * FT;
Inode * getFileFD(int);
Inode * getFilePath(char*);
int fileSize(Inode *);
int loadFS();
int ceil_bytes(int);

0 comments on commit 31f4760

Please sign in to comment.