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