blob: e913698779c0b517b8449795266e14884f718888 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _SYSV_H
3#define _SYSV_H
4
5#include <linux/buffer_head.h>
6
7typedef __u16 __bitwise __fs16;
8typedef __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
22struct 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) */
26 char s_truncate; /* if 1: names > SYSV_NAMELEN chars are truncated */
27 /* if 0: they are disallowed (ENAMETOOLONG) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 unsigned int s_inodes_per_block; /* number of inodes per block */
29 unsigned int s_inodes_per_block_1; /* inodes_per_block - 1 */
30 unsigned int s_inodes_per_block_bits; /* log2(inodes_per_block) */
31 unsigned int s_ind_per_block; /* number of indirections per block */
32 unsigned int s_ind_per_block_bits; /* log2(ind_per_block) */
33 unsigned int s_ind_per_block_2; /* ind_per_block ^ 2 */
34 unsigned int s_toobig_block; /* 10 + ipb + ipb^2 + ipb^3 */
35 unsigned int s_block_base; /* physical block number of block 0 */
36 unsigned short s_fic_size; /* free inode cache size, NICINOD */
37 unsigned short s_flc_size; /* free block list chunk size, NICFREE */
38 /* The superblock is kept in one or two disk buffers: */
39 struct buffer_head *s_bh1;
40 struct buffer_head *s_bh2;
41 /* These are pointers into the disk buffer, to compensate for
42 different superblock layout. */
43 char * s_sbd1; /* entire superblock data, for part 1 */
44 char * s_sbd2; /* entire superblock data, for part 2 */
45 __fs16 *s_sb_fic_count; /* pointer to s_sbd->s_ninode */
46 sysv_ino_t *s_sb_fic_inodes; /* pointer to s_sbd->s_inode */
47 __fs16 *s_sb_total_free_inodes; /* pointer to s_sbd->s_tinode */
48 __fs16 *s_bcache_count; /* pointer to s_sbd->s_nfree */
49 sysv_zone_t *s_bcache; /* pointer to s_sbd->s_free */
50 __fs32 *s_free_blocks; /* pointer to s_sbd->s_tfree */
51 __fs32 *s_sb_time; /* pointer to s_sbd->s_time */
52 __fs32 *s_sb_state; /* pointer to s_sbd->s_state, only FSTYPE_SYSV */
53 /* We keep those superblock entities that don't change here;
54 this saves us an indirection and perhaps a conversion. */
55 u32 s_firstinodezone; /* index of first inode zone */
56 u32 s_firstdatazone; /* same as s_sbd->s_isize */
57 u32 s_ninodes; /* total number of inodes */
58 u32 s_ndatazones; /* total number of data zones */
59 u32 s_nzones; /* same as s_sbd->s_fsize */
60 u16 s_namelen; /* max length of dir entry */
61 int s_forced_ro;
Marco Stornellic07cb012012-10-06 12:41:46 +020062 struct mutex s_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
65/*
66 * SystemV/V7/Coherent FS inode data in memory
67 */
68struct sysv_inode_info {
69 __fs32 i_data[13];
70 u32 i_dir_start_lookup;
71 struct inode vfs_inode;
72};
73
74
75static inline struct sysv_inode_info *SYSV_I(struct inode *inode)
76{
Rasmus Villemoesdb6172c2015-03-19 12:28:04 +010077 return container_of(inode, struct sysv_inode_info, vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
80static inline struct sysv_sb_info *SYSV_SB(struct super_block *sb)
81{
82 return sb->s_fs_info;
83}
84
85
86/* identify the FS in memory */
87enum {
88 FSTYPE_NONE = 0,
89 FSTYPE_XENIX,
90 FSTYPE_SYSV4,
91 FSTYPE_SYSV2,
92 FSTYPE_COH,
93 FSTYPE_V7,
94 FSTYPE_AFS,
95 FSTYPE_END,
96};
97
98#define SYSV_MAGIC_BASE 0x012FF7B3
99
100#define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
101#define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
102#define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
103#define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
104
105
106/* Admissible values for i_nlink: 0.._LINK_MAX */
107enum {
108 XENIX_LINK_MAX = 126, /* ?? */
109 SYSV_LINK_MAX = 126, /* 127? 251? */
110 V7_LINK_MAX = 126, /* ?? */
111 COH_LINK_MAX = 10000,
112};
113
114
115static inline void dirty_sb(struct super_block *sb)
116{
117 struct sysv_sb_info *sbi = SYSV_SB(sb);
118
119 mark_buffer_dirty(sbi->s_bh1);
120 if (sbi->s_bh1 != sbi->s_bh2)
121 mark_buffer_dirty(sbi->s_bh2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124
125/* ialloc.c */
126extern struct sysv_inode *sysv_raw_inode(struct super_block *, unsigned,
127 struct buffer_head **);
Al Virodd716e62011-07-26 02:49:38 -0400128extern struct inode * sysv_new_inode(const struct inode *, umode_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129extern void sysv_free_inode(struct inode *);
130extern unsigned long sysv_count_free_inodes(struct super_block *);
131
132/* balloc.c */
133extern sysv_zone_t sysv_new_block(struct super_block *);
134extern void sysv_free_block(struct super_block *, sysv_zone_t);
135extern unsigned long sysv_count_free_blocks(struct super_block *);
136
137/* itree.c */
138extern void sysv_truncate(struct inode *);
Christoph Hellwigf4e420d2010-06-04 11:29:56 +0200139extern int sysv_prepare_chunk(struct page *page, loff_t pos, unsigned len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141/* inode.c */
David Howellsb8e13432008-02-07 00:15:47 -0800142extern struct inode *sysv_iget(struct super_block *, unsigned int);
Christoph Hellwiga9185b42010-03-05 09:21:37 +0100143extern int sysv_write_inode(struct inode *, struct writeback_control *wbc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144extern int sysv_sync_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145extern void sysv_set_inode(struct inode *, dev_t);
David Howellsa528d352017-01-31 16:46:22 +0000146extern int sysv_getattr(const struct path *, struct kstat *, u32, unsigned int);
Adrian Bunk3b2b96a2006-12-22 01:07:09 -0800147extern int sysv_init_icache(void);
148extern void sysv_destroy_icache(void);
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/* dir.c */
152extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **);
153extern int sysv_add_link(struct dentry *, struct inode *);
154extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *);
155extern int sysv_make_empty(struct inode *, struct inode *);
156extern int sysv_empty_dir(struct inode *);
157extern void sysv_set_link(struct sysv_dir_entry *, struct page *,
158 struct inode *);
159extern struct sysv_dir_entry *sysv_dotdot(struct inode *, struct page **);
160extern ino_t sysv_inode_by_name(struct dentry *);
161
162
Arjan van de Venc5ef1c42007-02-12 00:55:40 -0800163extern const struct inode_operations sysv_file_inode_operations;
164extern const struct inode_operations sysv_dir_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800165extern const struct file_operations sysv_file_operations;
166extern const struct file_operations sysv_dir_operations;
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700167extern const struct address_space_operations sysv_aops;
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800168extern const struct super_operations sysv_sops;
Al Viroe16404e2009-02-20 05:55:13 +0000169extern const struct dentry_operations sysv_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171
172enum {
173 BYTESEX_LE,
174 BYTESEX_PDP,
175 BYTESEX_BE,
176};
177
178static inline u32 PDP_swab(u32 x)
179{
180#ifdef __LITTLE_ENDIAN
181 return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
182#else
183#ifdef __BIG_ENDIAN
184 return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
185#else
186#error BYTESEX
187#endif
188#endif
189}
190
191static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
192{
193 if (sbi->s_bytesex == BYTESEX_PDP)
194 return PDP_swab((__force __u32)n);
195 else if (sbi->s_bytesex == BYTESEX_LE)
196 return le32_to_cpu((__force __le32)n);
197 else
198 return be32_to_cpu((__force __be32)n);
199}
200
201static inline __fs32 cpu_to_fs32(struct sysv_sb_info *sbi, __u32 n)
202{
203 if (sbi->s_bytesex == BYTESEX_PDP)
204 return (__force __fs32)PDP_swab(n);
205 else if (sbi->s_bytesex == BYTESEX_LE)
206 return (__force __fs32)cpu_to_le32(n);
207 else
208 return (__force __fs32)cpu_to_be32(n);
209}
210
211static inline __fs32 fs32_add(struct sysv_sb_info *sbi, __fs32 *n, int d)
212{
213 if (sbi->s_bytesex == BYTESEX_PDP)
214 *(__u32*)n = PDP_swab(PDP_swab(*(__u32*)n)+d);
215 else if (sbi->s_bytesex == BYTESEX_LE)
Marcin Slusarz07132922008-04-30 00:54:49 -0700216 le32_add_cpu((__le32 *)n, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 else
Marcin Slusarz07132922008-04-30 00:54:49 -0700218 be32_add_cpu((__be32 *)n, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return *n;
220}
221
222static inline __u16 fs16_to_cpu(struct sysv_sb_info *sbi, __fs16 n)
223{
224 if (sbi->s_bytesex != BYTESEX_BE)
225 return le16_to_cpu((__force __le16)n);
226 else
227 return be16_to_cpu((__force __be16)n);
228}
229
230static inline __fs16 cpu_to_fs16(struct sysv_sb_info *sbi, __u16 n)
231{
232 if (sbi->s_bytesex != BYTESEX_BE)
233 return (__force __fs16)cpu_to_le16(n);
234 else
235 return (__force __fs16)cpu_to_be16(n);
236}
237
238static inline __fs16 fs16_add(struct sysv_sb_info *sbi, __fs16 *n, int d)
239{
240 if (sbi->s_bytesex != BYTESEX_BE)
Marcin Slusarz07132922008-04-30 00:54:49 -0700241 le16_add_cpu((__le16 *)n, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 else
Marcin Slusarz07132922008-04-30 00:54:49 -0700243 be16_add_cpu((__be16 *)n, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return *n;
245}
246
247#endif /* _SYSV_H */