Skip to content
Permalink
Browse files

before merging hardlinks with maddie

  • Loading branch information
joshspicer committed Dec 5, 2017
1 parent 3d8acb1 commit bebddb634d30271171c6bccd8de3502530666ad7
Showing with 111 additions and 177 deletions.
  1. BIN data.nufs
  2. +1 −9 datablock.c
  3. +0 −1 mnt/a.txt
  4. +0 −1 mnt/dfdsfd.txt
  5. 0 mnt/g.txt
  6. +2 −2 node.c
  7. +10 −23 node.h
  8. BIN nufs
  9. +9 −32 nufs.c
  10. +1 −10 superblock.c
  11. +65 −23 test.log
  12. BIN upload/ch03.tar.gz
  13. +1 −9 upload/ch03/datablock.c
  14. +2 −2 upload/ch03/node.c
  15. +10 −23 upload/ch03/node.h
  16. +9 −32 upload/ch03/nufs.c
  17. +1 −10 upload/ch03/superblock.c
BIN +0 Bytes (100%) data.nufs
Binary file not shown.
@@ -1,5 +1,5 @@
//
// Created by Joshua Spicer on 12/3/17.
// Created by Joshua Spicer on 12/3/17. .
//

#include "datablock.h"
@@ -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;
}

// ---------------------------------------------------------------------------- //
@@ -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;
}
}
}
}


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


This file was deleted.

This file was deleted.

No changes.
4 node.c
@@ -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");
}
33 node.h
@@ -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);

BIN +368 Bytes (100%) nufs
Binary file not shown.
41 nufs.c
@@ -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;
@@ -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);
@@ -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();
@@ -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);
@@ -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;
@@ -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.
}


@@ -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);
@@ -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
@@ -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");



}


0 comments on commit bebddb6

Please sign in to comment.
You can’t perform that action at this time.