/filesystems/unixfs/ancientfs/ancientfs_2.11bsd.h

http://macfuse.googlecode.com/ · C Header · 229 lines · 143 code · 27 blank · 59 comment · 0 complexity · 404ede637412a5248748baf3254fce4d MD5 · raw file

  1. /*
  2. * Ancient UNIX File Systems for MacFUSE
  3. * Amit Singh
  4. * http://osxbook.com
  5. */
  6. #ifndef _ANCIENTFS_211BSD_H_
  7. #define _ANCIENTFS_211BSD_H_
  8. #include "unixfs_internal.h"
  9. typedef uint8_t a_uchar; /* ancient unsigned char */
  10. typedef int16_t a_short; /* ancient short */
  11. typedef uint16_t a_ushort; /* ancient unsigned short */
  12. typedef int16_t a_int; /* ancient int */
  13. typedef uint16_t a_uint; /* ancient unsigned int */
  14. typedef int32_t a_long; /* ancient long */
  15. typedef uint32_t a_ulong; /* ancient unsigned long */
  16. typedef a_ushort a_ino_t; /* ancient inode type (ancient unsigned int) */
  17. typedef a_long a_off_t; /* ancient offset type (ancient long) */
  18. typedef a_long a_time_t; /* ancient time type (ancient long) */
  19. typedef a_long a_daddr_t; /* ancient disk address type (ancient long) */
  20. typedef a_short a_dev_t; /* ancient device type (ancient int) */
  21. typedef a_ushort a_uid_t; /* ancient user id type (ancient unsigned short) */
  22. typedef a_ushort a_gid_t; /* ancient grp id type (ancient unsigned short) */
  23. /*
  24. * The file system is made out of blocks of MAXBSIZE units.
  25. */
  26. #define MAXBSIZE 1024
  27. /*
  28. * MAXPATHLEN defines the longest permissable path length
  29. * after expanding symbolic links. It is used to allocate
  30. * a temporary buffer from the buffer pool in which to do the
  31. * name expansion, hence should be a power of two, and must
  32. * be less than or equal to MAXBSIZE.
  33. * MAXSYMLINKS defines the maximum number of symbolic links
  34. * that may be expanded in a path name. It should be set high
  35. * enough to allow all legitimate uses, but halt infinite loops
  36. * reasonably quickly.
  37. */
  38. #define MAXPATHLEN 256
  39. #define MAXSYMLINKS 8
  40. #undef CLSIZE
  41. #define CLSIZE 2 /* number of blocks / cluster */
  42. #define DEV_BSIZE 1024 /* size of secondary block (bytes) */
  43. #define NINDIR (DEV_BSIZE/sizeof(a_daddr_t))
  44. #define DEV_BMASK 0x3ffL /* DEV_BSIZE - 1 */
  45. #define DEV_DBMASK 0777L /* directory block */
  46. #define DEV_BSHIFT 10 /* LOG2(DEV_BSIZE) */
  47. #define NMASK 0377L /* NINDIR - 1 */
  48. #define NSHIFT 8 /* LOG2(NINDIR) */
  49. /*
  50. * The root inode is the root of the file system.
  51. * Inode 0 can't be used for normal purposes and
  52. * historically bad blocks were linked to inode 1,
  53. * thus the root inode is 2. (inode 1 is no longer used for
  54. * this purpose, however numerous dump tapes make this
  55. * assumption, so we are stuck with it)
  56. * The lost+found directory is given the next available
  57. * inode when it is created by ``mkfs''.
  58. */
  59. #define ROOTINO 2 /* i number of all roots */
  60. #define SUPERB ((a_daddr_t)1) /* block number of the super block */
  61. #define SBSIZE DEV_BSIZE /* super block size */
  62. #define NICFREE 50 /* number of super block free blocks */
  63. #define NICINOD 100 /* number of super block inodes */
  64. #define MAXMNTLEN 12
  65. #define MAXNAMLEN 63
  66. /*
  67. * Definition of the unix super block.
  68. */
  69. struct fs
  70. {
  71. a_ushort s_isize; /* size in blocks of i-list */
  72. a_daddr_t s_fsize; /* size in blocks of entire volume */
  73. a_short s_nfree; /* number of addresses in s_free */
  74. a_daddr_t s_free[NICFREE]; /* free block list */
  75. a_short s_ninode; /* number of i-nodes in s_inode */
  76. a_ino_t s_inode[NICINOD]; /* free i-node list */
  77. char s_flock; /* lock during free list manipulation */
  78. char s_ilock; /* lock during i-list manipulation */
  79. char s_fmod; /* super block modified flag */
  80. char s_ronly; /* mounted read-only flag */
  81. time_t s_time; /* last super block update */
  82. a_daddr_t s_tfree; /* total free blocks*/
  83. a_ino_t s_tinode; /* total free inodes */
  84. a_short s_dinfo[2]; /* interleave stuff */
  85. #define s_m s_dinfo[0] /* optimal step in free list pattern */
  86. #define s_n s_dinfo[1] /* number of blocks per pattern */
  87. char s_fsmnt[MAXMNTLEN]; /* ordinary file mounted on */
  88. ino_t s_lasti; /* start place for circular search */
  89. ino_t s_nbehind; /* est # free inodes before s_lasti */
  90. a_ushort s_flags; /* mount time flags */
  91. /* actually longer */
  92. } __attribute__((packed));
  93. struct icommon2 {
  94. a_time_t ic_atime;
  95. a_time_t ic_mtime;
  96. a_time_t ic_ctime;
  97. } __attribute__((packed));
  98. struct icommon1 {
  99. a_ushort ic_mode; /* mode and type of file */
  100. a_ushort ic_nlink; /* number of links to file */
  101. a_uid_t ic_uid; /* owner's user id */
  102. a_gid_t ic_gid; /* owner's group id */
  103. a_off_t ic_size; /* number of bytes in file */
  104. } __attribute__((packed));
  105. /*
  106. * Inode struct as it appears on a disk block.
  107. */
  108. struct dinode
  109. {
  110. struct icommon1 di_icom1;
  111. a_daddr_t di_addr[7]; /* 7 block addresses 4 bytes each */
  112. a_ushort di_reserved[5]; /* pad of 10 to make total size 64 */
  113. a_ushort di_flags;
  114. struct icommon2 di_icom2;
  115. } __attribute__((packed));
  116. #define di_ic1 di_icom1
  117. #define di_ic2 di_icom2
  118. #define di_mode di_icom1.ic_mode
  119. #define di_nlink di_icom1.ic_nlink
  120. #define di_uid di_icom1.ic_uid
  121. #define di_gid di_icom1.ic_gid
  122. #define di_size di_icom1.ic_size
  123. #define di_atime di_icom2.ic_atime
  124. #define di_mtime di_icom2.ic_mtime
  125. #define di_ctime di_icom2.ic_ctime
  126. /*
  127. * Turn file system block numbers into disk block addresses.
  128. * This maps file system blocks to device size blocks.
  129. */
  130. #define fsbtodb(b) ((a_daddr_t)((a_daddr_t)(b) << 1))
  131. #define dbtofsb(b) ((a_daddr_t)((a_daddr_t)(b) >> 1))
  132. /*
  133. * Macros for handling inode numbers:
  134. * inode number to file system block offset.
  135. * inode number to file system block address.
  136. */
  137. #define itoo(x) ((a_int)(((x) + 2 * INOPB - 1) % INOPB))
  138. #define itod(x) ((a_daddr_t)((((a_uint)(x) + 2 * INOPB - 1) / INOPB)))
  139. /*
  140. * The following macros optimize certain frequently calculated
  141. * quantities by using shifts and masks in place of divisions
  142. * modulos and multiplications.
  143. */
  144. #define blkoff(loc) ((loc) & DEV_BMASK) /* calculates (loc % fs->fs_bsize) */
  145. #define lblkno(loc) ((loc) >> DEV_BSHIFT) /* calculates (loc / fs->fs_bsize) */
  146. /*
  147. * INOPB is the number of inodes in a secondary storage block.
  148. */
  149. #define INOPB 16 /* MAXBSIZE / sizeof(struct dinode) */
  150. /*
  151. * 28 of the di_addr address bytes are used; 7 addresses of 4
  152. * bytes each: 4 direct (4Kb directly accessible) and 3 indirect.
  153. */
  154. #define NDADDR 4 /* direct addresses in inode */
  155. #define NIADDR 3 /* indirect addresses in inode */
  156. #define NADDR (NDADDR + NIADDR) /* total addresses in inode */
  157. /* i_flag */
  158. #define ILOCKED 0x1 /* inode is locked */
  159. #define IUPD 0x2 /* file has been modified */
  160. #define IACC 0x4 /* inode access time to be updated */
  161. #define IMOUNT 0x8 /* inode is mounted on */
  162. #define IWANT 0x10 /* some process waiting on lock */
  163. #define ITEXT 0x20 /* inode is pure text prototype */
  164. #define ICHG 0x40 /* inode has been changed */
  165. #define ISHLOCK 0x80 /* file has shared lock */
  166. #define IEXLOCK 0x100 /* file has exclusive lock */
  167. #define ILWAIT 0x200 /* someone waiting on file lock */
  168. #define IMOD 0x400 /* inode has been modified */
  169. #define IRENAME 0x800 /* inode is being renamed */
  170. #define IPIPE 0x1000 /* inode is a pipe */
  171. #define IRCOLL 0x2000 /* read select collision on pipe */
  172. #define IWCOLL 0x4000 /* write select collision on pipe */
  173. #define IXMOD 0x8000 /* inode is text, but impure (XXX) */
  174. /* i_mode */
  175. #define IFMT 0170000 /* type of file */
  176. #define IFCHR 0020000 /* character special */
  177. #define IFDIR 0040000 /* directory */
  178. #define IFBLK 0060000 /* block special */
  179. #define IFREG 0100000 /* regular */
  180. #define IFLNK 0120000 /* symbolic link */
  181. #define IFSOCK 0140000 /* socket */
  182. #define ISUID 04000 /* set user id on execution */
  183. #define ISGID 02000 /* set group id on execution */
  184. #define ISVTX 01000 /* save swapped text even after use */
  185. #define IREAD 0400 /* read, write, execute permissions */
  186. #define IWRITE 0200
  187. #define IEXEC 0100
  188. #define ANCIENTFS_211BSD_DIRBLKSIZ 512
  189. struct direct {
  190. a_ino_t d_ino; /* inode number of entry */
  191. a_ushort d_reclen; /* length of this record */
  192. a_ushort d_namlen; /* length of string in d_name */
  193. char d_name[UNIXFS_MAXNAMLEN + 1];
  194. } __attribute__((packed));
  195. #define ANCIENTFS_211BSD_DIRSIZ(dp) \
  196. ((((sizeof(struct direct) - (UNIXFS_MAXNAMLEN + 1)) + \
  197. (dp)->d_namlen + 1) + 3) & ~3)
  198. struct fblk {
  199. a_short df_nfree;
  200. a_daddr_t df_free[NICFREE];
  201. } __attribute__((packed));
  202. #endif /* _ANCIENTFS_211BSD_H_ */