Skip to content

Commit

Permalink
maddie told you so
Browse files Browse the repository at this point in the history
  • Loading branch information
madisoncool committed Dec 2, 2017
1 parent 40b6ebc commit 79377ac
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
Binary file modified data.nufs
Binary file not shown.
Binary file modified nufs
Binary file not shown.
15 changes: 4 additions & 11 deletions nufs.c
Expand Up @@ -16,13 +16,6 @@
// Josh added this
#include "pages.h"

char* concat(const char *string1, const char *string2)
{
char *newStr = malloc(strlen(string1)+strlen(string2)+1);
strcpy(newStr, string1); strcat(newStr, string2);
return newStr;
}

// implementation for: man 2 access
// Checks if a file exists.
int
Expand Down Expand Up @@ -80,10 +73,10 @@ nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
void* currentPtr = ((void*)(GET_ptr_start_iNode_Table() + sizeof(pnode)*i));
pnode* current = ((pnode*)currentPtr);

if (!(streq(current->path, "/"))) {
printf("%s\n",current->path);
get_stat(concat("/","maddie.txt"), &st);
filler(buf, "maddie.txt", &st, 0);
if (!(streq(concat(current->path, current->fileName), "/"))) {
printf("path: %s; name: %s\n", current->path, current->fileName);
get_stat(concat(current->path, current->fileName), &st);
filler(buf, current->fileName, &st, 0);
}

// get_stat("/maddie.txt", &st);
Expand Down
11 changes: 6 additions & 5 deletions pages.c
Expand Up @@ -68,14 +68,14 @@ pages_init(const char* path)
printf("4stOffset: %d\n",start_dataBlocks);

// Test inserting Inode into thing TEMP
add_node("/",040755,25,145,0);
add_node("/", "", 040755,25,145,0);
flip_iNode_bit(0,1);
printf("Bit On: %d\n",*((int*)(GET_ptr_start_iNode_bitMap() + sizeof(int)*0)));
print_node((pnode*)(GET_ptr_start_iNode_Table() + sizeof(pnode)*0));
//TODO fix the weird bug where commenting out "addnode" above
// causes the last part of this print node to print garbage

add_node("/maddie.txt",S_IFREG,50,166,1);
add_node("/", "maddie.txt",S_IFREG,50,166,1);
flip_iNode_bit(1,1);
}

Expand All @@ -91,7 +91,7 @@ write_int_offset(int offset, int data) {
// }

void
add_node(const char* path,int mode, int size, int xtra, int which_iNode) {
add_node(const char* path, char* fileName, int mode, int size, int xtra, int which_iNode) {
//TODO add the data block array as an argument of this function and set.

void* locationToPlace =
Expand All @@ -102,6 +102,7 @@ add_node(const char* path,int mode, int size, int xtra, int which_iNode) {
newNode->size = size;
newNode->xtra = xtra;
newNode->path = path;
newNode->fileName = fileName;

printf("%s\n", "add node got to this point");
}
Expand Down Expand Up @@ -158,8 +159,8 @@ void
print_node(pnode* node)
{
if (node) {
printf("node{refs: %d, mode: %04o, size: %d, xtra: %d, path: %s}\n",
node->refs, node->mode, node->size, node->xtra, node->path);
printf("node{refs: %d, mode: %04o, size: %d, xtra: %d, path: %s, fileName: %d}\n",
node->refs, node->mode, node->size, node->xtra, node->path, node->fileName);
}
else {
printf("node{null}\n");
Expand Down
4 changes: 3 additions & 1 deletion pages.h
Expand Up @@ -11,6 +11,8 @@ typedef struct inode {

// Path of file
const char* path;
// File rename
char* fileName;

// IDs of all data blocks in use.
int blocksIDS[];
Expand Down Expand Up @@ -40,7 +42,7 @@ int pages_find_empty();
void print_node(pnode* node);

// Josh: My new methods
void add_node(const char* path, int mode, int size, int xtra, int which_iNode);
void add_node(const char* path, char* fileName, int mode, int size, int xtra, int which_iNode);
void flip_iNode_bit(int which_iNode, int state); // 0 == off, 1 == on

void write_int_offset(int offset, int data);
Expand Down
11 changes: 9 additions & 2 deletions storage.c
Expand Up @@ -64,6 +64,13 @@ streq(const char* aa, const char* bb)
return strcmp(aa, bb) == 0;
}

char* concat(const char *string1, const char *string2)
{
char *newStr = malloc(strlen(string1)+strlen(string2)+1);
strcpy(newStr, string1); strcat(newStr, string2);
return newStr;
}

static pnode*
get_file_data(const char* path) {

Expand All @@ -79,10 +86,10 @@ get_file_data(const char* path) {
void* currentPtr = ((void*)(GET_ptr_start_iNode_Table() + sizeof(pnode)*i));
pnode* current = ((pnode*)currentPtr);

printf("Current's Path: %s\n", current->path);
printf("Current's Path: %s\n", concat(current->path, current->fileName));
printf("Inputted Path: %s\n",path);

if (streq(path, current->path)) { //If this pnode's path is same.
if (streq(path, concat(current->path, current->fileName))) { //If this pnode's path is same.
printf("File <%s> FOUND in get_file_data\n", path);
return current;
}
Expand Down
3 changes: 3 additions & 0 deletions storage.h
Expand Up @@ -5,12 +5,15 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <bsd/string.h>
#include <stdlib.h>

void storage_init(const char* path);
int get_stat(const char* path, struct stat* st);
const char* get_data(const char* path);

int streq(const char* aa, const char* bb);

char* concat(const char *string1, const char *string2);


#endif

0 comments on commit 79377ac

Please sign in to comment.