1 /* 2 * linux/include/linux/ufs_fs.h 3 * 4 * Copyright (C) 1996 5 * Adrian Rodriguez (adrian (at) franklins-tower.rutgers.edu) 6 * Laboratory for Computer Science Research Computing Facility 7 * Rutgers, The State University of New Jersey 8 * 9 * Clean swab support by Fare <fare (at) tunes.org> 10 * just hope no one is using NNUUXXI on __?64 structure elements 11 * 64-bit clean thanks to Maciej W. Rozycki <macro (at) ds2.pg.gda.pl> 12 * 13 * 4.4BSD (FreeBSD) support added on February 1st 1998 by 14 * Niels Kristian Bech Jensen <nkbj (at) image.dk> partially based 15 * on code by Martin von Loewis <martin (at) mira.isdn.cs.tu-berlin.de>. 16 * 17 * NeXTstep support added on February 5th 1998 by 18 * Niels Kristian Bech Jensen <nkbj (at) image.dk>. 19 * 20 * Write support by Daniel Pirkl <daniel.pirkl (at) email.cz> 21 * 22 * HP/UX hfs filesystem support added by 23 * Martin K. Petersen <mkp (at) mkp.net>, August 1999 24 * 25 * UFS2 (of FreeBSD 5.x) support added by 26 * Niraj Kumar <niraj17 (at) iitbombay.org> , Jan 2004 27 * 28 */ 29 30 #ifndef __LINUX_UFS_FS_H 31 #define __LINUX_UFS_FS_H 32 33 #include <linux/types.h> 34 #include <linux/kernel.h> 35 #include <linux/stat.h> 36 #include <linux/fs.h> 37 38 typedef __u64 __fs64; 39 typedef __u32 __fs32; 40 typedef __u16 __fs16; 41 42 #define UFS_BBLOCK 0 43 #define UFS_BBSIZE 8192 44 #define UFS_SBLOCK 8192 45 #define UFS_SBSIZE 8192 46 47 #define UFS_SECTOR_SIZE 512 48 #define UFS_SECTOR_BITS 9 49 #define UFS_MAGIC 0x00011954 50 #define UFS2_MAGIC 0x19540119 51 #define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */ 52 53 /* Copied from FreeBSD */ 54 /* 55 * Each disk drive contains some number of filesystems. 56 * A filesystem consists of a number of cylinder groups. 57 * Each cylinder group has inodes and data. 58 * 59 * A filesystem is described by its super-block, which in turn 60 * describes the cylinder groups. The super-block is critical 61 * data and is replicated in each cylinder group to protect against 62 * catastrophic loss. This is done at `newfs' time and the critical 63 * super-block data does not change, so the copies need not be 64 * referenced further unless disaster strikes. 65 * 66 * For filesystem fs, the offsets of the various blocks of interest 67 * are given in the super block as: 68 * [fs->fs_sblkno] Super-block 69 * [fs->fs_cblkno] Cylinder group block 70 * [fs->fs_iblkno] Inode blocks 71 * [fs->fs_dblkno] Data blocks 72 * The beginning of cylinder group cg in fs, is given by 73 * the ``cgbase(fs, cg)'' macro. 74 * 75 * Depending on the architecture and the media, the superblock may 76 * reside in any one of four places. For tiny media where every block 77 * counts, it is placed at the very front of the partition. Historically, 78 * UFS1 placed it 8K from the front to leave room for the disk label and 79 * a small bootstrap. For UFS2 it got moved to 64K from the front to leave 80 * room for the disk label and a bigger bootstrap, and for really piggy 81 * systems we check at 256K from the front if the first three fail. In 82 * all cases the size of the superblock will be SBLOCKSIZE. All values are 83 * given in byte-offset form, so they do not imply a sector size. The 84 * SBLOCKSEARCH specifies the order in which the locations should be searched. 85 */ 86 #define SBLOCK_FLOPPY 0 87 #define SBLOCK_UFS1 8192 88 #define SBLOCK_UFS2 65536 89 #define SBLOCK_PIGGY 262144 90 #define SBLOCKSIZE 8192 91 #define SBLOCKSEARCH \ 92 { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 } 93 94 95 /* HP specific MAGIC values */ 96 97 #define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */ 98 #define UFS_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */ 99 100 #define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */ 101 #define UFS_CIGAM_SEC 0x95216100 102 103 #define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */ 104 #define UFS_CIGAM_FEA 0x12561900 105 106 #define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */ 107 #define UFS_CIGAM_4GB 0x94192305 108 109 /* Seems somebody at HP goofed here. B1 and lfs are both 0x2 !?! */ 110 #define UFS_FSF_LFN 0x00000001 /* long file names */ 111 #define UFS_FSF_B1 0x00000002 /* B1 security */ 112 #define UFS_FSF_LFS 0x00000002 /* large files */ 113 #define UFS_FSF_LUID 0x00000004 /* large UIDs */ 114 115 /* End of HP stuff */ 116 117 118 #define UFS_BSIZE 8192 119 #define UFS_MINBSIZE 4096 120 #define UFS_FSIZE 1024 121 #define UFS_MAXFRAG (UFS_BSIZE / UFS_FSIZE) 122 123 #define UFS_NDADDR 12 124 #define UFS_NINDIR 3 125 126 #define UFS_IND_BLOCK (UFS_NDADDR + 0) 127 #define UFS_DIND_BLOCK (UFS_NDADDR + 1) 128 #define UFS_TIND_BLOCK (UFS_NDADDR + 2) 129 130 #define UFS_NDIR_FRAGMENT (UFS_NDADDR << uspi->s_fpbshift) 131 #define UFS_IND_FRAGMENT (UFS_IND_BLOCK << uspi->s_fpbshift) 132 #define UFS_DIND_FRAGMENT (UFS_DIND_BLOCK << uspi->s_fpbshift) 133 #define UFS_TIND_FRAGMENT (UFS_TIND_BLOCK << uspi->s_fpbshift) 134 135 #define UFS_ROOTINO 2 136 #define UFS_FIRST_INO (UFS_ROOTINO + 1) 137 138 #define UFS_USEEFT ((__u16)65535) 139 140 #define UFS_FSOK 0x7c269d38 141 #define UFS_FSACTIVE ((__s8)0x00) 142 #define UFS_FSCLEAN ((__s8)0x01) 143 #define UFS_FSSTABLE ((__s8)0x02) 144 #define UFS_FSOSF1 ((__s8)0x03) /* is this correct for DEC OSF/1? */ 145 #define UFS_FSBAD ((__s8)0xff) 146 147 /* From here to next blank line, s_flags for ufs_sb_info */ 148 /* directory entry encoding */ 149 #define UFS_DE_MASK 0x00000010 /* mask for the following */ 150 #define UFS_DE_OLD 0x00000000 151 #define UFS_DE_44BSD 0x00000010 152 /* uid encoding */ 153 #define UFS_UID_MASK 0x00000060 /* mask for the following */ 154 #define UFS_UID_OLD 0x00000000 155 #define UFS_UID_44BSD 0x00000020 156 #define UFS_UID_EFT 0x00000040 157 /* superblock state encoding */ 158 #define UFS_ST_MASK 0x00000700 /* mask for the following */ 159 #define UFS_ST_OLD 0x00000000 160 #define UFS_ST_44BSD 0x00000100 161 #define UFS_ST_SUN 0x00000200 /* Solaris */ 162 #define UFS_ST_SUNOS 0x00000300 163 #define UFS_ST_SUNx86 0x00000400 /* Solaris x86 */ 164 /*cylinder group encoding */ 165 #define UFS_CG_MASK 0x00003000 /* mask for the following */ 166 #define UFS_CG_OLD 0x00000000 167 #define UFS_CG_44BSD 0x00002000 168 #define UFS_CG_SUN 0x00001000 169 /* filesystem type encoding */ 170 #define UFS_TYPE_MASK 0x00010000 /* mask for the following */ 171 #define UFS_TYPE_UFS1 0x00000000 172 #define UFS_TYPE_UFS2 0x00010000 173 174 175 /* fs_inodefmt options */ 176 #define UFS_42INODEFMT -1 177 #define UFS_44INODEFMT 2 178 179 /* 180 * MINFREE gives the minimum acceptable percentage of file system 181 * blocks which may be free. If the freelist drops below this level 182 * only the superuser may continue to allocate blocks. This may 183 * be set to 0 if no reserve of free blocks is deemed necessary, 184 * however throughput drops by fifty percent if the file system 185 * is run at between 95% and 100% full; thus the minimum default 186 * value of fs_minfree is 5%. However, to get good clustering 187 * performance, 10% is a better choice. hence we use 10% as our 188 * default value. With 10% free space, fragmentation is not a 189 * problem, so we choose to optimize for time. 190 */ 191 #define UFS_MINFREE 5 192 #define UFS_DEFAULTOPT UFS_OPTTIME 193 194 /* 195 * Turn file system block numbers into disk block addresses. 196 * This maps file system blocks to device size blocks. 197 */ 198 #define ufs_fsbtodb(uspi, b) ((b) << (uspi)->s_fsbtodb) 199 #define ufs_dbtofsb(uspi, b) ((b) >> (uspi)->s_fsbtodb) 200 201 /* 202 * Cylinder group macros to locate things in cylinder groups. 203 * They calc file system addresses of cylinder group data structures. 204 */ 205 #define ufs_cgbase(c) (uspi->s_fpg * (c)) 206 #define ufs_cgstart(c) ((uspi)->fs_magic == UFS2_MAGIC ? ufs_cgbase(c) : \ 207 (ufs_cgbase(c) + uspi->s_cgoffset * ((c) & ~uspi->s_cgmask))) 208 #define ufs_cgsblock(c) (ufs_cgstart(c) + uspi->s_sblkno) /* super blk */ 209 #define ufs_cgcmin(c) (ufs_cgstart(c) + uspi->s_cblkno) /* cg block */ 210 #define ufs_cgimin(c) (ufs_cgstart(c) + uspi->s_iblkno) /* inode blk */ 211 #define ufs_cgdmin(c) (ufs_cgstart(c) + uspi->s_dblkno) /* 1st data */ 212 213 /* 214 * Macros for handling inode numbers: 215 * inode number to file system block offset. 216 * inode number to cylinder group number. 217 * inode number to file system block address. 218 */ 219 #define ufs_inotocg(x) ((x) / uspi->s_ipg) 220 #define ufs_inotocgoff(x) ((x) % uspi->s_ipg) 221 #define ufs_inotofsba(x) (((u64)ufs_cgimin(ufs_inotocg(x))) + ufs_inotocgoff(x) / uspi->s_inopf) 222 #define ufs_inotofsbo(x) ((x) % uspi->s_inopf) 223 224 /* 225 * Compute the cylinder and rotational position of a cyl block addr. 226 */ 227 #define ufs_cbtocylno(bno) \ 228 ((bno) * uspi->s_nspf / uspi->s_spc) 229 #define ufs_cbtorpos(bno) \ 230 ((((bno) * uspi->s_nspf % uspi->s_spc / uspi->s_nsect \ 231 * uspi->s_trackskew + (bno) * uspi->s_nspf % uspi->s_spc \ 232 % uspi->s_nsect * uspi->s_interleave) % uspi->s_nsect \ 233 * uspi->s_nrpos) / uspi->s_npsect) 234 235 /* 236 * The following macros optimize certain frequently calculated 237 * quantities by using shifts and masks in place of divisions 238 * modulos and multiplications. 239 */ 240 #define ufs_blkoff(loc) ((loc) & uspi->s_qbmask) 241 #define ufs_fragoff(loc) ((loc) & uspi->s_qfmask) 242 #define ufs_lblktosize(blk) ((blk) << uspi->s_bshift) 243 #define ufs_lblkno(loc) ((loc) >> uspi->s_bshift) 244 #define ufs_numfrags(loc) ((loc) >> uspi->s_fshift) 245 #define ufs_blkroundup(size) (((size) + uspi->s_qbmask) & uspi->s_bmask) 246 #define ufs_fragroundup(size) (((size) + uspi->s_qfmask) & uspi->s_fmask) 247 #define ufs_fragstoblks(frags) ((frags) >> uspi->s_fpbshift) 248 #define ufs_blkstofrags(blks) ((blks) << uspi->s_fpbshift) 249 #define ufs_fragnum(fsb) ((fsb) & uspi->s_fpbmask) 250 #define ufs_blknum(fsb) ((fsb) & ~uspi->s_fpbmask) 251 252 #define UFS_MAXNAMLEN 255 253 #define UFS_MAXMNTLEN 512 254 #define UFS2_MAXMNTLEN 468 255 #define UFS2_MAXVOLLEN 32 256 #define UFS_MAXCSBUFS 31 257 #define UFS_LINK_MAX 32000 258 /* 259 #define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4) 260 */ 261 #define UFS2_NOCSPTRS 28 262 263 /* 264 * UFS_DIR_PAD defines the directory entries boundaries 265 * (must be a multiple of 4) 266 */ 267 #define UFS_DIR_PAD 4 268 #define UFS_DIR_ROUND (UFS_DIR_PAD - 1) 269 #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND) 270 271 struct ufs_timeval { 272 __fs32 tv_sec; 273 __fs32 tv_usec; 274 }; 275 276 struct ufs_dir_entry { 277 __fs32 d_ino; /* inode number of this entry */ 278 __fs16 d_reclen; /* length of this entry */ 279 union { 280 __fs16 d_namlen; /* actual length of d_name */ 281 struct { 282 __u8 d_type; /* file type */ 283 __u8 d_namlen; /* length of string in d_name */ 284 } d_44; 285 } d_u; 286 __u8 d_name[UFS_MAXNAMLEN + 1]; /* file name */ 287 }; 288 289 struct ufs_csum { 290 __fs32 cs_ndir; /* number of directories */ 291 __fs32 cs_nbfree; /* number of free blocks */ 292 __fs32 cs_nifree; /* number of free inodes */ 293 __fs32 cs_nffree; /* number of free frags */ 294 }; 295 struct ufs2_csum_total { 296 __fs64 cs_ndir; /* number of directories */ 297 __fs64 cs_nbfree; /* number of free blocks */ 298 __fs64 cs_nifree; /* number of free inodes */ 299 __fs64 cs_nffree; /* number of free frags */ 300 __fs64 cs_numclusters; /* number of free clusters */ 301 __fs64 cs_spare[3]; /* future expansion */ 302 }; 303 304 struct ufs_csum_core { 305 __u64 cs_ndir; /* number of directories */ 306 __u64 cs_nbfree; /* number of free blocks */ 307 __u64 cs_nifree; /* number of free inodes */ 308 __u64 cs_nffree; /* number of free frags */ 309 __u64 cs_numclusters; /* number of free clusters */ 310 }; 311 312 /* 313 * File system flags 314 */ 315 #define UFS_UNCLEAN 0x01 /* file system not clean at mount (unused) */ 316 #define UFS_DOSOFTDEP 0x02 /* file system using soft dependencies */ 317 #define UFS_NEEDSFSCK 0x04 /* needs sync fsck (FreeBSD compat, unused) */ 318 #define UFS_INDEXDIRS 0x08 /* kernel supports indexed directories */ 319 #define UFS_ACLS 0x10 /* file system has ACLs enabled */ 320 #define UFS_MULTILABEL 0x20 /* file system is MAC multi-label */ 321 #define UFS_FLAGS_UPDATED 0x80 /* flags have been moved to new location */ 322 323 #if 0 324 /* 325 * This is the actual superblock, as it is laid out on the disk. 326 * Do NOT use this structure, because of sizeof(ufs_super_block) > 512 and 327 * it may occupy several blocks, use 328 * struct ufs_super_block_(first,second,third) instead. 329 */ 330 struct ufs_super_block { 331 union { 332 struct { 333 __fs32 fs_link; /* UNUSED */ 334 } fs_42; 335 struct { 336 __fs32 fs_state; /* file system state flag */ 337 } fs_sun; 338 } fs_u0; 339 __fs32 fs_rlink; /* UNUSED */ 340 __fs32 fs_sblkno; /* addr of super-block in filesys */ 341 __fs32 fs_cblkno; /* offset of cyl-block in filesys */ 342 __fs32 fs_iblkno; /* offset of inode-blocks in filesys */ 343 __fs32 fs_dblkno; /* offset of first data after cg */ 344 __fs32 fs_cgoffset; /* cylinder group offset in cylinder */ 345 __fs32 fs_cgmask; /* used to calc mod fs_ntrak */ 346 __fs32 fs_time; /* last time written -- time_t */ 347 __fs32 fs_size; /* number of blocks in fs */ 348 __fs32 fs_dsize; /* number of data blocks in fs */ 349 __fs32 fs_ncg; /* number of cylinder groups */ 350 __fs32 fs_bsize; /* size of basic blocks in fs */ 351 __fs32 fs_fsize; /* size of frag blocks in fs */ 352 __fs32 fs_frag; /* number of frags in a block in fs */ 353 /* these are configuration parameters */ 354 __fs32 fs_minfree; /* minimum percentage of free blocks */ 355 __fs32 fs_rotdelay; /* num of ms for optimal next block */ 356 __fs32 fs_rps; /* disk revolutions per second */ 357 /* these fields can be computed from the others */ 358 __fs32 fs_bmask; /* ``blkoff'' calc of blk offsets */ 359 __fs32 fs_fmask; /* ``fragoff'' calc of frag offsets */ 360 __fs32 fs_bshift; /* ``lblkno'' calc of logical blkno */ 361 __fs32 fs_fshift; /* ``numfrags'' calc number of frags */ 362 /* these are configuration parameters */ 363 __fs32 fs_maxcontig; /* max number of contiguous blks */ 364 __fs32 fs_maxbpg; /* max number of blks per cyl group */ 365 /* these fields can be computed from the others */ 366 __fs32 fs_fragshift; /* block to frag shift */ 367 __fs32 fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 368 __fs32 fs_sbsize; /* actual size of super block */ 369 __fs32 fs_csmask; /* csum block offset */ 370 __fs32 fs_csshift; /* csum block number */ 371 __fs32 fs_nindir; /* value of NINDIR */ 372 __fs32 fs_inopb; /* value of INOPB */ 373 __fs32 fs_nspf; /* value of NSPF */ 374 /* yet another configuration parameter */ 375 __fs32 fs_optim; /* optimization preference, see below */ 376 /* these fields are derived from the hardware */ 377 union { 378 struct { 379 __fs32 fs_npsect; /* # sectors/track including spares */ 380 } fs_sun; 381 struct { 382 __fs32 fs_state; /* file system state time stamp */ 383 } fs_sunx86; 384 } fs_u1; 385 __fs32 fs_interleave; /* hardware sector interleave */ 386 __fs32 fs_trackskew; /* sector 0 skew, per track */ 387 /* a unique id for this filesystem (currently unused and unmaintained) */ 388 /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */ 389 /* Neither of those fields is used in the Tahoe code right now but */ 390 /* there could be problems if they are. */ 391 __fs32 fs_id[2]; /* file system id */ 392 /* sizes determined by number of cylinder groups and their sizes */ 393 __fs32 fs_csaddr; /* blk addr of cyl grp summary area */ 394 __fs32 fs_cssize; /* size of cyl grp summary area */ 395 __fs32 fs_cgsize; /* cylinder group size */ 396 /* these fields are derived from the hardware */ 397 __fs32 fs_ntrak; /* tracks per cylinder */ 398 __fs32 fs_nsect; /* sectors per track */ 399 __fs32 fs_spc; /* sectors per cylinder */ 400 /* this comes from the disk driver partitioning */ 401 __fs32 fs_ncyl; /* cylinders in file system */ 402 /* these fields can be computed from the others */ 403 __fs32 fs_cpg; /* cylinders per group */ 404 __fs32 fs_ipg; /* inodes per cylinder group */ 405 __fs32 fs_fpg; /* blocks per group * fs_frag */ 406 /* this data must be re-computed after crashes */ 407 struct ufs_csum fs_cstotal; /* cylinder summary information */ 408 /* these fields are cleared at mount time */ 409 __s8 fs_fmod; /* super block modified flag */ 410 __s8 fs_clean; /* file system is clean flag */ 411 __s8 fs_ronly; /* mounted read-only flag */ 412 __s8 fs_flags; 413 union { 414 struct { 415 __s8 fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */ 416 __fs32 fs_cgrotor; /* last cg searched */ 417 __fs32 fs_csp[UFS_MAXCSBUFS];/*list of fs_cs info buffers */ 418 __fs32 fs_maxcluster; 419 __fs32 fs_cpc; /* cyl per cycle in postbl */ 420 __fs16 fs_opostbl[16][8]; /* old rotation block list head */ 421 } fs_u1; 422 struct { 423 __s8 fs_fsmnt[UFS2_MAXMNTLEN]; /* name mounted on */ 424 __u8 fs_volname[UFS2_MAXVOLLEN]; /* volume name */ 425 __fs64 fs_swuid; /* system-wide uid */ 426 __fs32 fs_pad; /* due to alignment of fs_swuid */ 427 __fs32 fs_cgrotor; /* last cg searched */ 428 __fs32 fs_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info buffers */ 429 __fs32 fs_contigdirs;/*# of contiguously allocated dirs */ 430 __fs32 fs_csp; /* cg summary info buffer for fs_cs */ 431 __fs32 fs_maxcluster; 432 __fs32 fs_active;/* used by snapshots to track fs */ 433 __fs32 fs_old_cpc; /* cyl per cycle in postbl */ 434 __fs32 fs_maxbsize;/*maximum blocking factor permitted */ 435 __fs64 fs_sparecon64[17];/*old rotation block list head */ 436 __fs64 fs_sblockloc; /* byte offset of standard superblock */ 437 struct ufs2_csum_total fs_cstotal;/*cylinder summary information*/ 438 struct ufs_timeval fs_time; /* last time written */ 439 __fs64 fs_size; /* number of blocks in fs */ 440 __fs64 fs_dsize; /* number of data blocks in fs */ 441 __fs64 fs_csaddr; /* blk addr of cyl grp summary area */ 442 __fs64 fs_pendingblocks;/* blocks in process of being freed */ 443 __fs32 fs_pendinginodes;/*inodes in process of being freed */ 444 } fs_u2; 445 } fs_u11; 446 union { 447 struct { 448 __fs32 fs_sparecon[53];/* reserved for future constants */ 449 __fs32 fs_reclaim; 450 __fs32 fs_sparecon2[1]; 451 __fs32 fs_state; /* file system state time stamp */ 452 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 453 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 454 } fs_sun; 455 struct { 456 __fs32 fs_sparecon[53];/* reserved for future constants */ 457 __fs32 fs_reclaim; 458 __fs32 fs_sparecon2[1]; 459 __fs32 fs_npsect; /* # sectors/track including spares */ 460 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 461 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 462 } fs_sunx86; 463 struct { 464 __fs32 fs_sparecon[50];/* reserved for future constants */ 465 __fs32 fs_contigsumsize;/* size of cluster summary array */ 466 __fs32 fs_maxsymlinklen;/* max length of an internal symlink */ 467 __fs32 fs_inodefmt; /* format of on-disk inodes */ 468 __fs32 fs_maxfilesize[2]; /* max representable file size */ 469 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 470 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 471 __fs32 fs_state; /* file system state time stamp */ 472 } fs_44; 473 } fs_u2; 474 __fs32 fs_postblformat; /* format of positional layout tables */ 475 __fs32 fs_nrpos; /* number of rotational positions */ 476 __fs32 fs_postbloff; /* (__s16) rotation block list head */ 477 __fs32 fs_rotbloff; /* (__u8) blocks for each rotation */ 478 __fs32 fs_magic; /* magic number */ 479 __u8 fs_space[1]; /* list of blocks for each rotation */ 480 }; 481 #endif/*struct ufs_super_block*/ 482 483 /* 484 * Preference for optimization. 485 */ 486 #define UFS_OPTTIME 0 /* minimize allocation time */ 487 #define UFS_OPTSPACE 1 /* minimize disk fragmentation */ 488 489 /* 490 * Rotational layout table format types 491 */ 492 #define UFS_42POSTBLFMT -1 /* 4.2BSD rotational table format */ 493 #define UFS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */ 494 495 /* 496 * Convert cylinder group to base address of its global summary info. 497 */ 498 #define fs_cs(indx) s_csp[(indx)] 499 500 /* 501 * Cylinder group block for a file system. 502 * 503 * Writable fields in the cylinder group are protected by the associated 504 * super block lock fs->fs_lock. 505 */ 506 #define CG_MAGIC 0x090255 507 #define ufs_cg_chkmagic(sb, ucg) \ 508 (fs32_to_cpu((sb), (ucg)->cg_magic) == CG_MAGIC) 509 /* 510 * Macros for access to old cylinder group array structures 511 */ 512 #define ufs_ocg_blktot(sb, ucg) fs32_to_cpu((sb), ((struct ufs_old_cylinder_group *)(ucg))->cg_btot) 513 #define ufs_ocg_blks(sb, ucg, cylno) fs32_to_cpu((sb), ((struct ufs_old_cylinder_group *)(ucg))->cg_b[cylno]) 514 #define ufs_ocg_inosused(sb, ucg) fs32_to_cpu((sb), ((struct ufs_old_cylinder_group *)(ucg))->cg_iused) 515 #define ufs_ocg_blksfree(sb, ucg) fs32_to_cpu((sb), ((struct ufs_old_cylinder_group *)(ucg))->cg_free) 516 #define ufs_ocg_chkmagic(sb, ucg) \ 517 (fs32_to_cpu((sb), ((struct ufs_old_cylinder_group *)(ucg))->cg_magic) == CG_MAGIC) 518 519 /* 520 * size of this structure is 172 B 521 */ 522 struct ufs_cylinder_group { 523 __fs32 cg_link; /* linked list of cyl groups */ 524 __fs32 cg_magic; /* magic number */ 525 __fs32 cg_time; /* time last written */ 526 __fs32 cg_cgx; /* we are the cgx'th cylinder group */ 527 __fs16 cg_ncyl; /* number of cyl's this cg */ 528 __fs16 cg_niblk; /* number of inode blocks this cg */ 529 __fs32 cg_ndblk; /* number of data blocks this cg */ 530 struct ufs_csum cg_cs; /* cylinder summary information */ 531 __fs32 cg_rotor; /* position of last used block */ 532 __fs32 cg_frotor; /* position of last used frag */ 533 __fs32 cg_irotor; /* position of last used inode */ 534 __fs32 cg_frsum[UFS_MAXFRAG]; /* counts of available frags */ 535 __fs32 cg_btotoff; /* (__u32) block totals per cylinder */ 536 __fs32 cg_boff; /* (short) free block positions */ 537 __fs32 cg_iusedoff; /* (char) used inode map */ 538 __fs32 cg_freeoff; /* (u_char) free block map */ 539 __fs32 cg_nextfreeoff; /* (u_char) next available space */ 540 union { 541 struct { 542 __fs32 cg_clustersumoff; /* (u_int32) counts of avail clusters */ 543 __fs32 cg_clusteroff; /* (u_int8) free cluster map */ 544 __fs32 cg_nclusterblks; /* number of clusters this cg */ 545 __fs32 cg_sparecon[13]; /* reserved for future use */ 546 } cg_44; 547 struct { 548 __fs32 cg_clustersumoff;/* (u_int32) counts of avail clusters */ 549 __fs32 cg_clusteroff; /* (u_int8) free cluster map */ 550 __fs32 cg_nclusterblks;/* number of clusters this cg */ 551 __fs32 cg_niblk; /* number of inode blocks this cg */ 552 __fs32 cg_initediblk; /* last initialized inode */ 553 __fs32 cg_sparecon32[3];/* reserved for future use */ 554 __fs64 cg_time; /* time last written */ 555 __fs64 cg_sparecon[3]; /* reserved for future use */ 556 } cg_u2; 557 __fs32 cg_sparecon[16]; /* reserved for future use */ 558 } cg_u; 559 __u8 cg_space[1]; /* space for cylinder group maps */ 560 /* actually longer */ 561 }; 562 563 /* Historic Cylinder group info */ 564 struct ufs_old_cylinder_group { 565 __fs32 cg_link; /* linked list of cyl groups */ 566 __fs32 cg_rlink; /* for incore cyl groups */ 567 __fs32 cg_time; /* time last written */ 568 __fs32 cg_cgx; /* we are the cgx'th cylinder group */ 569 __fs16 cg_ncyl; /* number of cyl's this cg */ 570 __fs16 cg_niblk; /* number of inode blocks this cg */ 571 __fs32 cg_ndblk; /* number of data blocks this cg */ 572 struct ufs_csum cg_cs; /* cylinder summary information */ 573 __fs32 cg_rotor; /* position of last used block */ 574 __fs32 cg_frotor; /* position of last used frag */ 575 __fs32 cg_irotor; /* position of last used inode */ 576 __fs32 cg_frsum[8]; /* counts of available frags */ 577 __fs32 cg_btot[32]; /* block totals per cylinder */ 578 __fs16 cg_b[32][8]; /* positions of free blocks */ 579 __u8 cg_iused[256]; /* used inode map */ 580 __fs32 cg_magic; /* magic number */ 581 __u8 cg_free[1]; /* free block map */ 582 /* actually longer */ 583 }; 584 585 /* 586 * structure of an on-disk inode 587 */ 588 struct ufs_inode { 589 __fs16 ui_mode; /* 0x0 */ 590 __fs16 ui_nlink; /* 0x2 */ 591 union { 592 struct { 593 __fs16 ui_suid; /* 0x4 */ 594 __fs16 ui_sgid; /* 0x6 */ 595 } oldids; 596 __fs32 ui_inumber; /* 0x4 lsf: inode number */ 597 __fs32 ui_author; /* 0x4 GNU HURD: author */ 598 } ui_u1; 599 __fs64 ui_size; /* 0x8 */ 600 struct ufs_timeval ui_atime; /* 0x10 access */ 601 struct ufs_timeval ui_mtime; /* 0x18 modification */ 602 struct ufs_timeval ui_ctime; /* 0x20 creation */ 603 union { 604 struct { 605 __fs32 ui_db[UFS_NDADDR];/* 0x28 data blocks */ 606 __fs32 ui_ib[UFS_NINDIR];/* 0x58 indirect blocks */ 607 } ui_addr; 608 __u8 ui_symlink[4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */ 609 } ui_u2; 610 __fs32 ui_flags; /* 0x64 immutable, append-only... */ 611 __fs32 ui_blocks; /* 0x68 blocks in use */ 612 __fs32 ui_gen; /* 0x6c like ext2 i_version, for NFS support */ 613 union { 614 struct { 615 __fs32 ui_shadow; /* 0x70 shadow inode with security data */ 616 __fs32 ui_uid; /* 0x74 long EFT version of uid */ 617 __fs32 ui_gid; /* 0x78 long EFT version of gid */ 618 __fs32 ui_oeftflag; /* 0x7c reserved */ 619 } ui_sun; 620 struct { 621 __fs32 ui_uid; /* 0x70 File owner */ 622 __fs32 ui_gid; /* 0x74 File group */ 623 __fs32 ui_spare[2]; /* 0x78 reserved */ 624 } ui_44; 625 struct { 626 __fs32 ui_uid; /* 0x70 */ 627 __fs32 ui_gid; /* 0x74 */ 628 __fs16 ui_modeh; /* 0x78 mode high bits */ 629 __fs16 ui_spare; /* 0x7A unused */ 630 __fs32 ui_trans; /* 0x7c filesystem translator */ 631 } ui_hurd; 632 } ui_u3; 633 }; 634 635 #define UFS_NXADDR 2 /* External addresses in inode. */ 636 struct ufs2_inode { 637 __fs16 ui_mode; /* 0: IFMT, permissions; see below. */ 638 __fs16 ui_nlink; /* 2: File link count. */ 639 __fs32 ui_uid; /* 4: File owner. */ 640 __fs32 ui_gid; /* 8: File group. */ 641 __fs32 ui_blksize; /* 12: Inode blocksize. */ 642 __fs64 ui_size; /* 16: File byte count. */ 643 __fs64 ui_blocks; /* 24: Bytes actually held. */ 644 __fs64 ui_atime; /* 32: Last access time. */ 645 __fs64 ui_mtime; /* 40: Last modified time. */ 646 __fs64 ui_ctime; /* 48: Last inode change time. */ 647 __fs64 ui_birthtime; /* 56: Inode creation time. */ 648 __fs32 ui_mtimensec; /* 64: Last modified time. */ 649 __fs32 ui_atimensec; /* 68: Last access time. */ 650 __fs32 ui_ctimensec; /* 72: Last inode change time. */ 651 __fs32 ui_birthnsec; /* 76: Inode creation time. */ 652 __fs32 ui_gen; /* 80: Generation number. */ 653 __fs32 ui_kernflags; /* 84: Kernel flags. */ 654 __fs32 ui_flags; /* 88: Status flags (chflags). */ 655 __fs32 ui_extsize; /* 92: External attributes block. */ 656 __fs64 ui_extb[UFS_NXADDR];/* 96: External attributes block. */ 657 union { 658 struct { 659 __fs64 ui_db[UFS_NDADDR]; /* 112: Direct disk blocks. */ 660 __fs64 ui_ib[UFS_NINDIR];/* 208: Indirect disk blocks.*/ 661 } ui_addr; 662 __u8 ui_symlink[2*4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */ 663 } ui_u2; 664 __fs64 ui_spare[3]; /* 232: Reserved; currently unused */ 665 }; 666 667 668 /* FreeBSD has these in sys/stat.h */ 669 /* ui_flags that can be set by a file owner */ 670 #define UFS_UF_SETTABLE 0x0000ffff 671 #define UFS_UF_NODUMP 0x00000001 /* do not dump */ 672 #define UFS_UF_IMMUTABLE 0x00000002 /* immutable (can't "change") */ 673 #define UFS_UF_APPEND 0x00000004 /* append-only */ 674 #define UFS_UF_OPAQUE 0x00000008 /* directory is opaque (unionfs) */ 675 #define UFS_UF_NOUNLINK 0x00000010 /* can't be removed or renamed */ 676 /* ui_flags that only root can set */ 677 #define UFS_SF_SETTABLE 0xffff0000 678 #define UFS_SF_ARCHIVED 0x00010000 /* archived */ 679 #define UFS_SF_IMMUTABLE 0x00020000 /* immutable (can't "change") */ 680 #define UFS_SF_APPEND 0x00040000 /* append-only */ 681 #define UFS_SF_NOUNLINK 0x00100000 /* can't be removed or renamed */ 682 683 /* 684 * This structure is used for reading disk structures larger 685 * than the size of fragment. 686 */ 687 struct ufs_buffer_head { 688 __u64 fragment; /* first fragment */ 689 __u64 count; /* number of fragments */ 690 struct buffer_head * bh[UFS_MAXFRAG]; /* buffers */ 691 }; 692 693 struct ufs_cg_private_info { 694 struct ufs_buffer_head c_ubh; 695 __u32 c_cgx; /* number of cylidner group */ 696 __u16 c_ncyl; /* number of cyl's this cg */ 697 __u16 c_niblk; /* number of inode blocks this cg */ 698 __u32 c_ndblk; /* number of data blocks this cg */ 699 __u32 c_rotor; /* position of last used block */ 700 __u32 c_frotor; /* position of last used frag */ 701 __u32 c_irotor; /* position of last used inode */ 702 __u32 c_btotoff; /* (__u32) block totals per cylinder */ 703 __u32 c_boff; /* (short) free block positions */ 704 __u32 c_iusedoff; /* (char) used inode map */ 705 __u32 c_freeoff; /* (u_char) free block map */ 706 __u32 c_nextfreeoff; /* (u_char) next available space */ 707 __u32 c_clustersumoff;/* (u_int32) counts of avail clusters */ 708 __u32 c_clusteroff; /* (u_int8) free cluster map */ 709 __u32 c_nclusterblks; /* number of clusters this cg */ 710 }; 711 712 713 struct ufs_sb_private_info { 714 struct ufs_buffer_head s_ubh; /* buffer containing super block */ 715 struct ufs_csum_core cs_total; 716 __u32 s_sblkno; /* offset of super-blocks in filesys */ 717 __u32 s_cblkno; /* offset of cg-block in filesys */ 718 __u32 s_iblkno; /* offset of inode-blocks in filesys */ 719 __u32 s_dblkno; /* offset of first data after cg */ 720 __u32 s_cgoffset; /* cylinder group offset in cylinder */ 721 __u32 s_cgmask; /* used to calc mod fs_ntrak */ 722 __u32 s_size; /* number of blocks (fragments) in fs */ 723 __u32 s_dsize; /* number of data blocks in fs */ 724 __u64 s_u2_size; /* ufs2: number of blocks (fragments) in fs */ 725 __u64 s_u2_dsize; /*ufs2: number of data blocks in fs */ 726 __u32 s_ncg; /* number of cylinder groups */ 727 __u32 s_bsize; /* size of basic blocks */ 728 __u32 s_fsize; /* size of fragments */ 729 __u32 s_fpb; /* fragments per block */ 730 __u32 s_minfree; /* minimum percentage of free blocks */ 731 __u32 s_bmask; /* `blkoff'' calc of blk offsets */ 732 __u32 s_fmask; /* s_fsize mask */ 733 __u32 s_bshift; /* `lblkno'' calc of logical blkno */ 734 __u32 s_fshift; /* s_fsize shift */ 735 __u32 s_fpbshift; /* fragments per block shift */ 736 __u32 s_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 737 __u32 s_sbsize; /* actual size of super block */ 738 __u32 s_csmask; /* csum block offset */ 739 __u32 s_csshift; /* csum block number */ 740 __u32 s_nindir; /* value of NINDIR */ 741 __u32 s_inopb; /* value of INOPB */ 742 __u32 s_nspf; /* value of NSPF */ 743 __u32 s_npsect; /* # sectors/track including spares */ 744 __u32 s_interleave; /* hardware sector interleave */ 745 __u32 s_trackskew; /* sector 0 skew, per track */ 746 __u64 s_csaddr; /* blk addr of cyl grp summary area */ 747 __u32 s_cssize; /* size of cyl grp summary area */ 748 __u32 s_cgsize; /* cylinder group size */ 749 __u32 s_ntrak; /* tracks per cylinder */ 750 __u32 s_nsect; /* sectors per track */ 751 __u32 s_spc; /* sectors per cylinder */ 752 __u32 s_ipg; /* inodes per cylinder group */ 753 __u32 s_fpg; /* fragments per group */ 754 __u32 s_cpc; /* cyl per cycle in postbl */ 755 __s32 s_contigsumsize;/* size of cluster summary array, 44bsd */ 756 __s64 s_qbmask; /* ~usb_bmask */ 757 __s64 s_qfmask; /* ~usb_fmask */ 758 __s32 s_postblformat; /* format of positional layout tables */ 759 __s32 s_nrpos; /* number of rotational positions */ 760 __s32 s_postbloff; /* (__s16) rotation block list head */ 761 __s32 s_rotbloff; /* (__u8) blocks for each rotation */ 762 763 __u32 s_fpbmask; /* fragments per block mask */ 764 __u32 s_apb; /* address per block */ 765 __u32 s_2apb; /* address per block^2 */ 766 __u32 s_3apb; /* address per block^3 */ 767 __u32 s_apbmask; /* address per block mask */ 768 __u32 s_apbshift; /* address per block shift */ 769 __u32 s_2apbshift; /* address per block shift * 2 */ 770 __u32 s_3apbshift; /* address per block shift * 3 */ 771 __u32 s_nspfshift; /* number of sector per fragment shift */ 772 __u32 s_nspb; /* number of sector per block */ 773 __u32 s_inopf; /* inodes per fragment */ 774 __u32 s_sbbase; /* offset of NeXTstep superblock */ 775 __u32 s_bpf; /* bits per fragment */ 776 __u32 s_bpfshift; /* bits per fragment shift*/ 777 __u32 s_bpfmask; /* bits per fragment mask */ 778 779 __u32 s_maxsymlinklen;/* upper limit on fast symlinks' size */ 780 __s32 fs_magic; /* filesystem magic */ 781 unsigned int s_dirblksize; 782 }; 783 784 /* 785 * Sizes of this structures are: 786 * ufs_super_block_first 512 787 * ufs_super_block_second 512 788 * ufs_super_block_third 356 789 */ 790 struct ufs_super_block_first { 791 union { 792 struct { 793 __fs32 fs_link; /* UNUSED */ 794 } fs_42; 795 struct { 796 __fs32 fs_state; /* file system state flag */ 797 } fs_sun; 798 } fs_u0; 799 __fs32 fs_rlink; 800 __fs32 fs_sblkno; 801 __fs32 fs_cblkno; 802 __fs32 fs_iblkno; 803 __fs32 fs_dblkno; 804 __fs32 fs_cgoffset; 805 __fs32 fs_cgmask; 806 __fs32 fs_time; 807 __fs32 fs_size; 808 __fs32 fs_dsize; 809 __fs32 fs_ncg; 810 __fs32 fs_bsize; 811 __fs32 fs_fsize; 812 __fs32 fs_frag; 813 __fs32 fs_minfree; 814 __fs32 fs_rotdelay; 815 __fs32 fs_rps; 816 __fs32 fs_bmask; 817 __fs32 fs_fmask; 818 __fs32 fs_bshift; 819 __fs32 fs_fshift; 820 __fs32 fs_maxcontig; 821 __fs32 fs_maxbpg; 822 __fs32 fs_fragshift; 823 __fs32 fs_fsbtodb; 824 __fs32 fs_sbsize; 825 __fs32 fs_csmask; 826 __fs32 fs_csshift; 827 __fs32 fs_nindir; 828 __fs32 fs_inopb; 829 __fs32 fs_nspf; 830 __fs32 fs_optim; 831 union { 832 struct { 833 __fs32 fs_npsect; 834 } fs_sun; 835 struct { 836 __fs32 fs_state; 837 } fs_sunx86; 838 } fs_u1; 839 __fs32 fs_interleave; 840 __fs32 fs_trackskew; 841 __fs32 fs_id[2]; 842 __fs32 fs_csaddr; 843 __fs32 fs_cssize; 844 __fs32 fs_cgsize; 845 __fs32 fs_ntrak; 846 __fs32 fs_nsect; 847 __fs32 fs_spc; 848 __fs32 fs_ncyl; 849 __fs32 fs_cpg; 850 __fs32 fs_ipg; 851 __fs32 fs_fpg; 852 struct ufs_csum fs_cstotal; 853 __s8 fs_fmod; 854 __s8 fs_clean; 855 __s8 fs_ronly; 856 __s8 fs_flags; 857 __s8 fs_fsmnt[UFS_MAXMNTLEN - 212]; 858 859 }; 860 861 struct ufs_super_block_second { 862 union { 863 struct { 864 __s8 fs_fsmnt[212]; 865 __fs32 fs_cgrotor; 866 __fs32 fs_csp[UFS_MAXCSBUFS]; 867 __fs32 fs_maxcluster; 868 __fs32 fs_cpc; 869 __fs16 fs_opostbl[82]; 870 } fs_u1; 871 struct { 872 __s8 fs_fsmnt[UFS2_MAXMNTLEN - UFS_MAXMNTLEN + 212]; 873 __u8 fs_volname[UFS2_MAXVOLLEN]; 874 __fs64 fs_swuid; 875 __fs32 fs_pad; 876 __fs32 fs_cgrotor; 877 __fs32 fs_ocsp[UFS2_NOCSPTRS]; 878 __fs32 fs_contigdirs; 879 __fs32 fs_csp; 880 __fs32 fs_maxcluster; 881 __fs32 fs_active; 882 __fs32 fs_old_cpc; 883 __fs32 fs_maxbsize; 884 __fs64 fs_sparecon64[17]; 885 __fs64 fs_sblockloc; 886 __fs64 cs_ndir; 887 __fs64 cs_nbfree; 888 } fs_u2; 889 } fs_un; 890 }; 891 892 struct ufs_super_block_third { 893 union { 894 struct { 895 __fs16 fs_opostbl[46]; 896 } fs_u1; 897 struct { 898 __fs64 cs_nifree; /* number of free inodes */ 899 __fs64 cs_nffree; /* number of free frags */ 900 __fs64 cs_numclusters; /* number of free clusters */ 901 __fs64 cs_spare[3]; /* future expansion */ 902 struct ufs_timeval fs_time; /* last time written */ 903 __fs64 fs_size; /* number of blocks in fs */ 904 __fs64 fs_dsize; /* number of data blocks in fs */ 905 __fs64 fs_csaddr; /* blk addr of cyl grp summary area */ 906 __fs64 fs_pendingblocks;/* blocks in process of being freed */ 907 __fs32 fs_pendinginodes;/*inodes in process of being freed */ 908 } __attribute__ ((packed)) fs_u2; 909 } fs_un1; 910 union { 911 struct { 912 __fs32 fs_sparecon[53];/* reserved for future constants */ 913 __fs32 fs_reclaim; 914 __fs32 fs_sparecon2[1]; 915 __fs32 fs_state; /* file system state time stamp */ 916 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 917 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 918 } fs_sun; 919 struct { 920 __fs32 fs_sparecon[53];/* reserved for future constants */ 921 __fs32 fs_reclaim; 922 __fs32 fs_sparecon2[1]; 923 __fs32 fs_npsect; /* # sectors/track including spares */ 924 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 925 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 926 } fs_sunx86; 927 struct { 928 __fs32 fs_sparecon[50];/* reserved for future constants */ 929 __fs32 fs_contigsumsize;/* size of cluster summary array */ 930 __fs32 fs_maxsymlinklen;/* max length of an internal symlink */ 931 __fs32 fs_inodefmt; /* format of on-disk inodes */ 932 __fs32 fs_maxfilesize[2]; /* max representable file size */ 933 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 934 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 935 __fs32 fs_state; /* file system state time stamp */ 936 } fs_44; 937 } fs_un2; 938 __fs32 fs_postblformat; 939 __fs32 fs_nrpos; 940 __fs32 fs_postbloff; 941 __fs32 fs_rotbloff; 942 __fs32 fs_magic; 943 __u8 fs_space[1]; 944 }; 945 946 #endif /* __LINUX_UFS_FS_H */ 947