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