-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBlocks.h
61 lines (45 loc) · 1.75 KB
/
Blocks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// CPSC 3500: Blocks that make up the filesystem
#ifndef BLOCKS_H
#define BLOCKS_H
// CONSTANTS
// Size of block - must be an even power of two
const int BLOCK_SIZE = 128;
// Number of blocks - set so a bitmap can fit in one block
const int NUM_BLOCKS = (BLOCK_SIZE * 8);
// Maximum filename size
const int MAX_FNAME_SIZE = 9;
// Maximum number of files in a directory
const int MAX_DIR_ENTRIES = ((BLOCK_SIZE - 8) / 12);
// Maximum number of blocks in a data file
const int MAX_DATA_BLOCKS = ((BLOCK_SIZE - 8) / 2);
// Maximum file size for a data file
const int MAX_FILE_SIZE = (MAX_DATA_BLOCKS * BLOCK_SIZE);
// Magic numbers - used to distinguish between directory blocks and inodes
const unsigned int DIR_MAGIC_NUM = 0xFFFFFFFF;
const unsigned int INODE_MAGIC_NUM = 0xFFFFFFFE;
// BLOCK TYPES
// Superblock - keeps track of which blocks are used in the filesystem.
// Block 0 is the only super block in the system.
struct superblock_t {
unsigned char bitmap[BLOCK_SIZE]; // bitmap of free blocks
};
// Directory block - represents a directory
struct dirblock_t {
unsigned int magic; // magic number, must be DIR_MAGIC_NUM
unsigned int num_entries; // number of files in directory
struct {
char name[MAX_FNAME_SIZE + 1]; // file name (extra space for null)
short block_num; // block number of file (0 - unused)
} dir_entries[MAX_DIR_ENTRIES]; // list of directory entries
};
// Inode - index node for a data file
struct inode_t {
unsigned int magic; // magic number, must be INODE_MAGIC_NUM
unsigned int size; // file size in bytes
short blocks[MAX_DATA_BLOCKS]; // array of direct indices to data blocks
};
// Data block - stores data for a data file
struct datablock_t {
char data[BLOCK_SIZE]; // data (BLOCK_SIZE bytes)
};
#endif