File: /usr/src/linux/include/linux/sysv_fs.h
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
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 /* The admissible values for i_mode are listed in <linux/stat.h> :
245 * #define S_IFMT 00170000 mask for type
246 * #define S_IFREG 0100000 type = regular file
247 * #define S_IFBLK 0060000 type = block device
248 * #define S_IFDIR 0040000 type = directory
249 * #define S_IFCHR 0020000 type = character device
250 * #define S_IFIFO 0010000 type = named pipe
251 * #define S_ISUID 0004000 set user id
252 * #define S_ISGID 0002000 set group id
253 * #define S_ISVTX 0001000 save swapped text even after use
254 * Additionally for SystemV:
255 * #define S_IFLNK 0120000 type = symbolic link
256 * #define S_IFNAM 0050000 type = XENIX special named file ??
257 * Additionally for Coherent:
258 * #define S_IFMPB 0070000 type = multiplexed block device ??
259 * #define S_IFMPC 0030000 type = multiplexed character device ??
260 *
261 * Since Coherent doesn't know about symbolic links, we use a kludgey
262 * implementation of symbolic links: i_mode = COH_KLUDGE_SYMLINK_MODE
263 * denotes a symbolic link. When a regular file should get this mode by
264 * accident, it is automatically converted to COH_KLUDGE_NOT_SYMLINK.
265 * We use S_IFREG because only regular files (and Coherent pipes...) can have
266 * data blocks with arbitrary contents associated with them, and S_ISVTX
267 * ("save swapped text after use") because it is unused on both Linux and
268 * Coherent: Linux does much more intelligent paging, and Coherent hasn't
269 * virtual memory at all.
270 * Same trick for Xenix.
271 */
272 #define COH_KLUDGE_SYMLINK_MODE (S_IFREG | S_ISVTX)
273 #define COH_KLUDGE_NOT_SYMLINK (S_IFREG | S_ISVTX | S_IRUSR) /* force read access */
274 static inline mode_t from_coh_imode(unsigned short mode)
275 {
276 if (mode == COH_KLUDGE_SYMLINK_MODE)
277 return (S_IFLNK | 0777);
278 else
279 return mode;
280 }
281 static inline unsigned short to_coh_imode(mode_t mode)
282 {
283 if (S_ISLNK(mode))
284 return COH_KLUDGE_SYMLINK_MODE;
285 else if (mode == COH_KLUDGE_SYMLINK_MODE)
286 return COH_KLUDGE_NOT_SYMLINK;
287 else
288 return mode;
289 }
290
291 /* Admissible values for i_nlink: 0.._LINK_MAX */
292 enum {
293 XENIX_LINK_MAX = 126, /* ?? */
294 SYSV_LINK_MAX = 126, /* 127? 251? */
295 V7_LINK_MAX = 126, /* ?? */
296 COH_LINK_MAX = 10000,
297 };
298
299 /* The number of inodes per block is
300 sb->sv_inodes_per_block = block_size / sizeof(struct sysv_inode) */
301 /* The number of indirect pointers per block is
302 sb->sv_ind_per_block = block_size / sizeof(u32) */
303
304
305 /* SystemV/Coherent directory entry on disk */
306
307 #define SYSV_NAMELEN 14 /* max size of name in struct sysv_dir_entry */
308
309 struct sysv_dir_entry {
310 sysv_ino_t inode;
311 char name[SYSV_NAMELEN]; /* up to 14 characters, the rest are zeroes */
312 };
313
314 #define SYSV_DIRSIZE sizeof(struct sysv_dir_entry) /* size of every directory entry */
315
316
317 /* Operations */
318 /* ========== */
319
320 /* identify the FS in memory */
321 enum {
322 FSTYPE_NONE = 0,
323 FSTYPE_XENIX,
324 FSTYPE_SYSV4,
325 FSTYPE_SYSV2,
326 FSTYPE_COH,
327 FSTYPE_V7,
328 FSTYPE_AFS,
329 FSTYPE_END,
330 };
331
332 #define SYSV_MAGIC_BASE 0x012FF7B3
333
334 #define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
335 #define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
336 #define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
337 #define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
338
339 #ifdef __KERNEL__
340
341 enum {
342 BYTESEX_LE,
343 BYTESEX_PDP,
344 BYTESEX_BE,
345 };
346
347 /*
348 * Function prototypes
349 */
350
351 extern struct inode * sysv_new_inode(const struct inode *, mode_t);
352 extern void sysv_free_inode(struct inode *);
353 extern unsigned long sysv_count_free_inodes(struct super_block *);
354 extern u32 sysv_new_block(struct super_block *);
355 extern void sysv_free_block(struct super_block *, u32);
356 extern unsigned long sysv_count_free_blocks(struct super_block *);
357
358 extern void sysv_truncate(struct inode *);
359
360 extern void sysv_write_inode(struct inode *, int);
361 extern int sysv_sync_inode(struct inode *);
362 extern int sysv_sync_file(struct file *, struct dentry *, int);
363 extern int sysv_notify_change(struct dentry *, struct iattr *);
364 extern void sysv_set_inode(struct inode *, dev_t);
365
366 extern struct sysv_dir_entry *sysv_find_entry(struct dentry*, struct page**);
367 extern int sysv_add_link(struct dentry*, struct inode*);
368 extern int sysv_delete_entry(struct sysv_dir_entry*, struct page*);
369 extern int sysv_make_empty(struct inode*, struct inode*);
370 extern int sysv_empty_dir(struct inode*);
371 extern void sysv_set_link(struct sysv_dir_entry*, struct page*, struct inode*);
372 extern struct sysv_dir_entry *sysv_dotdot(struct inode*, struct page**);
373 extern ino_t sysv_inode_by_name(struct dentry*);
374
375 extern struct inode_operations sysv_file_inode_operations;
376 extern struct inode_operations sysv_dir_inode_operations;
377 extern struct inode_operations sysv_fast_symlink_inode_operations;
378 extern struct file_operations sysv_file_operations;
379 extern struct file_operations sysv_dir_operations;
380 extern struct address_space_operations sysv_aops;
381 extern struct super_operations sysv_sops;
382 extern struct dentry_operations sysv_dentry_operations;
383
384 extern struct sysv_inode *sysv_raw_inode(struct super_block *, unsigned, struct buffer_head **);
385
386 static inline void dirty_sb(struct super_block *sb)
387 {
388 mark_buffer_dirty(sb->sv_bh1);
389 if (sb->sv_bh1 != sb->sv_bh2)
390 mark_buffer_dirty(sb->sv_bh2);
391 sb->s_dirt = 1;
392 }
393
394 static inline u32 fs32_to_cpu(struct super_block *sb, u32 n)
395 {
396 if (sb->sv_bytesex == BYTESEX_PDP)
397 return PDP_swab(n);
398 else if (sb->sv_bytesex == BYTESEX_LE)
399 return le32_to_cpu(n);
400 else
401 return be32_to_cpu(n);
402 }
403
404 static inline u32 cpu_to_fs32(struct super_block *sb, u32 n)
405 {
406 if (sb->sv_bytesex == BYTESEX_PDP)
407 return PDP_swab(n);
408 else if (sb->sv_bytesex == BYTESEX_LE)
409 return cpu_to_le32(n);
410 else
411 return cpu_to_be32(n);
412 }
413
414 static inline u32 fs32_add(struct super_block *sb, u32 *n, int d)
415 {
416 if (sb->sv_bytesex == BYTESEX_PDP)
417 return *n = PDP_swab(PDP_swab(*n)+d);
418 else if (sb->sv_bytesex == BYTESEX_LE)
419 return *n = cpu_to_le32(le32_to_cpu(*n)+d);
420 else
421 return *n = cpu_to_be32(be32_to_cpu(*n)+d);
422 }
423
424 static inline u16 fs16_to_cpu(struct super_block *sb, u16 n)
425 {
426 if (sb->sv_bytesex != BYTESEX_BE)
427 return le16_to_cpu(n);
428 else
429 return be16_to_cpu(n);
430 }
431
432 static inline u16 cpu_to_fs16(struct super_block *sb, u16 n)
433 {
434 if (sb->sv_bytesex != BYTESEX_BE)
435 return cpu_to_le16(n);
436 else
437 return cpu_to_be16(n);
438 }
439
440 static inline u16 fs16_add(struct super_block *sb, u16 *n, int d)
441 {
442 if (sb->sv_bytesex != BYTESEX_BE)
443 return *n = cpu_to_le16(le16_to_cpu(*n)+d);
444 else
445 return *n = cpu_to_be16(be16_to_cpu(*n)+d);
446 }
447
448 #endif /* __KERNEL__ */
449
450 #endif
451