sysv_fs.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:13k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef _LINUX_SYSV_FS_H
  2. #define _LINUX_SYSV_FS_H
  3. /*
  4.  * The SystemV/Coherent filesystem constants/structures/macros
  5.  */
  6. /* This code assumes
  7.    - sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 4,
  8.    - alignof(short) = 2, alignof(long) = 4.
  9. */
  10. #ifdef __GNUC__
  11. #define __packed2__  __attribute__ ((packed, aligned(2)))
  12. #else
  13. #error I want gcc!
  14. #endif
  15. #include <linux/stat.h> /* declares S_IFLNK etc. */
  16. #include <linux/sched.h> /* declares wake_up() */
  17. #include <linux/sysv_fs_sb.h> /* defines the sv_... shortcuts */
  18. /* Layout on disk */
  19. /* ============== */
  20. static inline u32 PDP_swab(u32 x)
  21. {
  22. #ifdef __LITTLE_ENDIAN
  23. return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
  24. #else
  25. #ifdef __BIG_ENDIAN
  26. return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
  27. #else
  28. #error BYTESEX
  29. #endif
  30. #endif
  31. }
  32. /* inode numbers are 16 bit */
  33. typedef u16 sysv_ino_t;
  34. /* Block numbers are 24 bit, sometimes stored in 32 bit.
  35.    On Coherent FS, they are always stored in PDP-11 manner: the least
  36.    significant 16 bits come last.
  37. */
  38. typedef u32 sysv_zone_t;
  39. /* Among the blocks ... */
  40. /* Xenix FS, Coherent FS: block 0 is the boot block, block 1 the super-block.
  41.    SystemV FS: block 0 contains both the boot sector and the super-block. */
  42. /* The first inode zone is sb->sv_firstinodezone (1 or 2). */
  43. /* Among the inodes ... */
  44. /* 0 is non-existent */
  45. #define SYSV_BADBL_INO 1 /* inode of bad blocks file */
  46. #define SYSV_ROOT_INO 2 /* inode of root directory */
  47. /* Xenix super-block data on disk */
  48. #define XENIX_NICINOD 100 /* number of inode cache entries */
  49. #define XENIX_NICFREE 100 /* number of free block list chunk entries */
  50. struct xenix_super_block {
  51. u16 s_isize; /* index of first data zone */
  52. u32 s_fsize __packed2__; /* total number of zones of this fs */
  53. /* the start of the free block list: */
  54. u16 s_nfree; /* number of free blocks in s_free, <= XENIX_NICFREE */
  55. u32 s_free[XENIX_NICFREE]; /* first free block list chunk */
  56. /* the cache of free inodes: */
  57. u16 s_ninode; /* number of free inodes in s_inode, <= XENIX_NICINOD */
  58. sysv_ino_t s_inode[XENIX_NICINOD]; /* some free inodes */
  59. /* locks, not used by Linux: */
  60. char s_flock; /* lock during free block list manipulation */
  61. char s_ilock; /* lock during inode cache manipulation */
  62. char s_fmod; /* super-block modified flag */
  63. char s_ronly; /* flag whether fs is mounted read-only */
  64. u32 s_time __packed2__; /* time of last super block update */
  65. u32 s_tfree __packed2__; /* total number of free zones */
  66. u16 s_tinode; /* total number of free inodes */
  67. s16 s_dinfo[4]; /* device information ?? */
  68. char s_fname[6]; /* file system volume name */
  69. char s_fpack[6]; /* file system pack name */
  70. char s_clean; /* set to 0x46 when filesystem is properly unmounted */
  71. char s_fill[371];
  72. s32 s_magic; /* version of file system */
  73. s32 s_type; /* type of file system: 1 for 512 byte blocks
  74. 2 for 1024 byte blocks
  75. 3 for 2048 byte blocks */
  76. };
  77. /* SystemV FS comes in two variants:
  78.  * sysv2: System V Release 2 (e.g. Microport), structure elements aligned(2).
  79.  * sysv4: System V Release 4 (e.g. Consensys), structure elements aligned(4).
  80.  */
  81. #define SYSV_NICINOD 100 /* number of inode cache entries */
  82. #define SYSV_NICFREE 50 /* number of free block list chunk entries */
  83. /* SystemV4 super-block data on disk */
  84. struct sysv4_super_block {
  85. u16 s_isize; /* index of first data zone */
  86. u16 s_pad0;
  87. u32 s_fsize; /* total number of zones of this fs */
  88. /* the start of the free block list: */
  89. u16 s_nfree; /* number of free blocks in s_free, <= SYSV_NICFREE */
  90. u16 s_pad1;
  91. u32 s_free[SYSV_NICFREE]; /* first free block list chunk */
  92. /* the cache of free inodes: */
  93. u16 s_ninode; /* number of free inodes in s_inode, <= SYSV_NICINOD */
  94. u16 s_pad2;
  95. sysv_ino_t     s_inode[SYSV_NICINOD]; /* some free inodes */
  96. /* locks, not used by Linux: */
  97. char s_flock; /* lock during free block list manipulation */
  98. char s_ilock; /* lock during inode cache manipulation */
  99. char s_fmod; /* super-block modified flag */
  100. char s_ronly; /* flag whether fs is mounted read-only */
  101. u32 s_time; /* time of last super block update */
  102. s16 s_dinfo[4]; /* device information ?? */
  103. u32 s_tfree; /* total number of free zones */
  104. u16 s_tinode; /* total number of free inodes */
  105. u16 s_pad3;
  106. char s_fname[6]; /* file system volume name */
  107. char s_fpack[6]; /* file system pack name */
  108. s32 s_fill[12];
  109. s32 s_state; /* file system state: 0x7c269d38-s_time means clean */
  110. s32 s_magic; /* version of file system */
  111. s32 s_type; /* type of file system: 1 for 512 byte blocks
  112. 2 for 1024 byte blocks */
  113. };
  114. /* SystemV2 super-block data on disk */
  115. struct sysv2_super_block {
  116. u16 s_isize;  /* index of first data zone */
  117. u32 s_fsize __packed2__; /* total number of zones of this fs */
  118. /* the start of the free block list: */
  119. u16 s_nfree; /* number of free blocks in s_free, <= SYSV_NICFREE */
  120. u32 s_free[SYSV_NICFREE]; /* first free block list chunk */
  121. /* the cache of free inodes: */
  122. u16 s_ninode; /* number of free inodes in s_inode, <= SYSV_NICINOD */
  123. sysv_ino_t     s_inode[SYSV_NICINOD]; /* some free inodes */
  124. /* locks, not used by Linux: */
  125. char s_flock; /* lock during free block list manipulation */
  126. char s_ilock; /* lock during inode cache manipulation */
  127. char s_fmod; /* super-block modified flag */
  128. char s_ronly; /* flag whether fs is mounted read-only */
  129. u32 s_time __packed2__; /* time of last super block update */
  130. s16 s_dinfo[4]; /* device information ?? */
  131. u32 s_tfree __packed2__; /* total number of free zones */
  132. u16 s_tinode; /* total number of free inodes */
  133. char s_fname[6]; /* file system volume name */
  134. char s_fpack[6]; /* file system pack name */
  135. s32 s_fill[14];
  136. s32 s_state; /* file system state: 0xcb096f43 means clean */
  137. s32 s_magic; /* version of file system */
  138. s32 s_type; /* type of file system: 1 for 512 byte blocks
  139. 2 for 1024 byte blocks */
  140. };
  141. /* V7 super-block data on disk */
  142. #define V7_NICINOD     100     /* number of inode cache entries */
  143. #define V7_NICFREE     50      /* number of free block list chunk entries */
  144. struct v7_super_block {
  145. u16    s_isize;        /* index of first data zone */
  146. u32    s_fsize __packed2__; /* total number of zones of this fs */
  147. /* the start of the free block list: */
  148. u16    s_nfree;        /* number of free blocks in s_free, <= V7_NICFREE */
  149. u32    s_free[V7_NICFREE]; /* first free block list chunk */
  150. /* the cache of free inodes: */
  151. u16    s_ninode;       /* number of free inodes in s_inode, <= V7_NICINOD */
  152. sysv_ino_t      s_inode[V7_NICINOD]; /* some free inodes */
  153. /* locks, not used by Linux or V7: */
  154. char    s_flock;        /* lock during free block list manipulation */
  155. char    s_ilock;        /* lock during inode cache manipulation */
  156. char    s_fmod;         /* super-block modified flag */
  157. char    s_ronly;        /* flag whether fs is mounted read-only */
  158. u32     s_time __packed2__; /* time of last super block update */
  159. /* the following fields are not maintained by V7: */
  160. u32     s_tfree __packed2__; /* total number of free zones */
  161. u16     s_tinode;       /* total number of free inodes */
  162. u16     s_m;            /* interleave factor */
  163. u16     s_n;            /* interleave factor */
  164. char    s_fname[6];     /* file system name */
  165. char    s_fpack[6];     /* file system pack name */
  166. };
  167. /* Coherent super-block data on disk */
  168. #define COH_NICINOD 100 /* number of inode cache entries */
  169. #define COH_NICFREE 64 /* number of free block list chunk entries */
  170. struct coh_super_block {
  171. u16 s_isize; /* index of first data zone */
  172. u32 s_fsize __packed2__; /* total number of zones of this fs */
  173. /* the start of the free block list: */
  174. u16 s_nfree; /* number of free blocks in s_free, <= COH_NICFREE */
  175. u32 s_free[COH_NICFREE] __packed2__; /* first free block list chunk */
  176. /* the cache of free inodes: */
  177. u16 s_ninode; /* number of free inodes in s_inode, <= COH_NICINOD */
  178. sysv_ino_t s_inode[COH_NICINOD]; /* some free inodes */
  179. /* locks, not used by Linux: */
  180. char s_flock; /* lock during free block list manipulation */
  181. char s_ilock; /* lock during inode cache manipulation */
  182. char s_fmod; /* super-block modified flag */
  183. char s_ronly; /* flag whether fs is mounted read-only */
  184. u32 s_time __packed2__; /* time of last super block update */
  185. u32 s_tfree __packed2__; /* total number of free zones */
  186. u16 s_tinode; /* total number of free inodes */
  187. u16 s_interleave_m; /* interleave factor */
  188. u16 s_interleave_n;
  189. char s_fname[6]; /* file system volume name */
  190. char s_fpack[6]; /* file system pack name */
  191. u32 s_unique; /* zero, not used */
  192. };
  193. /* SystemV/Coherent inode data on disk */
  194. struct sysv_inode {
  195. u16 i_mode;
  196. u16 i_nlink;
  197. u16 i_uid;
  198. u16 i_gid;
  199. u32 i_size;
  200. union { /* directories, regular files, ... */
  201. unsigned char i_addb[3*(10+1+1+1)+1]; /* zone numbers: max. 10 data blocks,
  202.       * then 1 indirection block,
  203.       * then 1 double indirection block,
  204.       * then 1 triple indirection block.
  205.       * Then maybe a "file generation number" ??
  206.       */
  207. /* named pipes on Coherent */
  208. struct {
  209. char p_addp[30];
  210. s16 p_pnc;
  211. s16 p_prx;
  212. s16 p_pwx;
  213. } i_p;
  214. } i_a;
  215. u32 i_atime; /* time of last access */
  216. u32 i_mtime; /* time of last modification */
  217. u32 i_ctime; /* time of creation */
  218. };
  219. /* Admissible values for i_nlink: 0.._LINK_MAX */
  220. enum {
  221. XENIX_LINK_MAX = 126, /* ?? */
  222. SYSV_LINK_MAX = 126, /* 127? 251? */
  223. V7_LINK_MAX     = 126, /* ?? */
  224. COH_LINK_MAX = 10000,
  225. };
  226. /* The number of inodes per block is
  227.    sb->sv_inodes_per_block = block_size / sizeof(struct sysv_inode) */
  228. /* The number of indirect pointers per block is
  229.    sb->sv_ind_per_block = block_size / sizeof(u32) */
  230. /* SystemV/Coherent directory entry on disk */
  231. #define SYSV_NAMELEN 14 /* max size of name in struct sysv_dir_entry */
  232. struct sysv_dir_entry {
  233. sysv_ino_t inode;
  234. char name[SYSV_NAMELEN]; /* up to 14 characters, the rest are zeroes */
  235. };
  236. #define SYSV_DIRSIZE sizeof(struct sysv_dir_entry) /* size of every directory entry */
  237. /* Operations */
  238. /* ========== */
  239. /* identify the FS in memory */
  240. enum {
  241. FSTYPE_NONE = 0,
  242. FSTYPE_XENIX,
  243. FSTYPE_SYSV4,
  244. FSTYPE_SYSV2,
  245. FSTYPE_COH,
  246. FSTYPE_V7,
  247. FSTYPE_AFS,
  248. FSTYPE_END,
  249. };
  250. #define SYSV_MAGIC_BASE 0x012FF7B3
  251. #define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
  252. #define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
  253. #define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
  254. #define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
  255. #ifdef __KERNEL__
  256. enum {
  257. BYTESEX_LE,
  258. BYTESEX_PDP,
  259. BYTESEX_BE,
  260. };
  261. /*
  262.  * Function prototypes
  263.  */
  264. extern struct inode * sysv_new_inode(const struct inode *, mode_t);
  265. extern void sysv_free_inode(struct inode *);
  266. extern unsigned long sysv_count_free_inodes(struct super_block *);
  267. extern u32 sysv_new_block(struct super_block *);
  268. extern void sysv_free_block(struct super_block *, u32);
  269. extern unsigned long sysv_count_free_blocks(struct super_block *);
  270. extern void sysv_truncate(struct inode *);
  271. extern void sysv_write_inode(struct inode *, int);
  272. extern int sysv_sync_inode(struct inode *);
  273. extern int sysv_sync_file(struct file *, struct dentry *, int);
  274. extern void sysv_set_inode(struct inode *, dev_t);
  275. extern struct sysv_dir_entry *sysv_find_entry(struct dentry*, struct page**);
  276. extern int sysv_add_link(struct dentry*, struct inode*);
  277. extern int sysv_delete_entry(struct sysv_dir_entry*, struct page*);
  278. extern int sysv_make_empty(struct inode*, struct inode*);
  279. extern int sysv_empty_dir(struct inode*);
  280. extern void sysv_set_link(struct sysv_dir_entry*, struct page*, struct inode*);
  281. extern struct sysv_dir_entry *sysv_dotdot(struct inode*, struct page**);
  282. extern ino_t sysv_inode_by_name(struct dentry*);
  283. extern struct inode_operations sysv_file_inode_operations;
  284. extern struct inode_operations sysv_dir_inode_operations;
  285. extern struct inode_operations sysv_fast_symlink_inode_operations;
  286. extern struct file_operations sysv_file_operations;
  287. extern struct file_operations sysv_dir_operations;
  288. extern struct address_space_operations sysv_aops;
  289. extern struct super_operations sysv_sops;
  290. extern struct dentry_operations sysv_dentry_operations;
  291. extern struct sysv_inode *sysv_raw_inode(struct super_block *, unsigned, struct buffer_head **);
  292. static inline void dirty_sb(struct super_block *sb)
  293. {
  294. mark_buffer_dirty(sb->sv_bh1);
  295. if (sb->sv_bh1 != sb->sv_bh2)
  296. mark_buffer_dirty(sb->sv_bh2);
  297. sb->s_dirt = 1;
  298. }
  299. static inline u32 fs32_to_cpu(struct super_block *sb, u32 n)
  300. {
  301. if (sb->sv_bytesex == BYTESEX_PDP)
  302. return PDP_swab(n);
  303. else if (sb->sv_bytesex == BYTESEX_LE)
  304. return le32_to_cpu(n);
  305. else
  306. return be32_to_cpu(n);
  307. }
  308. static inline u32 cpu_to_fs32(struct super_block *sb, u32 n)
  309. {
  310. if (sb->sv_bytesex == BYTESEX_PDP)
  311. return PDP_swab(n);
  312. else if (sb->sv_bytesex == BYTESEX_LE)
  313. return cpu_to_le32(n);
  314. else
  315. return cpu_to_be32(n);
  316. }
  317. static inline u32 fs32_add(struct super_block *sb, u32 *n, int d)
  318. {
  319. if (sb->sv_bytesex == BYTESEX_PDP)
  320. return *n = PDP_swab(PDP_swab(*n)+d);
  321. else if (sb->sv_bytesex == BYTESEX_LE)
  322. return *n = cpu_to_le32(le32_to_cpu(*n)+d);
  323. else
  324. return *n = cpu_to_be32(be32_to_cpu(*n)+d);
  325. }
  326. static inline u16 fs16_to_cpu(struct super_block *sb, u16 n)
  327. {
  328. if (sb->sv_bytesex != BYTESEX_BE)
  329. return le16_to_cpu(n);
  330. else
  331. return be16_to_cpu(n);
  332. }
  333. static inline u16 cpu_to_fs16(struct super_block *sb, u16 n)
  334. {
  335. if (sb->sv_bytesex != BYTESEX_BE)
  336. return cpu_to_le16(n);
  337. else
  338. return cpu_to_be16(n);
  339. }
  340. static inline u16 fs16_add(struct super_block *sb, u16 *n, int d)
  341. {
  342. if (sb->sv_bytesex != BYTESEX_BE)
  343. return *n = cpu_to_le16(le16_to_cpu(*n)+d);
  344. else
  345. return *n = cpu_to_be16(be16_to_cpu(*n)+d);
  346. }
  347. #endif /* __KERNEL__ */
  348. #endif