2 * linux/include/linux/ufs_fs.h
5 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
6 * Laboratory for Computer Science Research Computing Facility
7 * Rutgers, The State University of New Jersey
9 * Clean swab support by Fare <fare@tunes.org>
10 * just hope no one is using NNUUXXI on __?64 structure elements
11 * 64-bit clean thanks to Maciej W. Rozycki <macro@ds2.pg.gda.pl>
13 * 4.4BSD (FreeBSD) support added on February 1st 1998 by
14 * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
15 * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
17 * NeXTstep support added on February 5th 1998 by
18 * Niels Kristian Bech Jensen <nkbj@image.dk>.
20 * Write support by Daniel Pirkl <daniel.pirkl@email.cz>
22 * HP/UX hfs filesystem support added by
23 * Martin K. Petersen <mkp@mkp.net>, August 1999
25 * UFS2 (of FreeBSD 5.x) support added by
26 * Niraj Kumar <niraj17@iitbombay.org> , Jan 2004
30 #ifndef __LINUX_UFS_FS_H
31 #define __LINUX_UFS_FS_H
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/stat.h>
43 #include <asm/div64.h>
44 typedef __u64 __bitwise __fs64
;
45 typedef __u32 __bitwise __fs32
;
46 typedef __u16 __bitwise __fs16
;
50 #include <linux/ufs_fs_i.h>
51 #include <linux/ufs_fs_sb.h>
55 #define UFS_BBSIZE 8192
56 #define UFS_SBLOCK 8192
57 #define UFS_SBSIZE 8192
59 #define UFS_SECTOR_SIZE 512
60 #define UFS_SECTOR_BITS 9
61 #define UFS_MAGIC 0x00011954
62 #define UFS2_MAGIC 0x19540119
63 #define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */
65 /* Copied from FreeBSD */
67 * Each disk drive contains some number of filesystems.
68 * A filesystem consists of a number of cylinder groups.
69 * Each cylinder group has inodes and data.
71 * A filesystem is described by its super-block, which in turn
72 * describes the cylinder groups. The super-block is critical
73 * data and is replicated in each cylinder group to protect against
74 * catastrophic loss. This is done at `newfs' time and the critical
75 * super-block data does not change, so the copies need not be
76 * referenced further unless disaster strikes.
78 * For filesystem fs, the offsets of the various blocks of interest
79 * are given in the super block as:
80 * [fs->fs_sblkno] Super-block
81 * [fs->fs_cblkno] Cylinder group block
82 * [fs->fs_iblkno] Inode blocks
83 * [fs->fs_dblkno] Data blocks
84 * The beginning of cylinder group cg in fs, is given by
85 * the ``cgbase(fs, cg)'' macro.
87 * Depending on the architecture and the media, the superblock may
88 * reside in any one of four places. For tiny media where every block
89 * counts, it is placed at the very front of the partition. Historically,
90 * UFS1 placed it 8K from the front to leave room for the disk label and
91 * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
92 * room for the disk label and a bigger bootstrap, and for really piggy
93 * systems we check at 256K from the front if the first three fail. In
94 * all cases the size of the superblock will be SBLOCKSIZE. All values are
95 * given in byte-offset form, so they do not imply a sector size. The
96 * SBLOCKSEARCH specifies the order in which the locations should be searched.
98 #define SBLOCK_FLOPPY 0
99 #define SBLOCK_UFS1 8192
100 #define SBLOCK_UFS2 65536
101 #define SBLOCK_PIGGY 262144
102 #define SBLOCKSIZE 8192
103 #define SBLOCKSEARCH \
104 { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
107 /* HP specific MAGIC values */
109 #define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
110 #define UFS_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */
112 #define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */
113 #define UFS_CIGAM_SEC 0x95216100
115 #define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
116 #define UFS_CIGAM_FEA 0x12561900
118 #define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
119 #define UFS_CIGAM_4GB 0x94192305
121 /* Seems somebody at HP goofed here. B1 and lfs are both 0x2 !?! */
122 #define UFS_FSF_LFN 0x00000001 /* long file names */
123 #define UFS_FSF_B1 0x00000002 /* B1 security */
124 #define UFS_FSF_LFS 0x00000002 /* large files */
125 #define UFS_FSF_LUID 0x00000004 /* large UIDs */
127 /* End of HP stuff */
130 #define UFS_BSIZE 8192
131 #define UFS_MINBSIZE 4096
132 #define UFS_FSIZE 1024
133 #define UFS_MAXFRAG (UFS_BSIZE / UFS_FSIZE)
135 #define UFS_NDADDR 12
138 #define UFS_IND_BLOCK (UFS_NDADDR + 0)
139 #define UFS_DIND_BLOCK (UFS_NDADDR + 1)
140 #define UFS_TIND_BLOCK (UFS_NDADDR + 2)
142 #define UFS_NDIR_FRAGMENT (UFS_NDADDR << uspi->s_fpbshift)
143 #define UFS_IND_FRAGMENT (UFS_IND_BLOCK << uspi->s_fpbshift)
144 #define UFS_DIND_FRAGMENT (UFS_DIND_BLOCK << uspi->s_fpbshift)
145 #define UFS_TIND_FRAGMENT (UFS_TIND_BLOCK << uspi->s_fpbshift)
147 #define UFS_ROOTINO 2
148 #define UFS_FIRST_INO (UFS_ROOTINO + 1)
150 #define UFS_USEEFT ((__u16)65535)
152 #define UFS_FSOK 0x7c269d38
153 #define UFS_FSACTIVE ((__s8)0x00)
154 #define UFS_FSCLEAN ((__s8)0x01)
155 #define UFS_FSSTABLE ((__s8)0x02)
156 #define UFS_FSOSF1 ((__s8)0x03) /* is this correct for DEC OSF/1? */
157 #define UFS_FSBAD ((__s8)0xff)
159 /* From here to next blank line, s_flags for ufs_sb_info */
160 /* directory entry encoding */
161 #define UFS_DE_MASK 0x00000010 /* mask for the following */
162 #define UFS_DE_OLD 0x00000000
163 #define UFS_DE_44BSD 0x00000010
165 #define UFS_UID_MASK 0x00000060 /* mask for the following */
166 #define UFS_UID_OLD 0x00000000
167 #define UFS_UID_44BSD 0x00000020
168 #define UFS_UID_EFT 0x00000040
169 /* superblock state encoding */
170 #define UFS_ST_MASK 0x00000700 /* mask for the following */
171 #define UFS_ST_OLD 0x00000000
172 #define UFS_ST_44BSD 0x00000100
173 #define UFS_ST_SUN 0x00000200
174 #define UFS_ST_SUNx86 0x00000400
175 /*cylinder group encoding */
176 #define UFS_CG_MASK 0x00003000 /* mask for the following */
177 #define UFS_CG_OLD 0x00000000
178 #define UFS_CG_44BSD 0x00002000
179 #define UFS_CG_SUN 0x00001000
180 /* filesystem type encoding */
181 #define UFS_TYPE_MASK 0x00010000 /* mask for the following */
182 #define UFS_TYPE_UFS1 0x00000000
183 #define UFS_TYPE_UFS2 0x00010000
186 /* fs_inodefmt options */
187 #define UFS_42INODEFMT -1
188 #define UFS_44INODEFMT 2
191 #define UFS_MOUNT_ONERROR 0x0000000F
192 #define UFS_MOUNT_ONERROR_PANIC 0x00000001
193 #define UFS_MOUNT_ONERROR_LOCK 0x00000002
194 #define UFS_MOUNT_ONERROR_UMOUNT 0x00000004
195 #define UFS_MOUNT_ONERROR_REPAIR 0x00000008
197 #define UFS_MOUNT_UFSTYPE 0x0000FFF0
198 #define UFS_MOUNT_UFSTYPE_OLD 0x00000010
199 #define UFS_MOUNT_UFSTYPE_44BSD 0x00000020
200 #define UFS_MOUNT_UFSTYPE_SUN 0x00000040
201 #define UFS_MOUNT_UFSTYPE_NEXTSTEP 0x00000080
202 #define UFS_MOUNT_UFSTYPE_NEXTSTEP_CD 0x00000100
203 #define UFS_MOUNT_UFSTYPE_OPENSTEP 0x00000200
204 #define UFS_MOUNT_UFSTYPE_SUNx86 0x00000400
205 #define UFS_MOUNT_UFSTYPE_HP 0x00000800
206 #define UFS_MOUNT_UFSTYPE_UFS2 0x00001000
208 #define ufs_clear_opt(o,opt) o &= ~UFS_MOUNT_##opt
209 #define ufs_set_opt(o,opt) o |= UFS_MOUNT_##opt
210 #define ufs_test_opt(o,opt) ((o) & UFS_MOUNT_##opt)
213 * MINFREE gives the minimum acceptable percentage of file system
214 * blocks which may be free. If the freelist drops below this level
215 * only the superuser may continue to allocate blocks. This may
216 * be set to 0 if no reserve of free blocks is deemed necessary,
217 * however throughput drops by fifty percent if the file system
218 * is run at between 95% and 100% full; thus the minimum default
219 * value of fs_minfree is 5%. However, to get good clustering
220 * performance, 10% is a better choice. hence we use 10% as our
221 * default value. With 10% free space, fragmentation is not a
222 * problem, so we choose to optimize for time.
224 #define UFS_MINFREE 5
225 #define UFS_DEFAULTOPT UFS_OPTTIME
230 #ifdef CONFIG_UFS_DEBUG
231 # define UFSD(f, a...) { \
232 printk ("UFSD (%s, %d): %s:", \
233 __FILE__, __LINE__, __FUNCTION__); \
237 # define UFSD(f, a...) /**/
241 * Turn file system block numbers into disk block addresses.
242 * This maps file system blocks to device size blocks.
244 #define ufs_fsbtodb(uspi, b) ((b) << (uspi)->s_fsbtodb)
245 #define ufs_dbtofsb(uspi, b) ((b) >> (uspi)->s_fsbtodb)
248 * Cylinder group macros to locate things in cylinder groups.
249 * They calc file system addresses of cylinder group data structures.
251 #define ufs_cgbase(c) (uspi->s_fpg * (c))
252 #define ufs_cgstart(c) ((uspi)->fs_magic == UFS2_MAGIC ? ufs_cgbase(c) : \
253 (ufs_cgbase(c) + uspi->s_cgoffset * ((c) & ~uspi->s_cgmask)))
254 #define ufs_cgsblock(c) (ufs_cgstart(c) + uspi->s_sblkno) /* super blk */
255 #define ufs_cgcmin(c) (ufs_cgstart(c) + uspi->s_cblkno) /* cg block */
256 #define ufs_cgimin(c) (ufs_cgstart(c) + uspi->s_iblkno) /* inode blk */
257 #define ufs_cgdmin(c) (ufs_cgstart(c) + uspi->s_dblkno) /* 1st data */
260 * Macros for handling inode numbers:
261 * inode number to file system block offset.
262 * inode number to cylinder group number.
263 * inode number to file system block address.
265 #define ufs_inotocg(x) ((x) / uspi->s_ipg)
266 #define ufs_inotocgoff(x) ((x) % uspi->s_ipg)
267 #define ufs_inotofsba(x) (((u64)ufs_cgimin(ufs_inotocg(x))) + ufs_inotocgoff(x) / uspi->s_inopf)
268 #define ufs_inotofsbo(x) ((x) % uspi->s_inopf)
271 * Compute the cylinder and rotational position of a cyl block addr.
273 #define ufs_cbtocylno(bno) \
274 ((bno) * uspi->s_nspf / uspi->s_spc)
275 #define ufs_cbtorpos(bno) \
276 ((((bno) * uspi->s_nspf % uspi->s_spc / uspi->s_nsect \
277 * uspi->s_trackskew + (bno) * uspi->s_nspf % uspi->s_spc \
278 % uspi->s_nsect * uspi->s_interleave) % uspi->s_nsect \
279 * uspi->s_nrpos) / uspi->s_npsect)
282 * The following macros optimize certain frequently calculated
283 * quantities by using shifts and masks in place of divisions
284 * modulos and multiplications.
286 #define ufs_blkoff(loc) ((loc) & uspi->s_qbmask)
287 #define ufs_fragoff(loc) ((loc) & uspi->s_qfmask)
288 #define ufs_lblktosize(blk) ((blk) << uspi->s_bshift)
289 #define ufs_lblkno(loc) ((loc) >> uspi->s_bshift)
290 #define ufs_numfrags(loc) ((loc) >> uspi->s_fshift)
291 #define ufs_blkroundup(size) (((size) + uspi->s_qbmask) & uspi->s_bmask)
292 #define ufs_fragroundup(size) (((size) + uspi->s_qfmask) & uspi->s_fmask)
293 #define ufs_fragstoblks(frags) ((frags) >> uspi->s_fpbshift)
294 #define ufs_blkstofrags(blks) ((blks) << uspi->s_fpbshift)
295 #define ufs_fragnum(fsb) ((fsb) & uspi->s_fpbmask)
296 #define ufs_blknum(fsb) ((fsb) & ~uspi->s_fpbmask)
298 #define UFS_MAXNAMLEN 255
299 #define UFS_MAXMNTLEN 512
300 #define UFS2_MAXMNTLEN 468
301 #define UFS2_MAXVOLLEN 32
302 #define UFS_MAXCSBUFS 31
303 #define UFS_LINK_MAX 32000
305 #define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4)
307 #define UFS2_NOCSPTRS 28
310 * UFS_DIR_PAD defines the directory entries boundaries
311 * (must be a multiple of 4)
313 #define UFS_DIR_PAD 4
314 #define UFS_DIR_ROUND (UFS_DIR_PAD - 1)
315 #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND)
322 struct ufs_dir_entry
{
323 __fs32 d_ino
; /* inode number of this entry */
324 __fs16 d_reclen
; /* length of this entry */
326 __fs16 d_namlen
; /* actual length of d_name */
328 __u8 d_type
; /* file type */
329 __u8 d_namlen
; /* length of string in d_name */
332 __u8 d_name
[UFS_MAXNAMLEN
+ 1]; /* file name */
336 __fs32 cs_ndir
; /* number of directories */
337 __fs32 cs_nbfree
; /* number of free blocks */
338 __fs32 cs_nifree
; /* number of free inodes */
339 __fs32 cs_nffree
; /* number of free frags */
341 struct ufs2_csum_total
{
342 __fs64 cs_ndir
; /* number of directories */
343 __fs64 cs_nbfree
; /* number of free blocks */
344 __fs64 cs_nifree
; /* number of free inodes */
345 __fs64 cs_nffree
; /* number of free frags */
346 __fs64 cs_numclusters
; /* number of free clusters */
347 __fs64 cs_spare
[3]; /* future expansion */
350 struct ufs_csum_core
{
351 __u64 cs_ndir
; /* number of directories */
352 __u64 cs_nbfree
; /* number of free blocks */
353 __u64 cs_nifree
; /* number of free inodes */
354 __u64 cs_nffree
; /* number of free frags */
355 __u64 cs_numclusters
; /* number of free clusters */
361 #define UFS_UNCLEAN 0x01 /* file system not clean at mount (unused) */
362 #define UFS_DOSOFTDEP 0x02 /* file system using soft dependencies */
363 #define UFS_NEEDSFSCK 0x04 /* needs sync fsck (FreeBSD compat, unused) */
364 #define UFS_INDEXDIRS 0x08 /* kernel supports indexed directories */
365 #define UFS_ACLS 0x10 /* file system has ACLs enabled */
366 #define UFS_MULTILABEL 0x20 /* file system is MAC multi-label */
367 #define UFS_FLAGS_UPDATED 0x80 /* flags have been moved to new location */
371 * This is the actual superblock, as it is laid out on the disk.
372 * Do NOT use this structure, because of sizeof(ufs_super_block) > 512 and
373 * it may occupy several blocks, use
374 * struct ufs_super_block_(first,second,third) instead.
376 struct ufs_super_block
{
377 __fs32 fs_link
; /* UNUSED */
378 __fs32 fs_rlink
; /* UNUSED */
379 __fs32 fs_sblkno
; /* addr of super-block in filesys */
380 __fs32 fs_cblkno
; /* offset of cyl-block in filesys */
381 __fs32 fs_iblkno
; /* offset of inode-blocks in filesys */
382 __fs32 fs_dblkno
; /* offset of first data after cg */
383 __fs32 fs_cgoffset
; /* cylinder group offset in cylinder */
384 __fs32 fs_cgmask
; /* used to calc mod fs_ntrak */
385 __fs32 fs_time
; /* last time written -- time_t */
386 __fs32 fs_size
; /* number of blocks in fs */
387 __fs32 fs_dsize
; /* number of data blocks in fs */
388 __fs32 fs_ncg
; /* number of cylinder groups */
389 __fs32 fs_bsize
; /* size of basic blocks in fs */
390 __fs32 fs_fsize
; /* size of frag blocks in fs */
391 __fs32 fs_frag
; /* number of frags in a block in fs */
392 /* these are configuration parameters */
393 __fs32 fs_minfree
; /* minimum percentage of free blocks */
394 __fs32 fs_rotdelay
; /* num of ms for optimal next block */
395 __fs32 fs_rps
; /* disk revolutions per second */
396 /* these fields can be computed from the others */
397 __fs32 fs_bmask
; /* ``blkoff'' calc of blk offsets */
398 __fs32 fs_fmask
; /* ``fragoff'' calc of frag offsets */
399 __fs32 fs_bshift
; /* ``lblkno'' calc of logical blkno */
400 __fs32 fs_fshift
; /* ``numfrags'' calc number of frags */
401 /* these are configuration parameters */
402 __fs32 fs_maxcontig
; /* max number of contiguous blks */
403 __fs32 fs_maxbpg
; /* max number of blks per cyl group */
404 /* these fields can be computed from the others */
405 __fs32 fs_fragshift
; /* block to frag shift */
406 __fs32 fs_fsbtodb
; /* fsbtodb and dbtofsb shift constant */
407 __fs32 fs_sbsize
; /* actual size of super block */
408 __fs32 fs_csmask
; /* csum block offset */
409 __fs32 fs_csshift
; /* csum block number */
410 __fs32 fs_nindir
; /* value of NINDIR */
411 __fs32 fs_inopb
; /* value of INOPB */
412 __fs32 fs_nspf
; /* value of NSPF */
413 /* yet another configuration parameter */
414 __fs32 fs_optim
; /* optimization preference, see below */
415 /* these fields are derived from the hardware */
418 __fs32 fs_npsect
; /* # sectors/track including spares */
421 __fs32 fs_state
; /* file system state time stamp */
424 __fs32 fs_interleave
; /* hardware sector interleave */
425 __fs32 fs_trackskew
; /* sector 0 skew, per track */
426 /* a unique id for this filesystem (currently unused and unmaintained) */
427 /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
428 /* Neither of those fields is used in the Tahoe code right now but */
429 /* there could be problems if they are. */
430 __fs32 fs_id
[2]; /* file system id */
431 /* sizes determined by number of cylinder groups and their sizes */
432 __fs32 fs_csaddr
; /* blk addr of cyl grp summary area */
433 __fs32 fs_cssize
; /* size of cyl grp summary area */
434 __fs32 fs_cgsize
; /* cylinder group size */
435 /* these fields are derived from the hardware */
436 __fs32 fs_ntrak
; /* tracks per cylinder */
437 __fs32 fs_nsect
; /* sectors per track */
438 __fs32 fs_spc
; /* sectors per cylinder */
439 /* this comes from the disk driver partitioning */
440 __fs32 fs_ncyl
; /* cylinders in file system */
441 /* these fields can be computed from the others */
442 __fs32 fs_cpg
; /* cylinders per group */
443 __fs32 fs_ipg
; /* inodes per cylinder group */
444 __fs32 fs_fpg
; /* blocks per group * fs_frag */
445 /* this data must be re-computed after crashes */
446 struct ufs_csum fs_cstotal
; /* cylinder summary information */
447 /* these fields are cleared at mount time */
448 __s8 fs_fmod
; /* super block modified flag */
449 __s8 fs_clean
; /* file system is clean flag */
450 __s8 fs_ronly
; /* mounted read-only flag */
454 __s8 fs_fsmnt
[UFS_MAXMNTLEN
];/* name mounted on */
455 __fs32 fs_cgrotor
; /* last cg searched */
456 __fs32 fs_csp
[UFS_MAXCSBUFS
];/*list of fs_cs info buffers */
457 __fs32 fs_maxcluster
;
458 __fs32 fs_cpc
; /* cyl per cycle in postbl */
459 __fs16 fs_opostbl
[16][8]; /* old rotation block list head */
462 __s8 fs_fsmnt
[UFS2_MAXMNTLEN
]; /* name mounted on */
463 __u8 fs_volname
[UFS2_MAXVOLLEN
]; /* volume name */
464 __fs64 fs_swuid
; /* system-wide uid */
465 __fs32 fs_pad
; /* due to alignment of fs_swuid */
466 __fs32 fs_cgrotor
; /* last cg searched */
467 __fs32 fs_ocsp
[UFS2_NOCSPTRS
]; /*list of fs_cs info buffers */
468 __fs32 fs_contigdirs
;/*# of contiguously allocated dirs */
469 __fs32 fs_csp
; /* cg summary info buffer for fs_cs */
470 __fs32 fs_maxcluster
;
471 __fs32 fs_active
;/* used by snapshots to track fs */
472 __fs32 fs_old_cpc
; /* cyl per cycle in postbl */
473 __fs32 fs_maxbsize
;/*maximum blocking factor permitted */
474 __fs64 fs_sparecon64
[17];/*old rotation block list head */
475 __fs64 fs_sblockloc
; /* byte offset of standard superblock */
476 struct ufs2_csum_total fs_cstotal
;/*cylinder summary information*/
477 struct ufs_timeval fs_time
; /* last time written */
478 __fs64 fs_size
; /* number of blocks in fs */
479 __fs64 fs_dsize
; /* number of data blocks in fs */
480 __fs64 fs_csaddr
; /* blk addr of cyl grp summary area */
481 __fs64 fs_pendingblocks
;/* blocks in process of being freed */
482 __fs32 fs_pendinginodes
;/*inodes in process of being freed */
487 __fs32 fs_sparecon
[53];/* reserved for future constants */
489 __fs32 fs_sparecon2
[1];
490 __fs32 fs_state
; /* file system state time stamp */
491 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
492 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
495 __fs32 fs_sparecon
[53];/* reserved for future constants */
497 __fs32 fs_sparecon2
[1];
498 __fs32 fs_npsect
; /* # sectors/track including spares */
499 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
500 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
503 __fs32 fs_sparecon
[50];/* reserved for future constants */
504 __fs32 fs_contigsumsize
;/* size of cluster summary array */
505 __fs32 fs_maxsymlinklen
;/* max length of an internal symlink */
506 __fs32 fs_inodefmt
; /* format of on-disk inodes */
507 __fs32 fs_maxfilesize
[2]; /* max representable file size */
508 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
509 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
510 __fs32 fs_state
; /* file system state time stamp */
513 __fs32 fs_postblformat
; /* format of positional layout tables */
514 __fs32 fs_nrpos
; /* number of rotational positions */
515 __fs32 fs_postbloff
; /* (__s16) rotation block list head */
516 __fs32 fs_rotbloff
; /* (__u8) blocks for each rotation */
517 __fs32 fs_magic
; /* magic number */
518 __u8 fs_space
[1]; /* list of blocks for each rotation */
520 #endif/*struct ufs_super_block*/
523 * Preference for optimization.
525 #define UFS_OPTTIME 0 /* minimize allocation time */
526 #define UFS_OPTSPACE 1 /* minimize disk fragmentation */
529 * Rotational layout table format types
531 #define UFS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
532 #define UFS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
535 * Convert cylinder group to base address of its global summary info.
537 #define fs_cs(indx) s_csp[(indx)]
540 * Cylinder group block for a file system.
542 * Writable fields in the cylinder group are protected by the associated
543 * super block lock fs->fs_lock.
545 #define CG_MAGIC 0x090255
546 #define ufs_cg_chkmagic(sb, ucg) \
547 (fs32_to_cpu((sb), (ucg)->cg_magic) == CG_MAGIC)
550 * size of this structure is 172 B
552 struct ufs_cylinder_group
{
553 __fs32 cg_link
; /* linked list of cyl groups */
554 __fs32 cg_magic
; /* magic number */
555 __fs32 cg_time
; /* time last written */
556 __fs32 cg_cgx
; /* we are the cgx'th cylinder group */
557 __fs16 cg_ncyl
; /* number of cyl's this cg */
558 __fs16 cg_niblk
; /* number of inode blocks this cg */
559 __fs32 cg_ndblk
; /* number of data blocks this cg */
560 struct ufs_csum cg_cs
; /* cylinder summary information */
561 __fs32 cg_rotor
; /* position of last used block */
562 __fs32 cg_frotor
; /* position of last used frag */
563 __fs32 cg_irotor
; /* position of last used inode */
564 __fs32 cg_frsum
[UFS_MAXFRAG
]; /* counts of available frags */
565 __fs32 cg_btotoff
; /* (__u32) block totals per cylinder */
566 __fs32 cg_boff
; /* (short) free block positions */
567 __fs32 cg_iusedoff
; /* (char) used inode map */
568 __fs32 cg_freeoff
; /* (u_char) free block map */
569 __fs32 cg_nextfreeoff
; /* (u_char) next available space */
572 __fs32 cg_clustersumoff
; /* (u_int32) counts of avail clusters */
573 __fs32 cg_clusteroff
; /* (u_int8) free cluster map */
574 __fs32 cg_nclusterblks
; /* number of clusters this cg */
575 __fs32 cg_sparecon
[13]; /* reserved for future use */
578 __fs32 cg_clustersumoff
;/* (u_int32) counts of avail clusters */
579 __fs32 cg_clusteroff
; /* (u_int8) free cluster map */
580 __fs32 cg_nclusterblks
;/* number of clusters this cg */
581 __fs32 cg_niblk
; /* number of inode blocks this cg */
582 __fs32 cg_initediblk
; /* last initialized inode */
583 __fs32 cg_sparecon32
[3];/* reserved for future use */
584 __fs64 cg_time
; /* time last written */
585 __fs64 cg_sparecon
[3]; /* reserved for future use */
587 __fs32 cg_sparecon
[16]; /* reserved for future use */
589 __u8 cg_space
[1]; /* space for cylinder group maps */
590 /* actually longer */
594 * structure of an on-disk inode
597 __fs16 ui_mode
; /* 0x0 */
598 __fs16 ui_nlink
; /* 0x2 */
601 __fs16 ui_suid
; /* 0x4 */
602 __fs16 ui_sgid
; /* 0x6 */
604 __fs32 ui_inumber
; /* 0x4 lsf: inode number */
605 __fs32 ui_author
; /* 0x4 GNU HURD: author */
607 __fs64 ui_size
; /* 0x8 */
608 struct ufs_timeval ui_atime
; /* 0x10 access */
609 struct ufs_timeval ui_mtime
; /* 0x18 modification */
610 struct ufs_timeval ui_ctime
; /* 0x20 creation */
613 __fs32 ui_db
[UFS_NDADDR
];/* 0x28 data blocks */
614 __fs32 ui_ib
[UFS_NINDIR
];/* 0x58 indirect blocks */
616 __u8 ui_symlink
[4*(UFS_NDADDR
+UFS_NINDIR
)];/* 0x28 fast symlink */
618 __fs32 ui_flags
; /* 0x64 immutable, append-only... */
619 __fs32 ui_blocks
; /* 0x68 blocks in use */
620 __fs32 ui_gen
; /* 0x6c like ext2 i_version, for NFS support */
623 __fs32 ui_shadow
; /* 0x70 shadow inode with security data */
624 __fs32 ui_uid
; /* 0x74 long EFT version of uid */
625 __fs32 ui_gid
; /* 0x78 long EFT version of gid */
626 __fs32 ui_oeftflag
; /* 0x7c reserved */
629 __fs32 ui_uid
; /* 0x70 File owner */
630 __fs32 ui_gid
; /* 0x74 File group */
631 __fs32 ui_spare
[2]; /* 0x78 reserved */
634 __fs32 ui_uid
; /* 0x70 */
635 __fs32 ui_gid
; /* 0x74 */
636 __fs16 ui_modeh
; /* 0x78 mode high bits */
637 __fs16 ui_spare
; /* 0x7A unused */
638 __fs32 ui_trans
; /* 0x7c filesystem translator */
643 #define UFS_NXADDR 2 /* External addresses in inode. */
645 __fs16 ui_mode
; /* 0: IFMT, permissions; see below. */
646 __fs16 ui_nlink
; /* 2: File link count. */
647 __fs32 ui_uid
; /* 4: File owner. */
648 __fs32 ui_gid
; /* 8: File group. */
649 __fs32 ui_blksize
; /* 12: Inode blocksize. */
650 __fs64 ui_size
; /* 16: File byte count. */
651 __fs64 ui_blocks
; /* 24: Bytes actually held. */
652 struct ufs_timeval ui_atime
; /* 32: Last access time. */
653 struct ufs_timeval ui_mtime
; /* 40: Last modified time. */
654 struct ufs_timeval ui_ctime
; /* 48: Last inode change time. */
655 struct ufs_timeval ui_birthtime
; /* 56: Inode creation time. */
656 __fs32 ui_mtimensec
; /* 64: Last modified time. */
657 __fs32 ui_atimensec
; /* 68: Last access time. */
658 __fs32 ui_ctimensec
; /* 72: Last inode change time. */
659 __fs32 ui_birthnsec
; /* 76: Inode creation time. */
660 __fs32 ui_gen
; /* 80: Generation number. */
661 __fs32 ui_kernflags
; /* 84: Kernel flags. */
662 __fs32 ui_flags
; /* 88: Status flags (chflags). */
663 __fs32 ui_extsize
; /* 92: External attributes block. */
664 __fs64 ui_extb
[UFS_NXADDR
];/* 96: External attributes block. */
667 __fs64 ui_db
[UFS_NDADDR
]; /* 112: Direct disk blocks. */
668 __fs64 ui_ib
[UFS_NINDIR
];/* 208: Indirect disk blocks.*/
670 __u8 ui_symlink
[2*4*(UFS_NDADDR
+UFS_NINDIR
)];/* 0x28 fast symlink */
672 __fs64 ui_spare
[3]; /* 232: Reserved; currently unused */
676 /* FreeBSD has these in sys/stat.h */
677 /* ui_flags that can be set by a file owner */
678 #define UFS_UF_SETTABLE 0x0000ffff
679 #define UFS_UF_NODUMP 0x00000001 /* do not dump */
680 #define UFS_UF_IMMUTABLE 0x00000002 /* immutable (can't "change") */
681 #define UFS_UF_APPEND 0x00000004 /* append-only */
682 #define UFS_UF_OPAQUE 0x00000008 /* directory is opaque (unionfs) */
683 #define UFS_UF_NOUNLINK 0x00000010 /* can't be removed or renamed */
684 /* ui_flags that only root can set */
685 #define UFS_SF_SETTABLE 0xffff0000
686 #define UFS_SF_ARCHIVED 0x00010000 /* archived */
687 #define UFS_SF_IMMUTABLE 0x00020000 /* immutable (can't "change") */
688 #define UFS_SF_APPEND 0x00040000 /* append-only */
689 #define UFS_SF_NOUNLINK 0x00100000 /* can't be removed or renamed */
692 * This structure is used for reading disk structures larger
693 * than the size of fragment.
695 struct ufs_buffer_head
{
696 __u64 fragment
; /* first fragment */
697 __u64 count
; /* number of fragments */
698 struct buffer_head
* bh
[UFS_MAXFRAG
]; /* buffers */
701 struct ufs_cg_private_info
{
702 struct ufs_buffer_head c_ubh
;
703 __u32 c_cgx
; /* number of cylidner group */
704 __u16 c_ncyl
; /* number of cyl's this cg */
705 __u16 c_niblk
; /* number of inode blocks this cg */
706 __u32 c_ndblk
; /* number of data blocks this cg */
707 __u32 c_rotor
; /* position of last used block */
708 __u32 c_frotor
; /* position of last used frag */
709 __u32 c_irotor
; /* position of last used inode */
710 __u32 c_btotoff
; /* (__u32) block totals per cylinder */
711 __u32 c_boff
; /* (short) free block positions */
712 __u32 c_iusedoff
; /* (char) used inode map */
713 __u32 c_freeoff
; /* (u_char) free block map */
714 __u32 c_nextfreeoff
; /* (u_char) next available space */
715 __u32 c_clustersumoff
;/* (u_int32) counts of avail clusters */
716 __u32 c_clusteroff
; /* (u_int8) free cluster map */
717 __u32 c_nclusterblks
; /* number of clusters this cg */
721 struct ufs_sb_private_info
{
722 struct ufs_buffer_head s_ubh
; /* buffer containing super block */
723 struct ufs_csum_core cs_total
;
724 __u32 s_sblkno
; /* offset of super-blocks in filesys */
725 __u32 s_cblkno
; /* offset of cg-block in filesys */
726 __u32 s_iblkno
; /* offset of inode-blocks in filesys */
727 __u32 s_dblkno
; /* offset of first data after cg */
728 __u32 s_cgoffset
; /* cylinder group offset in cylinder */
729 __u32 s_cgmask
; /* used to calc mod fs_ntrak */
730 __u32 s_size
; /* number of blocks (fragments) in fs */
731 __u32 s_dsize
; /* number of data blocks in fs */
732 __u64 s_u2_size
; /* ufs2: number of blocks (fragments) in fs */
733 __u64 s_u2_dsize
; /*ufs2: number of data blocks in fs */
734 __u32 s_ncg
; /* number of cylinder groups */
735 __u32 s_bsize
; /* size of basic blocks */
736 __u32 s_fsize
; /* size of fragments */
737 __u32 s_fpb
; /* fragments per block */
738 __u32 s_minfree
; /* minimum percentage of free blocks */
739 __u32 s_bmask
; /* `blkoff'' calc of blk offsets */
740 __u32 s_fmask
; /* s_fsize mask */
741 __u32 s_bshift
; /* `lblkno'' calc of logical blkno */
742 __u32 s_fshift
; /* s_fsize shift */
743 __u32 s_fpbshift
; /* fragments per block shift */
744 __u32 s_fsbtodb
; /* fsbtodb and dbtofsb shift constant */
745 __u32 s_sbsize
; /* actual size of super block */
746 __u32 s_csmask
; /* csum block offset */
747 __u32 s_csshift
; /* csum block number */
748 __u32 s_nindir
; /* value of NINDIR */
749 __u32 s_inopb
; /* value of INOPB */
750 __u32 s_nspf
; /* value of NSPF */
751 __u32 s_npsect
; /* # sectors/track including spares */
752 __u32 s_interleave
; /* hardware sector interleave */
753 __u32 s_trackskew
; /* sector 0 skew, per track */
754 __u64 s_csaddr
; /* blk addr of cyl grp summary area */
755 __u32 s_cssize
; /* size of cyl grp summary area */
756 __u32 s_cgsize
; /* cylinder group size */
757 __u32 s_ntrak
; /* tracks per cylinder */
758 __u32 s_nsect
; /* sectors per track */
759 __u32 s_spc
; /* sectors per cylinder */
760 __u32 s_ipg
; /* inodes per cylinder group */
761 __u32 s_fpg
; /* fragments per group */
762 __u32 s_cpc
; /* cyl per cycle in postbl */
763 __s32 s_contigsumsize
;/* size of cluster summary array, 44bsd */
764 __s64 s_qbmask
; /* ~usb_bmask */
765 __s64 s_qfmask
; /* ~usb_fmask */
766 __s32 s_postblformat
; /* format of positional layout tables */
767 __s32 s_nrpos
; /* number of rotational positions */
768 __s32 s_postbloff
; /* (__s16) rotation block list head */
769 __s32 s_rotbloff
; /* (__u8) blocks for each rotation */
771 __u32 s_fpbmask
; /* fragments per block mask */
772 __u32 s_apb
; /* address per block */
773 __u32 s_2apb
; /* address per block^2 */
774 __u32 s_3apb
; /* address per block^3 */
775 __u32 s_apbmask
; /* address per block mask */
776 __u32 s_apbshift
; /* address per block shift */
777 __u32 s_2apbshift
; /* address per block shift * 2 */
778 __u32 s_3apbshift
; /* address per block shift * 3 */
779 __u32 s_nspfshift
; /* number of sector per fragment shift */
780 __u32 s_nspb
; /* number of sector per block */
781 __u32 s_inopf
; /* inodes per fragment */
782 __u32 s_sbbase
; /* offset of NeXTstep superblock */
783 __u32 s_bpf
; /* bits per fragment */
784 __u32 s_bpfshift
; /* bits per fragment shift*/
785 __u32 s_bpfmask
; /* bits per fragment mask */
787 __u32 s_maxsymlinklen
;/* upper limit on fast symlinks' size */
788 __s32 fs_magic
; /* filesystem magic */
789 unsigned int s_dirblksize
;
793 * Sizes of this structures are:
794 * ufs_super_block_first 512
795 * ufs_super_block_second 512
796 * ufs_super_block_third 356
798 struct ufs_super_block_first
{
840 __fs32 fs_interleave
;
853 struct ufs_csum fs_cstotal
;
858 __s8 fs_fsmnt
[UFS_MAXMNTLEN
- 212];
862 struct ufs_super_block_second
{
867 __fs32 fs_csp
[UFS_MAXCSBUFS
];
868 __fs32 fs_maxcluster
;
870 __fs16 fs_opostbl
[82];
873 __s8 fs_fsmnt
[UFS2_MAXMNTLEN
- UFS_MAXMNTLEN
+ 212];
874 __u8 fs_volname
[UFS2_MAXVOLLEN
];
878 __fs32 fs_ocsp
[UFS2_NOCSPTRS
];
879 __fs32 fs_contigdirs
;
881 __fs32 fs_maxcluster
;
885 __fs64 fs_sparecon64
[17];
893 struct ufs_super_block_third
{
896 __fs16 fs_opostbl
[46];
899 __fs64 cs_nifree
; /* number of free inodes */
900 __fs64 cs_nffree
; /* number of free frags */
901 __fs64 cs_numclusters
; /* number of free clusters */
902 __fs64 cs_spare
[3]; /* future expansion */
903 struct ufs_timeval fs_time
; /* last time written */
904 __fs64 fs_size
; /* number of blocks in fs */
905 __fs64 fs_dsize
; /* number of data blocks in fs */
906 __fs64 fs_csaddr
; /* blk addr of cyl grp summary area */
907 __fs64 fs_pendingblocks
;/* blocks in process of being freed */
908 __fs32 fs_pendinginodes
;/*inodes in process of being freed */
909 } __attribute__ ((packed
)) fs_u2
;
913 __fs32 fs_sparecon
[53];/* reserved for future constants */
915 __fs32 fs_sparecon2
[1];
916 __fs32 fs_state
; /* file system state time stamp */
917 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
918 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
921 __fs32 fs_sparecon
[53];/* reserved for future constants */
923 __fs32 fs_sparecon2
[1];
924 __fs32 fs_npsect
; /* # sectors/track including spares */
925 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
926 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
929 __fs32 fs_sparecon
[50];/* reserved for future constants */
930 __fs32 fs_contigsumsize
;/* size of cluster summary array */
931 __fs32 fs_maxsymlinklen
;/* max length of an internal symlink */
932 __fs32 fs_inodefmt
; /* format of on-disk inodes */
933 __fs32 fs_maxfilesize
[2]; /* max representable file size */
934 __fs32 fs_qbmask
[2]; /* ~usb_bmask */
935 __fs32 fs_qfmask
[2]; /* ~usb_fmask */
936 __fs32 fs_state
; /* file system state time stamp */
939 __fs32 fs_postblformat
;
950 extern void ufs_free_fragments (struct inode
*, u64
, unsigned);
951 extern void ufs_free_blocks (struct inode
*, u64
, unsigned);
952 extern u64
ufs_new_fragments(struct inode
*, void *, u64
, u64
,
953 unsigned, int *, struct page
*);
956 extern struct ufs_cg_private_info
* ufs_load_cylinder (struct super_block
*, unsigned);
957 extern void ufs_put_cylinder (struct super_block
*, unsigned);
960 extern const struct inode_operations ufs_dir_inode_operations
;
961 extern int ufs_add_link (struct dentry
*, struct inode
*);
962 extern ino_t
ufs_inode_by_name(struct inode
*, struct dentry
*);
963 extern int ufs_make_empty(struct inode
*, struct inode
*);
964 extern struct ufs_dir_entry
*ufs_find_entry(struct inode
*, struct dentry
*, struct page
**);
965 extern int ufs_delete_entry(struct inode
*, struct ufs_dir_entry
*, struct page
*);
966 extern int ufs_empty_dir (struct inode
*);
967 extern struct ufs_dir_entry
*ufs_dotdot(struct inode
*, struct page
**);
968 extern void ufs_set_link(struct inode
*dir
, struct ufs_dir_entry
*de
,
969 struct page
*page
, struct inode
*inode
);
972 extern const struct inode_operations ufs_file_inode_operations
;
973 extern const struct file_operations ufs_file_operations
;
975 extern const struct address_space_operations ufs_aops
;
978 extern void ufs_free_inode (struct inode
*inode
);
979 extern struct inode
* ufs_new_inode (struct inode
*, int);
982 extern void ufs_read_inode (struct inode
*);
983 extern void ufs_put_inode (struct inode
*);
984 extern int ufs_write_inode (struct inode
*, int);
985 extern int ufs_sync_inode (struct inode
*);
986 extern void ufs_delete_inode (struct inode
*);
987 extern struct buffer_head
* ufs_bread (struct inode
*, unsigned, int, int *);
988 extern int ufs_getfrag_block (struct inode
*inode
, sector_t fragment
, struct buffer_head
*bh_result
, int create
);
991 extern const struct file_operations ufs_dir_operations
;
994 extern void ufs_warning (struct super_block
*, const char *, const char *, ...) __attribute__ ((format (printf
, 3, 4)));
995 extern void ufs_error (struct super_block
*, const char *, const char *, ...) __attribute__ ((format (printf
, 3, 4)));
996 extern void ufs_panic (struct super_block
*, const char *, const char *, ...) __attribute__ ((format (printf
, 3, 4)));
999 extern const struct inode_operations ufs_fast_symlink_inode_operations
;
1002 extern int ufs_truncate (struct inode
*, loff_t
);
1004 static inline struct ufs_sb_info
*UFS_SB(struct super_block
*sb
)
1006 return sb
->s_fs_info
;
1009 static inline struct ufs_inode_info
*UFS_I(struct inode
*inode
)
1011 return container_of(inode
, struct ufs_inode_info
, vfs_inode
);
1015 * Give cylinder group number for a file system block.
1016 * Give cylinder group block number for a file system block.
1018 /* #define ufs_dtog(d) ((d) / uspi->s_fpg) */
1019 static inline u64
ufs_dtog(struct ufs_sb_private_info
* uspi
, u64 b
)
1021 do_div(b
, uspi
->s_fpg
);
1024 /* #define ufs_dtogd(d) ((d) % uspi->s_fpg) */
1025 static inline u32
ufs_dtogd(struct ufs_sb_private_info
* uspi
, u64 b
)
1027 return do_div(b
, uspi
->s_fpg
);
1030 #endif /* __KERNEL__ */
1032 #endif /* __LINUX_UFS_FS_H */