file.h 767 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // in-memory copy of an inode
  11. struct inode {
  12. uint dev; // Device number
  13. uint inum; // Inode number
  14. int ref; // Reference count
  15. int flags; // I_BUSY, I_VALID
  16. short type; // copy of disk inode
  17. short major;
  18. short minor;
  19. short nlink;
  20. uint size;
  21. uint addrs[NDIRECT+1];
  22. };
  23. #define I_BUSY 0x1
  24. #define I_VALID 0x2
  25. // table mapping major device number to
  26. // device functions
  27. struct devsw {
  28. int (*read)(struct inode*, char*, int);
  29. int (*write)(struct inode*, char*, int);
  30. };
  31. extern struct devsw devsw[];
  32. #define CONSOLE 1