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/time.h>
36 #include <linux/stat.h>
39 #include <linux/ufs_fs_i.h>
40 #include <linux/ufs_fs_sb.h>
43 #define UFS_BBSIZE 8192
44 #define UFS_SBLOCK 8192
45 #define UFS_SBSIZE 8192
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 */
53 /* Copied from FreeBSD */
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.
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.
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.
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.
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 }
95 /* HP specific MAGIC values */
97 #define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
98 #define UFS_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */
100 #define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */
101 #define UFS_CIGAM_SEC 0x95216100
103 #define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
104 #define UFS_CIGAM_FEA 0x12561900
106 #define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
107 #define UFS_CIGAM_4GB 0x94192305
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 */
115 /* End of HP stuff */
118 #define UFS_BSIZE 8192
119 #define UFS_MINBSIZE 4096
120 #define UFS_FSIZE 1024
121 #define UFS_MAXFRAG (UFS_BSIZE / UFS_FSIZE)
123 #define UFS_NDADDR 12
126 #define UFS_IND_BLOCK (UFS_NDADDR + 0)
127 #define UFS_DIND_BLOCK (UFS_NDADDR + 1)
128 #define UFS_TIND_BLOCK (UFS_NDADDR + 2)
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)
135 #define UFS_ROOTINO 2
136 #define UFS_FIRST_INO (UFS_ROOTINO + 1)
138 #define UFS_USEEFT ((__u16)65535)
140 #define UFS_FSOK 0x7c269d38
141 #define UFS_FSACTIVE ((char)0x00)
142 #define UFS_FSCLEAN ((char)0x01)
143 #define UFS_FSSTABLE ((char)0x02)
144 #define UFS_FSOSF1 ((char)0x03) /* is this correct for DEC OSF/1? */
145 #define UFS_FSBAD ((char)0xff)
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
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
162 #define UFS_ST_SUNx86 0x00000400
163 /*cylinder group encoding */
164 #define UFS_CG_MASK 0x00003000 /* mask for the following */
165 #define UFS_CG_OLD 0x00000000
166 #define UFS_CG_44BSD 0x00002000
167 #define UFS_CG_SUN 0x00001000
168 /* filesystem type encoding */
169 #define UFS_TYPE_MASK 0x00010000 /* mask for the following */
170 #define UFS_TYPE_UFS1 0x00000000
171 #define UFS_TYPE_UFS2 0x00010000
174 /* fs_inodefmt options */
175 #define UFS_42INODEFMT -1
176 #define UFS_44INODEFMT 2
179 #define UFS_MOUNT_ONERROR 0x0000000F
180 #define UFS_MOUNT_ONERROR_PANIC 0x00000001
181 #define UFS_MOUNT_ONERROR_LOCK 0x00000002
182 #define UFS_MOUNT_ONERROR_UMOUNT 0x00000004
183 #define UFS_MOUNT_ONERROR_REPAIR 0x00000008
185 #define UFS_MOUNT_UFSTYPE 0x0000FFF0
186 #define UFS_MOUNT_UFSTYPE_OLD 0x00000010
187 #define UFS_MOUNT_UFSTYPE_44BSD 0x00000020
188 #define UFS_MOUNT_UFSTYPE_SUN 0x00000040
189 #define UFS_MOUNT_UFSTYPE_NEXTSTEP 0x00000080
190 #define UFS_MOUNT_UFSTYPE_NEXTSTEP_CD 0x00000100
191 #define UFS_MOUNT_UFSTYPE_OPENSTEP 0x00000200
192 #define UFS_MOUNT_UFSTYPE_SUNx86 0x00000400
193 #define UFS_MOUNT_UFSTYPE_HP 0x00000800
194 #define UFS_MOUNT_UFSTYPE_UFS2 0x00001000
196 #define ufs_clear_opt(o,opt) o &= ~UFS_MOUNT_##opt
197 #define ufs_set_opt(o,opt) o |= UFS_MOUNT_##opt
198 #define ufs_test_opt(o,opt) ((o) & UFS_MOUNT_##opt)
201 * MINFREE gives the minimum acceptable percentage of file system
202 * blocks which may be free. If the freelist drops below this level
203 * only the superuser may continue to allocate blocks. This may
204 * be set to 0 if no reserve of free blocks is deemed necessary,
205 * however throughput drops by fifty percent if the file system
206 * is run at between 95% and 100% full; thus the minimum default
207 * value of fs_minfree is 5%. However, to get good clustering
208 * performance, 10% is a better choice. hence we use 10% as our
209 * default value. With 10% free space, fragmentation is not a
210 * problem, so we choose to optimize for time.
212 #define UFS_MINFREE 5
213 #define UFS_DEFAULTOPT UFS_OPTTIME
216 * Turn file system block numbers into disk block addresses.
217 * This maps file system blocks to device size blocks.
219 #define ufs_fsbtodb(uspi, b) ((b) << (uspi)->s_fsbtodb)
220 #define ufs_dbtofsb(uspi, b) ((b) >> (uspi)->s_fsbtodb)
223 * Cylinder group macros to locate things in cylinder groups.
224 * They calc file system addresses of cylinder group data structures.
226 #define ufs_cgbase(c) (uspi->s_fpg * (c))
227 #define ufs_cgstart(c) ((uspi)->fs_magic == UFS2_MAGIC ? ufs_cgbase(c) : \
228 (ufs_cgbase(c) + uspi->s_cgoffset * ((c) & ~uspi->s_cgmask)))
229 #define ufs_cgsblock(c) (ufs_cgstart(c) + uspi->s_sblkno) /* super blk */
230 #define ufs_cgcmin(c) (ufs_cgstart(c) + uspi->s_cblkno) /* cg block */
231 #define ufs_cgimin(c) (ufs_cgstart(c) + uspi->s_iblkno) /* inode blk */
232 #define ufs_cgdmin(c) (ufs_cgstart(c) + uspi->s_dblkno) /* 1st data */
235 * Macros for handling inode numbers:
236 * inode number to file system block offset.
237 * inode number to cylinder group number.
238 * inode number to file system block address.
240 #define ufs_inotocg(x) ((x) / uspi->s_ipg)
241 #define ufs_inotocgoff(x) ((x) % uspi->s_ipg)
242 #define ufs_inotofsba(x) (ufs_cgimin(ufs_inotocg(x)) + ufs_inotocgoff(x) / uspi->s_inopf)
243 #define ufs_inotofsbo(x) ((x) % uspi->s_inopf)
246 * Give cylinder group number for a file system block.
247 * Give cylinder group block number for a file system block.
249 #define ufs_dtog(d) ((d) / uspi->s_fpg)
250 #define ufs_dtogd(d) ((d) % uspi->s_fpg)
253 * Compute the cylinder and rotational position of a cyl block addr.
255 #define ufs_cbtocylno(bno) \
256 ((bno) * uspi->s_nspf / uspi->s_spc)
257 #define ufs_cbtorpos(bno) \
258 ((((bno) * uspi->s_nspf % uspi->s_spc / uspi->s_nsect \
259 * uspi->s_trackskew + (bno) * uspi->s_nspf % uspi->s_spc \
260 % uspi->s_nsect * uspi->s_interleave) % uspi->s_nsect \
261 * uspi->s_nrpos) / uspi->s_npsect)
264 * The following macros optimize certain frequently calculated
265 * quantities by using shifts and masks in place of divisions
266 * modulos and multiplications.
268 #define ufs_blkoff(loc) ((loc) & uspi->s_qbmask)
269 #define ufs_fragoff(loc) ((loc) & uspi->s_qfmask)
270 #define ufs_lblktosize(blk) ((blk) << uspi->s_bshift)
271 #define ufs_lblkno(loc) ((loc) >> uspi->s_bshift)
272 #define ufs_numfrags(loc) ((loc) >> uspi->s_fshift)
273 #define ufs_blkroundup(size) (((size) + uspi->s_qbmask) & uspi->s_bmask)
274 #define ufs_fragroundup(size) (((size) + uspi->s_qfmask) & uspi->s_fmask)
275 #define ufs_fragstoblks(frags) ((frags) >> uspi->s_fpbshift)
276 #define ufs_blkstofrags(blks) ((blks) << uspi->s_fpbshift)
277 #define ufs_fragnum(fsb) ((fsb) & uspi->s_fpbmask)
278 #define ufs_blknum(fsb) ((fsb) & ~uspi->s_fpbmask)
280 #define UFS_MAXNAMLEN 255
281 #define UFS_MAXMNTLEN 512
282 #define UFS2_MAXMNTLEN 468
283 #define UFS2_MAXVOLLEN 32
284 /* #define UFS_MAXCSBUFS 31 */
285 #define UFS_LINK_MAX 32000
287 #define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4)
289 #define UFS2_NOCSPTRS 28
292 * UFS_DIR_PAD defines the directory entries boundaries
293 * (must be a multiple of 4)
295 #define UFS_DIR_PAD 4
296 #define UFS_DIR_ROUND (UFS_DIR_PAD - 1)
297 #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND)
304 struct ufs_dir_entry {
305 __u32 d_ino; /* inode number of this entry */
306 __u16 d_reclen; /* length of this entry */
308 __u16 d_namlen; /* actual length of d_name */
310 __u8 d_type; /* file type */
311 __u8 d_namlen; /* length of string in d_name */
314 __u8 d_name[UFS_MAXNAMLEN + 1]; /* file name */
318 __u32 cs_ndir; /* number of directories */
319 __u32 cs_nbfree; /* number of free blocks */
320 __u32 cs_nifree; /* number of free inodes */
321 __u32 cs_nffree; /* number of free frags */
323 struct ufs2_csum_total {
324 __u64 cs_ndir; /* number of directories */
325 __u64 cs_nbfree; /* number of free blocks */
326 __u64 cs_nifree; /* number of free inodes */
327 __u64 cs_nffree; /* number of free frags */
328 __u64 cs_numclusters; /* number of free clusters */
329 __u64 cs_spare[3]; /* future expansion */
333 * This is the actual superblock, as it is laid out on the disk.
335 struct ufs_super_block {
336 __u32 fs_link; /* UNUSED */
337 __u32 fs_rlink; /* UNUSED */
338 __u32 fs_sblkno; /* addr of super-block in filesys */
339 __u32 fs_cblkno; /* offset of cyl-block in filesys */
340 __u32 fs_iblkno; /* offset of inode-blocks in filesys */
341 __u32 fs_dblkno; /* offset of first data after cg */
342 __u32 fs_cgoffset; /* cylinder group offset in cylinder */
343 __u32 fs_cgmask; /* used to calc mod fs_ntrak */
344 __u32 fs_time; /* last time written -- time_t */
345 __u32 fs_size; /* number of blocks in fs */
346 __u32 fs_dsize; /* number of data blocks in fs */
347 __u32 fs_ncg; /* number of cylinder groups */
348 __u32 fs_bsize; /* size of basic blocks in fs */
349 __u32 fs_fsize; /* size of frag blocks in fs */
350 __u32 fs_frag; /* number of frags in a block in fs */
351 /* these are configuration parameters */
352 __u32 fs_minfree; /* minimum percentage of free blocks */
353 __u32 fs_rotdelay; /* num of ms for optimal next block */
354 __u32 fs_rps; /* disk revolutions per second */
355 /* these fields can be computed from the others */
356 __u32 fs_bmask; /* ``blkoff'' calc of blk offsets */
357 __u32 fs_fmask; /* ``fragoff'' calc of frag offsets */
358 __u32 fs_bshift; /* ``lblkno'' calc of logical blkno */
359 __u32 fs_fshift; /* ``numfrags'' calc number of frags */
360 /* these are configuration parameters */
361 __u32 fs_maxcontig; /* max number of contiguous blks */
362 __u32 fs_maxbpg; /* max number of blks per cyl group */
363 /* these fields can be computed from the others */
364 __u32 fs_fragshift; /* block to frag shift */
365 __u32 fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
366 __u32 fs_sbsize; /* actual size of super block */
367 __u32 fs_csmask; /* csum block offset */
368 __u32 fs_csshift; /* csum block number */
369 __u32 fs_nindir; /* value of NINDIR */
370 __u32 fs_inopb; /* value of INOPB */
371 __u32 fs_nspf; /* value of NSPF */
372 /* yet another configuration parameter */
373 __u32 fs_optim; /* optimization preference, see below */
374 /* these fields are derived from the hardware */
377 __u32 fs_npsect; /* # sectors/track including spares */
380 __s32 fs_state; /* file system state time stamp */
383 __u32 fs_interleave; /* hardware sector interleave */
384 __u32 fs_trackskew; /* sector 0 skew, per track */
385 /* a unique id for this filesystem (currently unused and unmaintained) */
386 /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
387 /* Neither of those fields is used in the Tahoe code right now but */
388 /* there could be problems if they are. */
389 __u32 fs_id[2]; /* file system id */
390 /* sizes determined by number of cylinder groups and their sizes */
391 __u32 fs_csaddr; /* blk addr of cyl grp summary area */
392 __u32 fs_cssize; /* size of cyl grp summary area */
393 __u32 fs_cgsize; /* cylinder group size */
394 /* these fields are derived from the hardware */
395 __u32 fs_ntrak; /* tracks per cylinder */
396 __u32 fs_nsect; /* sectors per track */
397 __u32 fs_spc; /* sectors per cylinder */
398 /* this comes from the disk driver partitioning */
399 __u32 fs_ncyl; /* cylinders in file system */
400 /* these fields can be computed from the others */
401 __u32 fs_cpg; /* cylinders per group */
402 __u32 fs_ipg; /* inodes per cylinder group */
403 __u32 fs_fpg; /* blocks per group * fs_frag */
404 /* this data must be re-computed after crashes */
405 struct ufs_csum fs_cstotal; /* cylinder summary information */
406 /* these fields are cleared at mount time */
407 __s8 fs_fmod; /* super block modified flag */
408 __s8 fs_clean; /* file system is clean flag */
409 __s8 fs_ronly; /* mounted read-only flag */
410 __s8 fs_flags; /* currently unused flag */
413 __s8 fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */
414 __u32 fs_cgrotor; /* last cg searched */
415 __u32 fs_csp[UFS_MAXCSBUFS];/*list of fs_cs info buffers */
417 __u32 fs_cpc; /* cyl per cycle in postbl */
418 __u16 fs_opostbl[16][8]; /* old rotation block list head */
421 __s8 fs_fsmnt[UFS2_MAXMNTLEN]; /* name mounted on */
422 __u8 fs_volname[UFS2_MAXVOLLEN]; /* volume name */
423 __u64 fs_swuid; /* system-wide uid */
424 __s32 fs_pad; /* due to alignment of fs_swuid */
425 __u32 fs_cgrotor; /* last cg searched */
426 __u32 fs_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info buffers */
427 __u32 fs_contigdirs;/*# of contiguously allocated dirs */
428 __u32 fs_csp; /* cg summary info buffer for fs_cs */
430 __u32 fs_active;/* used by snapshots to track fs */
431 __s32 fs_old_cpc; /* cyl per cycle in postbl */
432 __s32 fs_maxbsize;/*maximum blocking factor permitted */
433 __s64 fs_sparecon64[17];/*old rotation block list head */
434 __s64 fs_sblockloc; /* byte offset of standard superblock */
435 struct ufs2_csum_total fs_cstotal;/*cylinder summary information*/
436 struct ufs_timeval fs_time; /* last time written */
437 __s64 fs_size; /* number of blocks in fs */
438 __s64 fs_dsize; /* number of data blocks in fs */
439 __u64 fs_csaddr; /* blk addr of cyl grp summary area */
440 __s64 fs_pendingblocks;/* blocks in process of being freed */
441 __s32 fs_pendinginodes;/*inodes in process of being freed */
446 __s32 fs_sparecon[53];/* reserved for future constants */
448 __s32 fs_sparecon2[1];
449 __s32 fs_state; /* file system state time stamp */
450 __u32 fs_qbmask[2]; /* ~usb_bmask */
451 __u32 fs_qfmask[2]; /* ~usb_fmask */
454 __s32 fs_sparecon[53];/* reserved for future constants */
456 __s32 fs_sparecon2[1];
457 __u32 fs_npsect; /* # sectors/track including spares */
458 __u32 fs_qbmask[2]; /* ~usb_bmask */
459 __u32 fs_qfmask[2]; /* ~usb_fmask */
462 __s32 fs_sparecon[50];/* reserved for future constants */
463 __s32 fs_contigsumsize;/* size of cluster summary array */
464 __s32 fs_maxsymlinklen;/* max length of an internal symlink */
465 __s32 fs_inodefmt; /* format of on-disk inodes */
466 __u32 fs_maxfilesize[2]; /* max representable file size */
467 __u32 fs_qbmask[2]; /* ~usb_bmask */
468 __u32 fs_qfmask[2]; /* ~usb_fmask */
469 __s32 fs_state; /* file system state time stamp */
472 __s32 fs_postblformat; /* format of positional layout tables */
473 __s32 fs_nrpos; /* number of rotational positions */
474 __s32 fs_postbloff; /* (__s16) rotation block list head */
475 __s32 fs_rotbloff; /* (__u8) blocks for each rotation */
476 __s32 fs_magic; /* magic number */
477 __u8 fs_space[1]; /* list of blocks for each rotation */
481 * Preference for optimization.
483 #define UFS_OPTTIME 0 /* minimize allocation time */
484 #define UFS_OPTSPACE 1 /* minimize disk fragmentation */
487 * Rotational layout table format types
489 #define UFS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
490 #define UFS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
493 * Convert cylinder group to base address of its global summary info.
495 #define fs_cs(indx) \
496 s_csp[(indx) >> uspi->s_csshift][(indx) & ~uspi->s_csmask]
499 * Cylinder group block for a file system.
501 * Writable fields in the cylinder group are protected by the associated
502 * super block lock fs->fs_lock.
504 #define CG_MAGIC 0x090255
505 #define ufs_cg_chkmagic(sb, ucg) \
506 (fs32_to_cpu((sb), (ucg)->cg_magic) == CG_MAGIC)
509 * size of this structure is 172 B
511 struct ufs_cylinder_group {
512 __u32 cg_link; /* linked list of cyl groups */
513 __u32 cg_magic; /* magic number */
514 __u32 cg_time; /* time last written */
515 __u32 cg_cgx; /* we are the cgx'th cylinder group */
516 __u16 cg_ncyl; /* number of cyl's this cg */
517 __u16 cg_niblk; /* number of inode blocks this cg */
518 __u32 cg_ndblk; /* number of data blocks this cg */
519 struct ufs_csum cg_cs; /* cylinder summary information */
520 __u32 cg_rotor; /* position of last used block */
521 __u32 cg_frotor; /* position of last used frag */
522 __u32 cg_irotor; /* position of last used inode */
523 __u32 cg_frsum[UFS_MAXFRAG]; /* counts of available frags */
524 __u32 cg_btotoff; /* (__u32) block totals per cylinder */
525 __u32 cg_boff; /* (short) free block positions */
526 __u32 cg_iusedoff; /* (char) used inode map */
527 __u32 cg_freeoff; /* (u_char) free block map */
528 __u32 cg_nextfreeoff; /* (u_char) next available space */
531 __u32 cg_clustersumoff; /* (u_int32) counts of avail clusters */
532 __u32 cg_clusteroff; /* (u_int8) free cluster map */
533 __u32 cg_nclusterblks; /* number of clusters this cg */
534 __u32 cg_sparecon[13]; /* reserved for future use */
537 __u32 cg_clustersumoff;/* (u_int32) counts of avail clusters */
538 __u32 cg_clusteroff; /* (u_int8) free cluster map */
539 __u32 cg_nclusterblks;/* number of clusters this cg */
540 __u32 cg_niblk; /* number of inode blocks this cg */
541 __u32 cg_initediblk; /* last initialized inode */
542 __u32 cg_sparecon32[3];/* reserved for future use */
543 __u64 cg_time; /* time last written */
544 __u64 cg_sparecon[3]; /* reserved for future use */
546 __u32 cg_sparecon[16]; /* reserved for future use */
548 __u8 cg_space[1]; /* space for cylinder group maps */
549 /* actually longer */
553 * structure of an on-disk inode
556 __u16 ui_mode; /* 0x0 */
557 __u16 ui_nlink; /* 0x2 */
560 __u16 ui_suid; /* 0x4 */
561 __u16 ui_sgid; /* 0x6 */
563 __u32 ui_inumber; /* 0x4 lsf: inode number */
564 __u32 ui_author; /* 0x4 GNU HURD: author */
566 __u64 ui_size; /* 0x8 */
567 struct ufs_timeval ui_atime; /* 0x10 access */
568 struct ufs_timeval ui_mtime; /* 0x18 modification */
569 struct ufs_timeval ui_ctime; /* 0x20 creation */
572 __u32 ui_db[UFS_NDADDR];/* 0x28 data blocks */
573 __u32 ui_ib[UFS_NINDIR];/* 0x58 indirect blocks */
575 __u8 ui_symlink[4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
577 __u32 ui_flags; /* 0x64 immutable, append-only... */
578 __u32 ui_blocks; /* 0x68 blocks in use */
579 __u32 ui_gen; /* 0x6c like ext2 i_version, for NFS support */
582 __u32 ui_shadow; /* 0x70 shadow inode with security data */
583 __u32 ui_uid; /* 0x74 long EFT version of uid */
584 __u32 ui_gid; /* 0x78 long EFT version of gid */
585 __u32 ui_oeftflag; /* 0x7c reserved */
588 __u32 ui_uid; /* 0x70 File owner */
589 __u32 ui_gid; /* 0x74 File group */
590 __s32 ui_spare[2]; /* 0x78 reserved */
593 __u32 ui_uid; /* 0x70 */
594 __u32 ui_gid; /* 0x74 */
595 __u16 ui_modeh; /* 0x78 mode high bits */
596 __u16 ui_spare; /* 0x7A unused */
597 __u32 ui_trans; /* 0x7c filesystem translator */
602 #define UFS_NXADDR 2 /* External addresses in inode. */
604 __u16 ui_mode; /* 0: IFMT, permissions; see below. */
605 __s16 ui_nlink; /* 2: File link count. */
606 __u32 ui_uid; /* 4: File owner. */
607 __u32 ui_gid; /* 8: File group. */
608 __u32 ui_blksize; /* 12: Inode blocksize. */
609 __u64 ui_size; /* 16: File byte count. */
610 __u64 ui_blocks; /* 24: Bytes actually held. */
611 struct ufs_timeval ui_atime; /* 32: Last access time. */
612 struct ufs_timeval ui_mtime; /* 40: Last modified time. */
613 struct ufs_timeval ui_ctime; /* 48: Last inode change time. */
614 struct ufs_timeval ui_birthtime; /* 56: Inode creation time. */
615 __s32 ui_mtimensec; /* 64: Last modified time. */
616 __s32 ui_atimensec; /* 68: Last access time. */
617 __s32 ui_ctimensec; /* 72: Last inode change time. */
618 __s32 ui_birthnsec; /* 76: Inode creation time. */
619 __s32 ui_gen; /* 80: Generation number. */
620 __u32 ui_kernflags; /* 84: Kernel flags. */
621 __u32 ui_flags; /* 88: Status flags (chflags). */
622 __s32 ui_extsize; /* 92: External attributes block. */
623 __s64 ui_extb[UFS_NXADDR];/* 96: External attributes block. */
626 __s64 ui_db[UFS_NDADDR]; /* 112: Direct disk blocks. */
627 __s64 ui_ib[UFS_NINDIR];/* 208: Indirect disk blocks.*/
629 __u8 ui_symlink[2*4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
631 __s64 ui_spare[3]; /* 232: Reserved; currently unused */
635 /* FreeBSD has these in sys/stat.h */
636 /* ui_flags that can be set by a file owner */
637 #define UFS_UF_SETTABLE 0x0000ffff
638 #define UFS_UF_NODUMP 0x00000001 /* do not dump */
639 #define UFS_UF_IMMUTABLE 0x00000002 /* immutable (can't "change") */
640 #define UFS_UF_APPEND 0x00000004 /* append-only */
641 #define UFS_UF_OPAQUE 0x00000008 /* directory is opaque (unionfs) */
642 #define UFS_UF_NOUNLINK 0x00000010 /* can't be removed or renamed */
643 /* ui_flags that only root can set */
644 #define UFS_SF_SETTABLE 0xffff0000
645 #define UFS_SF_ARCHIVED 0x00010000 /* archived */
646 #define UFS_SF_IMMUTABLE 0x00020000 /* immutable (can't "change") */
647 #define UFS_SF_APPEND 0x00040000 /* append-only */
648 #define UFS_SF_NOUNLINK 0x00100000 /* can't be removed or renamed */
651 * This structure is used for reading disk structures larger
652 * than the size of fragment.
654 struct ufs_buffer_head {
655 __u64 fragment; /* first fragment */
656 __u64 count; /* number of fragments */
657 struct buffer_head * bh[UFS_MAXFRAG]; /* buffers */
660 struct ufs_cg_private_info {
661 struct ufs_cylinder_group ucg;
662 __u32 c_cgx; /* number of cylidner group */
663 __u16 c_ncyl; /* number of cyl's this cg */
664 __u16 c_niblk; /* number of inode blocks this cg */
665 __u32 c_ndblk; /* number of data blocks this cg */
666 __u32 c_rotor; /* position of last used block */
667 __u32 c_frotor; /* position of last used frag */
668 __u32 c_irotor; /* position of last used inode */
669 __u32 c_btotoff; /* (__u32) block totals per cylinder */
670 __u32 c_boff; /* (short) free block positions */
671 __u32 c_iusedoff; /* (char) used inode map */
672 __u32 c_freeoff; /* (u_char) free block map */
673 __u32 c_nextfreeoff; /* (u_char) next available space */
674 __u32 c_clustersumoff;/* (u_int32) counts of avail clusters */
675 __u32 c_clusteroff; /* (u_int8) free cluster map */
676 __u32 c_nclusterblks; /* number of clusters this cg */
679 struct ufs_sb_private_info {
680 struct ufs_buffer_head s_ubh; /* buffer containing super block */
681 __u32 s_sblkno; /* offset of super-blocks in filesys */
682 __u32 s_cblkno; /* offset of cg-block in filesys */
683 __u32 s_iblkno; /* offset of inode-blocks in filesys */
684 __u32 s_dblkno; /* offset of first data after cg */
685 __u32 s_cgoffset; /* cylinder group offset in cylinder */
686 __u32 s_cgmask; /* used to calc mod fs_ntrak */
687 __u32 s_size; /* number of blocks (fragments) in fs */
688 __u32 s_dsize; /* number of data blocks in fs */
689 __u64 s_u2_size; /* ufs2: number of blocks (fragments) in fs */
690 __u64 s_u2_dsize; /*ufs2: number of data blocks in fs */
691 __u32 s_ncg; /* number of cylinder groups */
692 __u32 s_bsize; /* size of basic blocks */
693 __u32 s_fsize; /* size of fragments */
694 __u32 s_fpb; /* fragments per block */
695 __u32 s_minfree; /* minimum percentage of free blocks */
696 __u32 s_bmask; /* `blkoff'' calc of blk offsets */
697 __u32 s_fmask; /* s_fsize mask */
698 __u32 s_bshift; /* `lblkno'' calc of logical blkno */
699 __u32 s_fshift; /* s_fsize shift */
700 __u32 s_fpbshift; /* fragments per block shift */
701 __u32 s_fsbtodb; /* fsbtodb and dbtofsb shift constant */
702 __u32 s_sbsize; /* actual size of super block */
703 __u32 s_csmask; /* csum block offset */
704 __u32 s_csshift; /* csum block number */
705 __u32 s_nindir; /* value of NINDIR */
706 __u32 s_inopb; /* value of INOPB */
707 __u32 s_nspf; /* value of NSPF */
708 __u32 s_npsect; /* # sectors/track including spares */
709 __u32 s_interleave; /* hardware sector interleave */
710 __u32 s_trackskew; /* sector 0 skew, per track */
711 __u32 s_csaddr; /* blk addr of cyl grp summary area */
712 __u32 s_cssize; /* size of cyl grp summary area */
713 __u32 s_cgsize; /* cylinder group size */
714 __u32 s_ntrak; /* tracks per cylinder */
715 __u32 s_nsect; /* sectors per track */
716 __u32 s_spc; /* sectors per cylinder */
717 __u32 s_ipg; /* inodes per cylinder group */
718 __u32 s_fpg; /* fragments per group */
719 __u32 s_cpc; /* cyl per cycle in postbl */
720 __s32 s_contigsumsize;/* size of cluster summary array, 44bsd */
721 __s64 s_qbmask; /* ~usb_bmask */
722 __s64 s_qfmask; /* ~usb_fmask */
723 __s32 s_postblformat; /* format of positional layout tables */
724 __s32 s_nrpos; /* number of rotational positions */
725 __s32 s_postbloff; /* (__s16) rotation block list head */
726 __s32 s_rotbloff; /* (__u8) blocks for each rotation */
728 __u32 s_fpbmask; /* fragments per block mask */
729 __u32 s_apb; /* address per block */
730 __u32 s_2apb; /* address per block^2 */
731 __u32 s_3apb; /* address per block^3 */
732 __u32 s_apbmask; /* address per block mask */
733 __u32 s_apbshift; /* address per block shift */
734 __u32 s_2apbshift; /* address per block shift * 2 */
735 __u32 s_3apbshift; /* address per block shift * 3 */
736 __u32 s_nspfshift; /* number of sector per fragment shift */
737 __u32 s_nspb; /* number of sector per block */
738 __u32 s_inopf; /* inodes per fragment */
739 __u32 s_sbbase; /* offset of NeXTstep superblock */
740 __u32 s_bpf; /* bits per fragment */
741 __u32 s_bpfshift; /* bits per fragment shift*/
742 __u32 s_bpfmask; /* bits per fragment mask */
744 __u32 s_maxsymlinklen;/* upper limit on fast symlinks' size */
745 __s32 fs_magic; /* filesystem magic */
749 * Sizes of this structures are:
750 * ufs_super_block_first 512
751 * ufs_super_block_second 512
752 * ufs_super_block_third 356
754 struct ufs_super_block_first {
809 struct ufs_csum fs_cstotal;
814 __s8 fs_fsmnt[UFS_MAXMNTLEN - 212];
818 struct ufs_super_block_second {
821 __u32 fs_csp[UFS_MAXCSBUFS];
824 __u16 fs_opostbl[82];
827 struct ufs_super_block_third {
828 __u16 fs_opostbl[46];
831 __s32 fs_sparecon[53];/* reserved for future constants */
833 __s32 fs_sparecon2[1];
834 __s32 fs_state; /* file system state time stamp */
835 __u32 fs_qbmask[2]; /* ~usb_bmask */
836 __u32 fs_qfmask[2]; /* ~usb_fmask */
839 __s32 fs_sparecon[53];/* reserved for future constants */
841 __s32 fs_sparecon2[1];
842 __u32 fs_npsect; /* # sectors/track including spares */
843 __u32 fs_qbmask[2]; /* ~usb_bmask */
844 __u32 fs_qfmask[2]; /* ~usb_fmask */
847 __s32 fs_sparecon[50];/* reserved for future constants */
848 __s32 fs_contigsumsize;/* size of cluster summary array */
849 __s32 fs_maxsymlinklen;/* max length of an internal symlink */
850 __s32 fs_inodefmt; /* format of on-disk inodes */
851 __u32 fs_maxfilesize[2]; /* max representable file size */
852 __u32 fs_qbmask[2]; /* ~usb_bmask */
853 __u32 fs_qfmask[2]; /* ~usb_fmask */
854 __s32 fs_state; /* file system state time stamp */
857 __s32 fs_postblformat;
868 extern void ufs_free_fragments (struct inode *, unsigned, unsigned);
869 extern void ufs_free_blocks (struct inode *, unsigned, unsigned);
870 extern unsigned ufs_new_fragments (struct inode *, u32 *, unsigned, unsigned, unsigned, int *);
873 extern struct ufs_cg_private_info * ufs_load_cylinder (struct super_block *, unsigned);
874 extern void ufs_put_cylinder (struct super_block *, unsigned);
877 extern struct inode_operations ufs_dir_inode_operations;
878 extern int ufs_check_dir_entry (const char *, struct inode *, struct ufs_dir_entry *, struct buffer_head *, unsigned long);
879 extern int ufs_add_link (struct dentry *, struct inode *);
880 extern ino_t ufs_inode_by_name(struct inode *, struct dentry *);
881 extern int ufs_make_empty(struct inode *, struct inode *);
882 extern struct ufs_dir_entry * ufs_find_entry (struct dentry *, struct buffer_head **);
883 extern int ufs_delete_entry (struct inode *, struct ufs_dir_entry *, struct buffer_head *);
884 extern int ufs_empty_dir (struct inode *);
885 extern struct ufs_dir_entry * ufs_dotdot (struct inode *, struct buffer_head **);
886 extern void ufs_set_link(struct inode *, struct ufs_dir_entry *, struct buffer_head *, struct inode *);
889 extern struct inode_operations ufs_file_inode_operations;
890 extern struct file_operations ufs_file_operations;
892 extern struct address_space_operations ufs_aops;
895 extern void ufs_free_inode (struct inode *inode);
896 extern struct inode * ufs_new_inode (struct inode *, int);
899 extern u64 ufs_frag_map (struct inode *, sector_t);
900 extern void ufs_read_inode (struct inode *);
901 extern void ufs_put_inode (struct inode *);
902 extern void ufs_write_inode (struct inode *, int);
903 extern int ufs_sync_inode (struct inode *);
904 extern void ufs_delete_inode (struct inode *);
905 extern struct buffer_head * ufs_getfrag (struct inode *, unsigned, int, int *);
906 extern struct buffer_head * ufs_bread (struct inode *, unsigned, int, int *);
909 extern struct file_operations ufs_dir_operations;
912 extern struct file_system_type ufs_fs_type;
913 extern void ufs_warning (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
914 extern void ufs_error (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
915 extern void ufs_panic (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
916 extern void ufs_write_super (struct super_block *);
919 extern struct inode_operations ufs_fast_symlink_inode_operations;
922 extern void ufs_truncate (struct inode *);
924 static inline struct ufs_sb_info *UFS_SB(struct super_block *sb)
926 return sb->s_fs_info;
929 static inline struct ufs_inode_info *UFS_I(struct inode *inode)
931 return container_of(inode, struct ufs_inode_info, vfs_inode);
934 #endif /* __KERNEL__ */
936 #endif /* __LINUX_UFS_FS_H */