xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 51139)
1*51139Sbostic /*-
2*51139Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*51139Sbostic  * All rights reserved.
4*51139Sbostic  *
5*51139Sbostic  * %sccs.include.redist.c%
6*51139Sbostic  *
7*51139Sbostic  *	@(#)lfs.h	5.1 (Berkeley) 09/18/91
8*51139Sbostic  */
9*51139Sbostic 
10*51139Sbostic #define	MAXMNTLEN	512		/* XXX move from fs.h to mount.h */
11*51139Sbostic #define	LFSBLKSIZE	(4*1024)
12*51139Sbostic 
13*51139Sbostic /* On-disk super block. */
14*51139Sbostic typedef struct lfs_super {
15*51139Sbostic #define	LFS_MAGIC	0xabababab
16*51139Sbostic 	u_long	lfs_magic;		/* magic number */
17*51139Sbostic 	u_long	lfs_version;		/* version number */
18*51139Sbostic 
19*51139Sbostic 	u_long	lfs_size;		/* number of blocks in fs */
20*51139Sbostic 	u_long	lfs_ssize;		/* number of blocks per segment */
21*51139Sbostic 	u_long	lfs_dsize;		/* number of data blocks in fs */
22*51139Sbostic 	u_long	lfs_bsize;		/* size of basic blocks in fs */
23*51139Sbostic 	u_long	lfs_fsize;		/* size of frag blocks in fs */
24*51139Sbostic 	u_long	lfs_frag;		/* number of frags in a block in fs */
25*51139Sbostic 	u_long	lfs_sbsize;		/* actual size of super block */
26*51139Sbostic 
27*51139Sbostic /* Checkpoint region. */
28*51139Sbostic 	ino_t	lfs_free;		/* start of the free list */
29*51139Sbostic 	daddr_t	lfs_idaddr;		/* inode file disk address */
30*51139Sbostic 	ino_t	lfs_ifile;		/* inode file inode number */
31*51139Sbostic 	daddr_t	lfs_lastseg;		/* last segment written */
32*51139Sbostic 	u_long	lfs_tstamp;		/* time stamp */
33*51139Sbostic 
34*51139Sbostic /* These are configuration parameters. */
35*51139Sbostic 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
36*51139Sbostic 
37*51139Sbostic /* These fields can be computed from the others. */
38*51139Sbostic 	u_long	lfs_inopb;		/* inodes per block */
39*51139Sbostic 	u_long	lfs_ifpb;		/* IFILE entries per block */
40*51139Sbostic 	u_long	lfs_nindir;		/* indirect pointers per block */
41*51139Sbostic 	u_long	lfs_nseg;		/* number of segments */
42*51139Sbostic 	u_long	lfs_nspf;		/* number of sectors per fragment */
43*51139Sbostic 	u_long	lfs_segtabsz;		/* segment table size in blocks */
44*51139Sbostic 
45*51139Sbostic 	u_long	lfs_segmask;		/* calculate offset within a segment */
46*51139Sbostic 	u_long	lfs_segshift;		/* fast mult/div for segments */
47*51139Sbostic 	u_long	lfs_bmask;		/* calc block offset from file offset */
48*51139Sbostic 	u_long	lfs_bshift;		/* calc block number from file offset */
49*51139Sbostic 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
50*51139Sbostic 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
51*51139Sbostic 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
52*51139Sbostic 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
53*51139Sbostic 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
54*51139Sbostic 
55*51139Sbostic #define	MAXNUMSB	10
56*51139Sbostic 	daddr_t	lfs_sboffs[MAXNUMSB];	/* super-block disk offsets */
57*51139Sbostic } LFS_SUPER;
58*51139Sbostic 
59*51139Sbostic #define	blksize(fs, ip, lbn)	LFSBLKSIZE
60*51139Sbostic #define	blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
61*51139Sbostic 	((loc) & ~(fs)->fs_bmask)
62*51139Sbostic #define	fsbtodb(fs, b)		((b) << (fs)->fs_fsbtodb)
63*51139Sbostic #define	lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
64*51139Sbostic 	((loc) >> (fs)->fs_bshift)
65*51139Sbostic #define	itoo(fs, x)		((x) % INOPB(fs))
66*51139Sbostic #define	itod(fs, x)		LFS -- IMPLEMENT
67*51139Sbostic 
68*51139Sbostic /* In-memory super block. */
69*51139Sbostic typedef struct lfs {
70*51139Sbostic 	struct	fs *fs_link;		/* linked list of file systems */
71*51139Sbostic 	struct	fs *fs_rlink;		/*     used for incore super blocks */
72*51139Sbostic 	time_t	fs_time;		/* last time written */
73*51139Sbostic 
74*51139Sbostic /* These fields are cleared at mount time. */
75*51139Sbostic 	u_char	fs_fmod;		/* super block modified flag */
76*51139Sbostic 	u_char	fs_clean;		/* file system is clean flag */
77*51139Sbostic 	u_char	fs_ronly;		/* mounted read-only flag */
78*51139Sbostic 	u_char	fs_flags;		/* currently unused flag */
79*51139Sbostic 	u_char	fs_fsmnt[MAXMNTLEN];	/* name mounted on */
80*51139Sbostic 
81*51139Sbostic /* On-disk structure. */
82*51139Sbostic 	LFS_SUPER fs_super;
83*51139Sbostic } LFS;
84*51139Sbostic 
85*51139Sbostic #define	fs_bmask	fs_super.lfs_bmask
86*51139Sbostic #define	fs_bshift	fs_super.lfs_bshift
87*51139Sbostic #define	fs_bsize	fs_super.lfs_bsize
88*51139Sbostic #define	fs_dsize	fs_super.lfs_dsize
89*51139Sbostic #define	fs_fbmask	fs_super.lfs_fbmask
90*51139Sbostic #define	fs_fbshift	fs_super.lfs_fbshift
91*51139Sbostic #define	fs_ffmask	fs_super.lfs_ffmask
92*51139Sbostic #define	fs_ffshift	fs_super.lfs_ffshift
93*51139Sbostic #define	fs_frag		fs_super.lfs_frag
94*51139Sbostic #define	fs_free		fs_super.lfs_free
95*51139Sbostic #define	fs_fsbtodb	fs_super.lfs_fsbtodb
96*51139Sbostic #define	fs_fsize	fs_super.lfs_fsize
97*51139Sbostic #define	fs_idaddr	fs_super.lfs_idaddr
98*51139Sbostic #define	fs_ifile	fs_super.lfs_ifile
99*51139Sbostic #define	fs_ifpb		fs_super.lfs_ifpb
100*51139Sbostic #define	fs_inopb	fs_super.lfs_inopb
101*51139Sbostic #define	fs_lastseg	fs_super.lfs_lastseg
102*51139Sbostic #define	fs_magic	fs_super.lfs_magic
103*51139Sbostic #define	fs_minfree	fs_super.lfs_minfree
104*51139Sbostic #define	fs_nindir	fs_super.lfs_nindir
105*51139Sbostic #define	fs_nseg		fs_super.lfs_nseg
106*51139Sbostic #define	fs_nspf		fs_super.lfs_nspf
107*51139Sbostic #define	fs_sboffs	fs_super.lfs_sboffs
108*51139Sbostic #define	fs_sbsize	fs_super.lfs_sbsize
109*51139Sbostic #define	fs_segmask	fs_super.lfs_segmask
110*51139Sbostic #define	fs_segshift	fs_super.lfs_segshift
111*51139Sbostic #define	fs_segtabsz	fs_super.lfs_segtabsz
112*51139Sbostic #define	fs_size		fs_super.lfs_size
113*51139Sbostic #define	fs_ssize	fs_super.lfs_ssize
114*51139Sbostic #define	fs_tstamp	fs_super.lfs_tstamp
115*51139Sbostic #define	fs_version	fs_super.lfs_version
116*51139Sbostic 
117*51139Sbostic /* Data structures in the ifile */
118*51139Sbostic #define	IFILE_NUM	1		/* inode number of the ifile */
119*51139Sbostic 
120*51139Sbostic typedef struct ifile {
121*51139Sbostic 	u_long	if_version;		/* inode version number */
122*51139Sbostic #define	UNUSED_DADDR	0		/* out-of-band daddr */
123*51139Sbostic 	daddr_t	if_daddr;		/* inode disk address */
124*51139Sbostic 	union {
125*51139Sbostic 		ino_t	nextfree;	/* next-unallocated inode */
126*51139Sbostic 		time_t	st_atime;	/* access time */
127*51139Sbostic 	} __ifile_u;
128*51139Sbostic #define	if_st_atime	__ifile_u.st_atime;
129*51139Sbostic #define	if_nextfree	__ifile_u.nextfree;
130*51139Sbostic } IFILE;
131*51139Sbostic 
132*51139Sbostic /* Segment table size, in blocks. */
133*51139Sbostic #define	SEGTABSIZE(fs) \
134*51139Sbostic 	(((fs)->fs_nseg * sizeof(SEGUSAGE) + \
135*51139Sbostic 	    ((fs)->fs_bsize - 1)) << (fs)->fs_bshift)
136*51139Sbostic 
137*51139Sbostic /* In-memory and on-disk checkpoint segment usage structure. */
138*51139Sbostic typedef struct segusage {
139*51139Sbostic 	u_long	su_nbytes;		/* number of live bytes */
140*51139Sbostic 	u_long	su_lastmod;		/* last modified timestamp */
141*51139Sbostic } SEGUSAGE;
142*51139Sbostic 
143*51139Sbostic /* On-disk segment summary information */
144*51139Sbostic typedef struct segsum {
145*51139Sbostic 	daddr_t	ss_next;		/* next segment */
146*51139Sbostic 	daddr_t	ss_prev;		/* next segment */
147*51139Sbostic 	daddr_t	ss_nextsum;		/* next summary block */
148*51139Sbostic 	u_long	ss_create;		/* creation time stamp */
149*51139Sbostic 	u_long	ss_nfinfo;		/* number of file info structures */
150*51139Sbostic 	u_long	ss_niinfo;		/* number of inode info structures */
151*51139Sbostic 	u_long	ss_cksum;		/* check sum */
152*51139Sbostic } SEGSUM;
153*51139Sbostic 
154*51139Sbostic /* On-disk file information.  One per file with data blocks in the segment. */
155*51139Sbostic typedef struct finfo {
156*51139Sbostic 	u_long	fi_nblocks;		/* number of blocks */
157*51139Sbostic 	u_long	fi_version;		/* version number */
158*51139Sbostic 	ino_t	fi_ino;			/* inode number */
159*51139Sbostic 	u_long	fi_blocks[1];		/* array of logical block numbers */
160*51139Sbostic } FINFO;
161*51139Sbostic 
162*51139Sbostic /* On-disk inode information.  One per block of inodes in the segment. */
163*51139Sbostic typedef struct iinfo {
164*51139Sbostic 	u_long	ii_ninodes;		/* number of inodes */
165*51139Sbostic 	ino_t	ii_inodes;		/* array of inode numbers */
166*51139Sbostic } IINFO;
167