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