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>
44 typedef __u64 __bitwise __fs64;
45 typedef __u32 __bitwise __fs32;
46 typedef __u16 __bitwise __fs16;
49 #include <linux/ufs_fs_i.h>
50 #include <linux/ufs_fs_sb.h>
53 #define UFS_BBSIZE 8192
54 #define UFS_SBLOCK 8192
55 #define UFS_SBSIZE 8192
57 #define UFS_SECTOR_SIZE 512
58 #define UFS_SECTOR_BITS 9
59 #define UFS_MAGIC 0x00011954
60 #define UFS2_MAGIC 0x19540119
61 #define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */
63 /* Copied from FreeBSD */
65 * Each disk drive contains some number of filesystems.
66 * A filesystem consists of a number of cylinder groups.
67 * Each cylinder group has inodes and data.
69 * A filesystem is described by its super-block, which in turn
70 * describes the cylinder groups. The super-block is critical
71 * data and is replicated in each cylinder group to protect against
72 * catastrophic loss. This is done at `newfs' time and the critical
73 * super-block data does not change, so the copies need not be
74 * referenced further unless disaster strikes.
76 * For filesystem fs, the offsets of the various blocks of interest
77 * are given in the super block as:
78 * [fs->fs_sblkno] Super-block
79 * [fs->fs_cblkno] Cylinder group block
80 * [fs->fs_iblkno] Inode blocks
81 * [fs->fs_dblkno] Data blocks
82 * The beginning of cylinder group cg in fs, is given by
83 * the ``cgbase(fs, cg)'' macro.
85 * Depending on the architecture and the media, the superblock may
86 * reside in any one of four places. For tiny media where every block
87 * counts, it is placed at the very front of the partition. Historically,
88 * UFS1 placed it 8K from the front to leave room for the disk label and
89 * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
90 * room for the disk label and a bigger bootstrap, and for really piggy
91 * systems we check at 256K from the front if the first three fail. In
92 * all cases the size of the superblock will be SBLOCKSIZE. All values are
93 * given in byte-offset form, so they do not imply a sector size. The
94 * SBLOCKSEARCH specifies the order in which the locations should be searched.
96 #define SBLOCK_FLOPPY 0
97 #define SBLOCK_UFS1 8192
98 #define SBLOCK_UFS2 65536
99 #define SBLOCK_PIGGY 262144
100 #define SBLOCKSIZE 8192
101 #define SBLOCKSEARCH \
102 { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
105 /* HP specific MAGIC values */
107 #define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
108 #define UFS_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */
110 #define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */
111 #define UFS_CIGAM_SEC 0x95216100
113 #define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
114 #define UFS_CIGAM_FEA 0x12561900
116 #define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
117 #define UFS_CIGAM_4GB 0x94192305
119 /* Seems somebody at HP goofed here. B1 and lfs are both 0x2 !?! */
120 #define UFS_FSF_LFN 0x00000001 /* long file names */
121 #define UFS_FSF_B1 0x00000002 /* B1 security */
122 #define UFS_FSF_LFS 0x00000002 /* large files */
123 #define UFS_FSF_LUID 0x00000004 /* large UIDs */
125 /* End of HP stuff */
128 #define UFS_BSIZE 8192
129 #define UFS_MINBSIZE 4096
130 #define UFS_FSIZE 1024
131 #define UFS_MAXFRAG (UFS_BSIZE / UFS_FSIZE)
133 #define UFS_NDADDR 12
136 #define UFS_IND_BLOCK (UFS_NDADDR + 0)
137 #define UFS_DIND_BLOCK (UFS_NDADDR + 1)
138 #define UFS_TIND_BLOCK (UFS_NDADDR + 2)
140 #define UFS_NDIR_FRAGMENT (UFS_NDADDR << uspi->s_fpbshift)
141 #define UFS_IND_FRAGMENT (UFS_IND_BLOCK << uspi->s_fpbshift)
142 #define UFS_DIND_FRAGMENT (UFS_DIND_BLOCK << uspi->s_fpbshift)
143 #define UFS_TIND_FRAGMENT (UFS_TIND_BLOCK << uspi->s_fpbshift)
145 #define UFS_ROOTINO 2
146 #define UFS_FIRST_INO (UFS_ROOTINO + 1)
148 #define UFS_USEEFT ((__u16)65535)
150 #define UFS_FSOK 0x7c269d38
151 #define UFS_FSACTIVE ((__s8)0x00)
152 #define UFS_FSCLEAN ((__s8)0x01)
153 #define UFS_FSSTABLE ((__s8)0x02)
154 #define UFS_FSOSF1 ((__s8)0x03) /* is this correct for DEC OSF/1? */
155 #define UFS_FSBAD ((__s8)0xff)
157 /* From here to next blank line, s_flags for ufs_sb_info */
158 /* directory entry encoding */
159 #define UFS_DE_MASK 0x00000010 /* mask for the following */
160 #define UFS_DE_OLD 0x00000000
161 #define UFS_DE_44BSD 0x00000010
163 #define UFS_UID_MASK 0x00000060 /* mask for the following */
164 #define UFS_UID_OLD 0x00000000
165 #define UFS_UID_44BSD 0x00000020
166 #define UFS_UID_EFT 0x00000040
167 /* superblock state encoding */
168 #define UFS_ST_MASK 0x00000700 /* mask for the following */
169 #define UFS_ST_OLD 0x00000000
170 #define UFS_ST_44BSD 0x00000100
171 #define UFS_ST_SUN 0x00000200
172 #define UFS_ST_SUNx86 0x00000400
173 /*cylinder group encoding */
174 #define UFS_CG_MASK 0x00003000 /* mask for the following */
175 #define UFS_CG_OLD 0x00000000
176 #define UFS_CG_44BSD 0x00002000
177 #define UFS_CG_SUN 0x00001000
178 /* filesystem type encoding */
179 #define UFS_TYPE_MASK 0x00010000 /* mask for the following */
180 #define UFS_TYPE_UFS1 0x00000000
181 #define UFS_TYPE_UFS2 0x00010000
184 /* fs_inodefmt options */
185 #define UFS_42INODEFMT -1
186 #define UFS_44INODEFMT 2
189 #define UFS_MOUNT_ONERROR 0x0000000F
190 #define UFS_MOUNT_ONERROR_PANIC 0x00000001
191 #define UFS_MOUNT_ONERROR_LOCK 0x00000002
192 #define UFS_MOUNT_ONERROR_UMOUNT 0x00000004
193 #define UFS_MOUNT_ONERROR_REPAIR 0x00000008
195 #define UFS_MOUNT_UFSTYPE 0x0000FFF0
196 #define UFS_MOUNT_UFSTYPE_OLD 0x00000010
197 #define UFS_MOUNT_UFSTYPE_44BSD 0x00000020
198 #define UFS_MOUNT_UFSTYPE_SUN 0x00000040
199 #define UFS_MOUNT_UFSTYPE_NEXTSTEP 0x00000080
200 #define UFS_MOUNT_UFSTYPE_NEXTSTEP_CD 0x00000100
201 #define UFS_MOUNT_UFSTYPE_OPENSTEP 0x00000200
202 #define UFS_MOUNT_UFSTYPE_SUNx86 0x00000400
203 #define UFS_MOUNT_UFSTYPE_HP 0x00000800
204 #define UFS_MOUNT_UFSTYPE_UFS2 0x00001000
206 #define ufs_clear_opt(o,opt) o &= ~UFS_MOUNT_##opt
207 #define ufs_set_opt(o,opt) o |= UFS_MOUNT_##opt
208 #define ufs_test_opt(o,opt) ((o) & UFS_MOUNT_##opt)
211 * MINFREE gives the minimum acceptable percentage of file system
212 * blocks which may be free. If the freelist drops below this level
213 * only the superuser may continue to allocate blocks. This may
214 * be set to 0 if no reserve of free blocks is deemed necessary,
215 * however throughput drops by fifty percent if the file system
216 * is run at between 95% and 100% full; thus the minimum default
217 * value of fs_minfree is 5%. However, to get good clustering
218 * performance, 10% is a better choice. hence we use 10% as our
219 * default value. With 10% free space, fragmentation is not a
220 * problem, so we choose to optimize for time.
222 #define UFS_MINFREE 5
223 #define UFS_DEFAULTOPT UFS_OPTTIME
226 * Turn file system block numbers into disk block addresses.
227 * This maps file system blocks to device size blocks.
229 #define ufs_fsbtodb(uspi, b) ((b) << (uspi)->s_fsbtodb)
230 #define ufs_dbtofsb(uspi, b) ((b) >> (uspi)->s_fsbtodb)
233 * Cylinder group macros to locate things in cylinder groups.
234 * They calc file system addresses of cylinder group data structures.
236 #define ufs_cgbase(c) (uspi->s_fpg * (c))
237 #define ufs_cgstart(c) ((uspi)->fs_magic == UFS2_MAGIC ? ufs_cgbase(c) : \
238 (ufs_cgbase(c) + uspi->s_cgoffset * ((c) & ~uspi->s_cgmask)))
239 #define ufs_cgsblock(c) (ufs_cgstart(c) + uspi->s_sblkno) /* super blk */
240 #define ufs_cgcmin(c) (ufs_cgstart(c) + uspi->s_cblkno) /* cg block */
241 #define ufs_cgimin(c) (ufs_cgstart(c) + uspi->s_iblkno) /* inode blk */
242 #define ufs_cgdmin(c) (ufs_cgstart(c) + uspi->s_dblkno) /* 1st data */
245 * Macros for handling inode numbers:
246 * inode number to file system block offset.
247 * inode number to cylinder group number.
248 * inode number to file system block address.
250 #define ufs_inotocg(x) ((x) / uspi->s_ipg)
251 #define ufs_inotocgoff(x) ((x) % uspi->s_ipg)
252 #define ufs_inotofsba(x) (ufs_cgimin(ufs_inotocg(x)) + ufs_inotocgoff(x) / uspi->s_inopf)
253 #define ufs_inotofsbo(x) ((x) % uspi->s_inopf)
256 * Give cylinder group number for a file system block.
257 * Give cylinder group block number for a file system block.
259 #define ufs_dtog(d) ((d) / uspi->s_fpg)
260 #define ufs_dtogd(d) ((d) % uspi->s_fpg)
263 * Compute the cylinder and rotational position of a cyl block addr.
265 #define ufs_cbtocylno(bno) \
266 ((bno) * uspi->s_nspf / uspi->s_spc)
267 #define ufs_cbtorpos(bno) \
268 ((((bno) * uspi->s_nspf % uspi->s_spc / uspi->s_nsect \
269 * uspi->s_trackskew + (bno) * uspi->s_nspf % uspi->s_spc \
270 % uspi->s_nsect * uspi->s_interleave) % uspi->s_nsect \
271 * uspi->s_nrpos) / uspi->s_npsect)
274 * The following macros optimize certain frequently calculated
275 * quantities by using shifts and masks in place of divisions
276 * modulos and multiplications.
278 #define ufs_blkoff(loc) ((loc) & uspi->s_qbmask)
279 #define ufs_fragoff(loc) ((loc) & uspi->s_qfmask)
280 #define ufs_lblktosize(blk) ((blk) << uspi->s_bshift)
281 #define ufs_lblkno(loc) ((loc) >> uspi->s_bshift)
282 #define ufs_numfrags(loc) ((loc) >> uspi->s_fshift)
283 #define ufs_blkroundup(size) (((size) + uspi->s_qbmask) & uspi->s_bmask)
284 #define ufs_fragroundup(size) (((size) + uspi->s_qfmask) & uspi->s_fmask)
285 #define ufs_fragstoblks(frags) ((frags) >> uspi->s_fpbshift)
286 #define ufs_blkstofrags(blks) ((blks) << uspi->s_fpbshift)
287 #define ufs_fragnum(fsb) ((fsb) & uspi->s_fpbmask)
288 #define ufs_blknum(fsb) ((fsb) & ~uspi->s_fpbmask)
290 #define UFS_MAXNAMLEN 255
291 #define UFS_MAXMNTLEN 512
292 #define UFS2_MAXMNTLEN 468
293 #define UFS2_MAXVOLLEN 32
294 /* #define UFS_MAXCSBUFS 31 */
295 #define UFS_LINK_MAX 32000
297 #define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4)
299 #define UFS2_NOCSPTRS 28
302 * UFS_DIR_PAD defines the directory entries boundaries
303 * (must be a multiple of 4)
305 #define UFS_DIR_PAD 4
306 #define UFS_DIR_ROUND (UFS_DIR_PAD - 1)
307 #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND)
314 struct ufs_dir_entry {
315 __fs32 d_ino; /* inode number of this entry */
316 __fs16 d_reclen; /* length of this entry */
318 __fs16 d_namlen; /* actual length of d_name */
320 __u8 d_type; /* file type */
321 __u8 d_namlen; /* length of string in d_name */
324 __u8 d_name[UFS_MAXNAMLEN + 1]; /* file name */
328 __fs32 cs_ndir; /* number of directories */
329 __fs32 cs_nbfree; /* number of free blocks */
330 __fs32 cs_nifree; /* number of free inodes */
331 __fs32 cs_nffree; /* number of free frags */
333 struct ufs2_csum_total {
334 __fs64 cs_ndir; /* number of directories */
335 __fs64 cs_nbfree; /* number of free blocks */
336 __fs64 cs_nifree; /* number of free inodes */
337 __fs64 cs_nffree; /* number of free frags */
338 __fs64 cs_numclusters; /* number of free clusters */
339 __fs64 cs_spare[3]; /* future expansion */
343 * This is the actual superblock, as it is laid out on the disk.
345 struct ufs_super_block {
346 __fs32 fs_link; /* UNUSED */
347 __fs32 fs_rlink; /* UNUSED */
348 __fs32 fs_sblkno; /* addr of super-block in filesys */
349 __fs32 fs_cblkno; /* offset of cyl-block in filesys */
350 __fs32 fs_iblkno; /* offset of inode-blocks in filesys */
351 __fs32 fs_dblkno; /* offset of first data after cg */
352 __fs32 fs_cgoffset; /* cylinder group offset in cylinder */
353 __fs32 fs_cgmask; /* used to calc mod fs_ntrak */
354 __fs32 fs_time; /* last time written -- time_t */
355 __fs32 fs_size; /* number of blocks in fs */
356 __fs32 fs_dsize; /* number of data blocks in fs */
357 __fs32 fs_ncg; /* number of cylinder groups */
358 __fs32 fs_bsize; /* size of basic blocks in fs */
359 __fs32 fs_fsize; /* size of frag blocks in fs */
360 __fs32 fs_frag; /* number of frags in a block in fs */
361 /* these are configuration parameters */
362 __fs32 fs_minfree; /* minimum percentage of free blocks */
363 __fs32 fs_rotdelay; /* num of ms for optimal next block */
364 __fs32 fs_rps; /* disk revolutions per second */
365 /* these fields can be computed from the others */
366 __fs32 fs_bmask; /* ``blkoff'' calc of blk offsets */
367 __fs32 fs_fmask; /* ``fragoff'' calc of frag offsets */
368 __fs32 fs_bshift; /* ``lblkno'' calc of logical blkno */
369 __fs32 fs_fshift; /* ``numfrags'' calc number of frags */
370 /* these are configuration parameters */
371 __fs32 fs_maxcontig; /* max number of contiguous blks */
372 __fs32 fs_maxbpg; /* max number of blks per cyl group */
373 /* these fields can be computed from the others */
374 __fs32 fs_fragshift; /* block to frag shift */
375 __fs32 fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
376 __fs32 fs_sbsize; /* actual size of super block */
377 __fs32 fs_csmask; /* csum block offset */
378 __fs32 fs_csshift; /* csum block number */
379 __fs32 fs_nindir; /* value of NINDIR */
380 __fs32 fs_inopb; /* value of INOPB */
381 __fs32 fs_nspf; /* value of NSPF */
382 /* yet another configuration parameter */
383 __fs32 fs_optim; /* optimization preference, see below */
384 /* these fields are derived from the hardware */
387 __fs32 fs_npsect; /* # sectors/track including spares */
390 __fs32 fs_state; /* file system state time stamp */
393 __fs32 fs_interleave; /* hardware sector interleave */
394 __fs32 fs_trackskew; /* sector 0 skew, per track */
395 /* a unique id for this filesystem (currently unused and unmaintained) */
396 /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
397 /* Neither of those fields is used in the Tahoe code right now but */
398 /* there could be problems if they are. */
399 __fs32 fs_id[2]; /* file system id */
400 /* sizes determined by number of cylinder groups and their sizes */
401 __fs32 fs_csaddr; /* blk addr of cyl grp summary area */
402 __fs32 fs_cssize; /* size of cyl grp summary area */
403 __fs32 fs_cgsize; /* cylinder group size */
404 /* these fields are derived from the hardware */
405 __fs32 fs_ntrak; /* tracks per cylinder */
406 __fs32 fs_nsect; /* sectors per track */
407 __fs32 fs_spc; /* sectors per cylinder */
408 /* this comes from the disk driver partitioning */
409 __fs32 fs_ncyl; /* cylinders in file system */
410 /* these fields can be computed from the others */
411 __fs32 fs_cpg; /* cylinders per group */
412 __fs32 fs_ipg; /* inodes per cylinder group */
413 __fs32 fs_fpg; /* blocks per group * fs_frag */
414 /* this data must be re-computed after crashes */
415 struct ufs_csum fs_cstotal; /* cylinder summary information */
416 /* these fields are cleared at mount time */
417 __s8 fs_fmod; /* super block modified flag */
418 __s8 fs_clean; /* file system is clean flag */
419 __s8 fs_ronly; /* mounted read-only flag */
420 __s8 fs_flags; /* currently unused flag */
423 __s8 fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */
424 __fs32 fs_cgrotor; /* last cg searched */
425 __fs32 fs_csp[UFS_MAXCSBUFS];/*list of fs_cs info buffers */
426 __fs32 fs_maxcluster;
427 __fs32 fs_cpc; /* cyl per cycle in postbl */
428 __fs16 fs_opostbl[16][8]; /* old rotation block list head */
431 __s8 fs_fsmnt[UFS2_MAXMNTLEN]; /* name mounted on */
432 __u8 fs_volname[UFS2_MAXVOLLEN]; /* volume name */
433 __fs64 fs_swuid; /* system-wide uid */
434 __fs32 fs_pad; /* due to alignment of fs_swuid */
435 __fs32 fs_cgrotor; /* last cg searched */
436 __fs32 fs_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info buffers */
437 __fs32 fs_contigdirs;/*# of contiguously allocated dirs */
438 __fs32 fs_csp; /* cg summary info buffer for fs_cs */
439 __fs32 fs_maxcluster;
440 __fs32 fs_active;/* used by snapshots to track fs */
441 __fs32 fs_old_cpc; /* cyl per cycle in postbl */
442 __fs32 fs_maxbsize;/*maximum blocking factor permitted */
443 __fs64 fs_sparecon64[17];/*old rotation block list head */
444 __fs64 fs_sblockloc; /* byte offset of standard superblock */
445 struct ufs2_csum_total fs_cstotal;/*cylinder summary information*/
446 struct ufs_timeval fs_time; /* last time written */
447 __fs64 fs_size; /* number of blocks in fs */
448 __fs64 fs_dsize; /* number of data blocks in fs */
449 __fs64 fs_csaddr; /* blk addr of cyl grp summary area */
450 __fs64 fs_pendingblocks;/* blocks in process of being freed */
451 __fs32 fs_pendinginodes;/*inodes in process of being freed */
456 __fs32 fs_sparecon[53];/* reserved for future constants */
458 __fs32 fs_sparecon2[1];
459 __fs32 fs_state; /* file system state time stamp */
460 __fs32 fs_qbmask[2]; /* ~usb_bmask */
461 __fs32 fs_qfmask[2]; /* ~usb_fmask */
464 __fs32 fs_sparecon[53];/* reserved for future constants */
466 __fs32 fs_sparecon2[1];
467 __fs32 fs_npsect; /* # sectors/track including spares */
468 __fs32 fs_qbmask[2]; /* ~usb_bmask */
469 __fs32 fs_qfmask[2]; /* ~usb_fmask */
472 __fs32 fs_sparecon[50];/* reserved for future constants */
473 __fs32 fs_contigsumsize;/* size of cluster summary array */
474 __fs32 fs_maxsymlinklen;/* max length of an internal symlink */
475 __fs32 fs_inodefmt; /* format of on-disk inodes */
476 __fs32 fs_maxfilesize[2]; /* max representable file size */
477 __fs32 fs_qbmask[2]; /* ~usb_bmask */
478 __fs32 fs_qfmask[2]; /* ~usb_fmask */
479 __fs32 fs_state; /* file system state time stamp */
482 __fs32 fs_postblformat; /* format of positional layout tables */
483 __fs32 fs_nrpos; /* number of rotational positions */
484 __fs32 fs_postbloff; /* (__s16) rotation block list head */
485 __fs32 fs_rotbloff; /* (__u8) blocks for each rotation */
486 __fs32 fs_magic; /* magic number */
487 __u8 fs_space[1]; /* list of blocks for each rotation */
491 * Preference for optimization.
493 #define UFS_OPTTIME 0 /* minimize allocation time */
494 #define UFS_OPTSPACE 1 /* minimize disk fragmentation */
497 * Rotational layout table format types
499 #define UFS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
500 #define UFS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
503 * Convert cylinder group to base address of its global summary info.
505 #define fs_cs(indx) s_csp[(indx)]
508 * Cylinder group block for a file system.
510 * Writable fields in the cylinder group are protected by the associated
511 * super block lock fs->fs_lock.
513 #define CG_MAGIC 0x090255
514 #define ufs_cg_chkmagic(sb, ucg) \
515 (fs32_to_cpu((sb), (ucg)->cg_magic) == CG_MAGIC)
518 * size of this structure is 172 B
520 struct ufs_cylinder_group {
521 __fs32 cg_link; /* linked list of cyl groups */
522 __fs32 cg_magic; /* magic number */
523 __fs32 cg_time; /* time last written */
524 __fs32 cg_cgx; /* we are the cgx'th cylinder group */
525 __fs16 cg_ncyl; /* number of cyl's this cg */
526 __fs16 cg_niblk; /* number of inode blocks this cg */
527 __fs32 cg_ndblk; /* number of data blocks this cg */
528 struct ufs_csum cg_cs; /* cylinder summary information */
529 __fs32 cg_rotor; /* position of last used block */
530 __fs32 cg_frotor; /* position of last used frag */
531 __fs32 cg_irotor; /* position of last used inode */
532 __fs32 cg_frsum[UFS_MAXFRAG]; /* counts of available frags */
533 __fs32 cg_btotoff; /* (__u32) block totals per cylinder */
534 __fs32 cg_boff; /* (short) free block positions */
535 __fs32 cg_iusedoff; /* (char) used inode map */
536 __fs32 cg_freeoff; /* (u_char) free block map */
537 __fs32 cg_nextfreeoff; /* (u_char) next available space */
540 __fs32 cg_clustersumoff; /* (u_int32) counts of avail clusters */
541 __fs32 cg_clusteroff; /* (u_int8) free cluster map */
542 __fs32 cg_nclusterblks; /* number of clusters this cg */
543 __fs32 cg_sparecon[13]; /* reserved for future use */
546 __fs32 cg_clustersumoff;/* (u_int32) counts of avail clusters */
547 __fs32 cg_clusteroff; /* (u_int8) free cluster map */
548 __fs32 cg_nclusterblks;/* number of clusters this cg */
549 __fs32 cg_niblk; /* number of inode blocks this cg */
550 __fs32 cg_initediblk; /* last initialized inode */
551 __fs32 cg_sparecon32[3];/* reserved for future use */
552 __fs64 cg_time; /* time last written */
553 __fs64 cg_sparecon[3]; /* reserved for future use */
555 __fs32 cg_sparecon[16]; /* reserved for future use */
557 __u8 cg_space[1]; /* space for cylinder group maps */
558 /* actually longer */
562 * structure of an on-disk inode
565 __fs16 ui_mode; /* 0x0 */
566 __fs16 ui_nlink; /* 0x2 */
569 __fs16 ui_suid; /* 0x4 */
570 __fs16 ui_sgid; /* 0x6 */
572 __fs32 ui_inumber; /* 0x4 lsf: inode number */
573 __fs32 ui_author; /* 0x4 GNU HURD: author */
575 __fs64 ui_size; /* 0x8 */
576 struct ufs_timeval ui_atime; /* 0x10 access */
577 struct ufs_timeval ui_mtime; /* 0x18 modification */
578 struct ufs_timeval ui_ctime; /* 0x20 creation */
581 __fs32 ui_db[UFS_NDADDR];/* 0x28 data blocks */
582 __fs32 ui_ib[UFS_NINDIR];/* 0x58 indirect blocks */
584 __u8 ui_symlink[4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
586 __fs32 ui_flags; /* 0x64 immutable, append-only... */
587 __fs32 ui_blocks; /* 0x68 blocks in use */
588 __fs32 ui_gen; /* 0x6c like ext2 i_version, for NFS support */
591 __fs32 ui_shadow; /* 0x70 shadow inode with security data */
592 __fs32 ui_uid; /* 0x74 long EFT version of uid */
593 __fs32 ui_gid; /* 0x78 long EFT version of gid */
594 __fs32 ui_oeftflag; /* 0x7c reserved */
597 __fs32 ui_uid; /* 0x70 File owner */
598 __fs32 ui_gid; /* 0x74 File group */
599 __fs32 ui_spare[2]; /* 0x78 reserved */
602 __fs32 ui_uid; /* 0x70 */
603 __fs32 ui_gid; /* 0x74 */
604 __fs16 ui_modeh; /* 0x78 mode high bits */
605 __fs16 ui_spare; /* 0x7A unused */
606 __fs32 ui_trans; /* 0x7c filesystem translator */
611 #define UFS_NXADDR 2 /* External addresses in inode. */
613 __fs16 ui_mode; /* 0: IFMT, permissions; see below. */
614 __fs16 ui_nlink; /* 2: File link count. */
615 __fs32 ui_uid; /* 4: File owner. */
616 __fs32 ui_gid; /* 8: File group. */
617 __fs32 ui_blksize; /* 12: Inode blocksize. */
618 __fs64 ui_size; /* 16: File byte count. */
619 __fs64 ui_blocks; /* 24: Bytes actually held. */
620 struct ufs_timeval ui_atime; /* 32: Last access time. */
621 struct ufs_timeval ui_mtime; /* 40: Last modified time. */
622 struct ufs_timeval ui_ctime; /* 48: Last inode change time. */
623 struct ufs_timeval ui_birthtime; /* 56: Inode creation time. */
624 __fs32 ui_mtimensec; /* 64: Last modified time. */
625 __fs32 ui_atimensec; /* 68: Last access time. */
626 __fs32 ui_ctimensec; /* 72: Last inode change time. */
627 __fs32 ui_birthnsec; /* 76: Inode creation time. */
628 __fs32 ui_gen; /* 80: Generation number. */
629 __fs32 ui_kernflags; /* 84: Kernel flags. */
630 __fs32 ui_flags; /* 88: Status flags (chflags). */
631 __fs32 ui_extsize; /* 92: External attributes block. */
632 __fs64 ui_extb[UFS_NXADDR];/* 96: External attributes block. */
635 __fs64 ui_db[UFS_NDADDR]; /* 112: Direct disk blocks. */
636 __fs64 ui_ib[UFS_NINDIR];/* 208: Indirect disk blocks.*/
638 __u8 ui_symlink[2*4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
640 __fs64 ui_spare[3]; /* 232: Reserved; currently unused */
644 /* FreeBSD has these in sys/stat.h */
645 /* ui_flags that can be set by a file owner */
646 #define UFS_UF_SETTABLE 0x0000ffff
647 #define UFS_UF_NODUMP 0x00000001 /* do not dump */
648 #define UFS_UF_IMMUTABLE 0x00000002 /* immutable (can't "change") */
649 #define UFS_UF_APPEND 0x00000004 /* append-only */
650 #define UFS_UF_OPAQUE 0x00000008 /* directory is opaque (unionfs) */
651 #define UFS_UF_NOUNLINK 0x00000010 /* can't be removed or renamed */
652 /* ui_flags that only root can set */
653 #define UFS_SF_SETTABLE 0xffff0000
654 #define UFS_SF_ARCHIVED 0x00010000 /* archived */
655 #define UFS_SF_IMMUTABLE 0x00020000 /* immutable (can't "change") */
656 #define UFS_SF_APPEND 0x00040000 /* append-only */
657 #define UFS_SF_NOUNLINK 0x00100000 /* can't be removed or renamed */
660 * This structure is used for reading disk structures larger
661 * than the size of fragment.
663 struct ufs_buffer_head {
664 __u64 fragment; /* first fragment */
665 __u64 count; /* number of fragments */
666 struct buffer_head * bh[UFS_MAXFRAG]; /* buffers */
669 struct ufs_cg_private_info {
670 struct ufs_cylinder_group ucg;
671 __u32 c_cgx; /* number of cylidner group */
672 __u16 c_ncyl; /* number of cyl's this cg */
673 __u16 c_niblk; /* number of inode blocks this cg */
674 __u32 c_ndblk; /* number of data blocks this cg */
675 __u32 c_rotor; /* position of last used block */
676 __u32 c_frotor; /* position of last used frag */
677 __u32 c_irotor; /* position of last used inode */
678 __u32 c_btotoff; /* (__u32) block totals per cylinder */
679 __u32 c_boff; /* (short) free block positions */
680 __u32 c_iusedoff; /* (char) used inode map */
681 __u32 c_freeoff; /* (u_char) free block map */
682 __u32 c_nextfreeoff; /* (u_char) next available space */
683 __u32 c_clustersumoff;/* (u_int32) counts of avail clusters */
684 __u32 c_clusteroff; /* (u_int8) free cluster map */
685 __u32 c_nclusterblks; /* number of clusters this cg */
688 struct ufs_sb_private_info {
689 struct ufs_buffer_head s_ubh; /* buffer containing super block */
690 __u32 s_sblkno; /* offset of super-blocks in filesys */
691 __u32 s_cblkno; /* offset of cg-block in filesys */
692 __u32 s_iblkno; /* offset of inode-blocks in filesys */
693 __u32 s_dblkno; /* offset of first data after cg */
694 __u32 s_cgoffset; /* cylinder group offset in cylinder */
695 __u32 s_cgmask; /* used to calc mod fs_ntrak */
696 __u32 s_size; /* number of blocks (fragments) in fs */
697 __u32 s_dsize; /* number of data blocks in fs */
698 __u64 s_u2_size; /* ufs2: number of blocks (fragments) in fs */
699 __u64 s_u2_dsize; /*ufs2: number of data blocks in fs */
700 __u32 s_ncg; /* number of cylinder groups */
701 __u32 s_bsize; /* size of basic blocks */
702 __u32 s_fsize; /* size of fragments */
703 __u32 s_fpb; /* fragments per block */
704 __u32 s_minfree; /* minimum percentage of free blocks */
705 __u32 s_bmask; /* `blkoff'' calc of blk offsets */
706 __u32 s_fmask; /* s_fsize mask */
707 __u32 s_bshift; /* `lblkno'' calc of logical blkno */
708 __u32 s_fshift; /* s_fsize shift */
709 __u32 s_fpbshift; /* fragments per block shift */
710 __u32 s_fsbtodb; /* fsbtodb and dbtofsb shift constant */
711 __u32 s_sbsize; /* actual size of super block */
712 __u32 s_csmask; /* csum block offset */
713 __u32 s_csshift; /* csum block number */
714 __u32 s_nindir; /* value of NINDIR */
715 __u32 s_inopb; /* value of INOPB */
716 __u32 s_nspf; /* value of NSPF */
717 __u32 s_npsect; /* # sectors/track including spares */
718 __u32 s_interleave; /* hardware sector interleave */
719 __u32 s_trackskew; /* sector 0 skew, per track */
720 __u32 s_csaddr; /* blk addr of cyl grp summary area */
721 __u32 s_cssize; /* size of cyl grp summary area */
722 __u32 s_cgsize; /* cylinder group size */
723 __u32 s_ntrak; /* tracks per cylinder */
724 __u32 s_nsect; /* sectors per track */
725 __u32 s_spc; /* sectors per cylinder */
726 __u32 s_ipg; /* inodes per cylinder group */
727 __u32 s_fpg; /* fragments per group */
728 __u32 s_cpc; /* cyl per cycle in postbl */
729 __s32 s_contigsumsize;/* size of cluster summary array, 44bsd */
730 __s64 s_qbmask; /* ~usb_bmask */
731 __s64 s_qfmask; /* ~usb_fmask */
732 __s32 s_postblformat; /* format of positional layout tables */
733 __s32 s_nrpos; /* number of rotational positions */
734 __s32 s_postbloff; /* (__s16) rotation block list head */
735 __s32 s_rotbloff; /* (__u8) blocks for each rotation */
737 __u32 s_fpbmask; /* fragments per block mask */
738 __u32 s_apb; /* address per block */
739 __u32 s_2apb; /* address per block^2 */
740 __u32 s_3apb; /* address per block^3 */
741 __u32 s_apbmask; /* address per block mask */
742 __u32 s_apbshift; /* address per block shift */
743 __u32 s_2apbshift; /* address per block shift * 2 */
744 __u32 s_3apbshift; /* address per block shift * 3 */
745 __u32 s_nspfshift; /* number of sector per fragment shift */
746 __u32 s_nspb; /* number of sector per block */
747 __u32 s_inopf; /* inodes per fragment */
748 __u32 s_sbbase; /* offset of NeXTstep superblock */
749 __u32 s_bpf; /* bits per fragment */
750 __u32 s_bpfshift; /* bits per fragment shift*/
751 __u32 s_bpfmask; /* bits per fragment mask */
753 __u32 s_maxsymlinklen;/* upper limit on fast symlinks' size */
754 __s32 fs_magic; /* filesystem magic */
758 * Sizes of this structures are:
759 * ufs_super_block_first 512
760 * ufs_super_block_second 512
761 * ufs_super_block_third 356
763 struct ufs_super_block_first {
805 __fs32 fs_interleave;
818 struct ufs_csum fs_cstotal;
823 __s8 fs_fsmnt[UFS_MAXMNTLEN - 212];
827 struct ufs_super_block_second {
830 __fs32 fs_csp[UFS_MAXCSBUFS];
831 __fs32 fs_maxcluster;
833 __fs16 fs_opostbl[82];
836 struct ufs_super_block_third {
837 __fs16 fs_opostbl[46];
840 __fs32 fs_sparecon[53];/* reserved for future constants */
842 __fs32 fs_sparecon2[1];
843 __fs32 fs_state; /* file system state time stamp */
844 __fs32 fs_qbmask[2]; /* ~usb_bmask */
845 __fs32 fs_qfmask[2]; /* ~usb_fmask */
848 __fs32 fs_sparecon[53];/* reserved for future constants */
850 __fs32 fs_sparecon2[1];
851 __fs32 fs_npsect; /* # sectors/track including spares */
852 __fs32 fs_qbmask[2]; /* ~usb_bmask */
853 __fs32 fs_qfmask[2]; /* ~usb_fmask */
856 __fs32 fs_sparecon[50];/* reserved for future constants */
857 __fs32 fs_contigsumsize;/* size of cluster summary array */
858 __fs32 fs_maxsymlinklen;/* max length of an internal symlink */
859 __fs32 fs_inodefmt; /* format of on-disk inodes */
860 __fs32 fs_maxfilesize[2]; /* max representable file size */
861 __fs32 fs_qbmask[2]; /* ~usb_bmask */
862 __fs32 fs_qfmask[2]; /* ~usb_fmask */
863 __fs32 fs_state; /* file system state time stamp */
866 __fs32 fs_postblformat;
877 extern void ufs_free_fragments (struct inode *, unsigned, unsigned);
878 extern void ufs_free_blocks (struct inode *, unsigned, unsigned);
879 extern unsigned ufs_new_fragments (struct inode *, __fs32 *, unsigned, unsigned, unsigned, int *);
882 extern struct ufs_cg_private_info * ufs_load_cylinder (struct super_block *, unsigned);
883 extern void ufs_put_cylinder (struct super_block *, unsigned);
886 extern struct inode_operations ufs_dir_inode_operations;
887 extern int ufs_add_link (struct dentry *, struct inode *);
888 extern ino_t ufs_inode_by_name(struct inode *, struct dentry *);
889 extern int ufs_make_empty(struct inode *, struct inode *);
890 extern struct ufs_dir_entry * ufs_find_entry (struct dentry *, struct buffer_head **);
891 extern int ufs_delete_entry (struct inode *, struct ufs_dir_entry *, struct buffer_head *);
892 extern int ufs_empty_dir (struct inode *);
893 extern struct ufs_dir_entry * ufs_dotdot (struct inode *, struct buffer_head **);
894 extern void ufs_set_link(struct inode *, struct ufs_dir_entry *, struct buffer_head *, struct inode *);
897 extern struct inode_operations ufs_file_inode_operations;
898 extern const struct file_operations ufs_file_operations;
900 extern struct address_space_operations ufs_aops;
903 extern void ufs_free_inode (struct inode *inode);
904 extern struct inode * ufs_new_inode (struct inode *, int);
907 extern u64 ufs_frag_map (struct inode *, sector_t);
908 extern void ufs_read_inode (struct inode *);
909 extern void ufs_put_inode (struct inode *);
910 extern int ufs_write_inode (struct inode *, int);
911 extern int ufs_sync_inode (struct inode *);
912 extern void ufs_delete_inode (struct inode *);
913 extern struct buffer_head * ufs_getfrag (struct inode *, unsigned, int, int *);
914 extern struct buffer_head * ufs_bread (struct inode *, unsigned, int, int *);
915 extern int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create);
918 extern const struct file_operations ufs_dir_operations;
921 extern void ufs_warning (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
922 extern void ufs_error (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
923 extern void ufs_panic (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
926 extern struct inode_operations ufs_fast_symlink_inode_operations;
929 extern void ufs_truncate (struct inode *);
931 static inline struct ufs_sb_info *UFS_SB(struct super_block *sb)
933 return sb->s_fs_info;
936 static inline struct ufs_inode_info *UFS_I(struct inode *inode)
938 return container_of(inode, struct ufs_inode_info, vfs_inode);
941 #endif /* __KERNEL__ */
943 #endif /* __LINUX_UFS_FS_H */