sysv.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SYSV_H
  3. #define _SYSV_H
  4. #include <linux/buffer_head.h>
  5. typedef __u16 __bitwise __fs16;
  6. typedef __u32 __bitwise __fs32;
  7. #include <linux/sysv_fs.h>
  8. /*
  9. * SystemV/V7/Coherent super-block data in memory
  10. *
  11. * The SystemV/V7/Coherent superblock contains dynamic data (it gets modified
  12. * while the system is running). This is in contrast to the Minix and Berkeley
  13. * filesystems (where the superblock is never modified). This affects the
  14. * sync() operation: we must keep the superblock in a disk buffer and use this
  15. * one as our "working copy".
  16. */
  17. struct sysv_sb_info {
  18. struct super_block *s_sb; /* VFS superblock */
  19. int s_type; /* file system type: FSTYPE_{XENIX|SYSV|COH} */
  20. char s_bytesex; /* bytesex (le/be/pdp) */
  21. unsigned int s_inodes_per_block; /* number of inodes per block */
  22. unsigned int s_inodes_per_block_1; /* inodes_per_block - 1 */
  23. unsigned int s_inodes_per_block_bits; /* log2(inodes_per_block) */
  24. unsigned int s_ind_per_block; /* number of indirections per block */
  25. unsigned int s_ind_per_block_bits; /* log2(ind_per_block) */
  26. unsigned int s_ind_per_block_2; /* ind_per_block ^ 2 */
  27. unsigned int s_toobig_block; /* 10 + ipb + ipb^2 + ipb^3 */
  28. unsigned int s_block_base; /* physical block number of block 0 */
  29. unsigned short s_fic_size; /* free inode cache size, NICINOD */
  30. unsigned short s_flc_size; /* free block list chunk size, NICFREE */
  31. /* The superblock is kept in one or two disk buffers: */
  32. struct buffer_head *s_bh1;
  33. struct buffer_head *s_bh2;
  34. /* These are pointers into the disk buffer, to compensate for
  35. different superblock layout. */
  36. char * s_sbd1; /* entire superblock data, for part 1 */
  37. char * s_sbd2; /* entire superblock data, for part 2 */
  38. __fs16 *s_sb_fic_count; /* pointer to s_sbd->s_ninode */
  39. sysv_ino_t *s_sb_fic_inodes; /* pointer to s_sbd->s_inode */
  40. __fs16 *s_sb_total_free_inodes; /* pointer to s_sbd->s_tinode */
  41. __fs16 *s_bcache_count; /* pointer to s_sbd->s_nfree */
  42. sysv_zone_t *s_bcache; /* pointer to s_sbd->s_free */
  43. __fs32 *s_free_blocks; /* pointer to s_sbd->s_tfree */
  44. __fs32 *s_sb_time; /* pointer to s_sbd->s_time */
  45. __fs32 *s_sb_state; /* pointer to s_sbd->s_state, only FSTYPE_SYSV */
  46. /* We keep those superblock entities that don't change here;
  47. this saves us an indirection and perhaps a conversion. */
  48. u32 s_firstinodezone; /* index of first inode zone */
  49. u32 s_firstdatazone; /* same as s_sbd->s_isize */
  50. u32 s_ninodes; /* total number of inodes */
  51. u32 s_ndatazones; /* total number of data zones */
  52. u32 s_nzones; /* same as s_sbd->s_fsize */
  53. u16 s_namelen; /* max length of dir entry */
  54. int s_forced_ro;
  55. struct mutex s_lock;
  56. };
  57. /*
  58. * SystemV/V7/Coherent FS inode data in memory
  59. */
  60. struct sysv_inode_info {
  61. __fs32 i_data[13];
  62. u32 i_dir_start_lookup;
  63. struct inode vfs_inode;
  64. };
  65. static inline struct sysv_inode_info *SYSV_I(struct inode *inode)
  66. {
  67. return container_of(inode, struct sysv_inode_info, vfs_inode);
  68. }
  69. static inline struct sysv_sb_info *SYSV_SB(struct super_block *sb)
  70. {
  71. return sb->s_fs_info;
  72. }
  73. /* identify the FS in memory */
  74. enum {
  75. FSTYPE_NONE = 0,
  76. FSTYPE_XENIX,
  77. FSTYPE_SYSV4,
  78. FSTYPE_SYSV2,
  79. FSTYPE_COH,
  80. FSTYPE_V7,
  81. FSTYPE_AFS,
  82. FSTYPE_END,
  83. };
  84. #define SYSV_MAGIC_BASE 0x012FF7B3
  85. #define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
  86. #define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
  87. #define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
  88. #define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
  89. /* Admissible values for i_nlink: 0.._LINK_MAX */
  90. enum {
  91. XENIX_LINK_MAX = 126, /* ?? */
  92. SYSV_LINK_MAX = 126, /* 127? 251? */
  93. V7_LINK_MAX = 126, /* ?? */
  94. COH_LINK_MAX = 10000,
  95. };
  96. static inline void dirty_sb(struct super_block *sb)
  97. {
  98. struct sysv_sb_info *sbi = SYSV_SB(sb);
  99. mark_buffer_dirty(sbi->s_bh1);
  100. if (sbi->s_bh1 != sbi->s_bh2)
  101. mark_buffer_dirty(sbi->s_bh2);
  102. }
  103. /* ialloc.c */
  104. extern struct sysv_inode *sysv_raw_inode(struct super_block *, unsigned,
  105. struct buffer_head **);
  106. extern struct inode * sysv_new_inode(const struct inode *, umode_t);
  107. extern void sysv_free_inode(struct inode *);
  108. extern unsigned long sysv_count_free_inodes(struct super_block *);
  109. /* balloc.c */
  110. extern sysv_zone_t sysv_new_block(struct super_block *);
  111. extern void sysv_free_block(struct super_block *, sysv_zone_t);
  112. extern unsigned long sysv_count_free_blocks(struct super_block *);
  113. /* itree.c */
  114. extern void sysv_truncate(struct inode *);
  115. extern int sysv_prepare_chunk(struct page *page, loff_t pos, unsigned len);
  116. /* inode.c */
  117. extern struct inode *sysv_iget(struct super_block *, unsigned int);
  118. extern int sysv_write_inode(struct inode *, struct writeback_control *wbc);
  119. extern int sysv_sync_inode(struct inode *);
  120. extern void sysv_set_inode(struct inode *, dev_t);
  121. extern int sysv_getattr(const struct path *, struct kstat *, u32, unsigned int);
  122. extern int sysv_init_icache(void);
  123. extern void sysv_destroy_icache(void);
  124. /* dir.c */
  125. extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **);
  126. extern int sysv_add_link(struct dentry *, struct inode *);
  127. extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *);
  128. extern int sysv_make_empty(struct inode *, struct inode *);
  129. extern int sysv_empty_dir(struct inode *);
  130. extern void sysv_set_link(struct sysv_dir_entry *, struct page *,
  131. struct inode *);
  132. extern struct sysv_dir_entry *sysv_dotdot(struct inode *, struct page **);
  133. extern ino_t sysv_inode_by_name(struct dentry *);
  134. extern const struct inode_operations sysv_file_inode_operations;
  135. extern const struct inode_operations sysv_dir_inode_operations;
  136. extern const struct file_operations sysv_file_operations;
  137. extern const struct file_operations sysv_dir_operations;
  138. extern const struct address_space_operations sysv_aops;
  139. extern const struct super_operations sysv_sops;
  140. enum {
  141. BYTESEX_LE,
  142. BYTESEX_PDP,
  143. BYTESEX_BE,
  144. };
  145. static inline u32 PDP_swab(u32 x)
  146. {
  147. #ifdef __LITTLE_ENDIAN
  148. return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
  149. #else
  150. #ifdef __BIG_ENDIAN
  151. return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
  152. #else
  153. #error BYTESEX
  154. #endif
  155. #endif
  156. }
  157. static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
  158. {
  159. if (sbi->s_bytesex == BYTESEX_PDP)
  160. return PDP_swab((__force __u32)n);
  161. else if (sbi->s_bytesex == BYTESEX_LE)
  162. return le32_to_cpu((__force __le32)n);
  163. else
  164. return be32_to_cpu((__force __be32)n);
  165. }
  166. static inline __fs32 cpu_to_fs32(struct sysv_sb_info *sbi, __u32 n)
  167. {
  168. if (sbi->s_bytesex == BYTESEX_PDP)
  169. return (__force __fs32)PDP_swab(n);
  170. else if (sbi->s_bytesex == BYTESEX_LE)
  171. return (__force __fs32)cpu_to_le32(n);
  172. else
  173. return (__force __fs32)cpu_to_be32(n);
  174. }
  175. static inline __fs32 fs32_add(struct sysv_sb_info *sbi, __fs32 *n, int d)
  176. {
  177. if (sbi->s_bytesex == BYTESEX_PDP)
  178. *(__u32*)n = PDP_swab(PDP_swab(*(__u32*)n)+d);
  179. else if (sbi->s_bytesex == BYTESEX_LE)
  180. le32_add_cpu((__le32 *)n, d);
  181. else
  182. be32_add_cpu((__be32 *)n, d);
  183. return *n;
  184. }
  185. static inline __u16 fs16_to_cpu(struct sysv_sb_info *sbi, __fs16 n)
  186. {
  187. if (sbi->s_bytesex != BYTESEX_BE)
  188. return le16_to_cpu((__force __le16)n);
  189. else
  190. return be16_to_cpu((__force __be16)n);
  191. }
  192. static inline __fs16 cpu_to_fs16(struct sysv_sb_info *sbi, __u16 n)
  193. {
  194. if (sbi->s_bytesex != BYTESEX_BE)
  195. return (__force __fs16)cpu_to_le16(n);
  196. else
  197. return (__force __fs16)cpu_to_be16(n);
  198. }
  199. static inline __fs16 fs16_add(struct sysv_sb_info *sbi, __fs16 *n, int d)
  200. {
  201. if (sbi->s_bytesex != BYTESEX_BE)
  202. le16_add_cpu((__le16 *)n, d);
  203. else
  204. be16_add_cpu((__be16 *)n, d);
  205. return *n;
  206. }
  207. #endif /* _SYSV_H */