Skip to content

Commit

Permalink
before merging hardlinks with maddie
Browse files Browse the repository at this point in the history
  • Loading branch information
joshspicer committed Dec 5, 2017
1 parent 3d8acb1 commit bebddb6
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 177 deletions.
Binary file modified data.nufs
Binary file not shown.
10 changes: 1 addition & 9 deletions datablock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Created by Joshua Spicer on 12/3/17.
// Created by Joshua Spicer on 12/3/17. .
//

#include "datablock.h"
Expand All @@ -10,10 +10,7 @@ void flip_data_block_bit(int which_block, int state) {
assert(state == 0 || state == 1);

void *targetPtr = GET_ptr_start_dataBlock_bitMap() + sizeof(int) * which_block;
//printf("TargetPointer: %d\n", targetPtr);
//*((int*)(targetPtr)) = 1;
*((int *) targetPtr) = state;
//*((int*)targetPtr) = 4;
}

// ---------------------------------------------------------------------------- //
Expand All @@ -31,23 +28,18 @@ void
correctSizeForLinkedBlocks(int givenBlockID, int size) {

for (int i = 0; i < GET_NUMBER_OF_INODES();i++) {
printf("%s\n","1");
// Node exists!
if(*((int *) (GET_ptr_start_iNode_bitMap() + sizeof(int) * i)) == 1) {
printf("%s\n","2");
pnode* tmp = ((pnode *) (GET_ptr_start_iNode_Table() + sizeof(pnode) * i));
printf("%s\n","3");
// If this node is referring to "givenBlockID"
if (tmp->blockID == givenBlockID) {
printf("%s\n","4");
// Set the size to that size.
tmp->size = size;
}
}
}
}


// ---------------------------------------------------------------------------- //


Expand Down
1 change: 0 additions & 1 deletion mnt/a.txt

This file was deleted.

1 change: 0 additions & 1 deletion mnt/dfdsfd.txt

This file was deleted.

Empty file removed mnt/g.txt
Empty file.
4 changes: 2 additions & 2 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ find_empty_inode_index() {
void
print_node(pnode *node) {
if (node) {
printf("node{refs: %d, mode: %04o, size: %d, xtra: %d, path: %s, name: %s, blockID: %d, InodeID: %d}\n",
node->refs, node->mode, node->size, node->xtra, node->path, node->name, node->blockID, node->nodeID);
printf("node{mode: %04o, size: %d, xtra: %d, path: %s, name: %s, blockID: %d, InodeID: %d}\n",
node->mode, node->size, node->xtra, node->path, node->name, node->blockID, node->nodeID);
} else {
printf("node{null}\n");
}
Expand Down
33 changes: 10 additions & 23 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,21 @@
#include "superblock.h"


// Header file for helpful methods related to creating and modifying NODES (as an atomic unit).

// Header file for helpful methods related to
// creating and modifying NODES (as an atomic unit).
typedef struct inode {
int refs; // reference count
int mode; // permission & type
int size; // bytes for file
int xtra; // more stuff can go here

// Path of file
//const char* path;
char path[32];
// File rename
//const char* name;
char name[32];

// ID of data block this node is referencing to store data.
// It's simply an index
int blockID;

// Let the iNode know which node it is in the bitmap.
// Useful for removing.
int nodeID;


int mode; // permission & type
int size; // bytes for file
int xtra; // more stuff can go here
char path[32]; // full file path
char name[32]; // File name (last part of path).
int blockID; // ID of data block this node is referencing to store data.
int nodeID; // The ID of THIS node (in the associated bitmap).

} pnode;

// ------- FUNCTIONS -------
// ------- FUNCTIONS ------- //

void add_node(const char *fullPath, int mode, int xtra, int which_iNode);

Expand Down
Binary file modified nufs
Binary file not shown.
41 changes: 9 additions & 32 deletions nufs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ int
nufs_getattr(const char *path, struct stat *st) {
printf("getattr(%s)\n", path);

int rv = get_stat(path, st);
printf("Path: <%s>. Error code for getattr: %d\n",path,rv); //REMOVE
//printf("STAT numHardLinks for %s is %d \n", path,st->st_nlink); //REMOVE
int rv = get_stat(path, st); //All the work is done in get_stat.

if (rv == -1) {
//return 0;
Expand Down Expand Up @@ -75,7 +73,8 @@ nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,

if (!(streq(current->path, "/"))) {

//printf("CUR_PATH: %s, NODE PRECEEDING: %s\n",path, findPreceedingPath(current->path));
//printf("CUR_PATH: %s, NODE PRECEEDING:
//%s\n",path, findPreceedingPath(current->path));

get_stat(current->path, &st);
filler(buf, current->name, &st, 0);
Expand All @@ -93,9 +92,6 @@ nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
int
nufs_mknod(const char *path, mode_t mode, dev_t rdev) {

//open(path, O_CREAT, mode); --- maybe for mode do S_IRWXU | mode
//link()

printf("mknod(%s, %04o)\n", path, mode);

int index = find_empty_inode_index();
Expand Down Expand Up @@ -266,7 +262,7 @@ nufs_write(const char *path, const char *buf, size_t size, off_t offset,
// Update the timestamps on a file or directory.
int
nufs_utimens(const char *path, const struct timespec ts[2]) {
// //int rv = storage_set_time(path, ts);
//int rv = storage_set_time(path, ts); TODO TODO TODO
int rv = -1;
printf("utimens(%s, [%ld, %ld; %ld %ld]) -> %d\n",
path, ts[0].tv_sec, ts[0].tv_nsec, ts[1].tv_sec, ts[1].tv_nsec, rv);
Expand All @@ -278,18 +274,11 @@ nufs_utimens(const char *path, const struct timespec ts[2]) {

// TODO test. Seeing if I can add in additional fuse struct functions
int
josh_nufs_link(const char *target, const char *linkName) {
printf("%s\n","--------------------LINK CALLED------------------" );
nufs_link(const char *target, const char *linkName) {
printf("Linking target: <%s> to new file <%s>. \n",target, linkName);

// Get the target Node.
pnode* targetNode = get_file_data(target);
printf("%s\n","TARGET NODE: "); //REMOVE
print_node(targetNode); //REMOVE

// Create a new inode with "linkName"
// int idx = find_empty_inode_index();
// add_node(linkName, S_IFREG, 640, 5); //TODO change back from 5 to idx
// flip_iNode_bit(5,1); //same here.

nufs_mknod(linkName, S_IFREG, 0);
struct stat st;
Expand All @@ -298,23 +287,11 @@ josh_nufs_link(const char *target, const char *linkName) {
// Get that newly created inode.
pnode* linkedNODE = get_file_data(linkName);

printf("%s\n","NEW LINK NODE:"); //REMOVE
print_node(linkedNODE); //REMOVE

// Set the linkedNode's data block ID to that of target Block.

printf("BEFORE: targetBlockID: %d, linkedNodeBlockID: %d\n",targetNode->blockID,linkedNODE->blockID); //REMOVE
linkedNODE->blockID = targetNode->blockID;
linkedNODE->size = targetNode->size;

// targetNode->blockID = linkedNode->blockID;
// nufs_getattr(target,&st);
// nufs_getattr(linkName,&st);

printf("AFTER: targetBlockID: %d, linkedNodeBlockID: %d\n",targetNode->blockID,linkedNODE->blockID); //REMOVE


return 0; //TODO error checking and returning error codes.
return 0; // ln error checks for us.
}


Expand All @@ -336,15 +313,15 @@ nufs_init_ops(struct fuse_operations *ops) {
ops->write = nufs_write;
ops->utimens = nufs_utimens;

ops->link = josh_nufs_link;
ops->link = nufs_link;

};

struct fuse_operations nufs_ops;

int
main(int argc, char *argv[]) {
assert(argc > 2 && argc < 1000); //1000 was 6
assert(argc > 2 && argc < 6);
storage_init(argv[--argc]);
nufs_init_ops(&nufs_ops);
return fuse_main(argc, argv, &nufs_ops, NULL);
Expand Down
11 changes: 1 addition & 10 deletions superblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ superBlock_init(const char *path)
start_dataBlocks = start_iNode_Table
+ NUMBER_OF_INODES * sizeof(pnode);


// Write offset to start of inode bitmap in the superblock
write_int_offset(0, start_iNode_bitMap);
// Write offset to start of data block bitmap in the superblock
Expand All @@ -53,18 +54,8 @@ superBlock_init(const char *path)
flip_iNode_bit(0, 1);
print_node((pnode *) (GET_ptr_start_iNode_Table() + sizeof(pnode) * 0));


// // TODO TEST ADDING iNodes
// add_node("/aaa.txt",S_IFREG | S_IRWXU,55,1);
// flip_iNode_bit(1,1);
//
// add_node("/bbb.txt",S_IFREG | S_IRWXU,55,2);
// flip_iNode_bit(2,1);
//
// josh_nufs_link("/aaa.txt","/ccc.txt");



}


Expand Down
Loading

0 comments on commit bebddb6

Please sign in to comment.