-
Notifications
You must be signed in to change notification settings - Fork 4
/
file.h
78 lines (65 loc) · 1.63 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "list.h"
struct file {
enum { FD_NONE, FD_PIPE, FD_INODE, FD_FIFO } type;
int ref; // reference count
char readable;
char writable;
struct pipe *pipe;
struct inode *ip;
uint off;
struct spinlock lock;
};
struct filesystem;
struct fs_operations
{
struct inode* (*alloc)(struct filesystem*, short);
struct inode* (*get)(struct filesystem*, uint);
void (*put)(struct filesystem*, struct inode*);
};
struct filesystem
{
uint index;
uint dev;
struct fs_operations ops;
struct list_head list;
};
struct inode_operations
{
int (*read)(struct inode*, char*, uint, uint);
int (*write)(struct inode*, char*, uint, uint);
int (*permissions)(struct inode*);
struct inode* (*lookup)(struct inode*, char*, uint*);
int (*link)(struct inode*, struct inode*, char*);
int (*unlink)(struct inode*, char*);
void (*update)(struct inode*);
};
// in-memory copy of an inode
struct inode {
struct filesystem* fs; // File system containing this inode
uint inum; // Inode number
int ref; // Reference count
int flags; // I_BUSY, I_VALID
short major;
short minor;
short nlink;
uint size;
uint addrs[NDIRECT+1];
uint uid;
uint gid;
uint mode;
struct list_head list;
struct inode_operations ops;
void* additional_info;
// Two files for pipe, used only when type == T_PIPE
struct file *read_file, *write_file;
};
#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