xref: /freebsd/tools/tools/find-sb/mini_ufs.h (revision 069ac184)
1 /*
2  * This program, created 2002-10-03 by Garrett A. Wollman
3  * <wollman@FreeBSD.org>, is in the public domain.  Use at your own risk.
4  */
5 
6 /*
7  * Small extract from ufs/ffs/fs.h to get definition of superblock
8  * in order to make this tool portable to other unix-like systems.
9  *
10  * Based upon:
11  *
12  * FreeBSD: src/sys/ufs/ffs/fs.h,v 1.48 2005/02/20 08:02:15 delphij
13  * FreeBSD: src/sys/ufs/ufs/dinode.h,v 1.15 2005/01/07 02:29:26 imp
14  */
15 
16 #include <sys/types.h>
17 
18 #define	SBLOCKSIZE	8192
19 #define	DEV_BSIZE	(1<<9)
20 #define	FS_UFS1_MAGIC	0x011954
21 #define	FS_UFS2_MAGIC	0x19540119
22 #define	SBLOCK_UFS1	8192
23 #define	SBLOCK_UFS2	65536
24 #define	MAXMNTLEN	468
25 #define	MAXVOLLEN	32
26 #define	NOCSPTRS	((128 / sizeof(void *)) - 4)
27 #define	FSMAXSNAP	20
28 
29 typedef int64_t ufs_time_t;
30 typedef int64_t ufs2_daddr_t;
31 
32 struct csum {
33         int32_t cs_ndir;                /* number of directories */
34         int32_t cs_nbfree;              /* number of free blocks */
35         int32_t cs_nifree;              /* number of free inodes */
36         int32_t cs_nffree;              /* number of free frags */
37 };
38 
39 struct csum_total {
40         int64_t cs_ndir;                /* number of directories */
41         int64_t cs_nbfree;              /* number of free blocks */
42         int64_t cs_nifree;              /* number of free inodes */
43         int64_t cs_nffree;              /* number of free frags */
44         int64_t cs_numclusters;         /* number of free clusters */
45         int64_t cs_spare[3];            /* future expansion */
46 };
47 
48 /*
49  * Super block for an FFS filesystem.
50  */
51 struct fs {
52         int32_t  fs_firstfield;         /* historic filesystem linked list, */
53         int32_t  fs_unused_1;           /*     used for incore super blocks */
54         int32_t  fs_sblkno;             /* offset of super-block in filesys */
55         int32_t  fs_cblkno;             /* offset of cyl-block in filesys */
56         int32_t  fs_iblkno;             /* offset of inode-blocks in filesys */
57         int32_t  fs_dblkno;             /* offset of first data after cg */
58         int32_t  fs_old_cgoffset;       /* cylinder group offset in cylinder */
59         int32_t  fs_old_cgmask;         /* used to calc mod fs_ntrak */
60         int32_t  fs_old_time;           /* last time written */
61         int32_t  fs_old_size;           /* number of blocks in fs */
62         int32_t  fs_old_dsize;          /* number of data blocks in fs */
63         int32_t  fs_ncg;                /* number of cylinder groups */
64         int32_t  fs_bsize;              /* size of basic blocks in fs */
65         int32_t  fs_fsize;              /* size of frag blocks in fs */
66         int32_t  fs_frag;               /* number of frags in a block in fs */
67 /* these are configuration parameters */
68         int32_t  fs_minfree;            /* minimum percentage of free blocks */
69         int32_t  fs_old_rotdelay;       /* num of ms for optimal next block */
70         int32_t  fs_old_rps;            /* disk revolutions per second */
71 /* these fields can be computed from the others */
72         int32_t  fs_bmask;              /* ``blkoff'' calc of blk offsets */
73         int32_t  fs_fmask;              /* ``fragoff'' calc of frag offsets */
74         int32_t  fs_bshift;             /* ``lblkno'' calc of logical blkno */
75         int32_t  fs_fshift;             /* ``numfrags'' calc number of frags */
76 /* these are configuration parameters */
77         int32_t  fs_maxcontig;          /* max number of contiguous blks */
78         int32_t  fs_maxbpg;             /* max number of blks per cyl group */
79 /* these fields can be computed from the others */
80         int32_t  fs_fragshift;          /* block to frag shift */
81         int32_t  fs_fsbtodb;            /* fsbtodb and dbtofsb shift constant */
82         int32_t  fs_sbsize;             /* actual size of super block */
83         int32_t  fs_spare1[2];          /* old fs_csmask */
84                                         /* old fs_csshift */
85         int32_t  fs_nindir;             /* value of NINDIR */
86         int32_t  fs_inopb;              /* value of INOPB */
87         int32_t  fs_old_nspf;           /* value of NSPF */
88 /* yet another configuration parameter */
89         int32_t  fs_optim;              /* optimization preference, see below */
90         int32_t  fs_old_npsect;         /* # sectors/track including spares */
91         int32_t  fs_old_interleave;     /* hardware sector interleave */
92         int32_t  fs_old_trackskew;      /* sector 0 skew, per track */
93         int32_t  fs_id[2];              /* unique filesystem id */
94 /* sizes determined by number of cylinder groups and their sizes */
95         int32_t  fs_old_csaddr;         /* blk addr of cyl grp summary area */
96         int32_t  fs_cssize;             /* size of cyl grp summary area */
97         int32_t  fs_cgsize;             /* cylinder group size */
98         int32_t  fs_spare2;             /* old fs_ntrak */
99         int32_t  fs_old_nsect;          /* sectors per track */
100         int32_t  fs_old_spc;            /* sectors per cylinder */
101         int32_t  fs_old_ncyl;           /* cylinders in filesystem */
102         int32_t  fs_old_cpg;            /* cylinders per group */
103         int32_t  fs_ipg;                /* inodes per group */
104         int32_t  fs_fpg;                /* blocks per group * fs_frag */
105 /* this data must be re-computed after crashes */
106         struct  csum fs_old_cstotal;    /* cylinder summary information */
107 /* these fields are cleared at mount time */
108         int8_t   fs_fmod;               /* super block modified flag */
109         int8_t   fs_clean;              /* filesystem is clean flag */
110         int8_t   fs_ronly;              /* mounted read-only flag */
111         int8_t   fs_old_flags;          /* old FS_ flags */
112         u_char   fs_fsmnt[MAXMNTLEN];   /* name mounted on */
113         u_char   fs_volname[MAXVOLLEN]; /* volume name */
114         u_int64_t fs_swuid;             /* system-wide uid */
115         int32_t  fs_pad;                /* due to alignment of fs_swuid */
116 /* these fields retain the current block allocation info */
117         int32_t  fs_cgrotor;            /* last cg searched */
118         void    *fs_ocsp[NOCSPTRS];     /* padding; was list of fs_cs buffers */
119         u_int8_t *fs_contigdirs;        /* (u) # of contig. allocated dirs */
120         struct  csum *fs_csp;           /* (u) cg summary info buffer */
121         int32_t *fs_maxcluster;         /* (u) max cluster in each cyl group */
122         u_int   *fs_active;             /* (u) used by snapshots to track fs */
123         int32_t  fs_old_cpc;            /* cyl per cycle in postbl */
124         int32_t  fs_maxbsize;           /* maximum blocking factor permitted */
125         int64_t  fs_unrefs;             /* number of unreferenced inodes */
126         int64_t  fs_sparecon64[16];     /* old rotation block list head */
127         int64_t  fs_sblockloc;          /* byte offset of standard superblock */
128         struct  csum_total fs_cstotal;  /* (u) cylinder summary information */
129         ufs_time_t fs_time;             /* last time written */
130         int64_t  fs_size;               /* number of blocks in fs */
131         int64_t  fs_dsize;              /* number of data blocks in fs */
132         ufs2_daddr_t fs_csaddr;         /* blk addr of cyl grp summary area */
133         int64_t  fs_pendingblocks;      /* (u) blocks being freed */
134         int32_t  fs_pendinginodes;      /* (u) inodes being freed */
135         int32_t  fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
136         int32_t  fs_avgfilesize;        /* expected average file size */
137         int32_t  fs_avgfpdir;           /* expected # of files per directory */
138         int32_t  fs_save_cgsize;        /* save real cg size to use fs_bsize */
139         int32_t  fs_sparecon32[26];     /* reserved for future constants */
140         int32_t  fs_flags;              /* see FS_ flags below */
141         int32_t  fs_contigsumsize;      /* size of cluster summary array */
142         int32_t  fs_maxsymlinklen;      /* max length of an internal symlink */
143         int32_t  fs_old_inodefmt;       /* format of on-disk inodes */
144         u_int64_t fs_maxfilesize;       /* maximum representable file size */
145         int64_t  fs_qbmask;             /* ~fs_bmask for use with 64-bit size */
146         int64_t  fs_qfmask;             /* ~fs_fmask for use with 64-bit size */
147         int32_t  fs_state;              /* validate fs_clean field */
148         int32_t  fs_old_postblformat;   /* format of positional layout tables */
149         int32_t  fs_old_nrpos;          /* number of rotational positions */
150         int32_t  fs_spare5[2];          /* old fs_postbloff */
151                                         /* old fs_rotbloff */
152         int32_t  fs_magic;              /* magic number */
153 };
154