1*55860Sbostic /*-
2*55860Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*55860Sbostic  * All rights reserved.
4*55860Sbostic  *
5*55860Sbostic  * %sccs.include.redist.c%
6*55860Sbostic  *
7*55860Sbostic  *	@(#)clean.h	5.1 (Berkeley) 08/06/92
8*55860Sbostic  */
9*55860Sbostic 
1055491Sbostic /*
1155491Sbostic  * The LFS user-level library will be used when writing cleaners and
12*55860Sbostic  * checkers for LFS file systems.  It will have facilities for finding
13*55860Sbostic  * and parsing LFS segments.
1455491Sbostic  */
1555491Sbostic 
1655855Sbostic #define DUMP_SUM_HEADER		0x0001
1755855Sbostic #define DUMP_INODE_ADDRS	0x0002
1855855Sbostic #define DUMP_FINFOS		0x0004
1955855Sbostic #define	DUMP_ALL		0xFFFF
2055855Sbostic 
2155491Sbostic #define IFILE_NAME "ifile"
2255491Sbostic 
2355855Sbostic /*
2455855Sbostic  * Cleaner parameters
2555855Sbostic  *	BUSY_LIM: lower bound of the number of segments currently available
2655855Sbostic  *		as a percentage of the total number of free segments possibly
2755855Sbostic  *		available.
2855855Sbostic  *	IDLE_LIM: Same as BUSY_LIM but used when the system is idle.
2955855Sbostic  *	MIN_SEGS: Minimum number of segments you should always have.
3055855Sbostic  *		I have no idea what this should be, but it should probably
3155855Sbostic  *		be a function of lfsp.
3255855Sbostic  *	NUM_TO_CLEAN: Number of segments to clean at once.  Again, this
3355855Sbostic  *		should probably be based on the file system size and how
3455855Sbostic  *		full or empty the segments being cleaned are.
3555855Sbostic  */
3655855Sbostic 
3755855Sbostic #define	BUSY_LIM	0.50
3855855Sbostic #define	IDLE_LIM	0.90
39*55860Sbostic 
40*55860Sbostic #define	MIN_SEGS(lfsp)		(3)
4155855Sbostic #define	NUM_TO_CLEAN(fsp)	(5)
4255855Sbostic 
4355855Sbostic #define MAXLOADS	3
44*55860Sbostic #define	ONE_MIN		0
45*55860Sbostic #define	FIVE_MIN	1
46*55860Sbostic #define	FIFTEEN_MIN	2
4755855Sbostic 
4855491Sbostic typedef struct fs_info {
4955491Sbostic 	struct	statfs	*fi_statfsp;	/* fsstat info from getfsstat */
5055855Sbostic 	struct	lfs	fi_lfs;		/* superblock */
5155855Sbostic 	CLEANERINFO	*fi_cip;	/* Cleaner info from ifile */
5255491Sbostic 	SEGUSE	*fi_segusep;		/* segment usage table (from ifile) */
5355491Sbostic 	IFILE	*fi_ifilep;		/* ifile table (from ifile) */
5455491Sbostic 	u_long	fi_daddr_shift;		/* shift to get byte offset of daddr */
5555491Sbostic 	u_long	fi_ifile_count;		/* # entries in the ifile table */
5655855Sbostic 	off_t	fi_ifile_length;	/* length of the ifile */
5755491Sbostic } FS_INFO;
5855491Sbostic 
5955491Sbostic /*
6055491Sbostic  * XXX: size (in bytes) of a segment
6155491Sbostic  *	should lfs_bsize be fsbtodb(fs,1), blksize(fs), or lfs_dsize?
6255491Sbostic  */
6355855Sbostic #define seg_size(fs) ((fs)->lfs_ssize << (fs)->lfs_bshift)
6455491Sbostic 
6555491Sbostic /* daddr -> byte offset */
6655855Sbostic #define datobyte(fs, da) ((da) << (fs)->fi_daddr_shift)
6755855Sbostic #define bytetoda(fs, byte) ((byte) >> (fs)->fi_daddr_shift)
6855491Sbostic 
6955855Sbostic #define CLEANSIZE(fsp)	(fsp->fi_lfs.lfs_cleansz << fsp->fi_lfs.lfs_bshift)
7055855Sbostic #define SEGTABSIZE(fsp)	(fsp->fi_lfs.lfs_segtabsz << fsp->fi_lfs.lfs_bshift)
7155491Sbostic 
7255855Sbostic #define IFILE_ENTRY(fs, if, i) \
7355855Sbostic 	((IFILE *)((caddr_t)(if) + ((i) / (fs)->lfs_ifpb << (fs)->lfs_bshift)) \
7455855Sbostic 	+ (i) % (fs)->lfs_ifpb)
7555491Sbostic 
7655855Sbostic #define SEGUSE_ENTRY(fs, su, i) \
7755855Sbostic 	((SEGUSE *)((caddr_t)(su) + (fs)->lfs_bsize * ((i) / (fs)->lfs_sepb)) +\
7855855Sbostic 	(i) % (fs)->lfs_sepb)
7955491Sbostic 
8055855Sbostic __BEGIN_DECLS
8155855Sbostic int	 dump_summary __P((struct lfs *, SEGSUM *, u_long, daddr_t **));
8255855Sbostic void	 err __P((const int, const char *, ...));
8355855Sbostic int	 fs_getmntinfo __P((struct statfs **, int));
8455855Sbostic int	 get __P((int, off_t, void *, size_t));
8555855Sbostic FS_INFO	*get_fs_info __P((struct statfs *, int));
8655855Sbostic int 	 lfs_segmapv __P((FS_INFO *, int, caddr_t, BLOCK_INFO **, int *,
8755855Sbostic 	     INODE_INFO **, int *));
8855855Sbostic int	 mmap_segment __P((FS_INFO *, int, caddr_t *));
8955855Sbostic void	 munmap_segment __P((FS_INFO *, caddr_t));
9055855Sbostic void	 reread_fs_info __P((FS_INFO *, int));
9155855Sbostic void	 toss __P((void *, int *, size_t,
9255855Sbostic 	      int (*)(const void *, const void *, const void *), void *));
9355491Sbostic 
9455491Sbostic /*
9555855Sbostic  * USEFUL DEBUGGING FUNCTIONS:
9655491Sbostic  */
9755855Sbostic #ifdef VERBOSE
9855855Sbostic #define PRINT_FINFO(fp, ip) { \
9955855Sbostic 	(void)printf("    %s %s%d version %d nblocks %d\n", \
10055855Sbostic 	    (ip)->if_version > (fp)->fi_version ? "TOSSING" : "KEEPING", \
10155855Sbostic 	    "FINFO for inode: ", (fp)->fi_ino, \
10255855Sbostic 	    (fp)->fi_version, (fp)->fi_nblocks); \
10355855Sbostic 	fflush(stdout); \
10455855Sbostic }
10555491Sbostic 
10655855Sbostic #define PRINT_IINFO(b, iip) { \
10755855Sbostic 	(void) printf("\t%s inode: %d daddr: 0x%lx create: %s\n", \
10855855Sbostic 	    b ? "KEEPING" : "TOSSING", (iip)->ii_inode, (iip)->ii_daddr, \
10955855Sbostic 	    ctime((time_t *)&(iip)->ii_segcreate)); \
11055855Sbostic 	fflush(stdout); \
11155855Sbostic }
11255491Sbostic 
11355855Sbostic #define PRINT_BINFO(bip) { \
11455855Sbostic 	(void)printf("\tinode: %d lbn: %d daddr: 0x%lx create: %s\n", \
11555855Sbostic 	    (bip)->bi_inode, (bip)->bi_lbn, (bip)->bi_daddr, \
11655855Sbostic 	    ctime((time_t *)&(bip)->bi_segcreate)); \
11755855Sbostic 	fflush(stdout); \
11855855Sbostic }
11955491Sbostic 
12055855Sbostic #define PRINT_SEGUSE(sup, n) { \
12155855Sbostic 	(void)printf("Segment %d nbytes=%lu\tflags=%c%c%c ninos=%d nsums=%d lastmod: %s\n", \
12255855Sbostic 			n, (sup)->su_nbytes, \
12355855Sbostic 			(sup)->su_flags & SEGUSE_DIRTY ? 'D' : 'C', \
12455855Sbostic 			(sup)->su_flags & SEGUSE_ACTIVE ? 'A' : ' ', \
12555855Sbostic 			(sup)->su_flags & SEGUSE_SUPERBLOCK ? 'S' : ' ', \
12655855Sbostic 			(sup)->su_ninos, (sup)->su_nsums, \
12755855Sbostic 			ctime((time_t *)&(sup)->su_lastmod)); \
12855855Sbostic 	fflush(stdout); \
12955855Sbostic }
13055491Sbostic 
13155855Sbostic void	 dump_super __P((struct lfs *));
13255855Sbostic void	 dump_cleaner_info __P((void *));
13355855Sbostic void	 print_SEGSUM __P(( struct lfs *, SEGSUM *));
13455855Sbostic void	 print_CLEANERINFO __P((CLEANERINFO *));
13555855Sbostic #else
13655855Sbostic #define	PRINT_FINFO(fp, ip)
13755855Sbostic #define	PRINT_IINFO(b, iip)
13855855Sbostic #define PRINT_BINFO(bip)
13955855Sbostic #define	PRINT_SEGUSE(sup, n)
14055855Sbostic #define	dump_cleaner_info(cip)
14155855Sbostic #define	dump_super(lfsp)
14255855Sbostic #endif
14355855Sbostic __END_DECLS
144