155860Sbostic /*-
261433Sbostic  * Copyright (c) 1992, 1993
361433Sbostic  *	The Regents of the University of California.  All rights reserved.
455860Sbostic  *
555860Sbostic  * %sccs.include.redist.c%
655860Sbostic  *
7*69256Smckusick  *	@(#)clean.h	8.2 (Berkeley) 05/04/95
855860Sbostic  */
955860Sbostic 
1055491Sbostic /*
1155491Sbostic  * The LFS user-level library will be used when writing cleaners and
1255860Sbostic  * checkers for LFS file systems.  It will have facilities for finding
1355860Sbostic  * 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
3955860Sbostic 
4055860Sbostic #define	MIN_SEGS(lfsp)		(3)
4156087Sbostic #define	NUM_TO_CLEAN(fsp)	(1)
4255855Sbostic 
4355855Sbostic #define MAXLOADS	3
4455860Sbostic #define	ONE_MIN		0
4555860Sbostic #define	FIVE_MIN	1
4655860Sbostic #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 *, ...));
83*69256Smckusick int	 fs_getmntinfo __P((struct statfs **, char *, char *));
8455855Sbostic int	 get __P((int, off_t, void *, size_t));
8561371Scgd FS_INFO	*get_fs_info __P((struct statfs *, int));
8655929Sbostic int 	 lfs_segmapv __P((FS_INFO *, int, caddr_t, BLOCK_INFO **, int *));
8757199Smargo int	 mmap_segment __P((FS_INFO *, int, caddr_t *, int));
8857199Smargo void	 munmap_segment __P((FS_INFO *, caddr_t, int));
8961371Scgd void	 reread_fs_info __P((FS_INFO *, int));
9055855Sbostic void	 toss __P((void *, int *, size_t,
9155855Sbostic 	      int (*)(const void *, const void *, const void *), void *));
9255491Sbostic 
9355491Sbostic /*
9455855Sbostic  * USEFUL DEBUGGING FUNCTIONS:
9555491Sbostic  */
9655855Sbostic #ifdef VERBOSE
9755855Sbostic #define PRINT_FINFO(fp, ip) { \
9855855Sbostic 	(void)printf("    %s %s%d version %d nblocks %d\n", \
9955855Sbostic 	    (ip)->if_version > (fp)->fi_version ? "TOSSING" : "KEEPING", \
10055855Sbostic 	    "FINFO for inode: ", (fp)->fi_ino, \
10155855Sbostic 	    (fp)->fi_version, (fp)->fi_nblocks); \
10255855Sbostic 	fflush(stdout); \
10355855Sbostic }
10455491Sbostic 
10556035Sbostic #define PRINT_INODE(b, bip) { \
10655855Sbostic 	(void) printf("\t%s inode: %d daddr: 0x%lx create: %s\n", \
10755929Sbostic 	    b ? "KEEPING" : "TOSSING", (bip)->bi_inode, (bip)->bi_daddr, \
10855929Sbostic 	    ctime((time_t *)&(bip)->bi_segcreate)); \
10955855Sbostic 	fflush(stdout); \
11055855Sbostic }
11155491Sbostic 
11255855Sbostic #define PRINT_BINFO(bip) { \
11355855Sbostic 	(void)printf("\tinode: %d lbn: %d daddr: 0x%lx create: %s\n", \
11455855Sbostic 	    (bip)->bi_inode, (bip)->bi_lbn, (bip)->bi_daddr, \
11555855Sbostic 	    ctime((time_t *)&(bip)->bi_segcreate)); \
11655855Sbostic 	fflush(stdout); \
11755855Sbostic }
11855491Sbostic 
11955855Sbostic #define PRINT_SEGUSE(sup, n) { \
12055855Sbostic 	(void)printf("Segment %d nbytes=%lu\tflags=%c%c%c ninos=%d nsums=%d lastmod: %s\n", \
12155855Sbostic 			n, (sup)->su_nbytes, \
12255855Sbostic 			(sup)->su_flags & SEGUSE_DIRTY ? 'D' : 'C', \
12355855Sbostic 			(sup)->su_flags & SEGUSE_ACTIVE ? 'A' : ' ', \
12455855Sbostic 			(sup)->su_flags & SEGUSE_SUPERBLOCK ? 'S' : ' ', \
12555855Sbostic 			(sup)->su_ninos, (sup)->su_nsums, \
12655855Sbostic 			ctime((time_t *)&(sup)->su_lastmod)); \
12755855Sbostic 	fflush(stdout); \
12855855Sbostic }
12955491Sbostic 
13055855Sbostic void	 dump_super __P((struct lfs *));
13155855Sbostic void	 dump_cleaner_info __P((void *));
13255855Sbostic void	 print_SEGSUM __P(( struct lfs *, SEGSUM *));
13355855Sbostic void	 print_CLEANERINFO __P((CLEANERINFO *));
13455855Sbostic #else
13555855Sbostic #define	PRINT_FINFO(fp, ip)
13656035Sbostic #define	PRINT_INODE(b, bip)
13755855Sbostic #define PRINT_BINFO(bip)
13855855Sbostic #define	PRINT_SEGUSE(sup, n)
13955855Sbostic #define	dump_cleaner_info(cip)
14055855Sbostic #define	dump_super(lfsp)
14155855Sbostic #endif
14255855Sbostic __END_DECLS
143