xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 51183)
151139Sbostic /*-
251139Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351139Sbostic  * All rights reserved.
451139Sbostic  *
551139Sbostic  * %sccs.include.redist.c%
651139Sbostic  *
7*51183Sbostic  *	@(#)lfs.h	5.4 (Berkeley) 09/25/91
851139Sbostic  */
951139Sbostic 
10*51183Sbostic typedef struct buf	BUF;
11*51183Sbostic typedef struct dinode	DINODE;
12*51183Sbostic typedef struct inode	INODE;
13*51183Sbostic typedef struct mount	MOUNT;
14*51183Sbostic typedef struct ucred	UCRED;
15*51183Sbostic typedef struct ufsmount	UFSMOUNT;
16*51183Sbostic typedef struct vnode	VNODE;
17*51183Sbostic 
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. */
23*51183Sbostic typedef struct segusage SEGUSE;
24*51183Sbostic struct segusage {
2551155Sbostic 	u_long	su_nbytes;		/* number of live bytes */
2651155Sbostic 	u_long	su_lastmod;		/* last modified timestamp */
27*51183Sbostic #define	SEGUSE_DIRTY	0x1		/* XXX fill in comment */
2851155Sbostic 	u_long	su_flags;
29*51183Sbostic };
3051155Sbostic 
31*51183Sbostic /* On-disk file information.  One per file with data blocks in the segment. */
32*51183Sbostic typedef struct finfo FINFO;
33*51183Sbostic struct finfo {
34*51183Sbostic 	u_long	fi_nblocks;		/* number of blocks */
35*51183Sbostic 	u_long	fi_version;		/* version number */
36*51183Sbostic 	ino_t	fi_ino;			/* inode number */
37*51183Sbostic 	long	fi_blocks[1];		/* array of logical block numbers */
38*51183Sbostic };
39*51183Sbostic 
40*51183Sbostic /* In-memory description of a segment about to be written */
41*51183Sbostic typedef struct segment SEGMENT;
42*51183Sbostic struct segment {
43*51183Sbostic 	SEGMENT	*nextp;			/* Links segments together */
44*51183Sbostic 	BUF	**bpp;			/* Pointer to buffer array */
45*51183Sbostic 	BUF	**cbpp;			/* Pointer to next available bp */
46*51183Sbostic 	void	*segsum;		/* Segment Summary info */
47*51183Sbostic 	u_long	sum_bytes_left;		/* Bytes left in summary */
48*51183Sbostic 	u_long	seg_bytes_left;		/* Bytes left in segment */
49*51183Sbostic 	daddr_t	saddr;			/* Current disk address */
50*51183Sbostic 	daddr_t	sum_addr;		/* Address of current summary */
51*51183Sbostic 	u_long	ninodes;		/* Number of inodes in this segment */
52*51183Sbostic 	u_long	sum_num;		/* Number of current summary block */
53*51183Sbostic 	u_long	seg_number;		/* Number of this segment */
54*51183Sbostic 	FINFO	*fip;			/* Current fileinfo pointer */
55*51183Sbostic };
56*51183Sbostic 
5751155Sbostic /* On-disk and in-memory super block. */
58*51183Sbostic typedef struct lfs LFS;
59*51183Sbostic struct lfs {
6051155Sbostic #define	LFS_MAGIC	0xbedead
6151139Sbostic 	u_long	lfs_magic;		/* magic number */
6251140Sbostic #define	LFS_VERSION	1
6351139Sbostic 	u_long	lfs_version;		/* version number */
6451139Sbostic 
6551139Sbostic 	u_long	lfs_size;		/* number of blocks in fs */
6651139Sbostic 	u_long	lfs_ssize;		/* number of blocks per segment */
6751139Sbostic 	u_long	lfs_dsize;		/* number of data blocks in fs */
6851139Sbostic 	u_long	lfs_bsize;		/* size of basic blocks in fs */
6951139Sbostic 	u_long	lfs_fsize;		/* size of frag blocks in fs */
7051139Sbostic 	u_long	lfs_frag;		/* number of frags in a block in fs */
7151139Sbostic 
7251139Sbostic /* Checkpoint region. */
7351139Sbostic 	ino_t	lfs_free;		/* start of the free list */
7451155Sbostic 	u_long	lfs_bfree;		/* number of free blocks */
7551155Sbostic 	u_long	lfs_nfiles;		/* number of allocated inodes */
7651139Sbostic 	daddr_t	lfs_idaddr;		/* inode file disk address */
7751139Sbostic 	ino_t	lfs_ifile;		/* inode file inode number */
7851139Sbostic 	daddr_t	lfs_lastseg;		/* last segment written */
7951155Sbostic 	daddr_t	lfs_nextseg;		/* next segment to write */
8051139Sbostic 	u_long	lfs_tstamp;		/* time stamp */
8151139Sbostic 
8251139Sbostic /* These are configuration parameters. */
8351139Sbostic 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
8451139Sbostic 
8551139Sbostic /* These fields can be computed from the others. */
8651139Sbostic 	u_long	lfs_inopb;		/* inodes per block */
8751139Sbostic 	u_long	lfs_ifpb;		/* IFILE entries per block */
8851139Sbostic 	u_long	lfs_nindir;		/* indirect pointers per block */
8951139Sbostic 	u_long	lfs_nseg;		/* number of segments */
9051139Sbostic 	u_long	lfs_nspf;		/* number of sectors per fragment */
9151139Sbostic 	u_long	lfs_segtabsz;		/* segment table size in blocks */
9251139Sbostic 
9351139Sbostic 	u_long	lfs_segmask;		/* calculate offset within a segment */
9451139Sbostic 	u_long	lfs_segshift;		/* fast mult/div for segments */
9551139Sbostic 	u_long	lfs_bmask;		/* calc block offset from file offset */
9651139Sbostic 	u_long	lfs_bshift;		/* calc block number from file offset */
9751139Sbostic 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
9851139Sbostic 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
9951139Sbostic 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
10051139Sbostic 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
10151139Sbostic 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
10251139Sbostic 
10351155Sbostic #define	LFS_MIN_SBINTERVAL	5	/* minimum superblock segment spacing */
10451155Sbostic #define	LFS_MAXNUMSB		10	/* superblock disk offsets */
10551155Sbostic 	daddr_t	lfs_sboffs[LFS_MAXNUMSB];
10651139Sbostic 
10751155Sbostic /* These fields are set at mount time and are meaningless on disk. */
108*51183Sbostic 	VNODE	*lfs_ivnode;		/* vnode for the ifile */
10951155Sbostic 	SEGUSE	*lfs_segtab;		/* in-memory segment usage table */
110*51183Sbostic 	SEGMENT	*lfs_seglist;		/* list of segments being written */
111*51183Sbostic 	u_long	lfs_iocount;		/* Number of ios pending */
11251155Sbostic 	u_char	lfs_fmod;		/* super block modified flag */
11351155Sbostic 	u_char	lfs_clean;		/* file system is clean flag */
11451155Sbostic 	u_char	lfs_ronly;		/* mounted read-only flag */
11551155Sbostic 	u_char	lfs_flags;		/* currently unused flag */
11651155Sbostic 	u_char	lfs_fsmnt[MAXMNTLEN];	/* name mounted on */
11751155Sbostic 	u_char	pad[3];			/* long-align */
11851139Sbostic 
11951155Sbostic /* Checksum; valid on disk. */
12051155Sbostic 	u_long	lfs_cksum;		/* checksum for superblock checking */
121*51183Sbostic };
12251139Sbostic 
12351155Sbostic /*
12451155Sbostic  * The root inode is the root of the file system.  Inode 0 is the out-of-band
12551155Sbostic  * inode, and inode 1 is the inode number for the ifile.  Thus the root inode
12651155Sbostic  * is 2.
12751155Sbostic  */
12851155Sbostic #define ROOTINO         ((ino_t)2)
12951155Sbostic #define	LOSTFOUNDINO	((ino_t)3)
13051139Sbostic 
13151140Sbostic /* Fixed inode numbers. */
13251140Sbostic #define	LFS_UNUSED_INUM	0		/* Out of band inode number. */
13351140Sbostic #define	LFS_IFILE_INUM	1		/* Inode number of the ifile. */
13451155Sbostic 					/* First free inode number. */
13551155Sbostic #define	LFS_FIRST_INUM	(LOSTFOUNDINO + 1)
13651139Sbostic 
13751155Sbostic /*
13851140Sbostic  * Used to access the first spare of the dinode which we use to store
13951140Sbostic  * the ifile number so we can identify them
14051140Sbostic  */
14151140Sbostic #define	di_inum	di_spare[0]
14251140Sbostic 
143*51183Sbostic /*
144*51183Sbostic  * Logical block numbers of indirect blocks.
145*51183Sbostic  */
146*51183Sbostic #define S_INDIR	-1
147*51183Sbostic #define D_INDIR -2
148*51183Sbostic #define T_INDIR -3
149*51183Sbostic 
150*51183Sbostic typedef struct ifile IFILE;
151*51183Sbostic struct ifile {
15251139Sbostic 	u_long	if_version;		/* inode version number */
15351155Sbostic #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
15451139Sbostic 	daddr_t	if_daddr;		/* inode disk address */
15551139Sbostic 	union {
15651139Sbostic 		ino_t	nextfree;	/* next-unallocated inode */
15751139Sbostic 		time_t	st_atime;	/* access time */
15851139Sbostic 	} __ifile_u;
15951140Sbostic #define	if_st_atime	__ifile_u.st_atime
16051140Sbostic #define	if_nextfree	__ifile_u.nextfree
161*51183Sbostic };
16251139Sbostic 
16351139Sbostic /* Segment table size, in blocks. */
16451139Sbostic #define	SEGTABSIZE(fs) \
16551155Sbostic 	(((fs)->fs_nseg * sizeof(SEGUSE) + \
16651155Sbostic 	    ((fs)->fs_bsize - 1)) >> (fs)->fs_bshift)
16751139Sbostic 
16851140Sbostic #define	SEGTABSIZE_SU(fs) \
16951155Sbostic 	(((fs)->lfs_nseg * sizeof(SEGUSE) + \
17051140Sbostic 	    ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift)
17151140Sbostic 
17251140Sbostic /*
17351140Sbostic  * All summary blocks are the same size, so we can always read a summary
17451140Sbostic  * block easily from a segment
17551140Sbostic  */
17651140Sbostic #define	LFS_SUMMARY_SIZE	512
17751140Sbostic 
17851139Sbostic /* On-disk segment summary information */
179*51183Sbostic typedef struct segsum SEGSUM;
180*51183Sbostic struct segsum {
18151155Sbostic 	u_long	ss_cksum;		/* check sum */
18251139Sbostic 	daddr_t	ss_next;		/* next segment */
18351139Sbostic 	daddr_t	ss_prev;		/* next segment */
18451139Sbostic 	daddr_t	ss_nextsum;		/* next summary block */
18551139Sbostic 	u_long	ss_create;		/* creation time stamp */
18651139Sbostic 	u_long	ss_nfinfo;		/* number of file info structures */
18751155Sbostic 	u_long	ss_ninos;		/* number of inode blocks */
18851155Sbostic 	/* FINFO's... */
189*51183Sbostic };
19051139Sbostic 
19151155Sbostic /* NINDIR is the number of indirects in a file system block. */
19251155Sbostic #define	NINDIR(fs)	((fs)->lfs_nindir)
19351155Sbostic 
19451155Sbostic /* INOPB is the number of inodes in a secondary storage block. */
19551155Sbostic #define	INOPB(fs)	((fs)->lfs_inopb)
19651155Sbostic 
19751155Sbostic /* IFPB -- IFILE's per block */
19851155Sbostic #define	IFPB(fs)	((fs)->lfs_ifpb)
19951155Sbostic 
20051155Sbostic #define	blksize(fs)		((fs)->lfs_bsize)
20151155Sbostic #define	blkoff(fs, loc)		((loc) & (fs)->lfs_bmask)
20251155Sbostic #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
20351155Sbostic #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
20451155Sbostic #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
205*51183Sbostic #define numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
206*51183Sbostic 	((loc) >> (fs)->lfs_bshift)
207*51183Sbostic #define satosn(fs, saddr) \
208*51183Sbostic 	((int)((saddr - fs->lfs_sboffs[0]) / fsbtodb(fs, fs->lfs_ssize)))
209*51183Sbostic #define sntosa(fs, sn) \
210*51183Sbostic 	((daddr_t)(sn * (fs->lfs_ssize << fs->lfs_fsbtodb) + fs->lfs_sboffs[0]))
211