xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 51850)
151139Sbostic /*-
251139Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351139Sbostic  * All rights reserved.
451139Sbostic  *
551139Sbostic  * %sccs.include.redist.c%
651139Sbostic  *
7*51850Sbostic  *	@(#)lfs.h	7.3 (Berkeley) 12/06/91
851139Sbostic  */
951139Sbostic 
1051183Sbostic typedef struct buf	BUF;
1151183Sbostic typedef struct dinode	DINODE;
1251183Sbostic typedef struct inode	INODE;
1351183Sbostic typedef struct mount	MOUNT;
1451183Sbostic typedef struct ucred	UCRED;
1551183Sbostic typedef struct ufsmount	UFSMOUNT;
1651183Sbostic typedef struct vnode	VNODE;
1751183Sbostic 
1851140Sbostic #define	LFS_LABELPAD	8192		/* LFS label size */
1951140Sbostic #define	LFS_SBPAD	8192		/* LFS superblock size */
2051140Sbostic #define MAXMNTLEN	512		/* XXX move from fs.h to mount.h */
2151139Sbostic 
2251155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */
2351183Sbostic typedef struct segusage SEGUSE;
2451183Sbostic struct segusage {
2551155Sbostic 	u_long	su_nbytes;		/* number of live bytes */
2651350Sbostic 	u_long	su_lastmod;		/* SEGUSE last modified timestamp */
2751183Sbostic #define	SEGUSE_DIRTY	0x1		/* XXX fill in comment */
2851155Sbostic 	u_long	su_flags;
2951183Sbostic };
3051155Sbostic 
31*51850Sbostic #define	SEGTABSIZE_SU(fs) \
32*51850Sbostic 	(((fs)->lfs_nseg * sizeof(SEGUSE) + \
33*51850Sbostic 	((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift)
34*51850Sbostic 
3551183Sbostic /* On-disk file information.  One per file with data blocks in the segment. */
3651183Sbostic typedef struct finfo FINFO;
3751183Sbostic struct finfo {
3851183Sbostic 	u_long	fi_nblocks;		/* number of blocks */
3951183Sbostic 	u_long	fi_version;		/* version number */
4051215Sbostic 	u_long	fi_ino;			/* inode number */
4151183Sbostic 	long	fi_blocks[1];		/* array of logical block numbers */
4251183Sbostic };
4351183Sbostic 
4451155Sbostic /* On-disk and in-memory super block. */
4551183Sbostic struct lfs {
4651155Sbostic #define	LFS_MAGIC	0xbedead
4751139Sbostic 	u_long	lfs_magic;		/* magic number */
4851140Sbostic #define	LFS_VERSION	1
4951139Sbostic 	u_long	lfs_version;		/* version number */
5051139Sbostic 
5151139Sbostic 	u_long	lfs_size;		/* number of blocks in fs */
5251139Sbostic 	u_long	lfs_ssize;		/* number of blocks per segment */
5351139Sbostic 	u_long	lfs_dsize;		/* number of data blocks in fs */
5451139Sbostic 	u_long	lfs_bsize;		/* size of basic blocks in fs */
5551139Sbostic 	u_long	lfs_fsize;		/* size of frag blocks in fs */
5651139Sbostic 	u_long	lfs_frag;		/* number of frags in a block in fs */
5751139Sbostic 
5851139Sbostic /* Checkpoint region. */
5951139Sbostic 	ino_t	lfs_free;		/* start of the free list */
6051155Sbostic 	u_long	lfs_bfree;		/* number of free blocks */
6151155Sbostic 	u_long	lfs_nfiles;		/* number of allocated inodes */
6251139Sbostic 	daddr_t	lfs_idaddr;		/* inode file disk address */
6351139Sbostic 	ino_t	lfs_ifile;		/* inode file inode number */
6451303Sbostic 	daddr_t	lfs_lastseg;		/* address of last segment written */
6551303Sbostic 	daddr_t	lfs_nextseg;		/* address of next segment to write */
66*51850Sbostic 	daddr_t	lfs_curseg;		/* Current segment being written */
67*51850Sbostic 	daddr_t	lfs_offset;		/* offset in curseg for next partial */
6851139Sbostic 	u_long	lfs_tstamp;		/* time stamp */
6951139Sbostic 
7051139Sbostic /* These are configuration parameters. */
7151139Sbostic 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
7251139Sbostic 
7351139Sbostic /* These fields can be computed from the others. */
74*51850Sbostic 	u_long	lfs_dbpseg;		/* disk blocks per segment */
7551139Sbostic 	u_long	lfs_inopb;		/* inodes per block */
7651139Sbostic 	u_long	lfs_ifpb;		/* IFILE entries per block */
77*51850Sbostic 	u_long	lfs_sepb;		/* SEGUSE entries per block */
7851139Sbostic 	u_long	lfs_nindir;		/* indirect pointers per block */
7951139Sbostic 	u_long	lfs_nseg;		/* number of segments */
8051139Sbostic 	u_long	lfs_nspf;		/* number of sectors per fragment */
81*51850Sbostic 	u_long	lfs_cleansz;		/* cleaner info size in blocks */
8251139Sbostic 	u_long	lfs_segtabsz;		/* segment table size in blocks */
8351139Sbostic 
8451139Sbostic 	u_long	lfs_segmask;		/* calculate offset within a segment */
8551139Sbostic 	u_long	lfs_segshift;		/* fast mult/div for segments */
8651139Sbostic 	u_long	lfs_bmask;		/* calc block offset from file offset */
8751139Sbostic 	u_long	lfs_bshift;		/* calc block number from file offset */
8851139Sbostic 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
8951139Sbostic 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
9051139Sbostic 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
9151139Sbostic 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
9251139Sbostic 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
9351139Sbostic 
9451155Sbostic #define	LFS_MIN_SBINTERVAL	5	/* minimum superblock segment spacing */
9551155Sbostic #define	LFS_MAXNUMSB		10	/* superblock disk offsets */
9651155Sbostic 	daddr_t	lfs_sboffs[LFS_MAXNUMSB];
9751139Sbostic 
9851155Sbostic /* These fields are set at mount time and are meaningless on disk. */
9951183Sbostic 	VNODE	*lfs_ivnode;		/* vnode for the ifile */
10051155Sbostic 	SEGUSE	*lfs_segtab;		/* in-memory segment usage table */
101*51850Sbostic 					/* XXX NOT USED */
102*51850Sbostic 	void	*XXXlfs_seglist;	/* list of segments being written */
10351303Sbostic 	u_long	lfs_iocount;		/* number of ios pending */
10451155Sbostic 	u_char	lfs_fmod;		/* super block modified flag */
10551155Sbostic 	u_char	lfs_clean;		/* file system is clean flag */
10651155Sbostic 	u_char	lfs_ronly;		/* mounted read-only flag */
10751155Sbostic 	u_char	lfs_flags;		/* currently unused flag */
10851155Sbostic 	u_char	lfs_fsmnt[MAXMNTLEN];	/* name mounted on */
10951155Sbostic 	u_char	pad[3];			/* long-align */
11051139Sbostic 
11151155Sbostic /* Checksum; valid on disk. */
11251155Sbostic 	u_long	lfs_cksum;		/* checksum for superblock checking */
11351183Sbostic };
11451139Sbostic 
11551155Sbostic /*
11651539Sbostic  * Inode 0 is the out-of-band inode, and inode 1 is the inode number for the
11751539Sbostic  * ifile.  Thus the root inode is 2, and the lost+found inode is 3.
11851155Sbostic  */
11951155Sbostic #define	LOSTFOUNDINO	((ino_t)3)
12051139Sbostic 
12151140Sbostic /* Fixed inode numbers. */
12251303Sbostic #define	LFS_UNUSED_INUM	0		/* out of band inode number */
12351303Sbostic #define	LFS_IFILE_INUM	1		/* inode number of the ifile */
12451303Sbostic 					/* first free inode number */
12551155Sbostic #define	LFS_FIRST_INUM	(LOSTFOUNDINO + 1)
12651139Sbostic 
12751155Sbostic /*
12851140Sbostic  * Used to access the first spare of the dinode which we use to store
12951140Sbostic  * the ifile number so we can identify them
13051140Sbostic  */
13151140Sbostic #define	di_inum	di_spare[0]
13251140Sbostic 
133*51850Sbostic /* Address calculations for metadata located in the inode */
134*51850Sbostic #define	S_INDIR(fs)	-NDADDR
135*51850Sbostic #define	D_INDIR(fs)	(S_INDIR - NINDIR(fs) - 1)
136*51850Sbostic #define	T_INDIR(fs)	(D_INDIR - NINDIR(fs) * NINDIR(fs) - 1)
13751183Sbostic 
138*51850Sbostic /* Structure used to pass around logical block paths. */
139*51850Sbostic typedef struct _indir {
140*51850Sbostic 	long	in_lbn;			/* logical block number */
141*51850Sbostic 	int	in_off;			/* offset in buffer */
142*51850Sbostic } INDIR;
143*51850Sbostic 
14451350Sbostic /* Unassigned disk address. */
14551350Sbostic #define	UNASSIGNED	-1
14651350Sbostic 
14751183Sbostic typedef struct ifile IFILE;
14851183Sbostic struct ifile {
14951139Sbostic 	u_long	if_version;		/* inode version number */
15051155Sbostic #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
15151139Sbostic 	daddr_t	if_daddr;		/* inode disk address */
15251139Sbostic 	union {
15351139Sbostic 		ino_t	nextfree;	/* next-unallocated inode */
15451139Sbostic 		time_t	st_atime;	/* access time */
15551139Sbostic 	} __ifile_u;
15651140Sbostic #define	if_st_atime	__ifile_u.st_atime
15751140Sbostic #define	if_nextfree	__ifile_u.nextfree
15851183Sbostic };
15951139Sbostic 
160*51850Sbostic /*
161*51850Sbostic  * Cleaner information structure.  This resides in the ifile and is used
162*51850Sbostic  * to pass information between the cleaner and the kernel.
163*51850Sbostic  */
164*51850Sbostic typedef struct _cleanerinfo {
165*51850Sbostic 	u_long	clean;			/* K: number of clean segments */
166*51850Sbostic 	u_long	dirty;			/* K: number of dirty segments */
167*51850Sbostic 	u_long	last_seg;		/* K: index of last seg written */
168*51850Sbostic 	time_t	last_time;		/* K: timestamp of last seg written */
169*51850Sbostic } CLEANERINFO;
17051139Sbostic 
171*51850Sbostic #define	CLEANSIZE_SU(fs) \
172*51850Sbostic 	((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift)
17351140Sbostic 
17451140Sbostic /*
17551140Sbostic  * All summary blocks are the same size, so we can always read a summary
17651303Sbostic  * block easily from a segment.
17751140Sbostic  */
17851140Sbostic #define	LFS_SUMMARY_SIZE	512
17951140Sbostic 
18051139Sbostic /* On-disk segment summary information */
18151183Sbostic typedef struct segsum SEGSUM;
18251183Sbostic struct segsum {
183*51850Sbostic 	u_long	ss_sumsum;		/* check sum of summary block */
184*51850Sbostic 	u_long	ss_datasum;		/* check sum of data */
18551139Sbostic 	daddr_t	ss_next;		/* next segment */
18651139Sbostic 	u_long	ss_create;		/* creation time stamp */
18751139Sbostic 	u_long	ss_nfinfo;		/* number of file info structures */
188*51850Sbostic 	u_long	ss_ninos;		/* number of inodes in summary */
18951155Sbostic 	/* FINFO's... */
19051183Sbostic };
19151139Sbostic 
19251155Sbostic /* NINDIR is the number of indirects in a file system block. */
19351155Sbostic #define	NINDIR(fs)	((fs)->lfs_nindir)
19451155Sbostic 
19551155Sbostic /* INOPB is the number of inodes in a secondary storage block. */
19651155Sbostic #define	INOPB(fs)	((fs)->lfs_inopb)
19751155Sbostic 
19851155Sbostic #define	blksize(fs)		((fs)->lfs_bsize)
19951155Sbostic #define	blkoff(fs, loc)		((loc) & (fs)->lfs_bmask)
20051155Sbostic #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
20151155Sbostic #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
20251155Sbostic #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
20351183Sbostic #define numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
20451183Sbostic 	((loc) >> (fs)->lfs_bshift)
20551350Sbostic 
206*51850Sbostic /* Read in the block with a specific inode from the ifile. */
20751481Sbostic #define	LFS_IENTRY(I, F, IN, BP) { \
208*51850Sbostic 	if (bread((F)->lfs_ivnode, \
209*51850Sbostic 	    (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \
21051481Sbostic 	    (F)->lfs_bsize, NOCRED, &BP)) \
21151481Sbostic 		panic("lfs: ifile read"); \
212*51850Sbostic 	(I) = (IFILE *)BP->b_un.b_addr + IN % (F)->lfs_ifpb; \
21351481Sbostic }
21451481Sbostic 
215*51850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */
216*51850Sbostic #define	LFS_SEGENTRY(I, F, IN, BP) { \
217*51850Sbostic 	if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \
218*51850Sbostic 	    (F)->lfs_bsize, NOCRED, &BP)) \
219*51850Sbostic 		panic("lfs: ifile read"); \
220*51850Sbostic 	(I) = (SEGUSE *)BP->b_un.b_addr + IN % (F)->lfs_sepb; \
221*51850Sbostic }
222*51850Sbostic 
223*51850Sbostic /*
224*51850Sbostic  * Structures used by lfs_bmapv and lfs_markv to communicate information
225*51850Sbostic  * about inodes and data blocks.
226*51850Sbostic  */
227*51850Sbostic typedef struct block_info {
228*51850Sbostic 	ino_t	bi_inode;		/* inode # */
229*51850Sbostic 	off_t	bi_lbn;			/* logical block w/in file */
230*51850Sbostic 	daddr_t	bi_daddr;		/* disk address of block */
231*51850Sbostic 	time_t	bi_segcreate;		/* origin segment create time */
232*51850Sbostic 	void	*bi_bp;			/* data buffer */
233*51850Sbostic } BLOCK_INFO;
234*51850Sbostic 
235*51850Sbostic typedef struct inode_info {
236*51850Sbostic 	ino_t	ii_inode;		/* inode # */
237*51850Sbostic 	daddr_t	ii_daddr;		/* disk address of block */
238*51850Sbostic 	time_t	ii_segcreate;		/* origin segment create time */
239*51850Sbostic 	struct dinode *ii_dinode;	/* data buffer */
240*51850Sbostic } INODE_INFO;
241