-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.h
63 lines (51 loc) · 1.75 KB
/
file.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
struct file {
enum { FD_NONE, FD_PIPE, FD_INODE } type;
int ref; // reference count
char readable;
char writable;
struct pipe *pipe;
struct inode *ip;
uint off;
};
/* file-system specific functions that are maintained for each
inode. When a new in-memory inode is allocated using iget(),
the parent inode is now passed in, and the functions are inherited.
If no parent is passed in, the standard file-system functions are assigned.
WARNING: this list of functions is likely incomplete, meaning that some operation
may not be supported in new file systems introduced. To improve
generality, add new file system function pointers here as needed.
*/
struct inode_functions {
void (*ipopulate)(struct inode*); // fill in inode details
void (*iupdate)(struct inode*); // write inode details back to disk
int (*readi)(struct inode*, char*, uint, uint); // read from file contents
int (*writei)(struct inode*, char*, uint, uint); // write to file contents
};
#define NDIRECT 12
// in-memory copy of an inode
struct inode {
uint dev; // Device number
uint inum; // Inode number
int ref; // Reference count
int flags; // I_BUSY, I_VALID
struct inode_functions *i_func;
short type; // copy of disk inode
short major;
short minor;
short nlink;
uint size;
uint mounted; //mounted on non-default file system
uint addrs[NDIRECT+1];
};
#define I_BUSY 0x1
#define I_VALID 0x2
// table mapping major device number to
// device functions
struct devsw {
int (*read)(struct inode*, char*, int);
int (*write)(struct inode*, char*, int);
};
extern struct devsw devsw[];
#define CONSOLE 1
//PAGEBREAK!
// Blank page.