-
Notifications
You must be signed in to change notification settings - Fork 0
/
myfs.h
100 lines (81 loc) · 2.35 KB
/
myfs.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef __MYFS_H
#define __MYFS_H
#include <stdlib.h>
#include <string.h>
enum mode { READ, WRITE, APPEND, READ_WRITE };
typedef struct inode{
int isDir;
int size;
int data_blocks[4];
char *sing_block;
char *double_block;
} inode;
//for simplicity assuming that a dir can store maximum of 10 files
typedef struct dir{
char filenames[10][10];
int fileinodes[10];
int dir_bitmap[10]; //hack to check which of the entry in dir is free
int num_of_files;
} dir;
typedef struct fd_entry{
int fd;
int inode_num;
int read_offset;
int write_offset;
enum mode mode;
void *next;
}fd_entry;
int my_open(const char *pathname, int mode);
int my_close(int fd);
int my_read(int fd, void *buffer, int count);
int my_write(int fd, void *buffer, int count);
int my_mkdir(const char *pathname);
int my_format(int blocksize);
int my_unlink(const char *pathname);
int my_rmdir(const char *pathname);
void mount_filesystem();
void unmount_disk();
int get_dir_entry(dir* _dir);
int get_inode_num();
int write_inode(inode *ptr, int inumber);
int write_data_block(int blockNum, void *block);
int get_free_datablock(int inumber);
int read_data_block(int blockNum,void *block);
char* read_inode(int inum);
inode* create_inode(int isDir, int size);
void rm_dir_recursively(dir* dir_to_remove);
void print_inode_bitmap();
void print_data_bitmap();
void print_all_files();
void print_dir(dir* root_dir, int* space);
fd_entry *find_fd_entry(int fd_or_inode_num);
int remove_fd_entry(int fd);
fd_entry *create_fd_entry(int inode_num, int read_offset, int write_offset, enum mode mode);
void print_dir(dir* root_dir, int* space);
void print_fd_table();
/* Super Block Data */
#define BLOCK_SIZE 4096
#define NUM_DATA_BLOCKS 237
#define TOTAL_NUM_INODES 1024
#define INODE_START_BLOCK 3
#define DATA_START_BLOCK 19
#define INODE_START_ADDRESS BLOCK_SIZE*INODE_START_BLOCK //inodes start from 3rd block
#define DATA_START_ADDRESS BLOCK_SIZE*DATA_START_BLOCK //inodes start from 3rd block
#define ROOT_INODE_NUM 0
#define INODE_BITMAP_BLOCK 1
#define DATA_BITMAP_BLOCK 2
typedef struct super_block{
int block_size;
int num_data_blocks;
int total_num_inodes;
int data_start_block;
int inode_start_block;
int inode_start_address;
int data_start_addresss;
int root_inode_num;
int inode_bitmap_block;
int data_bitmap_block;
}super_block;
char INODE_BITMAP[4096];
char DATA_BITMAP[4096];
#endif