Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. /* type.h for CS360 Project */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <fcntl.h>
  6. #include <ext2fs/ext2_fs.h>
  7. #include <libgen.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #include <sys/timeb.h>
  11. #include <sys/stat.h>
  12. #include <errno.h>
  13.  
  14. // define shorter TYPES, save typing efforts
  15. typedef struct ext2_group_desc GD;
  16. typedef struct ext2_super_block SUPER;
  17. typedef struct ext2_inode INODE;
  18. typedef struct ext2_dir_entry_2 DIR; // need this for new version of e2fs
  19.  
  20. GD *gp;
  21. SUPER *sp;
  22. INODE *ip;
  23. DIR *dp;
  24.  
  25. #define BLOCK_SIZE 1024
  26. #define BLKSIZE 1024
  27. #define BITS_PER_BLOCK (8*BLOCK_SIZE)
  28. #define INODES_PER_BLOCK (BLOCK_SIZE/sizeof(INODE))
  29. #define RED "\e[0;31m"
  30. #define GREEN "\x1b[32m"
  31. #define YELLOW "\x1b[33m"
  32. #define BLUE "\x1b[34m"
  33. #define MAGENTA "\x1b[35m"
  34. #define CYAN "\x1b[36m"
  35. #define RESET "\x1b[0m"
  36. #define BOLDRED "\e[1;31m"
  37. #define BOLDGREEN "\e[1;32m"
  38. #define BOLDYELLOW "\e[1;33m"
  39. #define BOLDBLUE "\e[1;34m"
  40. #define BOLDMAGENTA "\e[1;35m"
  41. #define BOLDCYAN "\e[1;36m"
  42. #define RESET "\x1b[0m"
  43.  
  44. #define BLOCK_SIZE 1024
  45. #define BLKSIZE 1024
  46. #define BITS_PER_BLOCK (8*BLOCK_SIZE)
  47. #define INODES_PER_BLOCK (BLOCK_SIZE/sizeof(INODE))
  48.  
  49. // Block number of EXT2 FS on FD
  50. #define SUPERBLOCK 1
  51. #define GDBLOCK 2
  52. #define BBITMAP 3
  53. #define IBITMAP 4
  54. #define INODEBLOCK 5
  55. #define ROOT_INODE 2
  56.  
  57. // Default dir and regulsr file modes
  58. #define DIR_MODE 0040777
  59. #define FILE_MODE 0100644
  60. #define SUPER_MAGIC 0xEF53
  61. #define SUPER_USER 0
  62.  
  63. // Proc status
  64. #define FREE 0
  65. #define BUSY 1
  66. #define KILLED 2
  67.  
  68. // Table sizes
  69. #define NMINODES 100
  70. #define NMOUNT 10
  71. #define NPROC 10
  72. #define NFD 10
  73. #define NOFT 50
  74.  
  75. // Open File Table
  76. typedef struct Oft{
  77. int mode; // flags
  78. int refCount; /* number of processes which share same instance of open file
  79. when a process opens a file, refCount is set to 1
  80. when a process forks, the child process inherits all opened fds of parent,
  81. which increments the refCount of every shared OFT by 1.
  82. when a process closes a fd, it decrements the OFT refCount by 1. */
  83.  
  84.  
  85. struct Minode *inodeptr; // pointer to inode in-memory
  86. long offset; /* conceptual pointer to the current byte position in the file for read/write
  87. initially set to 0 for R|R|RW or to file size for append */
  88. } OFT;
  89.  
  90. // PROC structure
  91. typedef struct Proc{
  92. int uid; // user id, 0 super user, 1 basic user
  93. int pid; // process id
  94. int gid; // group id
  95. int ppid; // parent process id
  96. int status; // indicates FREE, BUSY, or WAITING
  97.  
  98. struct Minode *cwd; // in-memory inode that points to the current working directory
  99. OFT *fd[NFD]; // array of file descriptors which point to opened file instances
  100.  
  101. struct Proc *next; // pointer to next process
  102. struct Proc *parent; // pointer to parent process
  103. struct Proc *child; // pointer to child process
  104. struct Proc *sibling; // pointer to sibling process
  105. } PROC;
  106.  
  107. // In-memory inodes structure
  108. typedef struct Minode{
  109. INODE INODE; // disk inode
  110. int dev, ino; // device number, inode number
  111.  
  112. int refCount; // records number of prcesses that are using the minode
  113. int dirty; // flag that indicates whether the inode has been modified
  114. int mounted; // flag that indicates whether the inode has been mounted
  115. struct Mount *mountptr; // points to the mount table entry of the mounted filesystem
  116. char name[128]; // name string of file
  117. } MINODE;
  118.  
  119. // Mount Table structure
  120. typedef struct Mount{
  121. int ninodes; // number of inodes
  122. int nblocks; // number of blocks
  123. int bmap; // ?
  124. int imap; // ?
  125. int iblock; // ?
  126. int dev, busy; // device number, busy flag?
  127. struct Minode *mounted_inode; // pointer to mounted inode in-memory
  128. char name[256]; // name string of ?
  129. char mount_name[64]; // name of mount ?
  130. } MOUNT;
  131.  
  132. // function proto types
  133. //MINODE *iget();
  134. //OFT *falloc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement