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 - a little endian processor like 386, 11 - sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 4, 12 - alignof(short) = 2, alignof(long) = 4. 13 */ 14
15 #ifdef__GNUC__ 16 #define__packed2____attribute__ ((packed, aligned(2)))
17 #else 18 #error I want gcc!
19 #endif 20
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 */ 24
25
26 /* Layout on disk */ 27 /* ============== */ 28
29
30 /* The block size is sb->sv_block_size which may be smaller than BLOCK_SIZE. */ 31
32 /* zones (= data allocation units) are blocks */ 33
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. 38 */ 39
40 typedefunsignedlongcoh_ulong;
41
42 staticinlinecoh_ulongto_coh_ulong (unsignedlongx)
/* */ 43 { 44 return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
45 } 46
47 staticinlineunsignedlongfrom_coh_ulong (coh_ulongx)
/* */ 48 { 49 return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
50 } 51
52 /* inode numbers are 16 bit */ 53
54 typedefunsignedshortsysv_ino_t;
55
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. 59 */ 60
61 typedefunsignedlongsysv_zone_t;
62
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). */ 67
68 /* Among the inodes ... */ 69 /* 0 is non-existent */ 70 #define SYSV_BADBL_INO 1 /* inode of bad blocks file */ 71 #defineSYSV_ROOT_INO 2 /* inode of root directory */ 72
73
74 /* Xenix super-block data on disk */ 75 #defineXENIX_NICINOD 100 /* number of inode cache entries */ 76 #defineXENIX_NICFREE 100 /* number of free block list chunk entries */ 77 structxenix_super_block{ 78 unsignedshorts_isize; /* index of first data zone */ 79 unsignedlongs_fsize__packed2__; /* total number of zones of this fs */ 80 /* the start of the free block list: */ 81 unsignedshorts_nfree; /* number of free blocks in s_free, <= XENIX_NICFREE */ 82 unsignedlongs_free[XENIX_NICFREE]; /* first free block list chunk */ 83 /* the cache of free inodes: */ 84 unsignedshorts_ninode; /* number of free inodes in s_inode, <= XENIX_NICINOD */ 85 sysv_ino_ts_inode[XENIX_NICINOD]; /* some free inodes */ 86 /* locks, not used by Linux: */ 87 chars_flock; /* lock during free block list manipulation */ 88 chars_ilock; /* lock during inode cache manipulation */ 89 chars_fmod; /* super-block modified flag */ 90 chars_ronly; /* flag whether fs is mounted read-only */ 91 unsignedlongs_time__packed2__; /* time of last super block update */ 92 unsignedlongs_tfree__packed2__; /* total number of free zones */ 93 unsignedshorts_tinode; /* total number of free inodes */ 94 shorts_dinfo[4]; /* device information ?? */ 95 chars_fname[6]; /* file system volume name */ 96 chars_fpack[6]; /* file system pack name */ 97 char s_clean; /* set to 0x46 when filesystem is properly unmounted */ 98 chars_fill[371];
99 longs_magic; /* version of file system */ 100 longs_type; /* type of file system: 1 for 512 byte blocks 101 2 for 1024 byte blocks */ 102 };
103
104 /* Xenix free list block on disk */ 105 structxenix_freelist_chunk{ 106 unsignedshortfl_nfree; /* number of free blocks in fl_free, <= XENIX_NICFREE] */ 107 unsignedlongfl_free[XENIX_NICFREE] __packed2__;
108 };
109
110 /* SystemV FS comes in two variants: 111 * sysv2: System V Release 2 (e.g. Microport), structure elements aligned(2). 112 * sysv4: System V Release 4 (e.g. Consensys), structure elements aligned(4). 113 */ 114 #defineSYSV_NICINOD 100 /* number of inode cache entries */ 115 #defineSYSV_NICFREE 50 /* number of free block list chunk entries */ 116
117 /* SystemV4 super-block data on disk */ 118 structsysv4_super_block{ 119 unsignedshorts_isize; /* index of first data zone */ 120 unsignedlongs_fsize; /* total number of zones of this fs */ 121 /* the start of the free block list: */ 122 unsignedshorts_nfree; /* number of free blocks in s_free, <= SYSV_NICFREE */ 123 unsignedlongs_free[SYSV_NICFREE]; /* first free block list chunk */ 124 /* the cache of free inodes: */ 125 unsignedshorts_ninode; /* number of free inodes in s_inode, <= SYSV_NICINOD */ 126 sysv_ino_ts_inode[SYSV_NICINOD]; /* some free inodes */ 127 /* locks, not used by Linux: */ 128 chars_flock; /* lock during free block list manipulation */ 129 chars_ilock; /* lock during inode cache manipulation */ 130 chars_fmod; /* super-block modified flag */ 131 chars_ronly; /* flag whether fs is mounted read-only */ 132 unsignedlongs_time; /* time of last super block update */ 133 shorts_dinfo[4]; /* device information ?? */ 134 unsignedlongs_tfree; /* total number of free zones */ 135 unsignedshorts_tinode; /* total number of free inodes */ 136 chars_fname[6]; /* file system volume name */ 137 chars_fpack[6]; /* file system pack name */ 138 longs_fill[12];
139 longs_state; /* file system state */ 140 longs_magic; /* version of file system */ 141 longs_type; /* type of file system: 1 for 512 byte blocks 142 2 for 1024 byte blocks */ 143 };
144
145 /* SystemV4 free list block on disk */ 146 structsysv4_freelist_chunk{ 147 unsignedshortfl_nfree; /* number of free blocks in fl_free, <= SYSV_NICFREE] */ 148 unsignedlongfl_free[SYSV_NICFREE];
149 };
150
151 /* SystemV2 super-block data on disk */ 152 structsysv2_super_block{ 153 unsignedshorts_isize; /* index of first data zone */ 154 unsignedlongs_fsize__packed2__; /* total number of zones of this fs */ 155 /* the start of the free block list: */ 156 unsignedshorts_nfree; /* number of free blocks in s_free, <= SYSV_NICFREE */ 157 unsignedlongs_free[SYSV_NICFREE]; /* first free block list chunk */ 158 /* the cache of free inodes: */ 159 unsignedshorts_ninode; /* number of free inodes in s_inode, <= SYSV_NICINOD */ 160 sysv_ino_ts_inode[SYSV_NICINOD]; /* some free inodes */ 161 /* locks, not used by Linux: */ 162 chars_flock; /* lock during free block list manipulation */ 163 chars_ilock; /* lock during inode cache manipulation */ 164 chars_fmod; /* super-block modified flag */ 165 chars_ronly; /* flag whether fs is mounted read-only */ 166 unsignedlongs_time__packed2__; /* time of last super block update */ 167 shorts_dinfo[4]; /* device information ?? */ 168 unsignedlongs_tfree__packed2__; /* total number of free zones */ 169 unsignedshorts_tinode; /* total number of free inodes */ 170 chars_fname[6]; /* file system volume name */ 171 chars_fpack[6]; /* file system pack name */ 172 longs_fill[14];
173 longs_state; /* file system state */ 174 longs_magic; /* version of file system */ 175 longs_type; /* type of file system: 1 for 512 byte blocks 176 2 for 1024 byte blocks */ 177 };
178
179 /* SystemV2 free list block on disk */ 180 structsysv2_freelist_chunk{ 181 unsignedshortfl_nfree; /* number of free blocks in fl_free, <= SYSV_NICFREE] */ 182 unsignedlongfl_free[SYSV_NICFREE] __packed2__;
183 };
184
185 /* Coherent super-block data on disk */ 186 #defineCOH_NICINOD 100 /* number of inode cache entries */ 187 #defineCOH_NICFREE 64 /* number of free block list chunk entries */ 188 structcoh_super_block{ 189 unsignedshorts_isize; /* index of first data zone */ 190 coh_ulongs_fsize__packed2__; /* total number of zones of this fs */ 191 /* the start of the free block list: */ 192 unsignedshorts_nfree; /* number of free blocks in s_free, <= COH_NICFREE */ 193 coh_ulongs_free[COH_NICFREE] __packed2__; /* first free block list chunk */ 194 /* the cache of free inodes: */ 195 unsignedshorts_ninode; /* number of free inodes in s_inode, <= COH_NICINOD */ 196 sysv_ino_ts_inode[COH_NICINOD]; /* some free inodes */ 197 /* locks, not used by Linux: */ 198 chars_flock; /* lock during free block list manipulation */ 199 chars_ilock; /* lock during inode cache manipulation */ 200 chars_fmod; /* super-block modified flag */ 201 chars_ronly; /* flag whether fs is mounted read-only */ 202 coh_ulongs_time__packed2__; /* time of last super block update */ 203 coh_ulongs_tfree__packed2__; /* total number of free zones */ 204 unsignedshorts_tinode; /* total number of free inodes */ 205 unsignedshort s_interleave_m; /* interleave factor */ 206 unsignedshort s_interleave_n;
207 chars_fname[6]; /* file system volume name */ 208 chars_fpack[6]; /* file system pack name */ 209 unsignedlong s_unique; /* zero, not used */ 210 };
211
212 /* Coherent free list block on disk */ 213 structcoh_freelist_chunk{ 214 unsignedshortfl_nfree; /* number of free blocks in fl_free, <= COH_NICFREE] */ 215 unsignedlongfl_free[COH_NICFREE] __packed2__;
216 };
217
218
219 /* SystemV/Coherent inode data on disk */ 220
221 structsysv_inode{ 222 unsignedshorti_mode;
223 unsignedshorti_nlink;
224 unsignedshorti_uid;
225 unsignedshorti_gid;
226 unsignedlongi_size;
227 union{/* directories, regular files, ... */ 228 chari_addb[3*(10+1+1+1)+1]; /* zone numbers: max. 10 data blocks, 229 * then 1 indirection block, 230 * then 1 double indirection block, 231 * then 1 triple indirection block. 232 * Then maybe a "file generation number" ?? 233 */ 234 /* devices */ 235 dev_ti_rdev;
236 /* named pipes on Coherent */ 237 struct{ 238 char p_addp[30];
239 short p_pnc;
240 short p_prx;
241 short p_pwx;
242 } i_p;
243 }i_a;
244 unsignedlongi_atime; /* time of last access */ 245 unsignedlongi_mtime; /* time of last modification */ 246 unsignedlongi_ctime; /* time of creation */ 247 };
248
249 /* The admissible values for i_mode are listed in <linux/stat.h> : 250 * #define S_IFMT 00170000 mask for type 251 * #define S_IFREG 0100000 type = regular file 252 * #define S_IFBLK 0060000 type = block device 253 * #define S_IFDIR 0040000 type = directory 254 * #define S_IFCHR 0020000 type = character device 255 * #define S_IFIFO 0010000 type = named pipe 256 * #define S_ISUID 0004000 set user id 257 * #define S_ISGID 0002000 set group id 258 * #define S_ISVTX 0001000 save swapped text even after use 259 * Additionally for SystemV: 260 * #define S_IFLNK 0120000 type = symbolic link 261 * #define S_IFNAM 0050000 type = XENIX special named file ?? 262 * Additionally for Coherent: 263 * #define S_IFMPB 0070000 type = multiplexed block device ?? 264 * #define S_IFMPC 0030000 type = multiplexed character device ?? 265 * 266 * Since Coherent doesn't know about symbolic links, we use a kludgey 267 * implementation of symbolic links: i_mode = COH_KLUDGE_SYMLINK_MODE 268 * denotes a symbolic link. When a regular file should get this mode by 269 * accident, it is automatically converted to COH_KLUDGE_NOT_SYMLINK. 270 * We use S_IFREG because only regular files (and Coherent pipes...) can have 271 * data blocks with arbitrary contents associated with them, and S_ISVTX 272 * ("save swapped text after use") because it is unused on both Linux and 273 * Coherent: Linux does much more intelligent paging, and Coherent hasn't 274 * virtual memory at all. 275 * Same trick for Xenix. 276 */ 277 #defineCOH_KLUDGE_SYMLINK_MODE (S_IFREG | S_ISVTX)
278 #defineCOH_KLUDGE_NOT_SYMLINK (S_IFREG | S_ISVTX | S_IRUSR) /* force read access */ 279 externinlinemode_tfrom_coh_imode(unsignedshortmode)
/* */ 280 { 281 if (mode == COH_KLUDGE_SYMLINK_MODE)
282 return (S_IFLNK | 0777);
283 else 284 returnmode;
285 } 286 externinlineunsignedshortto_coh_imode(mode_tmode)
/* */ 287 { 288 if (S_ISLNK(mode))
289 returnCOH_KLUDGE_SYMLINK_MODE;
290 elseif (mode == COH_KLUDGE_SYMLINK_MODE)
291 returnCOH_KLUDGE_NOT_SYMLINK;
292 else 293 returnmode;
294 } 295
296 /* Admissible values for i_nlink: 0.._LINK_MAX */ 297 #defineXENIX_LINK_MAX 126 /* ?? */ 298 #defineSYSV_LINK_MAX 126 /* 127? 251? */ 299 #defineCOH_LINK_MAX 10000 /* max number of hard links to an inode */ 300
301 /* The number of inodes per block is 302 sb->sv_inodes_per_block = block_size / sizeof(struct sysv_inode) */ 303 /* The number of indirect pointers per block is 304 sb->sv_ind_per_block = block_size / sizeof(unsigned long) */ 305
306
307 /* SystemV/Coherent directory entry on disk */ 308
309 #defineSYSV_NAMELEN 14 /* max size of name in struct sysv_dir_entry */ 310
311 structsysv_dir_entry{ 312 sysv_ino_tinode;
313 charname[SYSV_NAMELEN]; /* up to 14 characters, the rest are zeroes */ 314 };
315
316 #defineSYSV_DIRSIZEsizeof(structsysv_dir_entry) /* size of every directory entry */ 317
318
319 #ifdef__KERNEL__ 320
321 /* Operations */ 322 /* ========== */ 323
324
325 /* identify the FS in memory */ 326 #defineFSTYPE_XENIX 1
327 #defineFSTYPE_SYSV4 2
328 #defineFSTYPE_SYSV2 3
329 #defineFSTYPE_COH 4
330
331 #defineSYSV_MAGIC_BASE 0x012FF7B3
332
333 #define XENIX_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_XENIX)
334 #define SYSV4_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV4)
335 #define SYSV2_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_SYSV2)
336 #define COH_SUPER_MAGIC (SYSV_MAGIC_BASE+FSTYPE_COH)
337
338 /* Because the block size may be smaller than 1024 (which is the unit used by 339 the disk drivers and the buffer code), many functions must return a pointer 340 to the buffer data additionally to the buffer head pointer. 341 */ 342 #if 0
343 structbh_data{ 344 structbuffer_head * bh;
345 char * bh_data;
346 };
347 #endif 348
349 /* sysv_bread(sb,dev,block,...) would be equivalent to 350 bread(dev,block,BLOCK_SIZE) 351 if the block size were always 1024, which is the only one bread() supports. 352 */ 353 staticinlinestructbuffer_head *
354 sysv_bread (structsuper_block *sb, intdev, unsignedintblock, char* * data)
/* */ 355 { 356 structbuffer_head *bh;
357
358 if (!(bh = bread (dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE)))
359 returnNULL;
360 *data = bh->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
361 returnbh;
362 } 363
364
365 /* locks - protect against simultaneous write and truncate */ 366
367 externvoid_coh_wait_on_inode (structinode * inode);
368
369 externinlinevoid coh_wait_on_inode (structinode * inode)
/* */ 370 { 371 if (inode->u.sysv_i.i_lock)
372 _coh_wait_on_inode(inode);
373 } 374
375 externinlinevoidcoh_lock_inode (structinode * inode)
/* */ 376 { 377 if (inode->u.sysv_i.i_lock)
378 _coh_wait_on_inode(inode);
379 inode->u.sysv_i.i_lock = 1;
380 } 381
382 externinlinevoidcoh_unlock_inode (structinode * inode)
/* */ 383 { 384 inode->u.sysv_i.i_lock = 0;
385 wake_up(&inode->u.sysv_i.i_wait);
386 } 387
388
389 /* 390 * Function prototypes 391 */ 392
393 externintsysv_lookup(structinode * dir,constchar * name, intlen,
394 structinode ** result);
395 externintsysv_create(structinode * dir,constchar * name, intlen, intmode,
396 structinode ** result);
397 externintsysv_mkdir(structinode * dir, constchar * name, intlen, intmode);
398 externintsysv_rmdir(structinode * dir, constchar * name, intlen);
399 externintsysv_unlink(structinode * dir, constchar * name, intlen);
400 externintsysv_symlink(structinode * inode, constchar * name, intlen,
401 constchar * symname);
402 externintsysv_link(structinode * oldinode, structinode * dir, constchar * name, intlen);
403 externintsysv_mknod(structinode * dir, constchar * name, intlen, intmode, intrdev);
404 externintsysv_rename(structinode * old_dir, constchar * old_name, intold_len,
405 structinode * new_dir, constchar * new_name, intnew_len);
406 externstructinode * sysv_new_inode(conststructinode * dir);
407 externvoidsysv_free_inode(structinode * inode);
408 externunsignedlongsysv_count_free_inodes(structsuper_block *sb);
409 externintsysv_new_block(structsuper_block * sb);
410 externvoidsysv_free_block(structsuper_block * sb, unsignedintblock);
411 externunsignedlongsysv_count_free_blocks(structsuper_block *sb);
412
413 externintsysv_bmap(structinode *,int);
414
415 externstructbuffer_head * sysv_getblk(structinode *, unsignedint, int, char* *);
416 externstructbuffer_head * sysv_file_bread(structinode *, int, int, char* *);
417
418 externvoidsysv_truncate(structinode *);
419 externvoidsysv_put_super(structsuper_block *);
420 externstructsuper_block *sysv_read_super(structsuper_block *,void *,int);
421 externvoidsysv_write_super(structsuper_block *);
422 externvoidsysv_read_inode(structinode *);
423 externintsysv_notify_change(int,structinode *);
424 externvoidsysv_write_inode(structinode *);
425 externvoidsysv_put_inode(structinode *);
426 externvoidsysv_statfs(structsuper_block *, structstatfs *);
427 externintsysv_sync_inode(structinode *);
428 externintsysv_sync_file(structinode *, structfile *);
429 #if 0
430 externint sysv_mmap(structinode *, structfile *, unsignedlong, size_t, int, unsignedlong);
431 #endif 432
433 externstructinode_operationssysv_file_inode_operations;
434 externstructinode_operationssysv_file_inode_operations_with_bmap;
435 externstructinode_operationssysv_dir_inode_operations;
436 externstructinode_operationssysv_symlink_inode_operations;
437
438 #endif/* __KERNEL__ */ 439
440 #endif 441