xref: /titanic_50/usr/src/cmd/fs.d/udfs/fsck/fsck.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate /*
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
6*7c478bd9Sstevel@tonic-gate  * All rights reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
9*7c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
10*7c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
11*7c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
12*7c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
13*7c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
14*7c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
15*7c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
16*7c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
17*7c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
18*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20*7c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate /*
24*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, 1998-1999 by Sun Microsystems, Inc.
25*7c478bd9Sstevel@tonic-gate  * All rights reserved.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #ifndef	_FSCK_H
29*7c478bd9Sstevel@tonic-gate #define	_FSCK_H
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
34*7c478bd9Sstevel@tonic-gate extern "C" {
35*7c478bd9Sstevel@tonic-gate #endif
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #define		MAXDUP		10	/* limit on dup blks (per inode) */
38*7c478bd9Sstevel@tonic-gate #define		MAXBAD		10	/* limit on bad blks (per inode) */
39*7c478bd9Sstevel@tonic-gate #define		MAXBUFSPACE	256*1024	/* maximum space to allocate */
40*7c478bd9Sstevel@tonic-gate 						/* to buffers */
41*7c478bd9Sstevel@tonic-gate #define		INOBUFSIZE	256*1024	/* size of buffer to read */
42*7c478bd9Sstevel@tonic-gate 						/* inodes in pass1 */
43*7c478bd9Sstevel@tonic-gate #define	MAXBSIZE	8192	/* maximum allowed block size */
44*7c478bd9Sstevel@tonic-gate #define	FIRSTAVDP	256
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #ifndef BUFSIZ
47*7c478bd9Sstevel@tonic-gate #define		BUFSIZ 1024
48*7c478bd9Sstevel@tonic-gate #endif
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #ifdef sparc
51*7c478bd9Sstevel@tonic-gate #define	SWAP16(x) (((x) & 0xff) << 8 | ((x) >> 8) & 0xff)
52*7c478bd9Sstevel@tonic-gate #define	SWAP32(x) (((x) & 0xff) << 24 | ((x) & 0xff00) << 8 | \
53*7c478bd9Sstevel@tonic-gate 	((x) & 0xff0000) >> 8 | ((x) >> 24) & 0xff)
54*7c478bd9Sstevel@tonic-gate #define	SWAP64(x) (SWAP32((x) >> 32) & 0xffffffff | SWAP32(x) << 32)
55*7c478bd9Sstevel@tonic-gate #else
56*7c478bd9Sstevel@tonic-gate #define	SWAP16(x) (x)
57*7c478bd9Sstevel@tonic-gate #define	SWAP32(x) (x)
58*7c478bd9Sstevel@tonic-gate #define	SWAP64(x) (x)
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate #define	NOTBUSY 00		/* Not busy when busymarked is set */
62*7c478bd9Sstevel@tonic-gate #define		USTATE	01		/* inode not allocated */
63*7c478bd9Sstevel@tonic-gate #define		FSTATE	02		/* inode is file */
64*7c478bd9Sstevel@tonic-gate #define		DSTATE	03		/* inode is directory */
65*7c478bd9Sstevel@tonic-gate #define		DFOUND	04		/* directory found during descent */
66*7c478bd9Sstevel@tonic-gate #define		DCLEAR	05		/* directory is to be cleared */
67*7c478bd9Sstevel@tonic-gate #define		FCLEAR	06		/* file is to be cleared */
68*7c478bd9Sstevel@tonic-gate #define		SSTATE	07		/* inode is a shadow */
69*7c478bd9Sstevel@tonic-gate #define		SCLEAR	010		/* shadow is to be cleared */
70*7c478bd9Sstevel@tonic-gate #define	ESTATE	011		/* Inode extension */
71*7c478bd9Sstevel@tonic-gate #define	ECLEAR	012		/* inode extension is to be cleared */
72*7c478bd9Sstevel@tonic-gate #define	IBUSY	013		/* inode is marked busy by first pass */
73*7c478bd9Sstevel@tonic-gate #define	LSTATE	014		/* Link tags */
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate struct dinode {
76*7c478bd9Sstevel@tonic-gate 	int dummy;
77*7c478bd9Sstevel@tonic-gate };
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * buffer cache structure.
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate struct bufarea {
83*7c478bd9Sstevel@tonic-gate 	struct bufarea	*b_next;		/* free list queue */
84*7c478bd9Sstevel@tonic-gate 	struct bufarea	*b_prev;		/* free list queue */
85*7c478bd9Sstevel@tonic-gate 	daddr_t	b_bno;
86*7c478bd9Sstevel@tonic-gate 	int	b_size;
87*7c478bd9Sstevel@tonic-gate 	int	b_errs;
88*7c478bd9Sstevel@tonic-gate 	int	b_flags;
89*7c478bd9Sstevel@tonic-gate 	union {
90*7c478bd9Sstevel@tonic-gate 		char	*b_buf;			/* buffer space */
91*7c478bd9Sstevel@tonic-gate 		daddr_t	*b_indir;		/* indirect block */
92*7c478bd9Sstevel@tonic-gate 		struct	fs *b_fs;		/* super block */
93*7c478bd9Sstevel@tonic-gate 		struct	cg *b_cg;		/* cylinder group */
94*7c478bd9Sstevel@tonic-gate 		struct	dinode *b_dinode;	/* inode block */
95*7c478bd9Sstevel@tonic-gate 	} b_un;
96*7c478bd9Sstevel@tonic-gate 	char	b_dirty;
97*7c478bd9Sstevel@tonic-gate };
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #define		B_INUSE 1
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #define		MINBUFS		5	/* minimum number of buffers required */
102*7c478bd9Sstevel@tonic-gate struct bufarea bufhead;		/* head of list of other blks in filesys */
103*7c478bd9Sstevel@tonic-gate struct bufarea *pbp;		/* pointer to inode data in buffer pool */
104*7c478bd9Sstevel@tonic-gate struct bufarea *pdirbp;		/* pointer to directory data in buffer pool */
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate struct pri_vol_desc *pvolp;
107*7c478bd9Sstevel@tonic-gate struct vdp_desc *volp;
108*7c478bd9Sstevel@tonic-gate struct iuvd_desc *iudp;
109*7c478bd9Sstevel@tonic-gate struct part_desc *partp;
110*7c478bd9Sstevel@tonic-gate struct phdr_desc *pheadp;
111*7c478bd9Sstevel@tonic-gate struct log_vol_desc *logvp;
112*7c478bd9Sstevel@tonic-gate struct unall_desc *unallp;
113*7c478bd9Sstevel@tonic-gate struct log_vol_int_desc *lvintp;
114*7c478bd9Sstevel@tonic-gate struct lvid_iu *lviup;
115*7c478bd9Sstevel@tonic-gate struct anch_vol_desc_ptr *avdp;
116*7c478bd9Sstevel@tonic-gate struct file_set_desc *fileset;
117*7c478bd9Sstevel@tonic-gate struct space_bmap_desc *spacep;
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #define		dirty(bp)	(bp)->b_dirty = isdirty = 1
120*7c478bd9Sstevel@tonic-gate #define		initbarea(bp) \
121*7c478bd9Sstevel@tonic-gate 	(bp)->b_dirty = 0; \
122*7c478bd9Sstevel@tonic-gate 	(bp)->b_bno = (daddr_t)-1; \
123*7c478bd9Sstevel@tonic-gate 	(bp)->b_flags = 0;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate #define		sbdirty()	sblk.b_dirty = isdirty = 1
126*7c478bd9Sstevel@tonic-gate #define		cgdirty()	cgblk.b_dirty = isdirty = 1
127*7c478bd9Sstevel@tonic-gate #define		sblock		(*sblk.b_un.b_fs)
128*7c478bd9Sstevel@tonic-gate #define		cgrp		(*cgblk.b_un.b_cg)
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate enum fixstate {DONTKNOW, NOFIX, FIX};
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate struct inodesc {
133*7c478bd9Sstevel@tonic-gate 	enum fixstate id_fix;	/* policy on fixing errors */
134*7c478bd9Sstevel@tonic-gate 	int (*id_func)();	/* function to be applied to blocks of inode */
135*7c478bd9Sstevel@tonic-gate 	ino_t id_number;	/* inode number described */
136*7c478bd9Sstevel@tonic-gate 	ino_t id_parent;	/* for DATA nodes, their parent */
137*7c478bd9Sstevel@tonic-gate 	daddr_t id_blkno;	/* current block number being examined */
138*7c478bd9Sstevel@tonic-gate 	int id_numfrags;	/* number of frags contained in block */
139*7c478bd9Sstevel@tonic-gate 	offset_t id_filesize;	/* for DATA nodes, the size of the directory */
140*7c478bd9Sstevel@tonic-gate 	int id_loc;		/* for DATA nodes, current location in dir */
141*7c478bd9Sstevel@tonic-gate 	int id_entryno;		/* for DATA nodes, current entry number */
142*7c478bd9Sstevel@tonic-gate 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
143*7c478bd9Sstevel@tonic-gate 	char *id_name;		/* for DATA nodes, name to find or enter */
144*7c478bd9Sstevel@tonic-gate 	char id_type;		/* type of descriptor, DATA or ADDR */
145*7c478bd9Sstevel@tonic-gate };
146*7c478bd9Sstevel@tonic-gate /* file types */
147*7c478bd9Sstevel@tonic-gate #define		DATA	1
148*7c478bd9Sstevel@tonic-gate #define		ADDR	2
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate /*
151*7c478bd9Sstevel@tonic-gate  * File entry cache structures.
152*7c478bd9Sstevel@tonic-gate  */
153*7c478bd9Sstevel@tonic-gate struct fileinfo {
154*7c478bd9Sstevel@tonic-gate 	struct	fileinfo *fe_nexthash;	/* next entry in hash chain */
155*7c478bd9Sstevel@tonic-gate 	uint32_t fe_block;		/* location of this file entry */
156*7c478bd9Sstevel@tonic-gate 	uint16_t fe_len;		/* size of file entry */
157*7c478bd9Sstevel@tonic-gate 	uint16_t fe_lseen;		/* number of links seen */
158*7c478bd9Sstevel@tonic-gate 	uint16_t fe_lcount;		/* count from the file entry */
159*7c478bd9Sstevel@tonic-gate 	uint8_t	 fe_type;		/* type of file entry */
160*7c478bd9Sstevel@tonic-gate 	uint8_t	 fe_state;		/* flag bits */
161*7c478bd9Sstevel@tonic-gate } *inphead, **inphash, *inpnext, *inplast;
162*7c478bd9Sstevel@tonic-gate long numdirs, numfiles, listmax;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate #define	FEGROW 512
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate char	*devname;		/* name of device being checked */
167*7c478bd9Sstevel@tonic-gate long	secsize;		/* actual disk sector size */
168*7c478bd9Sstevel@tonic-gate long	fsbsize;		/* file system block size (same as secsize) */
169*7c478bd9Sstevel@tonic-gate char	nflag;			/* assume a no response */
170*7c478bd9Sstevel@tonic-gate char	yflag;			/* assume a yes response */
171*7c478bd9Sstevel@tonic-gate int	debug;			/* output debugging info */
172*7c478bd9Sstevel@tonic-gate int	rflag;			/* check raw file systems */
173*7c478bd9Sstevel@tonic-gate int	wflag;			/* check only writable filesystems */
174*7c478bd9Sstevel@tonic-gate int	fflag;			/* check regardless of clean flag (force) */
175*7c478bd9Sstevel@tonic-gate int	sflag;			/* print status flag */
176*7c478bd9Sstevel@tonic-gate char	preen;			/* just fix normal inconsistencies */
177*7c478bd9Sstevel@tonic-gate char	mountedfs;		/* checking mounted device */
178*7c478bd9Sstevel@tonic-gate int	exitstat;		/* exit status (set to 8 if 'No' response) */
179*7c478bd9Sstevel@tonic-gate char	hotroot;		/* checking root device */
180*7c478bd9Sstevel@tonic-gate char	havesb;			/* superblock has been read */
181*7c478bd9Sstevel@tonic-gate int	fsmodified;		/* 1 => write done to file system */
182*7c478bd9Sstevel@tonic-gate int	fsreadfd;		/* file descriptor for reading file system */
183*7c478bd9Sstevel@tonic-gate int	fswritefd;		/* file descriptor for writing file system */
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate int	iscorrupt;		/* known to be corrupt/inconsistent */
186*7c478bd9Sstevel@tonic-gate int	isdirty;		/* 1 => write pending to file system */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate int	mountfd;		/* fd of mount point */
189*7c478bd9Sstevel@tonic-gate char	mountpoint[100];	/* string set to contain mount point */
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate char	*busymap;		/* ptr to primary blk busy map */
192*7c478bd9Sstevel@tonic-gate char	*freemap;		/* ptr to copy of disk map */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate uint32_t part_start;
195*7c478bd9Sstevel@tonic-gate uint32_t part_len;
196*7c478bd9Sstevel@tonic-gate uint32_t part_bmp_bytes;
197*7c478bd9Sstevel@tonic-gate uint32_t part_bmp_sectors;
198*7c478bd9Sstevel@tonic-gate uint32_t part_bmp_loc;
199*7c478bd9Sstevel@tonic-gate uint32_t filesetblock;
200*7c478bd9Sstevel@tonic-gate uint32_t filesetlen;
201*7c478bd9Sstevel@tonic-gate uint32_t rootblock;
202*7c478bd9Sstevel@tonic-gate uint32_t rootlen;
203*7c478bd9Sstevel@tonic-gate uint32_t lvintblock;
204*7c478bd9Sstevel@tonic-gate uint32_t lvintlen;
205*7c478bd9Sstevel@tonic-gate uint32_t disk_size;
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate daddr_t	n_blks;			/* number of blocks in use */
208*7c478bd9Sstevel@tonic-gate daddr_t	n_files;		/* number of files in use */
209*7c478bd9Sstevel@tonic-gate daddr_t	n_dirs;			/* number of dirs in use */
210*7c478bd9Sstevel@tonic-gate uint64_t maxuniqid;		/* maximum unique id on medium */
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate /*
213*7c478bd9Sstevel@tonic-gate  * bit map related macros
214*7c478bd9Sstevel@tonic-gate  */
215*7c478bd9Sstevel@tonic-gate #define		bitloc(a, i)	((a)[(i)/NBBY])
216*7c478bd9Sstevel@tonic-gate #define		setbit(a, i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
217*7c478bd9Sstevel@tonic-gate #define		clrbit(a, i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
218*7c478bd9Sstevel@tonic-gate #define		isset(a, i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
219*7c478bd9Sstevel@tonic-gate #define		isclr(a, i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate #define		setbmap(blkno)	setbit(blockmap, blkno)
222*7c478bd9Sstevel@tonic-gate #define		testbmap(blkno)	isset(blockmap, blkno)
223*7c478bd9Sstevel@tonic-gate #define		clrbmap(blkno)	clrbit(blockmap, blkno)
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate #define		setbusy(blkno)	setbit(busymap, blkno)
226*7c478bd9Sstevel@tonic-gate #define		testbusy(blkno)	isset(busymap, blkno)
227*7c478bd9Sstevel@tonic-gate #define		clrbusy(blkno)	clrbit(busymap, blkno)
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate #define	fsbtodb(blkno) ((blkno) * (fsbsize / DEV_BSIZE))
230*7c478bd9Sstevel@tonic-gate #define	dbtofsb(blkno) ((blkno) / (fsbsize / DEV_BSIZE))
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate #define		STOP	0x01
233*7c478bd9Sstevel@tonic-gate #define		SKIP	0x02
234*7c478bd9Sstevel@tonic-gate #define		KEEPON	0x04
235*7c478bd9Sstevel@tonic-gate #define		ALTERED	0x08
236*7c478bd9Sstevel@tonic-gate #define		FOUND	0x10
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate time_t time();
239*7c478bd9Sstevel@tonic-gate struct dinode *ginode();
240*7c478bd9Sstevel@tonic-gate struct inoinfo *getinoinfo();
241*7c478bd9Sstevel@tonic-gate struct fileinfo *cachefile();
242*7c478bd9Sstevel@tonic-gate ino_t allocino();
243*7c478bd9Sstevel@tonic-gate int findino();
244*7c478bd9Sstevel@tonic-gate char *setup();
245*7c478bd9Sstevel@tonic-gate void markbusy(daddr_t, long);
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate #ifndef MNTTYPE_UDFS
248*7c478bd9Sstevel@tonic-gate #define	MNTTYPE_UDFS		"udfs"
249*7c478bd9Sstevel@tonic-gate #endif
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate #define	SPACEMAP_OFF 24
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate #define	FID_LENGTH(fid)    (((sizeof (struct file_id) + \
254*7c478bd9Sstevel@tonic-gate 		(fid)->fid_iulen + (fid)->fid_idlen - 2) + 3) & ~3)
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate #define	EXTYPE(len) (((len) >> 30) & 3)
257*7c478bd9Sstevel@tonic-gate #define	EXTLEN(len) ((len) & 0x3fffffff)
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate /* Integrity descriptor types */
260*7c478bd9Sstevel@tonic-gate #define	LVI_OPEN 0
261*7c478bd9Sstevel@tonic-gate #define	LVI_CLOSE 1
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate #endif
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate #endif	/* _FSCK_H */
268