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