xref: /csrg-svn/sys/ufs/lfs/lfs.h (revision 51155)
151139Sbostic /*-
251139Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351139Sbostic  * All rights reserved.
451139Sbostic  *
551139Sbostic  * %sccs.include.redist.c%
651139Sbostic  *
7*51155Sbostic  *	@(#)lfs.h	5.3 (Berkeley) 09/20/91
851139Sbostic  */
951139Sbostic 
1051140Sbostic #define	LFS_LABELPAD	8192		/* LFS label size */
1151140Sbostic #define	LFS_SBPAD	8192		/* LFS superblock size */
1251140Sbostic #define MAXMNTLEN	512		/* XXX move from fs.h to mount.h */
1351139Sbostic 
14*51155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */
15*51155Sbostic typedef struct segusage {
16*51155Sbostic 	u_long	su_nbytes;		/* number of live bytes */
17*51155Sbostic 	u_long	su_lastmod;		/* last modified timestamp */
18*51155Sbostic #define	SEGUSE_DIRTY			0x1
19*51155Sbostic 	u_long	su_flags;
20*51155Sbostic } SEGUSE;
21*51155Sbostic 
22*51155Sbostic /* On-disk and in-memory super block. */
23*51155Sbostic typedef struct lfs {
24*51155Sbostic #define	LFS_MAGIC	0xbedead
2551139Sbostic 	u_long	lfs_magic;		/* magic number */
2651140Sbostic #define	LFS_VERSION	1
2751139Sbostic 	u_long	lfs_version;		/* version number */
2851139Sbostic 
2951139Sbostic 	u_long	lfs_size;		/* number of blocks in fs */
3051139Sbostic 	u_long	lfs_ssize;		/* number of blocks per segment */
3151139Sbostic 	u_long	lfs_dsize;		/* number of data blocks in fs */
3251139Sbostic 	u_long	lfs_bsize;		/* size of basic blocks in fs */
3351139Sbostic 	u_long	lfs_fsize;		/* size of frag blocks in fs */
3451139Sbostic 	u_long	lfs_frag;		/* number of frags in a block in fs */
3551139Sbostic 
3651139Sbostic /* Checkpoint region. */
3751139Sbostic 	ino_t	lfs_free;		/* start of the free list */
38*51155Sbostic 	u_long	lfs_bfree;		/* number of free blocks */
39*51155Sbostic 	u_long	lfs_nfiles;		/* number of allocated inodes */
4051139Sbostic 	daddr_t	lfs_idaddr;		/* inode file disk address */
4151139Sbostic 	ino_t	lfs_ifile;		/* inode file inode number */
4251139Sbostic 	daddr_t	lfs_lastseg;		/* last segment written */
43*51155Sbostic 	daddr_t	lfs_nextseg;		/* next segment to write */
4451139Sbostic 	u_long	lfs_tstamp;		/* time stamp */
4551139Sbostic 
4651139Sbostic /* These are configuration parameters. */
4751139Sbostic 	u_long	lfs_minfree;		/* minimum percentage of free blocks */
4851139Sbostic 
4951139Sbostic /* These fields can be computed from the others. */
5051139Sbostic 	u_long	lfs_inopb;		/* inodes per block */
5151139Sbostic 	u_long	lfs_ifpb;		/* IFILE entries per block */
5251139Sbostic 	u_long	lfs_nindir;		/* indirect pointers per block */
5351139Sbostic 	u_long	lfs_nseg;		/* number of segments */
5451139Sbostic 	u_long	lfs_nspf;		/* number of sectors per fragment */
5551139Sbostic 	u_long	lfs_segtabsz;		/* segment table size in blocks */
5651139Sbostic 
5751139Sbostic 	u_long	lfs_segmask;		/* calculate offset within a segment */
5851139Sbostic 	u_long	lfs_segshift;		/* fast mult/div for segments */
5951139Sbostic 	u_long	lfs_bmask;		/* calc block offset from file offset */
6051139Sbostic 	u_long	lfs_bshift;		/* calc block number from file offset */
6151139Sbostic 	u_long	lfs_ffmask;		/* calc frag offset from file offset */
6251139Sbostic 	u_long	lfs_ffshift;		/* fast mult/div for frag from file */
6351139Sbostic 	u_long	lfs_fbmask;		/* calc frag offset from block offset */
6451139Sbostic 	u_long	lfs_fbshift;		/* fast mult/div for frag from block */
6551139Sbostic 	u_long	lfs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
6651139Sbostic 
67*51155Sbostic #define	LFS_MIN_SBINTERVAL	5	/* minimum superblock segment spacing */
68*51155Sbostic #define	LFS_MAXNUMSB		10	/* superblock disk offsets */
69*51155Sbostic 	daddr_t	lfs_sboffs[LFS_MAXNUMSB];
7051139Sbostic 
71*51155Sbostic /* These fields are set at mount time and are meaningless on disk. */
72*51155Sbostic 	struct vnode *lfs_ivnode;	/* vnode for the ifile */
73*51155Sbostic 	SEGUSE	*lfs_segtab;		/* in-memory segment usage table */
74*51155Sbostic 	u_char	lfs_fmod;		/* super block modified flag */
75*51155Sbostic 	u_char	lfs_clean;		/* file system is clean flag */
76*51155Sbostic 	u_char	lfs_ronly;		/* mounted read-only flag */
77*51155Sbostic 	u_char	lfs_flags;		/* currently unused flag */
78*51155Sbostic 	u_char	lfs_fsmnt[MAXMNTLEN];	/* name mounted on */
79*51155Sbostic 	u_char	pad[3];			/* long-align */
8051139Sbostic 
81*51155Sbostic /* Checksum; valid on disk. */
82*51155Sbostic 	u_long	lfs_cksum;		/* checksum for superblock checking */
8351139Sbostic } LFS;
8451139Sbostic 
85*51155Sbostic /*
86*51155Sbostic  * The root inode is the root of the file system.  Inode 0 is the out-of-band
87*51155Sbostic  * inode, and inode 1 is the inode number for the ifile.  Thus the root inode
88*51155Sbostic  * is 2.
89*51155Sbostic  */
90*51155Sbostic #define ROOTINO         ((ino_t)2)
91*51155Sbostic #define	LOSTFOUNDINO	((ino_t)3)
9251139Sbostic 
9351140Sbostic /* Fixed inode numbers. */
9451140Sbostic #define	LFS_UNUSED_INUM	0		/* Out of band inode number. */
9551140Sbostic #define	LFS_IFILE_INUM	1		/* Inode number of the ifile. */
96*51155Sbostic 					/* First free inode number. */
97*51155Sbostic #define	LFS_FIRST_INUM	(LOSTFOUNDINO + 1)
9851139Sbostic 
99*51155Sbostic /*
10051140Sbostic  * Used to access the first spare of the dinode which we use to store
10151140Sbostic  * the ifile number so we can identify them
10251140Sbostic  */
10351140Sbostic #define	di_inum	di_spare[0]
10451140Sbostic 
10551139Sbostic typedef struct ifile {
10651139Sbostic 	u_long	if_version;		/* inode version number */
107*51155Sbostic #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
10851139Sbostic 	daddr_t	if_daddr;		/* inode disk address */
10951139Sbostic 	union {
11051139Sbostic 		ino_t	nextfree;	/* next-unallocated inode */
11151139Sbostic 		time_t	st_atime;	/* access time */
11251139Sbostic 	} __ifile_u;
11351140Sbostic #define	if_st_atime	__ifile_u.st_atime
11451140Sbostic #define	if_nextfree	__ifile_u.nextfree
11551139Sbostic } IFILE;
11651139Sbostic 
11751139Sbostic /* Segment table size, in blocks. */
11851139Sbostic #define	SEGTABSIZE(fs) \
119*51155Sbostic 	(((fs)->fs_nseg * sizeof(SEGUSE) + \
120*51155Sbostic 	    ((fs)->fs_bsize - 1)) >> (fs)->fs_bshift)
12151139Sbostic 
12251140Sbostic #define	SEGTABSIZE_SU(fs) \
123*51155Sbostic 	(((fs)->lfs_nseg * sizeof(SEGUSE) + \
12451140Sbostic 	    ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift)
12551140Sbostic 
12651140Sbostic /*
12751140Sbostic  * All summary blocks are the same size, so we can always read a summary
12851140Sbostic  * block easily from a segment
12951140Sbostic  */
13051140Sbostic #define	LFS_SUMMARY_SIZE	512
13151140Sbostic 
13251139Sbostic /* On-disk segment summary information */
13351139Sbostic typedef struct segsum {
134*51155Sbostic 	u_long	ss_cksum;		/* check sum */
13551139Sbostic 	daddr_t	ss_next;		/* next segment */
13651139Sbostic 	daddr_t	ss_prev;		/* next segment */
13751139Sbostic 	daddr_t	ss_nextsum;		/* next summary block */
13851139Sbostic 	u_long	ss_create;		/* creation time stamp */
13951139Sbostic 	u_long	ss_nfinfo;		/* number of file info structures */
140*51155Sbostic 	u_long	ss_ninos;		/* number of inode blocks */
141*51155Sbostic 	/* FINFO's... */
14251139Sbostic } SEGSUM;
14351139Sbostic 
14451139Sbostic /* On-disk file information.  One per file with data blocks in the segment. */
14551139Sbostic typedef struct finfo {
14651139Sbostic 	u_long	fi_nblocks;		/* number of blocks */
14751139Sbostic 	u_long	fi_version;		/* version number */
14851139Sbostic 	ino_t	fi_ino;			/* inode number */
14951139Sbostic 	u_long	fi_blocks[1];		/* array of logical block numbers */
15051139Sbostic } FINFO;
15151139Sbostic 
152*51155Sbostic /* NINDIR is the number of indirects in a file system block. */
153*51155Sbostic #define	NINDIR(fs)	((fs)->lfs_nindir)
154*51155Sbostic 
155*51155Sbostic /* INOPB is the number of inodes in a secondary storage block. */
156*51155Sbostic #define	INOPB(fs)	((fs)->lfs_inopb)
157*51155Sbostic 
158*51155Sbostic /* IFPB -- IFILE's per block */
159*51155Sbostic #define	IFPB(fs)	((fs)->lfs_ifpb)
160*51155Sbostic 
161*51155Sbostic #define	blksize(fs)		((fs)->lfs_bsize)
162*51155Sbostic #define	blkoff(fs, loc)		((loc) & (fs)->lfs_bmask)
163*51155Sbostic #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
164*51155Sbostic #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
165*51155Sbostic #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
166