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