1 struct file { 2 enum { FD_NONE, FD_PIPE, FD_INODE } type; 3 int ref; // reference count 4 char readable; 5 char writable; 6 struct pipe *pipe; 7 struct inode *ip; 8 uint off; 9 }; 10 11 12 // in-core file system types 13 14 struct inode { 15 uint dev; // Device number 16 uint inum; // Inode number 17 int ref; // Reference count 18 int flags; // I_BUSY, I_VALID 19 20 short type; // copy of disk inode 21 short major; 22 short minor; 23 short nlink; 24 uint size; 25 uint addrs[NDIRECT+1]; 26 }; 27 28 #define I_BUSY 0x1 29 #define I_VALID 0x2 30 31 // device implementations 32 33 struct devsw { 34 int (*read)(struct inode*, char*, int); 35 int (*write)(struct inode*, char*, int); 36 }; 37 38 extern struct devsw devsw[]; 39 40 #define CONSOLE 1 41