2005-04-12 03:19:24 +04:00
|
|
|
/* $NetBSD: fsck.h,v 1.14 2005/04/11 23:19:24 perseant Exp $ */
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2004-03-21 01:31:13 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Konrad E. Schroder <perseant@hhhh.org>.
|
1999-03-18 05:02:18 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
2003-08-07 14:04:22 +04:00
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-03-21 01:31:13 +03:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
2003-08-07 14:04:22 +04:00
|
|
|
*
|
2004-03-21 01:31:13 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2003-08-07 14:04:22 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-03-21 01:31:13 +03:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2003-08-07 14:04:22 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
1999-03-18 05:02:18 +03:00
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-03-21 01:31:13 +03:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-03-18 05:02:18 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)fsck.h 8.1 (Berkeley) 6/5/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef KS_DEBUG
|
2000-05-23 05:48:52 +04:00
|
|
|
#include <err.h>
|
|
|
|
#define debug_printf warn
|
1999-03-18 05:02:18 +03:00
|
|
|
#else
|
2000-05-23 05:48:52 +04:00
|
|
|
#define debug_printf
|
1999-03-18 05:02:18 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAXDUP 10 /* limit on dup blks (per inode) */
|
|
|
|
#define MAXBAD 10 /* limit on bad blks (per inode) */
|
|
|
|
#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */
|
|
|
|
#define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */
|
|
|
|
|
|
|
|
#ifndef BUFSIZ
|
|
|
|
#define BUFSIZ 1024
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define USTATE 01 /* inode not allocated */
|
|
|
|
#define FSTATE 02 /* inode is file */
|
|
|
|
#define DSTATE 03 /* inode is directory */
|
|
|
|
#define DFOUND 04 /* directory found during descent */
|
|
|
|
#define DCLEAR 05 /* directory is to be cleared */
|
|
|
|
#define FCLEAR 06 /* file is to be cleared */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* buffer cache structure.
|
|
|
|
*/
|
2003-03-28 11:09:52 +03:00
|
|
|
struct ubufarea {
|
|
|
|
struct ubufarea *b_next; /* free list queue */
|
|
|
|
struct ubufarea *b_prev; /* free list queue */
|
|
|
|
daddr_t b_bno;
|
|
|
|
int b_size;
|
|
|
|
int b_errs;
|
|
|
|
int b_flags;
|
1999-03-18 05:02:18 +03:00
|
|
|
union {
|
2003-03-28 11:09:52 +03:00
|
|
|
char *b_buf; /* buffer space */
|
2003-01-25 00:55:02 +03:00
|
|
|
/* XXX ondisk32 */
|
2003-03-28 11:09:52 +03:00
|
|
|
int32_t *b_indir; /* indirect block */
|
|
|
|
struct lfs *b_fs; /* super block */
|
|
|
|
struct cg *b_cg;/* cylinder group */
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode *b_dinode; /* inode block */
|
2003-03-28 11:09:52 +03:00
|
|
|
} b_un;
|
|
|
|
char b_dirty;
|
1999-03-18 05:02:18 +03:00
|
|
|
};
|
|
|
|
#define B_INUSE 1
|
|
|
|
|
|
|
|
#define MINBUFS 5 /* minimum number of buffers required */
|
|
|
|
|
|
|
|
#define dirty(bp) (bp)->b_dirty = 1
|
|
|
|
#define initbarea(bp) \
|
|
|
|
(bp)->b_dirty = 0; \
|
|
|
|
(bp)->b_bno = (daddr_t)-1; \
|
|
|
|
(bp)->b_flags = 0;
|
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
enum fixstate {
|
|
|
|
DONTKNOW, NOFIX, FIX, IGNORE
|
|
|
|
};
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
struct inodesc {
|
2003-03-28 11:09:52 +03:00
|
|
|
enum fixstate id_fix; /* policy on fixing errors */
|
|
|
|
int (*id_func) (struct inodesc *); /* function to be applied to
|
|
|
|
* blocks of inode */
|
|
|
|
ino_t id_number; /* inode number described */
|
|
|
|
ino_t id_parent; /* for DATA nodes, their parent */
|
|
|
|
daddr_t id_blkno; /* current block number being examined */
|
|
|
|
daddr_t id_lblkno; /* current logical block number */
|
|
|
|
int id_numfrags; /* number of frags contained in block */
|
|
|
|
quad_t id_filesize; /* for DATA nodes, the size of the directory */
|
|
|
|
int id_loc; /* for DATA nodes, current location in dir */
|
|
|
|
int id_entryno; /* for DATA nodes, current entry number */
|
|
|
|
struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
|
|
|
|
char *id_name; /* for DATA nodes, name to find or enter */
|
|
|
|
char id_type; /* type of descriptor, DATA or ADDR */
|
1999-03-18 05:02:18 +03:00
|
|
|
};
|
|
|
|
/* file types */
|
|
|
|
#define DATA 1
|
|
|
|
#define ADDR 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Linked list of duplicate blocks.
|
2000-05-23 05:48:52 +04:00
|
|
|
*
|
1999-03-18 05:02:18 +03:00
|
|
|
* The list is composed of two parts. The first part of the
|
|
|
|
* list (from duplist through the node pointed to by muldup)
|
2000-05-23 05:48:52 +04:00
|
|
|
* contains a single copy of each duplicate block that has been
|
1999-03-18 05:02:18 +03:00
|
|
|
* found. The second part of the list (from muldup to the end)
|
|
|
|
* contains duplicate blocks that have been found more than once.
|
|
|
|
* To check if a block has been found as a duplicate it is only
|
2000-05-23 05:48:52 +04:00
|
|
|
* necessary to search from duplist through muldup. To find the
|
1999-03-18 05:02:18 +03:00
|
|
|
* total number of times that a block has been found as a duplicate
|
2003-03-30 01:48:37 +03:00
|
|
|
* the entire list must be searched for occurrences of the block
|
1999-03-18 05:02:18 +03:00
|
|
|
* in question. The following diagram shows a sample list where
|
|
|
|
* w (found twice), x (found once), y (found three times), and z
|
|
|
|
* (found once) are duplicate block numbers:
|
|
|
|
*
|
|
|
|
* w -> y -> x -> z -> y -> w -> y
|
|
|
|
* ^ ^
|
|
|
|
* | |
|
|
|
|
* duplist muldup
|
|
|
|
*/
|
|
|
|
struct dups {
|
2003-03-28 11:09:52 +03:00
|
|
|
struct dups *next;
|
|
|
|
daddr_t dup;
|
1999-03-18 05:02:18 +03:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Linked list of inodes with zero link counts.
|
|
|
|
*/
|
|
|
|
struct zlncnt {
|
2003-03-28 11:09:52 +03:00
|
|
|
struct zlncnt *next;
|
|
|
|
ino_t zlncnt;
|
1999-03-18 05:02:18 +03:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Inode cache data structures.
|
|
|
|
*/
|
|
|
|
struct inoinfo {
|
2000-05-23 05:48:52 +04:00
|
|
|
struct inoinfo *i_nexthash; /* next entry in hash chain */
|
|
|
|
struct inoinfo *i_child, *i_sibling, *i_parentp;
|
2003-03-28 11:09:52 +03:00
|
|
|
ino_t i_number; /* inode number of this entry */
|
|
|
|
ino_t i_parent; /* inode number of parent */
|
|
|
|
ino_t i_dotdot; /* inode number of `..' */
|
|
|
|
size_t i_isize; /* size of inode */
|
|
|
|
u_int i_numblks; /* size of block array in bytes */
|
2003-01-25 00:55:02 +03:00
|
|
|
/* XXX ondisk32 */
|
2003-03-28 11:09:52 +03:00
|
|
|
int32_t i_blks[1]; /* actually longer */
|
|
|
|
} **inphead, **inpsort;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
#ifndef VERBOSE_BLOCKMAP
|
2000-05-23 05:48:52 +04:00
|
|
|
#define setbmap(blkno) setbit(blockmap, blkno)
|
|
|
|
#define testbmap(blkno) isset(blockmap, blkno)
|
|
|
|
#define clrbmap(blkno) clrbit(blockmap, blkno)
|
1999-03-18 05:02:18 +03:00
|
|
|
#else
|
2000-05-23 05:48:52 +04:00
|
|
|
#define setbmap(blkno,ino) if(blkno > maxfsblock)raise(1); else blockmap[blkno] = ino
|
|
|
|
#define testbmap(blkno) blockmap[blkno]
|
|
|
|
#define clrbmap(blkno) blockmap[blkno] = 0
|
1999-03-18 05:02:18 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STOP 0x01
|
|
|
|
#define SKIP 0x02
|
|
|
|
#define KEEPON 0x04
|
|
|
|
#define ALTERED 0x08
|
|
|
|
#define FOUND 0x10
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
ino_t allocino(ino_t, int);
|
|
|
|
int ino_to_fsba(struct lfs *, ino_t);
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode *ginode(ino_t);
|
2000-05-23 05:48:52 +04:00
|
|
|
struct inoinfo *getinoinfo(ino_t);
|
2003-03-28 11:09:52 +03:00
|
|
|
daddr_t lfs_ino_daddr(ino_t);
|
2004-07-19 00:51:30 +04:00
|
|
|
void clearinode(ino_t);
|
2005-04-12 03:19:24 +04:00
|
|
|
void reset_maxino(ino_t);
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
#include "fsck_vars.h"
|