[PATCH] EDAC config cleanup
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / include / linux / ufs_fs.h
CommitLineData
1da177e4
LT
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/time.h>
36#include <linux/stat.h>
37#include <linux/fs.h>
38
39#ifndef __KERNEL__
40typedef __u64 __fs64;
41typedef __u32 __fs32;
42typedef __u16 __fs16;
43#else
44typedef __u64 __bitwise __fs64;
45typedef __u32 __bitwise __fs32;
46typedef __u16 __bitwise __fs16;
47#endif
48
49#include <linux/ufs_fs_i.h>
50#include <linux/ufs_fs_sb.h>
51
52#define UFS_BBLOCK 0
53#define UFS_BBSIZE 8192
54#define UFS_SBLOCK 8192
55#define UFS_SBSIZE 8192
56
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 */
62
63/* Copied from FreeBSD */
64/*
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.
68 *
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.
75 *
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.
84 *
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.
95 */
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 }
103
104
105/* HP specific MAGIC values */
106
107#define UFS_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
108#define UFS_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */
109
110#define UFS_MAGIC_SEC 0x00612195 /* B1 security fs */
111#define UFS_CIGAM_SEC 0x95216100
112
113#define UFS_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
114#define UFS_CIGAM_FEA 0x12561900
115
116#define UFS_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
117#define UFS_CIGAM_4GB 0x94192305
118
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 */
124
125/* End of HP stuff */
126
127
128#define UFS_BSIZE 8192
129#define UFS_MINBSIZE 4096
130#define UFS_FSIZE 1024
131#define UFS_MAXFRAG (UFS_BSIZE / UFS_FSIZE)
132
133#define UFS_NDADDR 12
134#define UFS_NINDIR 3
135
136#define UFS_IND_BLOCK (UFS_NDADDR + 0)
137#define UFS_DIND_BLOCK (UFS_NDADDR + 1)
138#define UFS_TIND_BLOCK (UFS_NDADDR + 2)
139
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)
144
145#define UFS_ROOTINO 2
146#define UFS_FIRST_INO (UFS_ROOTINO + 1)
147
148#define UFS_USEEFT ((__u16)65535)
149
150#define UFS_FSOK 0x7c269d38
151#define UFS_FSACTIVE ((char)0x00)
152#define UFS_FSCLEAN ((char)0x01)
153#define UFS_FSSTABLE ((char)0x02)
154#define UFS_FSOSF1 ((char)0x03) /* is this correct for DEC OSF/1? */
155#define UFS_FSBAD ((char)0xff)
156
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
162/* uid encoding */
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
182
183
184/* fs_inodefmt options */
185#define UFS_42INODEFMT -1
186#define UFS_44INODEFMT 2
187
188/* mount options */
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
194
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
205
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)
209
210/*
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.
221 */
222#define UFS_MINFREE 5
223#define UFS_DEFAULTOPT UFS_OPTTIME
224
225/*
226 * Turn file system block numbers into disk block addresses.
227 * This maps file system blocks to device size blocks.
228 */
229#define ufs_fsbtodb(uspi, b) ((b) << (uspi)->s_fsbtodb)
230#define ufs_dbtofsb(uspi, b) ((b) >> (uspi)->s_fsbtodb)
231
232/*
233 * Cylinder group macros to locate things in cylinder groups.
234 * They calc file system addresses of cylinder group data structures.
235 */
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 */
243
244/*
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.
249 */
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)
254
255/*
256 * Give cylinder group number for a file system block.
257 * Give cylinder group block number for a file system block.
258 */
259#define ufs_dtog(d) ((d) / uspi->s_fpg)
260#define ufs_dtogd(d) ((d) % uspi->s_fpg)
261
262/*
263 * Compute the cylinder and rotational position of a cyl block addr.
264 */
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)
272
273/*
274 * The following macros optimize certain frequently calculated
275 * quantities by using shifts and masks in place of divisions
276 * modulos and multiplications.
277 */
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)
289
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
296/*
297#define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4)
298*/
299#define UFS2_NOCSPTRS 28
300
301/*
302 * UFS_DIR_PAD defines the directory entries boundaries
303 * (must be a multiple of 4)
304 */
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)
308
309struct ufs_timeval {
310 __fs32 tv_sec;
311 __fs32 tv_usec;
312};
313
314struct ufs_dir_entry {
315 __fs32 d_ino; /* inode number of this entry */
316 __fs16 d_reclen; /* length of this entry */
317 union {
318 __fs16 d_namlen; /* actual length of d_name */
319 struct {
320 __u8 d_type; /* file type */
321 __u8 d_namlen; /* length of string in d_name */
322 } d_44;
323 } d_u;
324 __u8 d_name[UFS_MAXNAMLEN + 1]; /* file name */
325};
326
327struct ufs_csum {
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 */
332};
333struct 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 */
340};
341
342/*
343 * This is the actual superblock, as it is laid out on the disk.
344 */
345struct 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 */
385 union {
386 struct {
387 __fs32 fs_npsect; /* # sectors/track including spares */
388 } fs_sun;
389 struct {
390 __fs32 fs_state; /* file system state time stamp */
391 } fs_sunx86;
392 } fs_u1;
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 */
421 union {
422 struct {
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 */
429 } fs_u1;
430 struct {
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 */
452 } fs_u2;
453 } fs_u11;
454 union {
455 struct {
456 __fs32 fs_sparecon[53];/* reserved for future constants */
457 __fs32 fs_reclaim;
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 */
462 } fs_sun;
463 struct {
464 __fs32 fs_sparecon[53];/* reserved for future constants */
465 __fs32 fs_reclaim;
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 */
470 } fs_sunx86;
471 struct {
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 */
480 } fs_44;
481 } fs_u2;
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 */
488};
489
490/*
491 * Preference for optimization.
492 */
493#define UFS_OPTTIME 0 /* minimize allocation time */
494#define UFS_OPTSPACE 1 /* minimize disk fragmentation */
495
496/*
497 * Rotational layout table format types
498 */
499#define UFS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
500#define UFS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
501
502/*
503 * Convert cylinder group to base address of its global summary info.
504 */
e295cfcb 505#define fs_cs(indx) s_csp[(indx)]
1da177e4
LT
506
507/*
508 * Cylinder group block for a file system.
509 *
510 * Writable fields in the cylinder group are protected by the associated
511 * super block lock fs->fs_lock.
512 */
513#define CG_MAGIC 0x090255
514#define ufs_cg_chkmagic(sb, ucg) \
515 (fs32_to_cpu((sb), (ucg)->cg_magic) == CG_MAGIC)
516
517/*
518 * size of this structure is 172 B
519 */
520struct 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 */
538 union {
539 struct {
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 */
544 } cg_44;
545 struct {
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 */
554 } cg_u2;
555 __fs32 cg_sparecon[16]; /* reserved for future use */
556 } cg_u;
557 __u8 cg_space[1]; /* space for cylinder group maps */
558/* actually longer */
559};
560
561/*
562 * structure of an on-disk inode
563 */
564struct ufs_inode {
565 __fs16 ui_mode; /* 0x0 */
566 __fs16 ui_nlink; /* 0x2 */
567 union {
568 struct {
569 __fs16 ui_suid; /* 0x4 */
570 __fs16 ui_sgid; /* 0x6 */
571 } oldids;
572 __fs32 ui_inumber; /* 0x4 lsf: inode number */
573 __fs32 ui_author; /* 0x4 GNU HURD: author */
574 } ui_u1;
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 */
579 union {
580 struct {
581 __fs32 ui_db[UFS_NDADDR];/* 0x28 data blocks */
582 __fs32 ui_ib[UFS_NINDIR];/* 0x58 indirect blocks */
583 } ui_addr;
584 __u8 ui_symlink[4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
585 } ui_u2;
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 */
589 union {
590 struct {
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 */
595 } ui_sun;
596 struct {
597 __fs32 ui_uid; /* 0x70 File owner */
598 __fs32 ui_gid; /* 0x74 File group */
599 __fs32 ui_spare[2]; /* 0x78 reserved */
600 } ui_44;
601 struct {
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 */
607 } ui_hurd;
608 } ui_u3;
609};
610
611#define UFS_NXADDR 2 /* External addresses in inode. */
612struct ufs2_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. */
633 union {
634 struct {
635 __fs64 ui_db[UFS_NDADDR]; /* 112: Direct disk blocks. */
636 __fs64 ui_ib[UFS_NINDIR];/* 208: Indirect disk blocks.*/
637 } ui_addr;
638 __u8 ui_symlink[2*4*(UFS_NDADDR+UFS_NINDIR)];/* 0x28 fast symlink */
639 } ui_u2;
640 __fs64 ui_spare[3]; /* 232: Reserved; currently unused */
641};
642
643
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 */
658
659/*
660 * This structure is used for reading disk structures larger
661 * than the size of fragment.
662 */
663struct ufs_buffer_head {
664 __u64 fragment; /* first fragment */
665 __u64 count; /* number of fragments */
666 struct buffer_head * bh[UFS_MAXFRAG]; /* buffers */
667};
668
669struct 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 */
686};
687
688struct 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 */
736
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 */
752
753 __u32 s_maxsymlinklen;/* upper limit on fast symlinks' size */
754 __s32 fs_magic; /* filesystem magic */
755};
756
757/*
758 * Sizes of this structures are:
759 * ufs_super_block_first 512
760 * ufs_super_block_second 512
761 * ufs_super_block_third 356
762 */
763struct ufs_super_block_first {
764 __fs32 fs_link;
765 __fs32 fs_rlink;
766 __fs32 fs_sblkno;
767 __fs32 fs_cblkno;
768 __fs32 fs_iblkno;
769 __fs32 fs_dblkno;
770 __fs32 fs_cgoffset;
771 __fs32 fs_cgmask;
772 __fs32 fs_time;
773 __fs32 fs_size;
774 __fs32 fs_dsize;
775 __fs32 fs_ncg;
776 __fs32 fs_bsize;
777 __fs32 fs_fsize;
778 __fs32 fs_frag;
779 __fs32 fs_minfree;
780 __fs32 fs_rotdelay;
781 __fs32 fs_rps;
782 __fs32 fs_bmask;
783 __fs32 fs_fmask;
784 __fs32 fs_bshift;
785 __fs32 fs_fshift;
786 __fs32 fs_maxcontig;
787 __fs32 fs_maxbpg;
788 __fs32 fs_fragshift;
789 __fs32 fs_fsbtodb;
790 __fs32 fs_sbsize;
791 __fs32 fs_csmask;
792 __fs32 fs_csshift;
793 __fs32 fs_nindir;
794 __fs32 fs_inopb;
795 __fs32 fs_nspf;
796 __fs32 fs_optim;
797 union {
798 struct {
799 __fs32 fs_npsect;
800 } fs_sun;
801 struct {
802 __fs32 fs_state;
803 } fs_sunx86;
804 } fs_u1;
805 __fs32 fs_interleave;
806 __fs32 fs_trackskew;
807 __fs32 fs_id[2];
808 __fs32 fs_csaddr;
809 __fs32 fs_cssize;
810 __fs32 fs_cgsize;
811 __fs32 fs_ntrak;
812 __fs32 fs_nsect;
813 __fs32 fs_spc;
814 __fs32 fs_ncyl;
815 __fs32 fs_cpg;
816 __fs32 fs_ipg;
817 __fs32 fs_fpg;
818 struct ufs_csum fs_cstotal;
819 __s8 fs_fmod;
820 __s8 fs_clean;
821 __s8 fs_ronly;
822 __s8 fs_flags;
823 __s8 fs_fsmnt[UFS_MAXMNTLEN - 212];
824
825};
826
827struct ufs_super_block_second {
828 __s8 fs_fsmnt[212];
829 __fs32 fs_cgrotor;
830 __fs32 fs_csp[UFS_MAXCSBUFS];
831 __fs32 fs_maxcluster;
832 __fs32 fs_cpc;
833 __fs16 fs_opostbl[82];
834};
835
836struct ufs_super_block_third {
837 __fs16 fs_opostbl[46];
838 union {
839 struct {
840 __fs32 fs_sparecon[53];/* reserved for future constants */
841 __fs32 fs_reclaim;
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 */
846 } fs_sun;
847 struct {
848 __fs32 fs_sparecon[53];/* reserved for future constants */
849 __fs32 fs_reclaim;
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 */
854 } fs_sunx86;
855 struct {
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 */
864 } fs_44;
865 } fs_u2;
866 __fs32 fs_postblformat;
867 __fs32 fs_nrpos;
868 __fs32 fs_postbloff;
869 __fs32 fs_rotbloff;
870 __fs32 fs_magic;
871 __u8 fs_space[1];
872};
873
874#ifdef __KERNEL__
875
876/* balloc.c */
877extern void ufs_free_fragments (struct inode *, unsigned, unsigned);
878extern void ufs_free_blocks (struct inode *, unsigned, unsigned);
879extern unsigned ufs_new_fragments (struct inode *, __fs32 *, unsigned, unsigned, unsigned, int *);
880
881/* cylinder.c */
882extern struct ufs_cg_private_info * ufs_load_cylinder (struct super_block *, unsigned);
883extern void ufs_put_cylinder (struct super_block *, unsigned);
884
885/* dir.c */
886extern struct inode_operations ufs_dir_inode_operations;
887extern int ufs_add_link (struct dentry *, struct inode *);
888extern ino_t ufs_inode_by_name(struct inode *, struct dentry *);
889extern int ufs_make_empty(struct inode *, struct inode *);
890extern struct ufs_dir_entry * ufs_find_entry (struct dentry *, struct buffer_head **);
891extern int ufs_delete_entry (struct inode *, struct ufs_dir_entry *, struct buffer_head *);
892extern int ufs_empty_dir (struct inode *);
893extern struct ufs_dir_entry * ufs_dotdot (struct inode *, struct buffer_head **);
894extern void ufs_set_link(struct inode *, struct ufs_dir_entry *, struct buffer_head *, struct inode *);
895
896/* file.c */
897extern struct inode_operations ufs_file_inode_operations;
898extern struct file_operations ufs_file_operations;
899
900extern struct address_space_operations ufs_aops;
901
902/* ialloc.c */
903extern void ufs_free_inode (struct inode *inode);
904extern struct inode * ufs_new_inode (struct inode *, int);
905
906/* inode.c */
907extern u64 ufs_frag_map (struct inode *, sector_t);
908extern void ufs_read_inode (struct inode *);
909extern void ufs_put_inode (struct inode *);
910extern int ufs_write_inode (struct inode *, int);
911extern int ufs_sync_inode (struct inode *);
912extern void ufs_delete_inode (struct inode *);
913extern struct buffer_head * ufs_getfrag (struct inode *, unsigned, int, int *);
914extern struct buffer_head * ufs_bread (struct inode *, unsigned, int, int *);
09114eb8 915extern int ufs_getfrag_block (struct inode *inode, sector_t fragment, struct buffer_head *bh_result, int create);
1da177e4
LT
916
917/* namei.c */
918extern struct file_operations ufs_dir_operations;
919
920/* super.c */
921extern void ufs_warning (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
922extern void ufs_error (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
923extern void ufs_panic (struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));
924
925/* symlink.c */
926extern struct inode_operations ufs_fast_symlink_inode_operations;
927
928/* truncate.c */
929extern void ufs_truncate (struct inode *);
930
931static inline struct ufs_sb_info *UFS_SB(struct super_block *sb)
932{
933 return sb->s_fs_info;
934}
935
936static inline struct ufs_inode_info *UFS_I(struct inode *inode)
937{
938 return container_of(inode, struct ufs_inode_info, vfs_inode);
939}
940
941#endif /* __KERNEL__ */
942
943#endif /* __LINUX_UFS_FS_H */