Skip to content
Permalink
Browse files

this is now the >4k branch. Just implemented modifications in get_data()

  • Loading branch information
joshspicer committed Dec 5, 2017
1 parent 3166cf1 commit 296fc26e81a210e1b73f809f370dfe881b56f6dd
Showing with 164 additions and 31 deletions.
  1. BIN data.nufs
  2. +22 −0 node.c
  3. +4 −0 node.h
  4. BIN nufs
  5. +8 −1 nufs.c
  6. +34 −0 storage.c
  7. +86 −23 test.log
  8. +10 −7 util.h
BIN +0 Bytes (100%) data.nufs
Binary file not shown.
22 node.c
@@ -44,6 +44,15 @@ add_node(const char *completePath, int mode, int xtra, int which_iNode) {
// Let the iNode know which node it is in the bitmap.
// Useful for removing.
newNode->nodeID = which_iNode;


// Set all additional blocks to -1, meaning they aren't in use.
for (int i = 0; i < 9;i++) {
newNode->additionalBlocks[i] = -1;
}

printf("Addtional Blocks for <%s>\n",completePath);
print_additionalBlocks(newNode);
}

// ---------------------------------------------------------------------------- //
@@ -139,3 +148,16 @@ print_node(pnode *node) {
printf("node{null}\n");
}
}

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

void print_additionalBlocks(pnode *node) {
if (node) {
printf("\nadditionalBlocks{\nA: %d, B: %d, C: %d,\n D: %d, E: %d, F: %d,\n G: %d, H: %d, I: %d}\n\n",
node->additionalBlocks[0],node->additionalBlocks[1],node->additionalBlocks[2],
node->additionalBlocks[3],node->additionalBlocks[4],node->additionalBlocks[5],
node->additionalBlocks[6],node->additionalBlocks[7], node->additionalBlocks[8]);
} else {
printf("node{null}\n");
}
}
4 node.h
@@ -25,6 +25,8 @@ typedef struct inode {
int blockID; // ID of data block this node is referencing to store data.
int nodeID; // The ID of THIS node (in the associated bitmap).

int additionalBlocks[9]; // Additional blocks for data > 4k

} pnode;

// ------- FUNCTIONS ------- //
@@ -35,6 +37,8 @@ void flip_iNode_bit(int which_iNode, int state); // 0 == off, 1 == on

void print_node(pnode *node);

void print_additionalBlocks(pnode *node);

int find_empty_inode_index(); // Returns the index of the first free iNode, or -1 if no empty inode.

const char *findName(const char *completePath);
BIN +696 Bytes (100%) nufs
Binary file not shown.
9 nufs.c
@@ -210,7 +210,9 @@ nufs_open(const char *path, struct fuse_file_info *fi) {
// Actually read data
int
nufs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {

printf("read(%s, %ld bytes, @%ld)\n", path, size, offset);

const char *data = get_data(path);

int len = strlen(data) + 1; // strlen(data) + 1
@@ -248,7 +250,12 @@ nufs_write(const char *path, const char *buf, size_t size, off_t offset,
memcpy(ptr, buf, size);
//int fd = fi->direct_io;

// TODO Change stat somehow??? (I don't get stat.)

// TODO ::: if you want to memcpy more than one page,
// recalculate ptr after copying 2048 bytes and then
// memcpy again!!!!!!!!!!
/// TODO :: size/4096 to find out which additionalBlock you need to fill!!!


// Set node's size to size of this file.
node->size = size;
@@ -18,6 +18,18 @@ storage_init(const char *path) {
superBlock_init(path);
}

// ----------------------------------------------------------------------------- //
char*
concatStrings(const char *string1, const char *string2) {
char *newStr =
malloc(strlen(string1) + strlen(string2) + 1);

strcpy(newStr, string1);
strcat(newStr, string2);

return newStr;
}

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


@@ -81,6 +93,7 @@ get_stat(const char *path, struct stat *st) {
// Get the data stored in the data block of the given Path.
const char *
get_data(const char *path) {

pnode *node = get_file_data(path);

if (!node) {
@@ -100,5 +113,26 @@ get_data(const char *path) {
return 0; // TODO error codes
}


// -- CODE BELOW HERE SUPPORTS DATA OVER 4K --
int sizeRemaining = node->size - 4096;

while (sizeRemaining > 0) {
printf("Inside over 4K get_data() block for <%s> ", node->path);
printf("Size Remaining: %d\n", sizeRemaining);
// Use the current Size to determine which additional block.
int idx = node->size - sizeRemaining;

// Fetch the data at the additional block.
void *tmp = data_block_ptr_at_index(node->additionalBlocks[idx]);
const char *tmpString = ((const char *) tmp);

// Append entire contents (4K) of tmpString to blockPtr.
blockPtr = concatStrings(((const char *) blockPtr), tmpString);

sizeRemaining -= 4096;
}


return ((const char *) blockPtr);
}
109 test.log
@@ -1,15 +1,24 @@
make[1]: Entering directory '/home/josh/Desktop/challenge03'
mkdir -p mnt || true
./nufs -s -f mnt data.nufs
Start of DataBlock: 71372
NUFS Size - start_dataBlocks: 977204
Num Blocks: 238
Start of DataBlock: 100172
NUFS Size - start_dataBlocks: 948404
Num Blocks: 231
BLOCK 0 FOUND FOR INODE
Addtional Blocks for </>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 40755, size: 0, xtra: 145, path: /, name: , blockID: 0, InodeID: 0}
access(/, 0004)
getattr(/.xdg-volume-info)
getattr(/)
File </> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
getattr(/autorun.inf)
getattr(/.Trash)
getattr(/.Trash-1000)
@@ -109,6 +118,13 @@ File </> FOUND in get_file_data
getattr(/one.txt)
mknod(/one.txt, 100664)
BLOCK 1 FOUND FOR INODE
Addtional Blocks for </one.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100664, size: 0, xtra: 0, path: /one.txt, name: one.txt, blockID: 1, InodeID: 1}
getattr(/one.txt)
File </one.txt> FOUND in get_file_data
@@ -117,8 +133,6 @@ write(/one.txt, 11 bytes, 0)
File </one.txt> FOUND in get_file_data
getattr(/one.txt)
File </one.txt> FOUND in get_file_data
getattr(/one.txt)
File </one.txt> FOUND in get_file_data
open(/one.txt)
read(/one.txt, 4096 bytes, @0)
File </one.txt> FOUND in get_file_data
@@ -127,6 +141,13 @@ File </one.txt> FOUND in get_file_data
getattr(/two.txt)
mknod(/two.txt, 100664)
BLOCK 2 FOUND FOR INODE
Addtional Blocks for </two.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100664, size: 0, xtra: 0, path: /two.txt, name: two.txt, blockID: 2, InodeID: 2}
getattr(/two.txt)
File </two.txt> FOUND in get_file_data
@@ -149,9 +170,20 @@ File </two.txt> FOUND in get_file_data
getattr(/2k.txt)
mknod(/2k.txt, 100664)
BLOCK 3 FOUND FOR INODE
node{mode: 100664, size: 0, xtra: 0, path: /2k.txt, name: 2k.txt, blockID: 3, InodeID: 3}
Addtional Blocks for </2k.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100664, size: 0, xtra: 0, pathmake[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
: /2k.txt, name: 2k.txt, blockID: 3, InodeID: 3}
getattr(/2k.txt)
File </2k.txt> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
open(/2k.txt)
write(/2k.txt, 2001 bytes, 0)
File </2k.txt> FOUND in get_file_data
@@ -164,26 +196,29 @@ getattr(/2k.txt)
File </2k.txt> FOUND in get_file_data
open(/2k.txt)
read(/2k.txt, 4096 bytes, @0)
File </2k.txt> FOUND in gmake[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
et_file_data
getattr(/)
File </> FOUND in get_file_data
File </2k.txt> FOUND in get_file_data
make[1]: Leaving directory '/home/josh/Desktop/challenge03'
make[1]: Leaving directory '/home/josh/Desktop/challenge03'
make[1]: Entering directory '/home/josh/Desktop/challenge03'
mkdir -p mnt || true
./nufs -s -f mnt data.nufs
Start of DataBlock: 71372
NUFS Size - start_dataBlocks: 977204
Num Blocks: 238
Start of DataBlock: 100172
NUFS Size - start_dataBlocks: 948404
Num Blocks: 231
BLOCK 4 FOUND FOR INODE
Addtional Blocks for </>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 40755, size: 0, xtra: 145, path: /, name: , blockID: 4, InodeID: 0}
access(/, 0004)
getattr(/.xdg-volume-info)
getattr(/autorun.inf)
getattr(/)
File </> FOUND in get_file_data
getattr(/autorun.inf)
getattr(/.Trash)
getattr(/.Trash-1000)
readdir(/)
@@ -319,8 +354,6 @@ File </two.txt> FOUND in get_file_data
File </2k.txt> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
readdir(/)
File </> FOUND in get_file_data
File </one.txt> FOUND in get_file_data
@@ -401,6 +434,13 @@ Linking target: </abc.txt> to new file </def.txt>.
File </abc.txt> FOUND in get_file_data
mknod(/def.txt, 100000)
BLOCK 1 FOUND FOR INODE
Addtional Blocks for </def.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100000, size: 0, xtra: 0, path: /def.txt, name: def.txt, blockID: 1, InodeID: 1}
getattr(/def.txt)
File </def.txt> FOUND in get_file_data
@@ -424,6 +464,13 @@ File </def.txt> FOUND in get_file_data
getattr(/foo)
mkdir(/foo) with mode <509>
BLOCK 2 FOUND FOR INODE
Addtional Blocks for </foo>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

getattr(/foo)
File </foo> FOUND in get_file_data
getattr(/foo/abc.txt)
@@ -432,6 +479,13 @@ open(/def.txt)
getattr(/foo/abc.txt)
mknod(/foo/abc.txt, 100000)
BLOCK 5 FOUND FOR INODE
Addtional Blocks for </foo/abc.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100000, size: 0, xtra: 0, path: /foo/abc.txt, name: foo/abc.txt, blockID: 5, InodeID: 4}
getattr(/foo/abc.txt)
File </foo/abc.txt> FOUND in get_file_data
@@ -442,24 +496,31 @@ write(/foo/abc.txt, 11 bytes, 0)
File </foo/abc.txt> FOUND in get_file_data
open(/foo/abc.txt)
getattr(/foo/abc.txt)
File </foo/abc.txt> FOUND in get_file_data
File </foo/abc.txt> FOUND in get_filemake[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
_data
getattr(/)
File </> FOUND in get_file_data
read(/foo/abc.txt, 4096 bytes, @0)
File </foo/abc.txt> FOUND in get_file_data
getattr(/foo/abc.txt)
File </foo/abc.txt> FOUND in get_file_data
getattr(/40k.txt)
mknod(/40k.txt, 100664)
BLOCK 6 FOUND FOR INODE
Addtional Blocks for </40k.txt>

additionalBlocks{
A: -1, B: -1, C: -1,
D: -1, E: -1, F: -1,
G: -1, H: -1, I: -1}

node{mode: 100664, size: 0, xtra: 0, path: /40k.txt, name: 40k.txt, blockID: 6, InodeID: 5}
getattr(/40k.txt)
File </40k.txt> FOUND in get_file_data
open(/40k.txt)
write(/40k.txt, 4096 bytes, 0)
File </40make[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
k.txt> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
File </40k.txt> FOUND in get_file_data
open(/40k.txt)
getattr(/40k.txt)
File </40k.txt> FOUND in get_file_data
@@ -472,5 +533,7 @@ File </40k.txt> FOUND in get_file_data
open(/40k.txt)
read(/40k.txt, 4096 bytes, @4096)
File </40k.txt> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
make[1]: Leaving directory '/home/josh/Desktop/challenge03'
make[1]: Leaving directory '/home/josh/Desktop/challenge03'
17 util.h
@@ -19,13 +19,16 @@ max(int x, int y) {
return (x > y) ? x : y;
}

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

static int
clamp(int x, int v0, int v1) {

0 comments on commit 296fc26

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