dat.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. typedef struct Xfs Xfs;
  2. typedef struct Xfile Xfile;
  3. typedef struct Iobuf Iobuf;
  4. typedef struct Ext2 Ext2;
  5. typedef struct SuperBlock SuperBlock;
  6. typedef struct GroupDesc GroupDesc;
  7. typedef struct Inode Inode;
  8. typedef struct DirEntry DirEntry;
  9. #define SECTORSIZE 512
  10. #define OFFSET_SUPER_BLOCK 1024
  11. #define EXT2_SUPER_MAGIC 0xEF53
  12. #define EXT2_MIN_BLOCK_SIZE 1024
  13. #define EXT2_MAX_BLOCK_SIZE 4096
  14. #define EXT2_ROOT_INODE 2
  15. #define EXT2_FIRST_INO 11
  16. #define EXT2_VALID_FS 0x0001
  17. #define EXT2_ERROR_FS 0x0002
  18. /*
  19. * Structure of the super block
  20. */
  21. struct SuperBlock {
  22. uint s_inodes_count; /* Inodes count */
  23. uint s_blocks_count; /* Blocks count */
  24. uint s_r_blocks_count; /* Reserved blocks count */
  25. uint s_free_blocks_count; /* Free blocks count */
  26. uint s_free_inodes_count; /* Free inodes count */
  27. uint s_first_data_block; /* First Data Block */
  28. uint s_log_block_size; /* Block size */
  29. int s_log_frag_size; /* Fragment size */
  30. uint s_blocks_per_group; /* # Blocks per group */
  31. uint s_frags_per_group; /* # Fragments per group */
  32. uint s_inodes_per_group; /* # Inodes per group */
  33. uint s_mtime; /* Mount time */
  34. uint s_wtime; /* Write time */
  35. ushort s_mnt_count; /* Mount count */
  36. short s_max_mnt_count; /* Maximal mount count */
  37. ushort s_magic; /* Magic signature */
  38. ushort s_state; /* File system state */
  39. ushort s_errors; /* Behaviour when detecting errors */
  40. ushort s_pad;
  41. uint s_lastcheck; /* time of last check */
  42. uint s_checkinterval; /* max. time between checks */
  43. uint s_creator_os; /* OS */
  44. uint s_rev_level; /* Revision level */
  45. ushort s_def_resuid; /* Default uid for reserved blocks */
  46. ushort s_def_resgid; /* Default gid for reserved blocks */
  47. uint s_reserved[235]; /* Padding to the end of the block */
  48. };
  49. /*
  50. * Structure of a blocks group descriptor
  51. */
  52. struct GroupDesc
  53. {
  54. uint bg_block_bitmap; /* Blocks bitmap block */
  55. uint bg_inode_bitmap; /* Inodes bitmap block */
  56. uint bg_inode_table; /* Inodes table block */
  57. ushort bg_free_blocks_count; /* Free blocks count */
  58. ushort bg_free_inodes_count; /* Free inodes count */
  59. ushort bg_used_dirs_count; /* Directories count */
  60. ushort bg_pad;
  61. uint bg_reserved[3];
  62. };
  63. /*
  64. * Constants relative to the data blocks
  65. */
  66. #define EXT2_NDIR_BLOCKS 12
  67. #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
  68. #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
  69. #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
  70. #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
  71. /*
  72. * Structure of an inode on the disk
  73. */
  74. struct Inode {
  75. ushort i_mode; /* File mode */
  76. ushort i_uid; /* Owner Uid */
  77. uint i_size; /* Size in bytes */
  78. uint i_atime; /* Access time */
  79. uint i_ctime; /* Creation time */
  80. uint i_mtime; /* Modification time */
  81. uint i_dtime; /* Deletion Time */
  82. ushort i_gid; /* Group Id */
  83. ushort i_links_count; /* Links count */
  84. uint i_blocks; /* Blocks count */
  85. uint i_flags; /* File flags */
  86. uint osd1;
  87. uint i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  88. uint i_version; /* File version (for NFS) */
  89. uint i_file_acl; /* File ACL */
  90. uint i_dir_acl; /* Directory ACL */
  91. uint i_faddr; /* Fragment address */
  92. uchar osd2[12];
  93. };
  94. /*
  95. * Structure of a directory entry
  96. */
  97. #define EXT2_NAME_LEN 255
  98. #define DIR_REC_LEN(name_len) (((name_len) + 8 + 3) & ~3)
  99. struct DirEntry {
  100. uint inode; /* Inode number */
  101. ushort rec_len; /* Directory entry length */
  102. uchar name_len; /* Name length */
  103. uchar reserved;
  104. char name[EXT2_NAME_LEN]; /* File name */
  105. };
  106. #define S_IFMT 00170000
  107. #define S_IFLNK 0120000
  108. #define S_IFREG 0100000
  109. #define S_IFDIR 0040000
  110. #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  111. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  112. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  113. #define DEFAULT_UID 200
  114. #define DEFAULT_GID 100
  115. struct Iobuf
  116. {
  117. Xfs *dev;
  118. long addr;
  119. Iobuf *next;
  120. Iobuf *prev;
  121. Iobuf *hash;
  122. int busy;
  123. int dirty;
  124. char *iobuf;
  125. };
  126. struct Xfs{
  127. Xfs *next;
  128. char *name; /* of file containing external f.s. */
  129. Qid qid; /* of file containing external f.s. */
  130. long ref; /* attach count */
  131. Qid rootqid; /* of plan9 constructed root directory */
  132. short dev;
  133. short fmt;
  134. void *ptr;
  135. /* data from super block */
  136. int block_size;
  137. int desc_per_block;
  138. int inodes_per_group;
  139. int inodes_per_block;
  140. int addr_per_block;
  141. int blocks_per_group;
  142. int ngroups;
  143. int superaddr, superoff;
  144. int grpaddr;
  145. };
  146. struct Xfile{
  147. Xfile *next; /* in hash bucket */
  148. long client;
  149. long fid;
  150. Xfs * xf;
  151. void * ptr;
  152. uint inbr; /* inode nbr */
  153. uint pinbr; /* parrent inode */
  154. ulong bufaddr; /* addr of inode block */
  155. ulong bufoffset;
  156. int root; /* true on attach for ref count */
  157. int dirindex; /* next dir entry to read */
  158. };
  159. #define EXT2_SUPER 1
  160. #define EXT2_DESC 2
  161. #define EXT2_BBLOCK 3
  162. #define EXT2_BINODE 4
  163. struct Ext2{
  164. char type;
  165. union{
  166. SuperBlock *sb;
  167. GroupDesc *gd;
  168. char *bmp;
  169. }u;
  170. Iobuf *buf;
  171. };
  172. #define DESC_ADDR(xf,n) ( (xf)->grpaddr + ((n)/(xf)->desc_per_block) )
  173. #define DESC_OFFSET(xf,d,n) ( ((GroupDesc *)(d)) + ((n)%(xf)->desc_per_block) )
  174. enum{
  175. Asis, Clean, Clunk
  176. };
  177. enum{
  178. Enevermind,
  179. Eformat,
  180. Eio,
  181. Enomem,
  182. Enonexist,
  183. Eexist,
  184. Eperm,
  185. Enofilsys,
  186. Eauth,
  187. Enospace,
  188. Elink,
  189. Elongname,
  190. Eintern,
  191. Ecorrupt,
  192. Enotclean
  193. };
  194. extern int chatty;
  195. extern int errno;
  196. extern char *deffile;
  197. extern int rdonly;