xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 51140)
151139Sbostic /*-
251139Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351139Sbostic  * All rights reserved.
451139Sbostic  *
551139Sbostic  * %sccs.include.redist.c%
651139Sbostic  *
7*51140Sbostic  *	@(#)lfs.h	5.2 (Berkeley) 09/18/91
851139Sbostic  */
951139Sbostic 
10*51140Sbostic #define	LFS_LABELPAD	8192		/* LFS label size */
11*51140Sbostic #define	LFS_SBPAD	8192		/* LFS superblock size */
12*51140Sbostic #define MAXMNTLEN	512		/* XXX move from fs.h to mount.h */
13*51140Sbostic #define	LFS_BLKSIZE	4096		/* LFS block size */
1451139Sbostic 
1551139Sbostic /* On-disk super block. */
1651139Sbostic typedef struct lfs_super {
17*51140Sbostic #define	LFS_MAGIC	0xdeadbeef
1851139Sbostic 	u_long	lfs_magic;		/* magic number */
19*51140Sbostic #define	LFS_VERSION	1
2051139Sbostic 	u_long	lfs_version;		/* version number */
2151139Sbostic 
2251139Sbostic 	u_long	lfs_size;		/* number of blocks in fs */
2351139Sbostic 	u_long	lfs_ssize;		/* number of blocks per segment */
2451139Sbostic 	u_long	lfs_dsize;		/* number of data blocks in fs */
2551139Sbostic 	u_long	lfs_bsize;		/* size of basic blocks in fs */
2651139Sbostic 	u_long	lfs_fsize;		/* size of frag blocks in fs */
2751139Sbostic 	u_long	lfs_frag;		/* number of frags in a block in fs */
2851139Sbostic 	u_long	lfs_sbsize;		/* actual size of super block */
2951139Sbostic 
3051139Sbostic /* Checkpoint region. */
3151139Sbostic 	ino_t	lfs_free;		/* start of the free list */
3251139Sbostic 	daddr_t	lfs_idaddr;		/* inode file disk address */
3351139Sbostic 	ino_t	lfs_ifile;		/* inode file inode number */
3451139Sbostic 	daddr_t	lfs_lastseg;		/* last segment written */
3551139Sbostic 	u_long	lfs_tstamp;		/* time stamp */
3651139Sbostic 
3751139Sbostic /* These are configuration parameters. */
3851139Sbostic 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
3951139Sbostic 
4051139Sbostic /* These fields can be computed from the others. */
4151139Sbostic 	u_long	lfs_inopb;		/* inodes per block */
4251139Sbostic 	u_long	lfs_ifpb;		/* IFILE entries per block */
4351139Sbostic 	u_long	lfs_nindir;		/* indirect pointers per block */
4451139Sbostic 	u_long	lfs_nseg;		/* number of segments */
4551139Sbostic 	u_long	lfs_nspf;		/* number of sectors per fragment */
4651139Sbostic 	u_long	lfs_segtabsz;		/* segment table size in blocks */
4751139Sbostic 
4851139Sbostic 	u_long	lfs_segmask;		/* calculate offset within a segment */
4951139Sbostic 	u_long	lfs_segshift;		/* fast mult/div for segments */
5051139Sbostic 	u_long	lfs_bmask;		/* calc block offset from file offset */
5151139Sbostic 	u_long	lfs_bshift;		/* calc block number from file offset */
5251139Sbostic 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
5351139Sbostic 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
5451139Sbostic 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
5551139Sbostic 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
5651139Sbostic 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
5751139Sbostic 
58*51140Sbostic #define	LFS_MAXNUMSB		10
59*51140Sbostic #define	LFS_MIN_SBINTERVAL	5
60*51140Sbostic 	daddr_t	lfs_sboffs[LFS_MAXNUMSB];	/* super-block disk offsets */
6151139Sbostic } LFS_SUPER;
6251139Sbostic 
6351139Sbostic #define	blksize(fs, ip, lbn)	LFSBLKSIZE
6451139Sbostic #define	blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
6551139Sbostic 	((loc) & ~(fs)->fs_bmask)
6651139Sbostic #define	fsbtodb(fs, b)		((b) << (fs)->fs_fsbtodb)
6751139Sbostic #define	lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
6851139Sbostic 	((loc) >> (fs)->fs_bshift)
6951139Sbostic #define	itoo(fs, x)		((x) % INOPB(fs))
7051139Sbostic #define	itod(fs, x)		LFS -- IMPLEMENT
7151139Sbostic 
7251139Sbostic /* In-memory super block. */
7351139Sbostic typedef struct lfs {
7451139Sbostic 	struct	fs *fs_link;		/* linked list of file systems */
7551139Sbostic 	struct	fs *fs_rlink;		/*     used for incore super blocks */
7651139Sbostic 	time_t	fs_time;		/* last time written */
7751139Sbostic 
7851139Sbostic /* These fields are cleared at mount time. */
7951139Sbostic 	u_char	fs_fmod;		/* super block modified flag */
8051139Sbostic 	u_char	fs_clean;		/* file system is clean flag */
8151139Sbostic 	u_char	fs_ronly;		/* mounted read-only flag */
8251139Sbostic 	u_char	fs_flags;		/* currently unused flag */
8351139Sbostic 	u_char	fs_fsmnt[MAXMNTLEN];	/* name mounted on */
8451139Sbostic 
8551139Sbostic /* On-disk structure. */
8651139Sbostic 	LFS_SUPER fs_super;
8751139Sbostic } LFS;
8851139Sbostic 
8951139Sbostic #define	fs_bmask	fs_super.lfs_bmask
9051139Sbostic #define	fs_bshift	fs_super.lfs_bshift
9151139Sbostic #define	fs_bsize	fs_super.lfs_bsize
9251139Sbostic #define	fs_dsize	fs_super.lfs_dsize
9351139Sbostic #define	fs_fbmask	fs_super.lfs_fbmask
9451139Sbostic #define	fs_fbshift	fs_super.lfs_fbshift
9551139Sbostic #define	fs_ffmask	fs_super.lfs_ffmask
9651139Sbostic #define	fs_ffshift	fs_super.lfs_ffshift
9751139Sbostic #define	fs_frag		fs_super.lfs_frag
9851139Sbostic #define	fs_free		fs_super.lfs_free
9951139Sbostic #define	fs_fsbtodb	fs_super.lfs_fsbtodb
10051139Sbostic #define	fs_fsize	fs_super.lfs_fsize
10151139Sbostic #define	fs_idaddr	fs_super.lfs_idaddr
10251139Sbostic #define	fs_ifile	fs_super.lfs_ifile
10351139Sbostic #define	fs_ifpb		fs_super.lfs_ifpb
10451139Sbostic #define	fs_inopb	fs_super.lfs_inopb
10551139Sbostic #define	fs_lastseg	fs_super.lfs_lastseg
10651139Sbostic #define	fs_magic	fs_super.lfs_magic
10751139Sbostic #define	fs_minfree	fs_super.lfs_minfree
10851139Sbostic #define	fs_nindir	fs_super.lfs_nindir
10951139Sbostic #define	fs_nseg		fs_super.lfs_nseg
11051139Sbostic #define	fs_nspf		fs_super.lfs_nspf
11151139Sbostic #define	fs_sboffs	fs_super.lfs_sboffs
11251139Sbostic #define	fs_sbsize	fs_super.lfs_sbsize
11351139Sbostic #define	fs_segmask	fs_super.lfs_segmask
11451139Sbostic #define	fs_segshift	fs_super.lfs_segshift
11551139Sbostic #define	fs_segtabsz	fs_super.lfs_segtabsz
11651139Sbostic #define	fs_size		fs_super.lfs_size
11751139Sbostic #define	fs_ssize	fs_super.lfs_ssize
11851139Sbostic #define	fs_tstamp	fs_super.lfs_tstamp
11951139Sbostic #define	fs_version	fs_super.lfs_version
12051139Sbostic 
121*51140Sbostic /* Fixed inode numbers. */
122*51140Sbostic #define	LFS_UNUSED_INUM	0		/* Out of band inode number. */
123*51140Sbostic #define	LFS_IFILE_INUM	1		/* Inode number of the ifile. */
124*51140Sbostic #define	LFS_FIRST_INUM	2		/* First free inode number. */
12551139Sbostic 
126*51140Sbostic /*
127*51140Sbostic  * Used to access the first spare of the dinode which we use to store
128*51140Sbostic  * the ifile number so we can identify them
129*51140Sbostic  */
130*51140Sbostic #define	di_inum	di_spare[0]
131*51140Sbostic 
13251139Sbostic typedef struct ifile {
13351139Sbostic 	u_long	if_version;		/* inode version number */
13451139Sbostic #define	UNUSED_DADDR	0		/* out-of-band daddr */
13551139Sbostic 	daddr_t	if_daddr;		/* inode disk address */
13651139Sbostic 	union {
13751139Sbostic 		ino_t	nextfree;	/* next-unallocated inode */
13851139Sbostic 		time_t	st_atime;	/* access time */
13951139Sbostic 	} __ifile_u;
140*51140Sbostic #define	if_st_atime	__ifile_u.st_atime
141*51140Sbostic #define	if_nextfree	__ifile_u.nextfree
14251139Sbostic } IFILE;
14351139Sbostic 
14451139Sbostic /* Segment table size, in blocks. */
14551139Sbostic #define	SEGTABSIZE(fs) \
14651139Sbostic 	(((fs)->fs_nseg * sizeof(SEGUSAGE) + \
14751139Sbostic 	    ((fs)->fs_bsize - 1)) << (fs)->fs_bshift)
14851139Sbostic 
149*51140Sbostic #define	SEGTABSIZE_SU(fs) \
150*51140Sbostic 	(((fs)->lfs_nseg * sizeof(SEGUSAGE) + \
151*51140Sbostic 	    ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift)
152*51140Sbostic 
15351139Sbostic /* In-memory and on-disk checkpoint segment usage structure. */
15451139Sbostic typedef struct segusage {
15551139Sbostic 	u_long	su_nbytes;		/* number of live bytes */
15651139Sbostic 	u_long	su_lastmod;		/* last modified timestamp */
157*51140Sbostic #define	SEGUSAGE_DIRTY			0x1
158*51140Sbostic 	u_long	su_flags;
15951139Sbostic } SEGUSAGE;
16051139Sbostic 
161*51140Sbostic /*
162*51140Sbostic  * All summary blocks are the same size, so we can always read a summary
163*51140Sbostic  * block easily from a segment
164*51140Sbostic  */
165*51140Sbostic #define	LFS_SUMMARY_SIZE	512
166*51140Sbostic 
16751139Sbostic /* On-disk segment summary information */
16851139Sbostic typedef struct segsum {
16951139Sbostic 	daddr_t	ss_next;		/* next segment */
17051139Sbostic 	daddr_t	ss_prev;		/* next segment */
17151139Sbostic 	daddr_t	ss_nextsum;		/* next summary block */
17251139Sbostic 	u_long	ss_create;		/* creation time stamp */
17351139Sbostic 	u_long	ss_nfinfo;		/* number of file info structures */
17451139Sbostic 	u_long	ss_niinfo;		/* number of inode info structures */
17551139Sbostic 	u_long	ss_cksum;		/* check sum */
17651139Sbostic } SEGSUM;
17751139Sbostic 
17851139Sbostic /* On-disk file information.  One per file with data blocks in the segment. */
17951139Sbostic typedef struct finfo {
18051139Sbostic 	u_long	fi_nblocks;		/* number of blocks */
18151139Sbostic 	u_long	fi_version;		/* version number */
18251139Sbostic 	ino_t	fi_ino;			/* inode number */
18351139Sbostic 	u_long	fi_blocks[1];		/* array of logical block numbers */
18451139Sbostic } FINFO;
18551139Sbostic 
18651139Sbostic /* On-disk inode information.  One per block of inodes in the segment. */
18751139Sbostic typedef struct iinfo {
18851139Sbostic 	u_long	ii_ninodes;		/* number of inodes */
18951139Sbostic 	ino_t	ii_inodes;		/* array of inode numbers */
19051139Sbostic } IINFO;
191