xref: /illumos-gate/usr/src/cmd/fs.d/udfs/fsck/fsck.h (revision bfbf29e2)
17c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*bfbf29e2SToomas Soome /*	  All Rights Reserved	*/
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate /*
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
67c478bd9Sstevel@tonic-gate  * All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
97c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
107c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
117c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
127c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
137c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
147c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
157c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
167c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
177c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
187c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
197c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
207c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, 1998-1999 by Sun Microsystems, Inc.
257c478bd9Sstevel@tonic-gate  * All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_FSCK_H
297c478bd9Sstevel@tonic-gate #define	_FSCK_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef __cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #define		MAXDUP		10	/* limit on dup blks (per inode) */
367c478bd9Sstevel@tonic-gate #define		MAXBAD		10	/* limit on bad blks (per inode) */
377c478bd9Sstevel@tonic-gate #define		MAXBUFSPACE	256*1024	/* maximum space to allocate */
387c478bd9Sstevel@tonic-gate 						/* to buffers */
397c478bd9Sstevel@tonic-gate #define		INOBUFSIZE	256*1024	/* size of buffer to read */
407c478bd9Sstevel@tonic-gate 						/* inodes in pass1 */
417c478bd9Sstevel@tonic-gate #define	MAXBSIZE	8192	/* maximum allowed block size */
427c478bd9Sstevel@tonic-gate #define	FIRSTAVDP	256
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifndef BUFSIZ
457c478bd9Sstevel@tonic-gate #define		BUFSIZ 1024
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #ifdef sparc
497c478bd9Sstevel@tonic-gate #define	SWAP16(x) (((x) & 0xff) << 8 | ((x) >> 8) & 0xff)
507c478bd9Sstevel@tonic-gate #define	SWAP32(x) (((x) & 0xff) << 24 | ((x) & 0xff00) << 8 | \
517c478bd9Sstevel@tonic-gate 	((x) & 0xff0000) >> 8 | ((x) >> 24) & 0xff)
527c478bd9Sstevel@tonic-gate #define	SWAP64(x) (SWAP32((x) >> 32) & 0xffffffff | SWAP32(x) << 32)
537c478bd9Sstevel@tonic-gate #else
547c478bd9Sstevel@tonic-gate #define	SWAP16(x) (x)
557c478bd9Sstevel@tonic-gate #define	SWAP32(x) (x)
567c478bd9Sstevel@tonic-gate #define	SWAP64(x) (x)
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	NOTBUSY 00		/* Not busy when busymarked is set */
607c478bd9Sstevel@tonic-gate #define		USTATE	01		/* inode not allocated */
617c478bd9Sstevel@tonic-gate #define		FSTATE	02		/* inode is file */
627c478bd9Sstevel@tonic-gate #define		DSTATE	03		/* inode is directory */
637c478bd9Sstevel@tonic-gate #define		DFOUND	04		/* directory found during descent */
647c478bd9Sstevel@tonic-gate #define		DCLEAR	05		/* directory is to be cleared */
657c478bd9Sstevel@tonic-gate #define		FCLEAR	06		/* file is to be cleared */
667c478bd9Sstevel@tonic-gate #define		SSTATE	07		/* inode is a shadow */
677c478bd9Sstevel@tonic-gate #define		SCLEAR	010		/* shadow is to be cleared */
687c478bd9Sstevel@tonic-gate #define	ESTATE	011		/* Inode extension */
697c478bd9Sstevel@tonic-gate #define	ECLEAR	012		/* inode extension is to be cleared */
707c478bd9Sstevel@tonic-gate #define	IBUSY	013		/* inode is marked busy by first pass */
717c478bd9Sstevel@tonic-gate #define	LSTATE	014		/* Link tags */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate struct dinode {
747c478bd9Sstevel@tonic-gate 	int dummy;
757c478bd9Sstevel@tonic-gate };
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * buffer cache structure.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate struct bufarea {
817c478bd9Sstevel@tonic-gate 	struct bufarea	*b_next;		/* free list queue */
827c478bd9Sstevel@tonic-gate 	struct bufarea	*b_prev;		/* free list queue */
837c478bd9Sstevel@tonic-gate 	daddr_t	b_bno;
847c478bd9Sstevel@tonic-gate 	int	b_size;
857c478bd9Sstevel@tonic-gate 	int	b_errs;
867c478bd9Sstevel@tonic-gate 	int	b_flags;
877c478bd9Sstevel@tonic-gate 	union {
887c478bd9Sstevel@tonic-gate 		char	*b_buf;			/* buffer space */
897c478bd9Sstevel@tonic-gate 		daddr_t	*b_indir;		/* indirect block */
907c478bd9Sstevel@tonic-gate 		struct	fs *b_fs;		/* super block */
917c478bd9Sstevel@tonic-gate 		struct	cg *b_cg;		/* cylinder group */
927c478bd9Sstevel@tonic-gate 		struct	dinode *b_dinode;	/* inode block */
937c478bd9Sstevel@tonic-gate 	} b_un;
947c478bd9Sstevel@tonic-gate 	char	b_dirty;
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define		B_INUSE 1
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define		MINBUFS		5	/* minimum number of buffers required */
100*bfbf29e2SToomas Soome 
101*bfbf29e2SToomas Soome extern struct log_vol_int_desc *lvintp;
102*bfbf29e2SToomas Soome extern struct lvid_iu *lviup;
103*bfbf29e2SToomas Soome extern struct space_bmap_desc *spacep;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define		dirty(bp)	(bp)->b_dirty = isdirty = 1
1067c478bd9Sstevel@tonic-gate #define		initbarea(bp) \
1077c478bd9Sstevel@tonic-gate 	(bp)->b_dirty = 0; \
1087c478bd9Sstevel@tonic-gate 	(bp)->b_bno = (daddr_t)-1; \
1097c478bd9Sstevel@tonic-gate 	(bp)->b_flags = 0;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate enum fixstate {DONTKNOW, NOFIX, FIX};
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate struct inodesc {
1147c478bd9Sstevel@tonic-gate 	enum fixstate id_fix;	/* policy on fixing errors */
1157c478bd9Sstevel@tonic-gate 	int (*id_func)();	/* function to be applied to blocks of inode */
1167c478bd9Sstevel@tonic-gate 	ino_t id_number;	/* inode number described */
1177c478bd9Sstevel@tonic-gate 	ino_t id_parent;	/* for DATA nodes, their parent */
1187c478bd9Sstevel@tonic-gate 	daddr_t id_blkno;	/* current block number being examined */
1197c478bd9Sstevel@tonic-gate 	int id_numfrags;	/* number of frags contained in block */
1207c478bd9Sstevel@tonic-gate 	offset_t id_filesize;	/* for DATA nodes, the size of the directory */
1217c478bd9Sstevel@tonic-gate 	int id_loc;		/* for DATA nodes, current location in dir */
1227c478bd9Sstevel@tonic-gate 	int id_entryno;		/* for DATA nodes, current entry number */
1237c478bd9Sstevel@tonic-gate 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
1247c478bd9Sstevel@tonic-gate 	char *id_name;		/* for DATA nodes, name to find or enter */
1257c478bd9Sstevel@tonic-gate 	char id_type;		/* type of descriptor, DATA or ADDR */
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate /* file types */
1287c478bd9Sstevel@tonic-gate #define		DATA	1
1297c478bd9Sstevel@tonic-gate #define		ADDR	2
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * File entry cache structures.
1337c478bd9Sstevel@tonic-gate  */
134*bfbf29e2SToomas Soome typedef struct fileinfo {
1357c478bd9Sstevel@tonic-gate 	struct	fileinfo *fe_nexthash;	/* next entry in hash chain */
1367c478bd9Sstevel@tonic-gate 	uint32_t fe_block;		/* location of this file entry */
1377c478bd9Sstevel@tonic-gate 	uint16_t fe_len;		/* size of file entry */
1387c478bd9Sstevel@tonic-gate 	uint16_t fe_lseen;		/* number of links seen */
1397c478bd9Sstevel@tonic-gate 	uint16_t fe_lcount;		/* count from the file entry */
1407c478bd9Sstevel@tonic-gate 	uint8_t	 fe_type;		/* type of file entry */
1417c478bd9Sstevel@tonic-gate 	uint8_t	 fe_state;		/* flag bits */
142*bfbf29e2SToomas Soome } fileinfo_t;
143*bfbf29e2SToomas Soome extern fileinfo_t *inphead, **inphash, *inpnext, *inplast;
144*bfbf29e2SToomas Soome extern long listmax;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	FEGROW 512
1477c478bd9Sstevel@tonic-gate 
148*bfbf29e2SToomas Soome extern char	*devname;	/* name of device being checked */
149*bfbf29e2SToomas Soome extern long	secsize;	/* actual disk sector size */
150*bfbf29e2SToomas Soome extern long	fsbsize;	/* file system block size (same as secsize) */
151*bfbf29e2SToomas Soome extern char	nflag;		/* assume a no response */
152*bfbf29e2SToomas Soome extern char	yflag;		/* assume a yes response */
153*bfbf29e2SToomas Soome extern int	debug;		/* output debugging info */
154*bfbf29e2SToomas Soome extern int	rflag;		/* check raw file systems */
155*bfbf29e2SToomas Soome extern int	fflag;		/* check regardless of clean flag (force) */
156*bfbf29e2SToomas Soome extern char	preen;		/* just fix normal inconsistencies */
157*bfbf29e2SToomas Soome extern char	mountedfs;	/* checking mounted device */
158*bfbf29e2SToomas Soome extern int	exitstat;	/* exit status (set to 8 if 'No' response) */
159*bfbf29e2SToomas Soome extern int	fsmodified;	/* 1 => write done to file system */
160*bfbf29e2SToomas Soome extern int	fsreadfd;	/* file descriptor for reading file system */
161*bfbf29e2SToomas Soome extern int	fswritefd;	/* file descriptor for writing file system */
162*bfbf29e2SToomas Soome 
163*bfbf29e2SToomas Soome extern int	iscorrupt;	/* known to be corrupt/inconsistent */
164*bfbf29e2SToomas Soome extern int	isdirty;	/* 1 => write pending to file system */
165*bfbf29e2SToomas Soome 
166*bfbf29e2SToomas Soome extern char	mountpoint[100]; /* string set to contain mount point */
167*bfbf29e2SToomas Soome 
168*bfbf29e2SToomas Soome extern char	*busymap;	/* ptr to primary blk busy map */
169*bfbf29e2SToomas Soome extern char	*freemap;	/* ptr to copy of disk map */
170*bfbf29e2SToomas Soome 
171*bfbf29e2SToomas Soome extern uint32_t part_start;
172*bfbf29e2SToomas Soome extern uint32_t part_len;
173*bfbf29e2SToomas Soome extern uint32_t part_bmp_bytes;
174*bfbf29e2SToomas Soome extern uint32_t part_bmp_sectors;
175*bfbf29e2SToomas Soome extern uint32_t part_bmp_loc;
176*bfbf29e2SToomas Soome extern uint32_t rootblock;
177*bfbf29e2SToomas Soome extern uint32_t rootlen;
178*bfbf29e2SToomas Soome extern uint32_t lvintblock;
179*bfbf29e2SToomas Soome extern uint32_t lvintlen;
180*bfbf29e2SToomas Soome 
181*bfbf29e2SToomas Soome extern daddr_t	n_blks;		/* number of blocks in use */
182*bfbf29e2SToomas Soome extern daddr_t	n_files;	/* number of files in use */
183*bfbf29e2SToomas Soome extern daddr_t	n_dirs;		/* number of dirs in use */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * bit map related macros
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate #define		bitloc(a, i)	((a)[(i)/NBBY])
1897c478bd9Sstevel@tonic-gate #define		setbit(a, i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1907c478bd9Sstevel@tonic-gate #define		clrbit(a, i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1917c478bd9Sstevel@tonic-gate #define		isset(a, i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1927c478bd9Sstevel@tonic-gate #define		isclr(a, i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define		setbmap(blkno)	setbit(blockmap, blkno)
1957c478bd9Sstevel@tonic-gate #define		testbmap(blkno)	isset(blockmap, blkno)
1967c478bd9Sstevel@tonic-gate #define		clrbmap(blkno)	clrbit(blockmap, blkno)
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate #define		setbusy(blkno)	setbit(busymap, blkno)
1997c478bd9Sstevel@tonic-gate #define		testbusy(blkno)	isset(busymap, blkno)
2007c478bd9Sstevel@tonic-gate #define		clrbusy(blkno)	clrbit(busymap, blkno)
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #define	fsbtodb(blkno) ((blkno) * (fsbsize / DEV_BSIZE))
2037c478bd9Sstevel@tonic-gate #define	dbtofsb(blkno) ((blkno) / (fsbsize / DEV_BSIZE))
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define		STOP	0x01
2067c478bd9Sstevel@tonic-gate #define		SKIP	0x02
2077c478bd9Sstevel@tonic-gate #define		KEEPON	0x04
2087c478bd9Sstevel@tonic-gate #define		ALTERED	0x08
2097c478bd9Sstevel@tonic-gate #define		FOUND	0x10
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate time_t time();
2127c478bd9Sstevel@tonic-gate struct dinode *ginode();
2137c478bd9Sstevel@tonic-gate struct inoinfo *getinoinfo();
2147c478bd9Sstevel@tonic-gate struct fileinfo *cachefile();
2157c478bd9Sstevel@tonic-gate ino_t allocino();
2167c478bd9Sstevel@tonic-gate int findino();
2177c478bd9Sstevel@tonic-gate char *setup();
2187c478bd9Sstevel@tonic-gate void markbusy(daddr_t, long);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #ifndef MNTTYPE_UDFS
2217c478bd9Sstevel@tonic-gate #define	MNTTYPE_UDFS		"udfs"
2227c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate #define	SPACEMAP_OFF 24
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #define	FID_LENGTH(fid)    (((sizeof (struct file_id) + \
2277c478bd9Sstevel@tonic-gate 		(fid)->fid_iulen + (fid)->fid_idlen - 2) + 3) & ~3)
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #define	EXTYPE(len) (((len) >> 30) & 3)
2307c478bd9Sstevel@tonic-gate #define	EXTLEN(len) ((len) & 0x3fffffff)
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /* Integrity descriptor types */
2337c478bd9Sstevel@tonic-gate #define	LVI_OPEN 0
2347c478bd9Sstevel@tonic-gate #define	LVI_CLOSE 1
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate #endif
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate #endif	/* _FSCK_H */
241