xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 54264)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)lfs.h	7.14 (Berkeley) 06/23/92
8  */
9 
10 #define	LFS_LABELPAD	8192		/* LFS label size */
11 #define	LFS_SBPAD	8192		/* LFS superblock size */
12 #define MAXMNTLEN	512		/* XXX move from fs.h to mount.h */
13 
14 /* On-disk and in-memory checkpoint segment usage structure. */
15 typedef struct segusage SEGUSE;
16 struct segusage {
17 	u_long	su_nbytes;		/* number of live bytes */
18 	u_long	su_lastmod;		/* SEGUSE last modified timestamp */
19 #define	SEGUSE_ACTIVE		0x1	/* segment is currently being written */
20 #define	SEGUSE_DIRTY		0x2	/* segment has data in it */
21 #define	SEGUSE_SUPERBLOCK	0x4	/* segment contains a superblock */
22 #define	SEGUSE_LIVELOG		0x8	/* segment has not been checkpointed */
23 	u_long	su_flags;
24 };
25 
26 #define	SEGTABSIZE_SU(fs) \
27 	(((fs)->lfs_nseg * sizeof(SEGUSE) + \
28 	((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift)
29 
30 /* On-disk file information.  One per file with data blocks in the segment. */
31 typedef struct finfo FINFO;
32 struct finfo {
33 	u_long	fi_nblocks;		/* number of blocks */
34 	u_long	fi_version;		/* version number */
35 	u_long	fi_ino;			/* inode number */
36 	long	fi_blocks[1];		/* array of logical block numbers */
37 };
38 
39 /* On-disk and in-memory super block. */
40 struct lfs {
41 #define	LFS_MAGIC	0x070162
42 	u_long	lfs_magic;		/* magic number */
43 #define	LFS_VERSION	1
44 	u_long	lfs_version;		/* version number */
45 
46 	u_long	lfs_size;		/* number of blocks in fs */
47 	u_long	lfs_ssize;		/* number of blocks per segment */
48 	u_long	lfs_dsize;		/* number of data blocks in fs */
49 	u_long	lfs_bsize;		/* size of basic blocks in fs */
50 	u_long	lfs_fsize;		/* size of frag blocks in fs */
51 	u_long	lfs_frag;		/* number of frags in a block in fs */
52 
53 /* Checkpoint region. */
54 	ino_t	lfs_free;		/* start of the free list */
55 	u_long	lfs_bfree;		/* number of free blocks */
56 	u_long	lfs_nfiles;		/* number of allocated inodes */
57 	daddr_t	lfs_idaddr;		/* inode file disk address */
58 	ino_t	lfs_ifile;		/* inode file inode number */
59 	daddr_t	lfs_lastseg;		/* address of last segment written */
60 	daddr_t	lfs_nextseg;		/* address of next segment to write */
61 	daddr_t	lfs_curseg;		/* current segment being written */
62 	daddr_t	lfs_offset;		/* offset in curseg for next partial */
63 	daddr_t	lfs_lastpseg;		/* address of last partial written */
64 	u_long	lfs_tstamp;		/* time stamp */
65 
66 /* These are configuration parameters. */
67 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
68 
69 /* These fields can be computed from the others. */
70 	u_long	lfs_dbpseg;		/* disk blocks per segment */
71 	u_long	lfs_inopb;		/* inodes per block */
72 	u_long	lfs_ifpb;		/* IFILE entries per block */
73 	u_long	lfs_sepb;		/* SEGUSE entries per block */
74 	u_long	lfs_nindir;		/* indirect pointers per block */
75 	u_long	lfs_nseg;		/* number of segments */
76 	u_long	lfs_nspf;		/* number of sectors per fragment */
77 	u_long	lfs_cleansz;		/* cleaner info size in blocks */
78 	u_long	lfs_segtabsz;		/* segment table size in blocks */
79 
80 	u_long	lfs_segmask;		/* calculate offset within a segment */
81 	u_long	lfs_segshift;		/* fast mult/div for segments */
82 	u_long	lfs_bmask;		/* calc block offset from file offset */
83 	u_long	lfs_bshift;		/* calc block number from file offset */
84 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
85 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
86 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
87 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
88 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
89 
90 #define	LFS_MIN_SBINTERVAL	5	/* minimum superblock segment spacing */
91 #define	LFS_MAXNUMSB		10	/* superblock disk offsets */
92 	daddr_t	lfs_sboffs[LFS_MAXNUMSB];
93 
94 /* These fields are set at mount time and are meaningless on disk. */
95 	struct	vnode *lfs_ivnode;	/* vnode for the ifile */
96 	SEGUSE	*lfs_segtab;		/* in-memory segment usage table */
97 					/* XXX NOT USED */
98 	void	*XXXlfs_seglist;	/* list of segments being written */
99 	u_long	lfs_iocount;		/* number of ios pending */
100 	u_long	lfs_writer;		/* don't allow any dirops to start */
101 	u_long	lfs_dirops;		/* count of active directory ops */
102 	u_long	lfs_doifile;		/* Write ifile blocks on next write */
103 	u_char	lfs_fmod;		/* super block modified flag */
104 	u_char	lfs_clean;		/* file system is clean flag */
105 	u_char	lfs_ronly;		/* mounted read-only flag */
106 	u_char	lfs_flags;		/* currently unused flag */
107 	u_char	lfs_fsmnt[MAXMNTLEN];	/* name mounted on */
108 	u_char	pad[3];			/* long-align */
109 
110 /* Checksum; valid on disk. */
111 	u_long	lfs_cksum;		/* checksum for superblock checking */
112 };
113 
114 /*
115  * Inode 0 is the out-of-band inode number, inode 1 is the inode number for
116  * the IFILE, the root inode is 2 and the lost+found inode is 3.
117  */
118 
119 /* Fixed inode numbers. */
120 #define	LFS_UNUSED_INUM	0		/* out of band inode number */
121 #define	LFS_IFILE_INUM	1		/* IFILE inode number */
122 #define	LOSTFOUNDINO	3		/* lost+found inode number */
123 #define	LFS_FIRST_INUM	4		/* first free inode number */
124 
125 /*
126  * Used to access the first spare of the dinode which we use to store
127  * the ifile number so we can identify them
128  */
129 #define	di_inum	di_spare[0]
130 
131 /* Address calculations for metadata located in the inode */
132 #define	S_INDIR(fs)	-NDADDR
133 #define	D_INDIR(fs)	(S_INDIR(fs) - NINDIR(fs) - 1)
134 #define	T_INDIR(fs)	(D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1)
135 
136 /* Structure used to pass around logical block paths. */
137 typedef struct _indir {
138 	long	in_lbn;			/* logical block number */
139 	int	in_off;			/* offset in buffer */
140 } INDIR;
141 
142 /* Unassigned disk address. */
143 #define	UNASSIGNED	-1
144 
145 typedef struct ifile IFILE;
146 struct ifile {
147 	u_long	if_version;		/* inode version number */
148 #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
149 	daddr_t	if_daddr;		/* inode disk address */
150 	ino_t	if_nextfree;		/* next-unallocated inode */
151 };
152 
153 /*
154  * Cleaner information structure.  This resides in the ifile and is used
155  * to pass information between the cleaner and the kernel.
156  */
157 typedef struct _cleanerinfo {
158 	u_long	clean;			/* K: number of clean segments */
159 	u_long	dirty;			/* K: number of dirty segments */
160 } CLEANERINFO;
161 
162 #define	CLEANSIZE_SU(fs) \
163 	((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift)
164 
165 /*
166  * All summary blocks are the same size, so we can always read a summary
167  * block easily from a segment.
168  */
169 #define	LFS_SUMMARY_SIZE	512
170 
171 /* On-disk segment summary information */
172 typedef struct segsum SEGSUM;
173 struct segsum {
174 	u_long	ss_sumsum;		/* check sum of summary block */
175 	u_long	ss_datasum;		/* check sum of data */
176 	daddr_t	ss_next;		/* next segment */
177 	u_long	ss_create;		/* creation time stamp */
178 	u_short	ss_nfinfo;		/* number of file info structures */
179 	u_short	ss_ninos;		/* number of inodes in summary */
180 #define	SS_DIROP	0x01		/* segment begins a dirop */
181 #define	SS_CONT		0x02		/* more partials to finish this write*/
182 	u_short	ss_flags;		/* used for directory operations */
183 	u_short	ss_pad;			/* extra space */
184 	/* FINFO's and inode daddr's... */
185 };
186 
187 /* NINDIR is the number of indirects in a file system block. */
188 #define	NINDIR(fs)	((fs)->lfs_nindir)
189 
190 /* INOPB is the number of inodes in a secondary storage block. */
191 #define	INOPB(fs)	((fs)->lfs_inopb)
192 
193 #define	blksize(fs)		((fs)->lfs_bsize)
194 #define	blkoff(fs, loc)		((loc) & (fs)->lfs_bmask)
195 #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
196 #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
197 #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
198 #define numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
199 	((loc) >> (fs)->lfs_bshift)
200 
201 #define	datosn(fs, daddr)	/* disk address to segment number */ \
202 	(((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize))
203 #define sntoda(fs, sn) 		/* segment number to disk address */ \
204 	((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \
205 	    (fs)->lfs_sboffs[0]))
206 
207 /* Read in the block with the cleaner info from the ifile. */
208 #define LFS_CLEANERINFO(CP, F, BP) { \
209 	VTOI((F)->lfs_ivnode)->i_flag |= IACC; \
210 	if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \
211 		panic("lfs: ifile read"); \
212 	(CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \
213 }
214 
215 /* Read in the block with a specific inode from the ifile. */
216 #define	LFS_IENTRY(IP, F, IN, BP) { \
217 	VTOI((F)->lfs_ivnode)->i_flag |= IACC; \
218 	if (bread((F)->lfs_ivnode, \
219 	    (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \
220 	    (F)->lfs_bsize, NOCRED, &(BP))) \
221 		panic("lfs: ifile read"); \
222 	(IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \
223 }
224 
225 /* Read in the block with a specific segment usage entry from the ifile. */
226 #define	LFS_SEGENTRY(SP, F, IN, BP) { \
227 	VTOI((F)->lfs_ivnode)->i_flag |= IACC; \
228 	if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \
229 	    (F)->lfs_bsize, NOCRED, &(BP))) \
230 		panic("lfs: ifile read"); \
231 	(SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \
232 }
233 
234 /* Write a block and update the inode change times. */
235 #define	LFS_UBWRITE(BP) { \
236 	USES_VOP_BWRITE; \
237 	VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \
238 	VOP_BWRITE(BP); \
239 }
240 
241 /*
242  * Structures used by lfs_bmapv and lfs_markv to communicate information
243  * about inodes and data blocks.
244  */
245 typedef struct block_info {
246 	ino_t	bi_inode;		/* inode # */
247 	off_t	bi_lbn;			/* logical block w/in file */
248 	daddr_t	bi_daddr;		/* disk address of block */
249 	time_t	bi_segcreate;		/* origin segment create time */
250 	void	*bi_bp;			/* data buffer */
251 } BLOCK_INFO;
252 
253 typedef struct inode_info {
254 	ino_t	ii_inode;		/* inode # */
255 	daddr_t	ii_daddr;		/* disk address of block */
256 	time_t	ii_segcreate;		/* origin segment create time */
257 	struct dinode *ii_dinode;	/* data buffer */
258 } INODE_INFO;
259