internal.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef INTERNAL_H_INCLUDED
  2. #define INTERNAL_H_INCLUDED
  3. #include <time.h>
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. /* Super block table. The root file system and every mounted file system
  7. * has an entry here. The entry holds information about the sizes of the bit
  8. * maps and inodes. The s_ninodes field gives the number of inodes available
  9. * for files and directories, including the root directory. Inode 0 is
  10. * on the disk, but not used. Thus s_ninodes = 4 means that 5 bits will be
  11. * used in the bit map, bit 0, which is always 1 and not used, and bits 1-4
  12. * for files and directories. The disk layout is:
  13. *
  14. * Item # blocks
  15. * boot block 1
  16. * super block 1
  17. * inode map s_imap_blocks
  18. * zone map s_zmap_blocks
  19. * inodes (s_ninodes + 'inodes per block' - 1)/'inodes per block'
  20. * unused whatever is needed to fill out the current zone
  21. * data zones (s_zones - s_firstdatazone) << s_log_zone_size
  22. *
  23. * A super_block slot is free if s_dev == NO_DEV.
  24. */
  25. #define MINIX_BLOCK_SIZE 1024
  26. #define BLOCK_SIZE MINIX_BLOCK_SIZE
  27. #define usizeof sizeof
  28. #define SUPER_V2_REV 0x2468 /* V2 magic written on PC, read on 68K or vv */
  29. /* Tables sizes */
  30. #define V1_NR_DZONES 7 /* # direct zone numbers in a V1 inode */
  31. #define V1_NR_TZONES 9 /* total # zone numbers in a V1 inode */
  32. #define V2_NR_DZONES 7 /* # direct zone numbers in a V2 inode */
  33. #define V2_NR_TZONES 10 /* total # zone numbers in a V2 inode */
  34. /* Types used in disk, inode, etc. data structures. */
  35. typedef short dev_t; /* holds (major|minor) device pair */
  36. typedef char gid_t; /* group id */
  37. typedef unsigned short ino_t; /* i-node number */
  38. typedef unsigned short mode_t; /* file type and permissions bits */
  39. typedef char nlink_t; /* number of links to a file */
  40. typedef unsigned long off_t; /* offset within a file */
  41. typedef int pid_t; /* process id (must be signed) */
  42. typedef short uid_t; /* user id */
  43. typedef unsigned long zone_t; /* zone number */
  44. typedef unsigned long block_t; /* block number */
  45. typedef unsigned long bit_t; /* bit number in a bit map */
  46. typedef unsigned short zone1_t; /* zone number for V1 file systems */
  47. typedef unsigned short bitchunk_t; /* collection of bits in a bitmap */
  48. typedef unsigned char u8_t; /* 8 bit type */
  49. typedef unsigned short u16_t; /* 16 bit type */
  50. typedef unsigned long u32_t; /* 32 bit type */
  51. typedef char i8_t; /* 8 bit signed type */
  52. typedef short i16_t; /* 16 bit signed type */
  53. typedef long i32_t; /* 32 bit signed type */
  54. #define ROOT_INODE 1 /* inode number for root directory */
  55. #define BOOT_BLOCK ((block_t) 0) /* block number of boot block */
  56. #define SUPER_BLOCK ((block_t) 1) /* block number of super block */
  57. #define DIR_ENTRY_SIZE usizeof (struct direct) /* # bytes/dir entry */
  58. #define NR_DIR_ENTRIES (BLOCK_SIZE/DIR_ENTRY_SIZE) /* # dir entries/blk */
  59. #define SUPER_SIZE usizeof (struct super_block) /* super_block size */
  60. #define PIPE_SIZE (V1_NR_DZONES*BLOCK_SIZE) /* pipe size in bytes */
  61. #define BITMAP_CHUNKS (BLOCK_SIZE/usizeof (bitchunk_t))/* # map chunks/blk */
  62. /* Derived sizes pertaining to the V1 file system. */
  63. #define V1_ZONE_NUM_SIZE usizeof (zone1_t) /* # bytes in V1 zone */
  64. #define V1_INODE_SIZE usizeof (d1_inode) /* bytes in V1 dsk ino */
  65. #define V1_INDIRECTS (BLOCK_SIZE/V1_ZONE_NUM_SIZE) /* # zones/indir block */
  66. #define V1_INODES_PER_BLOCK (BLOCK_SIZE/V1_INODE_SIZE)/* # V1 dsk inodes/blk */
  67. /* Derived sizes pertaining to the V2 file system. */
  68. #define V2_ZONE_NUM_SIZE usizeof (zone_t) /* # bytes in V2 zone */
  69. #define V2_INODE_SIZE usizeof (d2_inode) /* bytes in V2 dsk ino */
  70. #define V2_INDIRECTS (BLOCK_SIZE/V2_ZONE_NUM_SIZE) /* # zones/indir block */
  71. #define V2_INODES_PER_BLOCK (BLOCK_SIZE/V2_INODE_SIZE)/* # V2 dsk inodes/blk */
  72. struct super_block
  73. {
  74. ino_t s_ninodes; /* # usable inodes on the minor device */
  75. zone1_t s_nzones; /* total device size, including bit maps etc */
  76. short s_imap_blocks; /* # of blocks used by inode bit map */
  77. short s_zmap_blocks; /* # of blocks used by zone bit map */
  78. zone1_t s_firstdatazone; /* number of first data zone */
  79. short s_log_zone_size; /* log2 of blocks/zone */
  80. off_t s_max_size; /* maximum file size on this device */
  81. short s_magic; /* magic number to recognize super-blocks */
  82. short s_pad; /* try to avoid compiler-dependent padding */
  83. zone_t s_zones; /* number of zones (replaces s_nzones in V2) */
  84. };
  85. /* Declaration of the V1 inode as it is on the disk (not in core). */
  86. typedef struct { /* V1.x disk inode */
  87. mode_t d1_mode; /* file type, protection, etc. */
  88. uid_t d1_uid; /* user id of the file's owner */
  89. off_t d1_size; /* current file size in bytes */
  90. time_t d1_mtime; /* when was file data last changed */
  91. gid_t d1_gid; /* group number */
  92. nlink_t d1_nlinks; /* how many links to this file */
  93. u16_t d1_zone[V1_NR_TZONES]; /* block nums for direct, ind, and dbl ind */
  94. } d1_inode;
  95. /* Declaration of the V2 inode as it is on the disk (not in core). */
  96. typedef struct { /* V2.x disk inode */
  97. mode_t d2_mode; /* file type, protection, etc. */
  98. u16_t d2_nlinks; /* how many links to this file. HACK! */
  99. uid_t d2_uid; /* user id of the file's owner. */
  100. u16_t d2_gid; /* group number HACK! */
  101. off_t d2_size; /* current file size in bytes */
  102. time_t d2_atime; /* when was file data last accessed */
  103. time_t d2_mtime; /* when was file data last changed */
  104. time_t d2_ctime; /* when was inode data last changed */
  105. zone_t d2_zone[V2_NR_TZONES]; /* block nums for direct, ind, and dbl ind */
  106. } d2_inode;
  107. /* Flag bits for i_mode in the inode. */
  108. #define I_TYPE 0170000 /* this field gives inode type */
  109. #define I_REGULAR 0100000 /* regular file, not dir or special */
  110. #define I_BLOCK_SPECIAL 0060000 /* block special file */
  111. #define I_DIRECTORY 0040000 /* file is a directory */
  112. #define I_CHAR_SPECIAL 0020000 /* character special file */
  113. #define I_NAMED_PIPE 0010000 /* named pipe (FIFO) */
  114. #define I_SET_UID_BIT 0004000 /* set effective uid_t on exec */
  115. #define I_SET_GID_BIT 0002000 /* set effective gid_t on exec */
  116. #define ALL_MODES 0006777 /* all bits for user, group and others */
  117. #define RWX_MODES 0000777 /* mode bits for RWX only */
  118. #define R_BIT 0000004 /* Rwx protection bit */
  119. #define W_BIT 0000002 /* rWx protection bit */
  120. #define X_BIT 0000001 /* rwX protection bit */
  121. #define I_NOT_ALLOC 0000000 /* this inode is free */
  122. #define MAX_NAME_LEN 14
  123. typedef struct { /* V2.x disk inode */
  124. u16_t inode;
  125. char name[MAX_NAME_LEN];
  126. } minix_dir_entry;
  127. typedef d2_inode minix_inode;
  128. #endif // INTERNAL_H_INCLUDED