1 #ifndef _LINUX_SYSV_FS_H
2 #define _LINUX_SYSV_FS_H
5 * The SystemV/Coherent filesystem constants/structures/macros
10 - a little endian processor like 386,
11 - sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 4,
12 - alignof(short) = 2, alignof(long) = 4.
16 #define __packed2__ __attribute__ ((packed, aligned(2)))
21 #include <linux/stat.h> /* declares S_IFLNK etc. */
22 #include <linux/sched.h> /* declares wake_up() */
23 #include <linux/sysv_fs_sb.h> /* defines the sv_... shortcuts */
30 /* The block size is sb->sv_block_size which may be smaller than BLOCK_SIZE. */
32 /* zones (= data allocation units) are blocks */
34 /* On Coherent FS, 32 bit quantities are stored using (I quote the Coherent
35 manual) a "canonical byte ordering". This is the PDP-11 byte ordering:
36 x = 2^24 * byte3 + 2^16 * byte2 + 2^8 * byte1 + byte0 is stored
37 as { byte2, byte3, byte0, byte1 }. We need conversions.
40 typedef u32 coh_ulong
;
42 static inline coh_ulong
to_coh_ulong (u32 x
)
44 return ((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16);
47 static inline u32
from_coh_ulong (coh_ulong x
)
49 return ((x
& 0xffff) << 16) | ((x
& 0xffff0000) >> 16);
52 /* inode numbers are 16 bit */
54 typedef u16 sysv_ino_t
;
56 /* Block numbers are 24 bit, sometimes stored in 32 bit.
57 On Coherent FS, they are always stored in PDP-11 manner: the least
58 significant 16 bits come last.
61 typedef u32 sysv_zone_t
;
63 /* Among the blocks ... */
64 /* Xenix FS, Coherent FS: block 0 is the boot block, block 1 the super-block.
65 SystemV FS: block 0 contains both the boot sector and the super-block. */
66 /* The first inode zone is sb->sv_firstinodezone (1 or 2). */
68 /* Among the inodes ... */
69 /* 0 is non-existent */
70 #define SYSV_BADBL_INO 1 /* inode of bad blocks file */
71 #define SYSV_ROOT_INO 2 /* inode of root directory */
74 /* Xenix super-block data on disk */
75 #define XENIX_NICINOD 100 /* number of inode cache entries */
76 #define XENIX_NICFREE 100 /* number of free block list chunk entries */
77 struct xenix_super_block
{
78 u16 s_isize
; /* index of first data zone */
79 u32 s_fsize __packed2__
; /* total number of zones of this fs */
80 /* the start of the free block list: */
81 u16 s_nfree
; /* number of free blocks in s_free, <= XENIX_NICFREE */
82 u32 s_free
[XENIX_NICFREE
]; /* first free block list chunk */
83 /* the cache of free inodes: */
84 u16 s_ninode
; /* number of free inodes in s_inode, <= XENIX_NICINOD */
85 sysv_ino_t s_inode
[XENIX_NICINOD
]; /* some free inodes */
86 /* locks, not used by Linux: */
87 char s_flock
; /* lock during free block list manipulation */
88 char s_ilock
; /* lock during inode cache manipulation */
89 char s_fmod
; /* super-block modified flag */
90 char s_ronly
; /* flag whether fs is mounted read-only */
91 u32 s_time __packed2__
; /* time of last super block update */
92 u32 s_tfree __packed2__
; /* total number of free zones */
93 u16 s_tinode
; /* total number of free inodes */
94 s16 s_dinfo
[4]; /* device information ?? */
95 char s_fname
[6]; /* file system volume name */
96 char s_fpack
[6]; /* file system pack name */
97 char s_clean
; /* set to 0x46 when filesystem is properly unmounted */
99 s32 s_magic
; /* version of file system */
100 s32 s_type
; /* type of file system: 1 for 512 byte blocks
101 2 for 1024 byte blocks
102 3 for 2048 byte blocks */
106 /* Xenix free list block on disk */
107 struct xenix_freelist_chunk
{
108 u16 fl_nfree
; /* number of free blocks in fl_free, <= XENIX_NICFREE] */
109 u32 fl_free
[XENIX_NICFREE
] __packed2__
;
112 /* SystemV FS comes in two variants:
113 * sysv2: System V Release 2 (e.g. Microport), structure elements aligned(2).
114 * sysv4: System V Release 4 (e.g. Consensys), structure elements aligned(4).
116 #define SYSV_NICINOD 100 /* number of inode cache entries */
117 #define SYSV_NICFREE 50 /* number of free block list chunk entries */
119 /* SystemV4 super-block data on disk */
120 struct sysv4_super_block
{
121 u16 s_isize
; /* index of first data zone */
123 u32 s_fsize
; /* total number of zones of this fs */
124 /* the start of the free block list: */
125 u16 s_nfree
; /* number of free blocks in s_free, <= SYSV_NICFREE */
127 u32 s_free
[SYSV_NICFREE
]; /* first free block list chunk */
128 /* the cache of free inodes: */
129 u16 s_ninode
; /* number of free inodes in s_inode, <= SYSV_NICINOD */
131 sysv_ino_t s_inode
[SYSV_NICINOD
]; /* some free inodes */
132 /* locks, not used by Linux: */
133 char s_flock
; /* lock during free block list manipulation */
134 char s_ilock
; /* lock during inode cache manipulation */
135 char s_fmod
; /* super-block modified flag */
136 char s_ronly
; /* flag whether fs is mounted read-only */
137 u32 s_time
; /* time of last super block update */
138 s16 s_dinfo
[4]; /* device information ?? */
139 u32 s_tfree
; /* total number of free zones */
140 u16 s_tinode
; /* total number of free inodes */
142 char s_fname
[6]; /* file system volume name */
143 char s_fpack
[6]; /* file system pack name */
145 s32 s_state
; /* file system state: 0x7c269d38-s_time means clean */
146 s32 s_magic
; /* version of file system */
147 s32 s_type
; /* type of file system: 1 for 512 byte blocks
148 2 for 1024 byte blocks */
151 /* SystemV4 free list block on disk */
152 struct sysv4_freelist_chunk
{
153 u16 fl_nfree
; /* number of free blocks in fl_free, <= SYSV_NICFREE] */
154 u32 fl_free
[SYSV_NICFREE
];
157 /* SystemV2 super-block data on disk */
158 struct sysv2_super_block
{
159 u16 s_isize
; /* index of first data zone */
160 u32 s_fsize __packed2__
; /* total number of zones of this fs */
161 /* the start of the free block list: */
162 u16 s_nfree
; /* number of free blocks in s_free, <= SYSV_NICFREE */
163 u32 s_free
[SYSV_NICFREE
]; /* first free block list chunk */
164 /* the cache of free inodes: */
165 u16 s_ninode
; /* number of free inodes in s_inode, <= SYSV_NICINOD */
166 sysv_ino_t s_inode
[SYSV_NICINOD
]; /* some free inodes */
167 /* locks, not used by Linux: */
168 char s_flock
; /* lock during free block list manipulation */
169 char s_ilock
; /* lock during inode cache manipulation */
170 char s_fmod
; /* super-block modified flag */
171 char s_ronly
; /* flag whether fs is mounted read-only */
172 u32 s_time __packed2__
; /* time of last super block update */
173 s16 s_dinfo
[4]; /* device information ?? */
174 u32 s_tfree __packed2__
; /* total number of free zones */
175 u16 s_tinode
; /* total number of free inodes */
176 char s_fname
[6]; /* file system volume name */
177 char s_fpack
[6]; /* file system pack name */
179 s32 s_state
; /* file system state: 0xcb096f43 means clean */
180 s32 s_magic
; /* version of file system */
181 s32 s_type
; /* type of file system: 1 for 512 byte blocks
182 2 for 1024 byte blocks */
185 /* SystemV2 free list block on disk */
186 struct sysv2_freelist_chunk
{
187 u16 fl_nfree
; /* number of free blocks in fl_free, <= SYSV_NICFREE] */
188 u32 fl_free
[SYSV_NICFREE
] __packed2__
;
191 /* Coherent super-block data on disk */
192 #define COH_NICINOD 100 /* number of inode cache entries */
193 #define COH_NICFREE 64 /* number of free block list chunk entries */
194 struct coh_super_block
{
195 u16 s_isize
; /* index of first data zone */
196 coh_ulong s_fsize __packed2__
; /* total number of zones of this fs */
197 /* the start of the free block list: */
198 u16 s_nfree
; /* number of free blocks in s_free, <= COH_NICFREE */
199 coh_ulong s_free
[COH_NICFREE
] __packed2__
; /* first free block list chunk */
200 /* the cache of free inodes: */
201 u16 s_ninode
; /* number of free inodes in s_inode, <= COH_NICINOD */
202 sysv_ino_t s_inode
[COH_NICINOD
]; /* some free inodes */
203 /* locks, not used by Linux: */
204 char s_flock
; /* lock during free block list manipulation */
205 char s_ilock
; /* lock during inode cache manipulation */
206 char s_fmod
; /* super-block modified flag */
207 char s_ronly
; /* flag whether fs is mounted read-only */
208 coh_ulong s_time __packed2__
; /* time of last super block update */
209 coh_ulong s_tfree __packed2__
; /* total number of free zones */
210 u16 s_tinode
; /* total number of free inodes */
211 u16 s_interleave_m
; /* interleave factor */
213 char s_fname
[6]; /* file system volume name */
214 char s_fpack
[6]; /* file system pack name */
215 u32 s_unique
; /* zero, not used */
218 /* Coherent free list block on disk */
219 struct coh_freelist_chunk
{
220 u16 fl_nfree
; /* number of free blocks in fl_free, <= COH_NICFREE] */
221 u32 fl_free
[COH_NICFREE
] __packed2__
;
225 /* SystemV/Coherent inode data on disk */
233 union { /* directories, regular files, ... */
234 unsigned char i_addb
[3*(10+1+1+1)+1]; /* zone numbers: max. 10 data blocks,
235 * then 1 indirection block,
236 * then 1 double indirection block,
237 * then 1 triple indirection block.
238 * Then maybe a "file generation number" ??
242 /* named pipes on Coherent */
250 u32 i_atime
; /* time of last access */
251 u32 i_mtime
; /* time of last modification */
252 u32 i_ctime
; /* time of creation */
255 /* The admissible values for i_mode are listed in <linux/stat.h> :
256 * #define S_IFMT 00170000 mask for type
257 * #define S_IFREG 0100000 type = regular file
258 * #define S_IFBLK 0060000 type = block device
259 * #define S_IFDIR 0040000 type = directory
260 * #define S_IFCHR 0020000 type = character device
261 * #define S_IFIFO 0010000 type = named pipe
262 * #define S_ISUID 0004000 set user id
263 * #define S_ISGID 0002000 set group id
264 * #define S_ISVTX 0001000 save swapped text even after use
265 * Additionally for SystemV:
266 * #define S_IFLNK 0120000 type = symbolic link
267 * #define S_IFNAM 0050000 type = XENIX special named file ??
268 * Additionally for Coherent:
269 * #define S_IFMPB 0070000 type = multiplexed block device ??
270 * #define S_IFMPC 0030000 type = multiplexed character device ??
272 * Since Coherent doesn't know about symbolic links, we use a kludgey
273 * implementation of symbolic links: i_mode = COH_KLUDGE_SYMLINK_MODE
274 * denotes a symbolic link. When a regular file should get this mode by
275 * accident, it is automatically converted to COH_KLUDGE_NOT_SYMLINK.
276 * We use S_IFREG because only regular files (and Coherent pipes...) can have
277 * data blocks with arbitrary contents associated with them, and S_ISVTX
278 * ("save swapped text after use") because it is unused on both Linux and
279 * Coherent: Linux does much more intelligent paging, and Coherent hasn't
280 * virtual memory at all.
281 * Same trick for Xenix.
283 #define COH_KLUDGE_SYMLINK_MODE (S_IFREG | S_ISVTX)
284 #define COH_KLUDGE_NOT_SYMLINK (S_IFREG | S_ISVTX | S_IRUSR) /* force read access */
285 extern inline mode_t
from_coh_imode(unsigned short mode
)
287 if (mode
== COH_KLUDGE_SYMLINK_MODE
)
288 return (S_IFLNK
| 0777);
292 extern inline unsigned short to_coh_imode(mode_t mode
)
295 return COH_KLUDGE_SYMLINK_MODE
;
296 else if (mode
== COH_KLUDGE_SYMLINK_MODE
)
297 return COH_KLUDGE_NOT_SYMLINK
;
302 /* Admissible values for i_nlink: 0.._LINK_MAX */
303 #define XENIX_LINK_MAX 126 /* ?? */
304 #define SYSV_LINK_MAX 126 /* 127? 251? */
305 #define COH_LINK_MAX 10000 /* max number of hard links to an inode */
307 /* The number of inodes per block is
308 sb->sv_inodes_per_block = block_size / sizeof(struct sysv_inode) */
309 /* The number of indirect pointers per block is
310 sb->sv_ind_per_block = block_size / sizeof(u32) */
313 /* SystemV/Coherent directory entry on disk */
315 #define SYSV_NAMELEN 14 /* max size of name in struct sysv_dir_entry */
317 struct sysv_dir_entry
{
319 char name
[SYSV_NAMELEN
]; /* up to 14 characters, the rest are zeroes */
322 #define SYSV_DIRSIZE sizeof(struct sysv_dir_entry) /* size of every directory entry */
329 /* identify the FS in memory */
330 #define FSTYPE_XENIX 1
331 #define FSTYPE_SYSV4 2
332 #define FSTYPE_SYSV2 3
335 #define SYSV_MAGIC_BASE 0x012FF7B3
337 #define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
338 #define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
339 #define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
340 #define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
344 /* sv_get_hash_table(sb,dev,block) is equivalent to get_hash_table(dev,block,block_size) */
345 static inline struct buffer_head
*
346 sv_get_hash_table (struct super_block
*sb
, kdev_t dev
, unsigned int block
)
348 return get_hash_table (dev
, block
+ sb
->sv_block_base
, sb
->sv_block_size
);
351 /* sv_getblk(sb,dev,block) is equivalent to getblk(dev,block,block_size) */
352 static inline struct buffer_head
*
353 sv_getblk (struct super_block
*sb
, kdev_t dev
, unsigned int block
)
355 return getblk (dev
, block
+ sb
->sv_block_base
, sb
->sv_block_size
);
358 /* sv_bread(sb,dev,block) is equivalent to bread(dev,block,block_size) */
359 static inline struct buffer_head
*
360 sv_bread (struct super_block
*sb
, kdev_t dev
, unsigned int block
)
362 return bread (dev
, block
+ sb
->sv_block_base
, sb
->sv_block_size
);
367 * Function prototypes
370 extern struct dentry
*sysv_lookup(struct inode
* dir
, struct dentry
* dentry
);
371 extern int sysv_create(struct inode
* dir
, struct dentry
* dentry
, int mode
);
372 extern int sysv_mkdir(struct inode
* dir
, struct dentry
* dentry
, int mode
);
373 extern int sysv_rmdir(struct inode
* dir
, struct dentry
* dentry
);
374 extern int sysv_unlink(struct inode
* dir
, struct dentry
* dentry
);
375 extern int sysv_symlink(struct inode
* inode
, struct dentry
* dentry
, const char * symname
);
376 extern int sysv_link(struct dentry
* old_dentry
, struct inode
* dir
, struct dentry
* dentry
);
377 extern int sysv_mknod(struct inode
* dir
, struct dentry
* dentry
, int mode
, int rdev
);
378 extern int sysv_rename(struct inode
* old_dir
, struct dentry
* old_dentry
,
379 struct inode
* new_dir
, struct dentry
* new_dentry
);
380 extern struct inode
* sysv_new_inode(const struct inode
* dir
);
381 extern void sysv_free_inode(struct inode
* inode
);
382 extern unsigned long sysv_count_free_inodes(struct super_block
*sb
);
383 extern int sysv_new_block(struct super_block
* sb
);
384 extern void sysv_free_block(struct super_block
* sb
, unsigned int block
);
385 extern unsigned long sysv_count_free_blocks(struct super_block
*sb
);
387 extern struct buffer_head
* sysv_getblk(struct inode
*, unsigned int, int);
388 extern int sysv_get_block(struct inode
*, long, struct buffer_head
*, int);
389 extern struct buffer_head
* sysv_file_bread(struct inode
*, int, int);
391 extern void sysv_truncate(struct inode
*);
392 extern int init_sysv_fs(void);
393 extern void sysv_write_inode(struct inode
*);
394 extern int sysv_sync_inode(struct inode
*);
395 extern int sysv_sync_file(struct file
*, struct dentry
*);
397 extern struct inode_operations sysv_file_inode_operations
;
398 extern struct inode_operations sysv_file_inode_operations_with_bmap
;
399 extern struct inode_operations sysv_dir_inode_operations
;
400 extern struct inode_operations sysv_symlink_inode_operations
;
402 #endif /* __KERNEL__ */