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