1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
5 * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
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.
24 * Copyright (c) 1996, 1998-1999 by Sun Microsystems, Inc.
25 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
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 */
41 #define INOBUFSIZE 256*1024 /* size of buffer to read */
43 #define MAXBSIZE 8192 /* maximum allowed block size */
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)
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 */
80 * buffer cache structure.
83 struct bufarea
*b_next
; /* free list queue */
84 struct bufarea
*b_prev
; /* free list queue */
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 */
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 */
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
;
119 #define dirty(bp) (bp)->b_dirty = isdirty = 1
120 #define initbarea(bp) \
122 (bp)->b_bno = (daddr_t)-1; \
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)
130 enum fixstate
{DONTKNOW
, NOFIX
, FIX
};
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 */
151 * File entry cache structures.
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
;
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 */
185 int iscorrupt
; /* known to be corrupt/inconsistent */
186 int isdirty
; /* 1 => write pending to file system */
188 int mountfd
; /* fd of mount point */
189 char mountpoint
[100]; /* string set to contain mount point */
191 char *busymap
; /* ptr to primary blk busy map */
192 char *freemap
; /* ptr to copy of disk map */
196 uint32_t part_bmp_bytes
;
197 uint32_t part_bmp_sectors
;
198 uint32_t part_bmp_loc
;
199 uint32_t filesetblock
;
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 */
213 * bit map related macros
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)
221 #define setbmap(blkno) setbit(blockmap, blkno)
222 #define testbmap(blkno) isset(blockmap, blkno)
223 #define clrbmap(blkno) clrbit(blockmap, blkno)
225 #define setbusy(blkno) setbit(busymap, blkno)
226 #define testbusy(blkno) isset(busymap, blkno)
227 #define clrbusy(blkno) clrbit(busymap, blkno)
229 #define fsbtodb(blkno) ((blkno) * (fsbsize / DEV_BSIZE))
230 #define dbtofsb(blkno) ((blkno) / (fsbsize / DEV_BSIZE))
239 struct dinode
*ginode();
240 struct inoinfo
*getinoinfo();
241 struct fileinfo
*cachefile();
245 void markbusy(daddr_t
, long);
248 #define MNTTYPE_UDFS "udfs"
251 #define SPACEMAP_OFF 24
253 #define FID_LENGTH(fid) (((sizeof (struct file_id) + \
254 (fid)->fid_iulen + (fid)->fid_idlen - 2) + 3) & ~3)
256 #define EXTYPE(len) (((len) >> 30) & 3)
257 #define EXTLEN(len) ((len) & 0x3fffffff)
259 /* Integrity descriptor types */