Skip to content
Permalink
Browse files

constants for max inode and blocks are much bigger now

  • Loading branch information
joshspicer committed Dec 5, 2017
1 parent bebddb6 commit 3166cf1796f6977643a9be22c9f6d155bd4e95c1
Showing with 57 additions and 37 deletions.
  1. BIN data.nufs
  2. +15 −3 datablock.c
  3. +2 −9 node.c
  4. BIN nufs
  5. +12 −3 superblock.c
  6. +28 −22 test.log
BIN +0 Bytes (100%) data.nufs
Binary file not shown.
@@ -42,6 +42,18 @@ correctSizeForLinkedBlocks(int givenBlockID, int size) {

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



// TODO: implement find_empty_block_index() and replace my other stuff with it
// Finds the next empty data block, and returns that index.
// ALSO FLIPS THE BIT MAP
int
find_empty_block_index() {
for (int i = 0; i < GET_NUMBER_OF_DATABLOCKS(); i++) {

// check block bitmap. If value isn't one, then that block isn't active.
if (*((int *) (GET_ptr_start_dataBlock_bitMap() + sizeof(int) * i)) != 1) {
flip_data_block_bit(i, 1);
return i;
}
}
// If there's no empty slot, return -1
return -1;
}
11 node.c
@@ -24,19 +24,12 @@ add_node(const char *completePath, int mode, int xtra, int which_iNode) {
// TODO calculate how many blocks we can allot with our superblock (1MB limit)
// so that we don't go over.

//int MAX_BLOCKS = 10; //FIXME

// Keep searching for next available block according to bitmap
int firstAvailableBlockIdx = -1;
for (int i = 0; i < GET_NUMBER_OF_DATABLOCKS(); i++) {
if (*((int *) (GET_ptr_start_iNode_bitMap() + sizeof(int) * i)) == 0) {
firstAvailableBlockIdx = i;
break;
}
}
int firstAvailableBlockIdx = find_empty_block_index();

if (firstAvailableBlockIdx != -1) {
flip_data_block_bit(firstAvailableBlockIdx, 1);
//flip_data_block_bit(firstAvailableBlockIdx, 1); // ^^ find_empty_block_index does this.
newNode->blockID = firstAvailableBlockIdx;
printf("BLOCK %d FOUND FOR INODE\n", firstAvailableBlockIdx);

BIN +144 Bytes (100%) nufs
Binary file not shown.
@@ -10,7 +10,7 @@
#include "superblock.h"

const int NUFS_SIZE = 1024 * 1024; // 1MB
const int PAGE_COUNT = 256;


void
superBlock_init(const char *path)
@@ -28,8 +28,10 @@ superBlock_init(const char *path)
// --- CREATE SUPERBLOCK ASSIGNING OFFSETS ---
// Start location of iNode
SUPER_SIZE = 20;
NUMBER_OF_INODES = 8;
NUMBER_OF_DATABLOCKS = 10;
NUMBER_OF_INODES = 800;
NUMBER_OF_DATABLOCKS = 238;

//TODO calculate how much space we have for 4k data blocks, and make that many!

start_iNode_bitMap = SUPER_SIZE;
start_dataBlock_bitMap = start_iNode_bitMap
@@ -39,6 +41,13 @@ superBlock_init(const char *path)
start_dataBlocks = start_iNode_Table
+ NUMBER_OF_INODES * sizeof(pnode);

// Calculate how many Data blocks we have space for.
printf("Start of DataBlock: %d\n", start_dataBlocks);
int MaxSizeOfDataSection = NUFS_SIZE - start_dataBlocks;
printf("NUFS Size - start_dataBlocks: %d\n", MaxSizeOfDataSection);
int numBlocksFloor = MaxSizeOfDataSection / 4096;
printf("Num Blocks: %d\n",numBlocksFloor );


// Write offset to start of inode bitmap in the superblock
write_int_offset(0, start_iNode_bitMap);
@@ -1,8 +1,9 @@
make[1]: Entering directory '/home/josh/Desktop/challenge03'
mkdir -p mnt || true
./nufs -s -f mnt data.nufs
make[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
Start of DataBlock: 71372
NUFS Size - start_dataBlocks: 977204
Num Blocks: 238
BLOCK 0 FOUND FOR INODE
node{mode: 40755, size: 0, xtra: 145, path: /, name: , blockID: 0, InodeID: 0}
access(/, 0004)
@@ -105,28 +106,28 @@ File </> FOUND in get_file_data
getattr(/autorun.inf)
getattr(/)
File </> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
getattr(/one.txt)
mknod(/one.txt, 100664)
BLOCK 2 FOUND FOR INODE
node{mode: 100664, size: 0, xtra: 0, path: /one.txt, name: one.txt, blockID: 2, InodeID: 1}
BLOCK 1 FOUND FOR INODE
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
open(/one.txt)
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
getattr(/one.txt)
File </one.txt> FOUND in get_file_data
getattr(/two.txt)
mknod(/two.txt, 100664)
BLOCK 3 FOUND FOR INODE
node{mode: 100664, size: 0, xtra: 0, path: /two.txt, name: two.txt, blockID: 3, InodeID: 2}
BLOCK 2 FOUND FOR INODE
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
open(/two.txt)
@@ -147,8 +148,8 @@ File </one.txt> FOUND in get_file_data
File </two.txt> FOUND in get_file_data
getattr(/2k.txt)
mknod(/2k.txt, 100664)
BLOCK 4 FOUND FOR INODE
node{mode: 100664, size: 0, xtra: 0, path: /2k.txt, name: 2k.txt, blockID: 4, InodeID: 3}
BLOCK 3 FOUND FOR INODE
node{mode: 100664, size: 0, xtra: 0, path: /2k.txt, name: 2k.txt, blockID: 3, InodeID: 3}
getattr(/2k.txt)
File </2k.txt> FOUND in get_file_data
open(/2k.txt)
@@ -163,21 +164,26 @@ 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 get_file_data
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
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
BLOCK 4 FOUND FOR INODE
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(/)
@@ -313,15 +319,15 @@ 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
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
@@ -394,8 +400,8 @@ getattr(/def.txt)
Linking target: </abc.txt> to new file </def.txt>.
File </abc.txt> FOUND in get_file_data
mknod(/def.txt, 100000)
BLOCK 4 FOUND FOR INODE
node{mode: 100000, size: 0, xtra: 0, path: /def.txt, name: def.txt, blockID: 4, InodeID: 1}
BLOCK 1 FOUND FOR INODE
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
File </def.txt> FOUND in get_file_data
@@ -417,7 +423,7 @@ getattr(/def.txt)
File </def.txt> FOUND in get_file_data
getattr(/foo)
mkdir(/foo) with mode <509>
BLOCK 4 FOUND FOR INODE
BLOCK 2 FOUND FOR INODE
getattr(/foo)
File </foo> FOUND in get_file_data
getattr(/foo/abc.txt)
@@ -449,14 +455,14 @@ getattr(/40k.txt)
File </40k.txt> FOUND in get_file_data
open(/40k.txt)
write(/40k.txt, 4096 bytes, 0)
File </40k.txt> FOUND in get_file_data
open(/40k.txt)
getattr(/40k.txt)
File </40k.txt> make[1]: Entering directory '/home/josh/Desktop/challenge03'
File </40make[1]: Entering directory '/home/josh/Desktop/challenge03'
fusermount -u mnt || true
FOUND in get_file_data
k.txt> FOUND in get_file_data
getattr(/)
File </> FOUND in get_file_data
open(/40k.txt)
getattr(/40k.txt)
File </40k.txt> FOUND in get_file_data
read(/40k.txt, 4096 bytes, @0)
File </40k.txt> FOUND in get_file_data
read(/40k.txt, 4096 bytes, @4096)

0 comments on commit 3166cf1

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