2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause and BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2002-06-21 06:18:05 +00:00
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Marshall
|
|
|
|
* Kirk McKusick and Network Associates Laboratories, the Security
|
|
|
|
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
|
|
|
|
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
|
2003-02-14 21:08:14 +00:00
|
|
|
* research program.
|
2002-06-21 06:18:05 +00:00
|
|
|
*
|
2004-10-20 08:05:02 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
1994-05-26 06:35:07 +00:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-26 06:35:07 +00: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.
|
|
|
|
*
|
1997-03-11 12:20:21 +00:00
|
|
|
* @(#)fsck.h 8.4 (Berkeley) 5/9/95
|
2000-01-10 08:18:18 +00:00
|
|
|
* $FreeBSD$
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
|
|
|
|
2010-04-24 07:54:49 +00:00
|
|
|
#ifndef _FSCK_H_
|
|
|
|
#define _FSCK_H_
|
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-02-15 01:00:48 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#define MAXDUP 10 /* limit on dup blks (per inode) */
|
|
|
|
#define MAXBAD 10 /* limit on bad blks (per inode) */
|
2021-01-07 01:37:08 +00:00
|
|
|
#define MINBUFS 100 /* minimum number of buffers required */
|
2013-02-15 01:00:48 +00:00
|
|
|
#define INOBUFSIZE 64*1024 /* size of buffer to read inodes in pass1 */
|
2013-04-29 20:13:09 +00:00
|
|
|
#define ZEROBUFSIZE (dev_bsize * 128) /* size of zero buffer used by -Z */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode dp1;
|
|
|
|
struct ufs2_dinode dp2;
|
|
|
|
};
|
|
|
|
#define DIP(dp, field) \
|
|
|
|
((sblock.fs_magic == FS_UFS1_MAGIC) ? \
|
|
|
|
(dp)->dp1.field : (dp)->dp2.field)
|
|
|
|
|
2004-09-01 05:48:06 +00:00
|
|
|
#define DIP_SET(dp, field, val) do { \
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC) \
|
|
|
|
(dp)->dp1.field = (val); \
|
|
|
|
else \
|
|
|
|
(dp)->dp2.field = (val); \
|
|
|
|
} while (0)
|
|
|
|
|
1998-12-03 02:27:35 +00:00
|
|
|
/*
|
2002-08-21 18:11:48 +00:00
|
|
|
* Each inode on the file system is described by the following structure.
|
1998-12-03 02:27:35 +00:00
|
|
|
* The linkcnt is initially set to the value in the inode. Each time it
|
|
|
|
* is found during the descent in passes 2, 3, and 4 the count is
|
|
|
|
* decremented. Any inodes whose count is non-zero after pass 4 needs to
|
|
|
|
* have its link count adjusted by the value remaining in ino_linkcnt.
|
|
|
|
*/
|
|
|
|
struct inostat {
|
2021-01-07 01:37:08 +00:00
|
|
|
u_char ino_state; /* state of inode, see below */
|
|
|
|
u_char ino_type:4; /* type of inode */
|
|
|
|
u_char ino_idtype:4; /* idesc id_type, SNAP or ADDR */
|
|
|
|
u_short ino_linkcnt; /* number of links not found */
|
1998-12-03 02:27:35 +00:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Inode states.
|
|
|
|
*/
|
2004-10-08 20:44:47 +00:00
|
|
|
#define USTATE 0x1 /* inode not allocated */
|
|
|
|
#define FSTATE 0x2 /* inode is file */
|
|
|
|
#define FZLINK 0x3 /* inode is file with a link count of zero */
|
|
|
|
#define DSTATE 0x4 /* inode is directory */
|
|
|
|
#define DZLINK 0x5 /* inode is directory with a zero link count */
|
|
|
|
#define DFOUND 0x6 /* directory found during descent */
|
|
|
|
/* 0x7 UNUSED - see S_IS_DVALID() definition */
|
|
|
|
#define DCLEAR 0x8 /* directory is to be cleared */
|
|
|
|
#define FCLEAR 0x9 /* file is to be cleared */
|
|
|
|
/* DUNFOUND === (state == DSTATE || state == DZLINK) */
|
|
|
|
#define S_IS_DUNFOUND(state) (((state) & ~0x1) == DSTATE)
|
|
|
|
/* DVALID === (state == DSTATE || state == DZLINK || state == DFOUND) */
|
|
|
|
#define S_IS_DVALID(state) (((state) & ~0x3) == DSTATE)
|
|
|
|
#define INO_IS_DUNFOUND(ino) S_IS_DUNFOUND(inoinfo(ino)->ino_state)
|
|
|
|
#define INO_IS_DVALID(ino) S_IS_DVALID(inoinfo(ino)->ino_state)
|
1998-12-03 02:27:35 +00:00
|
|
|
/*
|
|
|
|
* Inode state information is contained on per cylinder group lists
|
|
|
|
* which are described by the following structure.
|
|
|
|
*/
|
2020-03-29 20:03:46 +00:00
|
|
|
extern struct inostatlist {
|
1998-12-03 02:27:35 +00:00
|
|
|
long il_numalloced; /* number of inodes allocated in this cg */
|
|
|
|
struct inostat *il_stat;/* inostat info for this cylinder group */
|
|
|
|
} *inostathead;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
/*
|
|
|
|
* Structure to reference a dinode.
|
|
|
|
*/
|
|
|
|
struct inode {
|
|
|
|
struct bufarea *i_bp; /* buffer containing the dinode */
|
|
|
|
union dinode *i_dp; /* pointer to dinode in buffer */
|
|
|
|
ino_t i_number; /* inode number */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size of hash tables
|
|
|
|
*/
|
|
|
|
#define HASHSIZE 2048
|
|
|
|
#define HASH(x) ((x * 2654435761) & (HASHSIZE - 1))
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* buffer cache structure.
|
|
|
|
*/
|
|
|
|
struct bufarea {
|
2021-01-07 01:37:08 +00:00
|
|
|
TAILQ_ENTRY(bufarea) b_list; /* LRU buffer queue */
|
|
|
|
LIST_ENTRY(bufarea) b_hash; /* hash list */
|
2020-12-31 23:15:44 +00:00
|
|
|
ufs2_daddr_t b_bno; /* disk block number */
|
|
|
|
int b_size; /* size of I/O */
|
|
|
|
int b_errs; /* I/O error */
|
|
|
|
int b_flags; /* B_ flags below */
|
|
|
|
int b_type; /* BT_ type below */
|
2021-01-07 01:37:08 +00:00
|
|
|
int b_refcnt; /* ref count of users */
|
|
|
|
int b_index; /* for BT_LEVEL, ptr index */
|
|
|
|
/* for BT_INODES, first inum */
|
1994-05-26 06:35:07 +00:00
|
|
|
union {
|
1997-03-11 12:20:21 +00:00
|
|
|
char *b_buf; /* buffer space */
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs1_daddr_t *b_indir1; /* UFS1 indirect block */
|
|
|
|
ufs2_daddr_t *b_indir2; /* UFS2 indirect block */
|
1997-03-11 12:20:21 +00:00
|
|
|
struct fs *b_fs; /* super block */
|
|
|
|
struct cg *b_cg; /* cylinder group */
|
2002-06-21 06:18:05 +00:00
|
|
|
struct ufs1_dinode *b_dinode1; /* UFS1 inode block */
|
|
|
|
struct ufs2_dinode *b_dinode2; /* UFS2 inode block */
|
1994-05-26 06:35:07 +00:00
|
|
|
} b_un;
|
|
|
|
};
|
2004-09-01 05:48:06 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
#define IBLK(bp, i) \
|
|
|
|
((sblock.fs_magic == FS_UFS1_MAGIC) ? \
|
|
|
|
(bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i])
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2004-09-01 05:48:06 +00:00
|
|
|
#define IBLK_SET(bp, i, val) do { \
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC) \
|
|
|
|
(bp)->b_un.b_indir1[i] = (val); \
|
|
|
|
else \
|
|
|
|
(bp)->b_un.b_indir2[i] = (val); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-02-15 01:00:48 +00:00
|
|
|
/*
|
|
|
|
* Buffer flags
|
|
|
|
*/
|
2021-01-07 01:37:08 +00:00
|
|
|
#define B_DIRTY 0x00000001 /* Buffer is dirty */
|
2013-02-24 06:44:29 +00:00
|
|
|
/*
|
|
|
|
* Type of data in buffer
|
|
|
|
*/
|
2020-12-31 23:15:44 +00:00
|
|
|
#define BT_UNKNOWN 0 /* Buffer type is unknown */
|
2013-02-24 06:44:29 +00:00
|
|
|
#define BT_SUPERBLK 1 /* Buffer holds a superblock */
|
|
|
|
#define BT_CYLGRP 2 /* Buffer holds a cylinder group map */
|
|
|
|
#define BT_LEVEL1 3 /* Buffer holds single level indirect */
|
|
|
|
#define BT_LEVEL2 4 /* Buffer holds double level indirect */
|
|
|
|
#define BT_LEVEL3 5 /* Buffer holds triple level indirect */
|
|
|
|
#define BT_EXTATTR 6 /* Buffer holds external attribute data */
|
2020-12-31 23:15:44 +00:00
|
|
|
#define BT_INODES 7 /* Buffer holds inodes */
|
2013-02-24 06:44:29 +00:00
|
|
|
#define BT_DIRDATA 8 /* Buffer holds directory data */
|
|
|
|
#define BT_DATA 9 /* Buffer holds user data */
|
2021-01-07 01:37:08 +00:00
|
|
|
#define BT_EMPTY 10 /* Buffer allocated but not filled */
|
|
|
|
#define BT_NUMBUFTYPES 11
|
2013-02-24 06:44:29 +00:00
|
|
|
#define BT_NAMES { \
|
|
|
|
"unknown", \
|
|
|
|
"Superblock", \
|
|
|
|
"Cylinder Group", \
|
|
|
|
"Single Level Indirect", \
|
|
|
|
"Double Level Indirect", \
|
|
|
|
"Triple Level Indirect", \
|
|
|
|
"External Attribute", \
|
|
|
|
"Inode Block", \
|
|
|
|
"Directory Contents", \
|
2021-01-07 01:37:08 +00:00
|
|
|
"User Data", \
|
|
|
|
"Allocated but not filled" }
|
|
|
|
extern char *buftype[];
|
|
|
|
#define BT_BUFTYPE(type) \
|
|
|
|
type < BT_NUMBUFTYPES ? buftype[type] : buftype[BT_UNKNOWN]
|
2013-12-30 01:16:08 +00:00
|
|
|
extern long readcnt[BT_NUMBUFTYPES];
|
|
|
|
extern long totalreadcnt[BT_NUMBUFTYPES];
|
|
|
|
extern struct timespec readtime[BT_NUMBUFTYPES];
|
|
|
|
extern struct timespec totalreadtime[BT_NUMBUFTYPES];
|
|
|
|
extern struct timespec startprog;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
extern struct bufarea *icachebp; /* inode cache buffer */
|
2013-12-30 01:16:08 +00:00
|
|
|
extern struct bufarea sblk; /* file system superblock */
|
|
|
|
extern struct bufarea *pdirbp; /* current directory contents */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2001-11-17 23:48:21 +00:00
|
|
|
#define dirty(bp) do { \
|
2001-03-21 09:48:03 +00:00
|
|
|
if (fswritefd < 0) \
|
|
|
|
pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \
|
|
|
|
else \
|
2021-01-07 01:37:08 +00:00
|
|
|
(bp)->b_flags |= B_DIRTY; \
|
2001-11-17 23:48:21 +00:00
|
|
|
} while (0)
|
2013-02-24 06:44:29 +00:00
|
|
|
#define initbarea(bp, type) do { \
|
2002-06-21 06:18:05 +00:00
|
|
|
(bp)->b_bno = (ufs2_daddr_t)-1; \
|
2021-04-02 18:57:34 +00:00
|
|
|
(bp)->b_size = 0; \
|
|
|
|
(bp)->b_errs = 0; \
|
2001-11-17 23:48:21 +00:00
|
|
|
(bp)->b_flags = 0; \
|
2021-04-02 18:57:34 +00:00
|
|
|
(bp)->b_type = type; \
|
2021-01-07 01:37:08 +00:00
|
|
|
(bp)->b_refcnt = 0; \
|
|
|
|
(bp)->b_index = 0; \
|
2001-11-17 23:48:21 +00:00
|
|
|
} while (0)
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2001-03-21 09:48:03 +00:00
|
|
|
#define sbdirty() dirty(&sblk)
|
1994-05-26 06:35:07 +00:00
|
|
|
#define sblock (*sblk.b_un.b_fs)
|
|
|
|
|
|
|
|
enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
|
2013-12-30 01:16:08 +00:00
|
|
|
extern ino_t cursnapshot;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
struct inodesc {
|
|
|
|
enum fixstate id_fix; /* policy on fixing errors */
|
2002-07-30 13:01:25 +00:00
|
|
|
int (*id_func)(struct inodesc *);
|
|
|
|
/* function to be applied to blocks of inode */
|
2021-01-07 01:37:08 +00:00
|
|
|
struct bufarea *id_bp; /* ckinode: buffer with indirect pointers */
|
|
|
|
union dinode *id_dp; /* ckinode: dinode being traversed */
|
1994-05-26 06:35:07 +00:00
|
|
|
ino_t id_number; /* inode number described */
|
|
|
|
ino_t id_parent; /* for DATA nodes, their parent */
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs_lbn_t id_lbn; /* logical block number of current block */
|
|
|
|
ufs2_daddr_t id_blkno; /* current block number being examined */
|
2019-04-13 13:31:06 +00:00
|
|
|
int id_level; /* level of indirection of this block */
|
1994-05-26 06:35:07 +00:00
|
|
|
int id_numfrags; /* number of frags contained in block */
|
2019-02-25 21:58:19 +00:00
|
|
|
ufs_lbn_t id_lballoc; /* pass1: last LBN that is allocated */
|
2002-06-21 06:18:05 +00:00
|
|
|
off_t id_filesize; /* for DATA nodes, the size of the directory */
|
|
|
|
ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
|
1994-05-26 06:35:07 +00:00
|
|
|
int id_loc; /* for DATA nodes, current location in dir */
|
|
|
|
struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
|
|
|
|
char *id_name; /* for DATA nodes, name to find or enter */
|
2021-01-07 01:37:08 +00:00
|
|
|
char id_type; /* type of descriptor, DATA, ADDR, or SNAP */
|
1994-05-26 06:35:07 +00:00
|
|
|
};
|
|
|
|
/* file types */
|
2000-07-06 02:03:11 +00:00
|
|
|
#define DATA 1 /* a directory */
|
|
|
|
#define SNAP 2 /* a snapshot */
|
|
|
|
#define ADDR 3 /* anything but a directory or a snapshot */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Linked list of duplicate blocks.
|
1995-05-30 06:12:45 +00:00
|
|
|
*
|
1994-05-26 06:35:07 +00:00
|
|
|
* The list is composed of two parts. The first part of the
|
|
|
|
* list (from duplist through the node pointed to by muldup)
|
1995-05-30 06:12:45 +00:00
|
|
|
* contains a single copy of each duplicate block that has been
|
1994-05-26 06:35:07 +00: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
|
1995-05-30 06:12:45 +00:00
|
|
|
* necessary to search from duplist through muldup. To find the
|
1994-05-26 06:35:07 +00:00
|
|
|
* total number of times that a block has been found as a duplicate
|
2012-01-07 16:09:33 +00:00
|
|
|
* the entire list must be searched for occurrences of the block
|
1994-05-26 06:35:07 +00: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 {
|
|
|
|
struct dups *next;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t dup;
|
1994-05-26 06:35:07 +00:00
|
|
|
};
|
2020-03-29 20:03:46 +00:00
|
|
|
extern struct dups *duplist; /* head of dup list */
|
|
|
|
extern struct dups *muldup; /* end of unique duplicate dup block numbers */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inode cache data structures.
|
|
|
|
*/
|
2020-03-29 20:03:46 +00:00
|
|
|
extern struct inoinfo {
|
1994-05-26 06:35:07 +00:00
|
|
|
struct inoinfo *i_nexthash; /* next entry in hash chain */
|
|
|
|
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 */
|
2022-09-03 21:46:50 +00:00
|
|
|
u_int i_flags; /* flags, see below */
|
1994-05-26 06:35:07 +00:00
|
|
|
u_int i_numblks; /* size of block array in bytes */
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t i_blks[1]; /* actually longer */
|
1994-05-26 06:35:07 +00:00
|
|
|
} **inphead, **inpsort;
|
2022-09-03 21:46:50 +00:00
|
|
|
/*
|
|
|
|
* flags for struct inoinfo
|
|
|
|
*/
|
|
|
|
#define INFO_NEW 0x0000001 /* replaced broken directory */
|
|
|
|
|
2017-04-22 14:50:11 +00:00
|
|
|
extern long dirhash, inplast;
|
|
|
|
extern unsigned long numdirs, listmax;
|
2013-12-30 01:16:08 +00:00
|
|
|
extern long countdirs; /* number of directories we actually found */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2001-03-21 09:48:03 +00:00
|
|
|
#define MIBSIZE 3 /* size of fsck sysctl MIBs */
|
2022-05-10 23:05:05 +00:00
|
|
|
extern int adjblkcnt[MIBSIZE]; /* MIB cmd to adjust inode block count */
|
|
|
|
extern int adjrefcnt[MIBSIZE]; /* MIB cmd to adjust inode reference count */
|
|
|
|
extern int adjndir[MIBSIZE]; /* MIB cmd to adjust number of directories */
|
|
|
|
extern int adjnbfree[MIBSIZE]; /* MIB cmd to adjust number of free blocks */
|
|
|
|
extern int adjnifree[MIBSIZE]; /* MIB cmd to adjust number of free inodes */
|
|
|
|
extern int adjnffree[MIBSIZE]; /* MIB cmd to adjust number of free frags */
|
|
|
|
extern int adjnumclusters[MIBSIZE]; /* MIB cmd adjust number of free clusters */
|
|
|
|
extern int freefiles[MIBSIZE]; /* MIB cmd to free a set of files */
|
|
|
|
extern int freedirs[MIBSIZE]; /* MIB cmd to free a set of directories */
|
|
|
|
extern int freeblks[MIBSIZE]; /* MIB cmd to free a set of data blocks */
|
|
|
|
extern int setsize[MIBSIZE]; /* MIB cmd to set inode size */
|
|
|
|
extern struct fsck_cmd cmd; /* sysctl file system update commands */
|
2013-12-30 01:16:08 +00:00
|
|
|
|
2022-05-10 23:05:05 +00:00
|
|
|
extern int bkgrdcheck; /* determine if background check is possible */
|
|
|
|
extern int bkgrdsumadj; /* whether the kernel has the ability to adjust
|
|
|
|
the superblock summary fields */
|
|
|
|
extern off_t bflag; /* location of alternate super block */
|
|
|
|
extern int bkgrdflag; /* use a snapshot to run on an active system */
|
|
|
|
extern char *blockmap; /* ptr to primary blk allocation map */
|
|
|
|
extern char *cdevname; /* name of device being checked */
|
|
|
|
extern char ckclean; /* only do work if not cleanly unmounted */
|
|
|
|
extern int ckhashadd; /* check hashes to be added */
|
|
|
|
extern int cvtlevel; /* convert to newer file system format */
|
|
|
|
extern long dev_bsize; /* computed value of DEV_BSIZE */
|
|
|
|
extern u_int real_dev_bsize; /* actual disk sector size, not overridden */
|
|
|
|
extern int debug; /* output debugging info */
|
|
|
|
extern int Eflag; /* delete empty data blocks */
|
|
|
|
extern int fsmodified; /* 1 => write done to file system */
|
|
|
|
extern int fsreadfd; /* file descriptor for reading file system */
|
|
|
|
extern int fswritefd; /* file descriptor for writing file system */
|
|
|
|
extern char havesb; /* superblock has been read */
|
|
|
|
extern int inoopt; /* trim out unused inodes */
|
|
|
|
extern ino_t lfdir; /* lost & found directory inode number */
|
|
|
|
extern int lfmode; /* lost & found directory creation mode */
|
|
|
|
extern const char *lfname; /* lost & found directory name */
|
|
|
|
extern ufs2_daddr_t maxfsblock; /* number of blocks in the file system */
|
|
|
|
extern ino_t maxino; /* number of inodes in file system */
|
|
|
|
extern ufs2_daddr_t n_blks; /* number of blocks in use */
|
|
|
|
extern ino_t n_files; /* number of files in use */
|
|
|
|
extern char nflag; /* assume a no response */
|
|
|
|
extern char preen; /* just fix normal inconsistencies */
|
|
|
|
extern char rerun; /* rerun fsck. Only used in non-preen mode */
|
|
|
|
extern char resolved; /* cleared if unresolved changes => not clean */
|
|
|
|
extern int returntosingle; /* 1 => return to single user mode on exit */
|
|
|
|
extern long secsize; /* actual disk sector size */
|
|
|
|
extern char skipclean; /* skip clean file systems if preening */
|
|
|
|
extern char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */
|
|
|
|
extern int sujrecovery; /* 1 => doing check using the journal */
|
|
|
|
extern int surrender; /* Give up if reads fail */
|
|
|
|
extern char usedsoftdep; /* just fix soft dependency inconsistencies */
|
|
|
|
extern int wantrestart; /* Restart fsck on early termination */
|
|
|
|
extern char yflag; /* assume a yes response */
|
|
|
|
extern int zflag; /* zero unused directory space */
|
|
|
|
extern int Zflag; /* zero empty data blocks */
|
2013-12-30 01:16:08 +00:00
|
|
|
|
|
|
|
extern volatile sig_atomic_t got_siginfo; /* received a SIGINFO */
|
|
|
|
extern volatile sig_atomic_t got_sigalarm; /* received a SIGALRM */
|
2000-12-15 14:23:55 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
#define clearinode(dp) \
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC) { \
|
2021-01-07 01:37:08 +00:00
|
|
|
(dp)->dp1 = zino.dp1; \
|
2002-06-21 06:18:05 +00:00
|
|
|
} else { \
|
2021-01-07 01:37:08 +00:00
|
|
|
(dp)->dp2 = zino.dp2; \
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
2021-01-07 01:37:08 +00:00
|
|
|
extern union dinode zino;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#define setbmap(blkno) setbit(blockmap, blkno)
|
|
|
|
#define testbmap(blkno) isset(blockmap, blkno)
|
|
|
|
#define clrbmap(blkno) clrbit(blockmap, blkno)
|
|
|
|
|
|
|
|
#define STOP 0x01
|
|
|
|
#define SKIP 0x02
|
|
|
|
#define KEEPON 0x04
|
|
|
|
#define ALTERED 0x08
|
|
|
|
#define FOUND 0x10
|
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
#define EEXIT 8 /* Standard error exit. */
|
Exit fsck_ffs with non-zero status when file system is not repaired.
When the fsck_ffs program cannot fully repair a file system, it will
output the message PLEASE RERUN FSCK. However, it does not exit with a
non-zero status in this case (contradicting the man page claim that it
"exits with 0 on success, and >0 if an error occurs." The fsck
rc-script (when running "fsck -y") tests the status from fsck (which
passes along the exit status from fsck_ffs) and issues a "stop_boot"
if the status fails. However, this is not effective since fsck_ffs can
return zero even on (some) errors. Effectively, it is left to a later
step in the boot process when the file systems are mounted to detect
the still-unclean file system and stop the boot.
This change modifies fsck_ffs so that when it cannot fully repair the
file system and issues the PLEASE RERUN FSCK message it also exits
with a non-zero status.
While here, the fsck_ffs man page has also been updated to document
the failing exit status codes used by fsck_ffs. Previously, only exit
status 7 was documented. Some of these exit statuses are tested for in
the fsck rc-script, so they are clearly depended upon and deserve
documentation.
Reviewed by: mckusick, vangyzen, jilles (manpages)
MFC after: 1 week
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D13862
2018-01-15 19:25:11 +00:00
|
|
|
#define ERERUN 16 /* fsck needs to be re-run. */
|
2013-12-30 01:16:08 +00:00
|
|
|
#define ERESTART -1
|
1997-03-11 12:20:21 +00:00
|
|
|
|
2013-03-23 20:00:02 +00:00
|
|
|
int flushentry(void);
|
|
|
|
/*
|
|
|
|
* Wrapper for malloc() that flushes the cylinder group cache to try
|
|
|
|
* to get space.
|
|
|
|
*/
|
|
|
|
static inline void*
|
2014-02-25 18:25:27 +00:00
|
|
|
Malloc(size_t size)
|
2013-03-23 20:00:02 +00:00
|
|
|
{
|
|
|
|
void *retval;
|
|
|
|
|
|
|
|
while ((retval = malloc(size)) == NULL)
|
|
|
|
if (flushentry() == 0)
|
|
|
|
break;
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for calloc() that flushes the cylinder group cache to try
|
|
|
|
* to get space.
|
|
|
|
*/
|
|
|
|
static inline void*
|
2014-02-25 18:25:27 +00:00
|
|
|
Calloc(size_t cnt, size_t size)
|
2013-03-23 20:00:02 +00:00
|
|
|
{
|
|
|
|
void *retval;
|
|
|
|
|
|
|
|
while ((retval = calloc(cnt, size)) == NULL)
|
|
|
|
if (flushentry() == 0)
|
|
|
|
break;
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
struct fstab;
|
|
|
|
|
1998-12-03 02:27:35 +00:00
|
|
|
|
2002-03-20 22:57:10 +00:00
|
|
|
void adjust(struct inodesc *, int lcnt);
|
2021-01-07 01:37:08 +00:00
|
|
|
void alarmhandler(int sig);
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t allocblk(long frags);
|
2002-03-20 22:57:10 +00:00
|
|
|
ino_t allocdir(ino_t parent, ino_t request, int mode);
|
|
|
|
ino_t allocino(ino_t request, int type);
|
2002-07-30 13:01:25 +00:00
|
|
|
void blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
|
2002-03-20 22:57:10 +00:00
|
|
|
char *blockcheck(char *name);
|
2006-10-31 22:06:56 +00:00
|
|
|
int blread(int fd, char *buf, ufs2_daddr_t blk, long size);
|
2002-03-20 22:57:10 +00:00
|
|
|
void bufinit(void);
|
2012-09-12 15:36:44 +00:00
|
|
|
void blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size);
|
2011-04-29 23:00:23 +00:00
|
|
|
void blerase(int fd, ufs2_daddr_t blk, long size);
|
2013-04-29 20:13:09 +00:00
|
|
|
void blzero(int fd, ufs2_daddr_t blk, long size);
|
2021-01-07 01:37:08 +00:00
|
|
|
void brelse(struct bufarea *);
|
2022-09-03 21:46:50 +00:00
|
|
|
struct inoinfo *cacheino(union dinode *dp, ino_t inumber);
|
2002-03-20 22:57:10 +00:00
|
|
|
void catch(int);
|
|
|
|
void catchquit(int);
|
2018-12-05 06:31:50 +00:00
|
|
|
void cgdirty(struct bufarea *);
|
2021-01-07 01:37:08 +00:00
|
|
|
struct bufarea *cglookup(int cg);
|
2002-07-30 13:01:25 +00:00
|
|
|
int changeino(ino_t dir, const char *name, ino_t newnum);
|
2021-01-07 01:37:08 +00:00
|
|
|
int check_cgmagic(int cg, struct bufarea *cgbp, int requestrebuild);
|
2002-06-21 06:18:05 +00:00
|
|
|
int chkrange(ufs2_daddr_t blk, int cnt);
|
2002-03-20 22:57:10 +00:00
|
|
|
void ckfini(int markclean);
|
2002-06-21 06:18:05 +00:00
|
|
|
int ckinode(union dinode *dp, struct inodesc *);
|
2002-07-30 13:01:25 +00:00
|
|
|
void clri(struct inodesc *, const char *type, int flag);
|
2002-03-20 22:57:10 +00:00
|
|
|
int clearentry(struct inodesc *);
|
2002-07-30 13:01:25 +00:00
|
|
|
void direrror(ino_t ino, const char *errmesg);
|
2002-03-20 22:57:10 +00:00
|
|
|
int dirscan(struct inodesc *);
|
2002-07-30 13:01:25 +00:00
|
|
|
int dofix(struct inodesc *, const char *msg);
|
2002-09-16 11:27:47 +00:00
|
|
|
int eascan(struct inodesc *, struct ufs2_dinode *dp);
|
2002-07-30 13:01:25 +00:00
|
|
|
void fileerror(ino_t cwd, ino_t ino, const char *errmesg);
|
2013-02-24 06:44:29 +00:00
|
|
|
void finalIOstats(void);
|
2002-03-20 22:57:10 +00:00
|
|
|
int findino(struct inodesc *);
|
|
|
|
int findname(struct inodesc *);
|
|
|
|
void flush(int fd, struct bufarea *bp);
|
2020-12-18 23:28:27 +00:00
|
|
|
int freeblock(struct inodesc *);
|
2002-03-20 22:57:10 +00:00
|
|
|
void freeino(ino_t ino);
|
|
|
|
void freeinodebuf(void);
|
2013-12-30 01:16:08 +00:00
|
|
|
void fsutilinit(void);
|
2002-06-21 06:18:05 +00:00
|
|
|
int ftypeok(union dinode *dp);
|
|
|
|
void getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
|
2013-02-24 06:44:29 +00:00
|
|
|
struct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
|
2002-03-20 22:57:10 +00:00
|
|
|
struct inoinfo *getinoinfo(ino_t inumber);
|
2009-02-04 01:02:56 +00:00
|
|
|
union dinode *getnextinode(ino_t inumber, int rebuildcg);
|
2002-03-20 22:57:10 +00:00
|
|
|
void getpathname(char *namebuf, ino_t curdir, ino_t ino);
|
2021-01-07 01:37:08 +00:00
|
|
|
void ginode(ino_t, struct inode *);
|
2002-03-20 22:57:10 +00:00
|
|
|
void infohandler(int sig);
|
2021-01-07 01:37:08 +00:00
|
|
|
void irelse(struct inode *);
|
|
|
|
ufs2_daddr_t ino_blkatoff(union dinode *, ino_t, ufs_lbn_t, int *,
|
|
|
|
struct bufarea **);
|
2002-03-20 22:57:10 +00:00
|
|
|
void inocleanup(void);
|
2021-01-07 01:37:08 +00:00
|
|
|
void inodirty(struct inode *);
|
2002-03-20 22:57:10 +00:00
|
|
|
struct inostat *inoinfo(ino_t inum);
|
2013-02-24 06:44:29 +00:00
|
|
|
void IOstats(char *what);
|
2002-03-20 22:57:10 +00:00
|
|
|
int linkup(ino_t orphan, ino_t parentdir, char *name);
|
2002-07-30 13:01:25 +00:00
|
|
|
int makeentry(ino_t parent, ino_t ino, const char *name);
|
2022-02-23 23:39:52 +00:00
|
|
|
int openfilesys(char *dev);
|
2002-03-20 22:57:10 +00:00
|
|
|
void panic(const char *fmt, ...) __printflike(1, 2);
|
|
|
|
void pass1(void);
|
|
|
|
void pass1b(void);
|
|
|
|
int pass1check(struct inodesc *);
|
|
|
|
void pass2(void);
|
|
|
|
void pass3(void);
|
|
|
|
void pass4(void);
|
|
|
|
void pass5(void);
|
|
|
|
void pfatal(const char *fmt, ...) __printflike(1, 2);
|
|
|
|
void propagate(void);
|
2021-01-07 01:37:08 +00:00
|
|
|
void prtinode(struct inode *);
|
2002-03-20 22:57:10 +00:00
|
|
|
void pwarn(const char *fmt, ...) __printflike(1, 2);
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 19:41:53 +00:00
|
|
|
int readsb(void);
|
2002-07-30 13:01:25 +00:00
|
|
|
int reply(const char *question);
|
|
|
|
void rwerror(const char *mesg, ufs2_daddr_t blk);
|
2002-03-20 22:57:10 +00:00
|
|
|
void sblock_init(void);
|
2021-01-07 01:37:08 +00:00
|
|
|
void setinodebuf(int, ino_t);
|
2002-03-20 22:57:10 +00:00
|
|
|
int setup(char *dev);
|
2006-10-31 22:06:56 +00:00
|
|
|
void gjournal_check(const char *filesys);
|
2010-04-24 07:05:35 +00:00
|
|
|
int suj_check(const char *filesys);
|
2011-07-15 15:43:40 +00:00
|
|
|
void update_maps(struct cg *, struct cg*, int);
|
2013-12-30 01:16:08 +00:00
|
|
|
void fsckinit(void);
|
2010-04-24 07:54:49 +00:00
|
|
|
|
|
|
|
#endif /* !_FSCK_H_ */
|