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