Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
/* $NetBSD: setup.c,v 1.29 2006/07/18 23:37:13 perseant Exp $ */
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 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>.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1999-03-18 05:02:18 +03: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.
|
2003-08-07 14:04:22 +04: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DKTYPENAMES */
|
|
|
|
#define FSTYPENAMES
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <sys/types.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/queue.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
#define vnode uvnode
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <ufs/lfs/lfs.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#undef vnode
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
#include <time.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
#include "bufcache.h"
|
|
|
|
#include "vnode.h"
|
2005-09-13 08:14:17 +04:00
|
|
|
#include "lfs_user.h"
|
2003-03-28 11:09:52 +03:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
#include "fsck.h"
|
|
|
|
#include "extern.h"
|
|
|
|
#include "fsutil.h"
|
|
|
|
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
extern u_int32_t cksum(void *, size_t);
|
2000-05-23 05:48:52 +04:00
|
|
|
static struct disklabel *getdisklabel(const char *, int);
|
2004-09-15 07:24:09 +04:00
|
|
|
static uint64_t calcmaxfilesize(int);
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
ufs_daddr_t *din_table;
|
|
|
|
SEGUSE *seg_table;
|
2000-05-16 08:55:58 +04:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
#ifdef DKTYPENAMES
|
2003-03-28 11:09:52 +03:00
|
|
|
int useless(void);
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
useless(void)
|
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
char **foo = (char **) dktypenames;
|
|
|
|
char **bar = (char **) fscknames;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
return foo - bar;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-15 07:24:09 +04:00
|
|
|
/*
|
|
|
|
* calculate the maximum file size allowed with the specified block shift.
|
|
|
|
*/
|
|
|
|
static uint64_t
|
|
|
|
calcmaxfilesize(int bshift)
|
|
|
|
{
|
|
|
|
uint64_t nptr; /* number of block pointers per block */
|
|
|
|
uint64_t maxblock;
|
|
|
|
|
|
|
|
nptr = (1 << bshift) / sizeof(uint32_t);
|
|
|
|
maxblock = NDADDR + nptr + nptr * nptr + nptr * nptr * nptr;
|
|
|
|
|
|
|
|
return maxblock << bshift;
|
|
|
|
}
|
2005-04-12 03:19:24 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
reset_maxino(ino_t len)
|
|
|
|
{
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
if (debug)
|
|
|
|
pwarn("maxino reset from %lld to %lld\n", (long long)maxino,
|
|
|
|
(long long)len);
|
|
|
|
|
2005-04-12 03:19:24 +04:00
|
|
|
din_table = (ufs_daddr_t *) realloc(din_table, len * sizeof(*din_table));
|
|
|
|
statemap = realloc(statemap, len * sizeof(char));
|
|
|
|
typemap = realloc(typemap, len * sizeof(char));
|
|
|
|
lncntp = (int16_t *) realloc(lncntp, len * sizeof(int16_t));
|
|
|
|
|
|
|
|
if (din_table == NULL || statemap == NULL || typemap == NULL ||
|
|
|
|
lncntp == NULL) {
|
|
|
|
errexit("expanding tables failed: out of memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(din_table + maxino, 0, (len - maxino) * sizeof(*din_table));
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
memset(statemap + maxino, USTATE, (len - maxino) * sizeof(char));
|
2005-04-12 03:19:24 +04:00
|
|
|
memset(typemap + maxino, 0, (len - maxino) * sizeof(char));
|
|
|
|
memset(lncntp + maxino, 0, (len - maxino) * sizeof(int16_t));
|
|
|
|
|
2005-06-08 23:09:55 +04:00
|
|
|
maxino = len;
|
|
|
|
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
/*
|
|
|
|
* We can't roll forward after allocating new inodes in previous
|
|
|
|
* phases, or thy would conflict (lost+found, for example, might
|
|
|
|
* disappear to be replaced by a file found in roll-forward).
|
|
|
|
*/
|
|
|
|
no_roll_forward = 1;
|
|
|
|
|
2005-04-12 03:19:24 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-09-15 07:24:09 +04:00
|
|
|
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
extern time_t write_time;
|
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
int
|
2000-05-23 05:48:52 +04:00
|
|
|
setup(const char *dev)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
long bmapsize;
|
1999-03-18 05:02:18 +03:00
|
|
|
struct disklabel *lp;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct stat statb;
|
|
|
|
int doskipclean;
|
|
|
|
u_int64_t maxfilesize;
|
|
|
|
int open_flags;
|
|
|
|
struct uvnode *ivp;
|
|
|
|
struct ubuf *bp;
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
int i, isdirty;
|
|
|
|
long sn, curseg;
|
2003-03-28 11:09:52 +03:00
|
|
|
SEGUSE *sup;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
havesb = 0;
|
|
|
|
doskipclean = skipclean;
|
|
|
|
if (stat(dev, &statb) < 0) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pfatal("Can't stat %s: %s\n", dev, strerror(errno));
|
1999-03-18 05:02:18 +03:00
|
|
|
return (0);
|
|
|
|
}
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
if (!S_ISCHR(statb.st_mode) && skipclean) {
|
1999-03-18 05:02:18 +03:00
|
|
|
pfatal("%s is not a character device", dev);
|
|
|
|
if (reply("CONTINUE") == 0)
|
|
|
|
return (0);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (nflag)
|
|
|
|
open_flags = O_RDONLY;
|
|
|
|
else
|
|
|
|
open_flags = O_RDWR;
|
|
|
|
|
|
|
|
if ((fsreadfd = open(dev, open_flags)) < 0) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pfatal("Can't open %s: %s\n", dev, strerror(errno));
|
1999-03-18 05:02:18 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (nflag) {
|
1999-03-18 05:02:18 +03:00
|
|
|
if (preen)
|
|
|
|
pfatal("NO WRITE ACCESS");
|
2005-04-15 01:15:59 +04:00
|
|
|
printf("** %s (NO WRITE)\n", dev);
|
|
|
|
quiet = 0;
|
|
|
|
} else if (!preen && !quiet)
|
|
|
|
printf("** %s\n", dev);
|
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
fsmodified = 0;
|
|
|
|
lfdir = 0;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
/* Initialize time in case we have to write */
|
|
|
|
time(&write_time);
|
|
|
|
|
2005-04-12 03:19:24 +04:00
|
|
|
bufinit(0); /* XXX we could make a better guess */
|
2005-02-26 08:45:54 +03:00
|
|
|
fs = lfs_init(fsreadfd, bflag, idaddr, 0, debug);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs == NULL) {
|
|
|
|
if (preen)
|
|
|
|
printf("%s: ", cdevname());
|
2006-04-28 04:07:54 +04:00
|
|
|
errexit("BAD SUPER BLOCK OR IFILE INODE NOT FOUND\n");
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2000-05-23 05:48:52 +04:00
|
|
|
if ((lp = getdisklabel((char *) NULL, fsreadfd)) != NULL)
|
1999-03-18 05:02:18 +03:00
|
|
|
dev_bsize = secsize = lp->d_secsize;
|
|
|
|
else
|
|
|
|
dev_bsize = secsize = DEV_BSIZE;
|
|
|
|
|
2005-04-12 03:19:24 +04:00
|
|
|
/* Resize buffer cache now that we have a superblock to guess from. */
|
|
|
|
bufrehash((fs->lfs_segtabsz + maxino / fs->lfs_ifpb) << 4);
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs->lfs_pflags & LFS_PF_CLEAN) {
|
|
|
|
if (doskipclean) {
|
2005-04-15 01:15:59 +04:00
|
|
|
if (!quiet)
|
|
|
|
pwarn("%sile system is clean; not checking\n",
|
|
|
|
preen ? "f" : "** F");
|
2003-03-28 11:09:52 +03:00
|
|
|
return (-1);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (!preen)
|
|
|
|
pwarn("** File system is already clean\n");
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2000-05-16 08:55:58 +04:00
|
|
|
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
if (idaddr) {
|
|
|
|
daddr_t tdaddr;
|
|
|
|
SEGSUM *sp;
|
|
|
|
FINFO *fp;
|
|
|
|
int bc;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
pwarn("adjusting offset, serial for -i 0x%lx\n",
|
|
|
|
(unsigned long)idaddr);
|
|
|
|
tdaddr = sntod(fs, dtosn(fs, idaddr));
|
|
|
|
if (sntod(fs, dtosn(fs, tdaddr)) == tdaddr) {
|
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
|
|
|
if (fs->lfs_sboffs[i] == tdaddr)
|
|
|
|
tdaddr += btofsb(fs, LFS_SBPAD);
|
|
|
|
if (fs->lfs_sboffs[i] > tdaddr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fs->lfs_offset = tdaddr;
|
|
|
|
if (debug)
|
|
|
|
pwarn("begin with offset/serial 0x%x/%d\n",
|
|
|
|
(int)fs->lfs_offset, (int)fs->lfs_serial);
|
|
|
|
while (tdaddr < idaddr) {
|
|
|
|
bread(fs->lfs_devvp, fsbtodb(fs, tdaddr),
|
|
|
|
fs->lfs_sumsize,
|
|
|
|
NULL, &bp);
|
|
|
|
sp = (SEGSUM *)bp->b_data;
|
|
|
|
if (sp->ss_sumsum != cksum(&sp->ss_datasum,
|
|
|
|
fs->lfs_sumsize -
|
|
|
|
sizeof(sp->ss_sumsum))) {
|
|
|
|
brelse(bp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fp = (FINFO *)(sp + 1);
|
|
|
|
bc = howmany(sp->ss_ninos, INOPB(fs)) <<
|
|
|
|
(fs->lfs_version > 1 ? fs->lfs_ffshift :
|
|
|
|
fs->lfs_bshift);
|
|
|
|
for (i = 0; i < sp->ss_nfinfo; i++) {
|
|
|
|
bc += fp->fi_lastlength + ((fp->fi_nblocks - 1)
|
|
|
|
<< fs->lfs_bshift);
|
|
|
|
fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
tdaddr += btofsb(fs, bc) + 1;
|
|
|
|
fs->lfs_offset = tdaddr;
|
|
|
|
fs->lfs_serial = sp->ss_serial + 1;
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set curseg, nextseg appropriately -- inlined from
|
|
|
|
* lfs_newseg()
|
|
|
|
*/
|
|
|
|
curseg = dtosn(fs, fs->lfs_offset);
|
|
|
|
fs->lfs_curseg = sntod(fs, curseg);
|
|
|
|
for (sn = curseg + fs->lfs_interleave;;) {
|
|
|
|
sn = (sn + 1) % fs->lfs_nseg;
|
|
|
|
if (sn == curseg)
|
|
|
|
errx(1, "init: no clean segments");
|
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
|
|
|
isdirty = sup->su_flags & SEGUSE_DIRTY;
|
|
|
|
brelse(bp);
|
|
|
|
|
|
|
|
if (!isdirty)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip superblock if necessary */
|
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++)
|
|
|
|
if (fs->lfs_offset == fs->lfs_sboffs[i])
|
|
|
|
fs->lfs_offset += btofsb(fs, LFS_SBPAD);
|
|
|
|
|
|
|
|
++fs->lfs_nactive;
|
|
|
|
fs->lfs_nextseg = sntod(fs, sn);
|
|
|
|
if (debug) {
|
|
|
|
pwarn("offset = 0x%" PRIx32 ", serial = %" PRId64 "\n",
|
|
|
|
fs->lfs_offset, fs->lfs_serial);
|
|
|
|
pwarn("curseg = %" PRIx32 ", nextseg = %" PRIx32 "\n",
|
|
|
|
fs->lfs_curseg, fs->lfs_nextseg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nflag && !skipclean) {
|
|
|
|
fs->lfs_idaddr = idaddr;
|
|
|
|
fsmodified = 1;
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
if (debug) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("idaddr = 0x%lx\n", idaddr ? (unsigned long)idaddr :
|
2003-03-31 23:56:59 +04:00
|
|
|
(unsigned long)fs->lfs_idaddr);
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("dev_bsize = %lu\n", dev_bsize);
|
|
|
|
pwarn("lfs_bsize = %lu\n", (unsigned long) fs->lfs_bsize);
|
|
|
|
pwarn("lfs_fsize = %lu\n", (unsigned long) fs->lfs_fsize);
|
|
|
|
pwarn("lfs_frag = %lu\n", (unsigned long) fs->lfs_frag);
|
|
|
|
pwarn("lfs_inopb = %lu\n", (unsigned long) fs->lfs_inopb);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs->lfs_version == 1)
|
|
|
|
maxfsblock = fs->lfs_size * (fs->lfs_bsize / dev_bsize);
|
|
|
|
else
|
|
|
|
maxfsblock = fs->lfs_size;
|
2004-09-15 07:24:09 +04:00
|
|
|
maxfilesize = calcmaxfilesize(fs->lfs_bshift);
|
2003-03-28 11:09:52 +03:00
|
|
|
if ((fs->lfs_minfree < 0 || fs->lfs_minfree > 99)) {
|
1999-03-18 05:02:18 +03:00
|
|
|
pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
|
2003-03-28 11:09:52 +03:00
|
|
|
fs->lfs_minfree);
|
1999-03-18 05:02:18 +03:00
|
|
|
if (reply("SET TO DEFAULT") == 1) {
|
2003-03-28 11:09:52 +03:00
|
|
|
fs->lfs_minfree = 10;
|
1999-03-18 05:02:18 +03:00
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs->lfs_bmask != fs->lfs_bsize - 1) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("INCORRECT BMASK=0x%x IN SUPERBLOCK (SHOULD BE 0x%x)",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned int) fs->lfs_bmask,
|
|
|
|
(unsigned int) fs->lfs_bsize - 1);
|
|
|
|
fs->lfs_bmask = fs->lfs_bsize - 1;
|
1999-03-18 05:02:18 +03:00
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
if (preen || reply("FIX") == 1) {
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs->lfs_ffmask != fs->lfs_fsize - 1) {
|
|
|
|
pwarn("INCORRECT FFMASK=%" PRId64 " IN SUPERBLOCK",
|
|
|
|
fs->lfs_ffmask);
|
|
|
|
fs->lfs_ffmask = fs->lfs_fsize - 1;
|
1999-03-18 05:02:18 +03:00
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
if (preen || reply("FIX") == 1) {
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (fs->lfs_fbmask != (1 << fs->lfs_fbshift) - 1) {
|
|
|
|
pwarn("INCORRECT FFMASK=%" PRId64 " IN SUPERBLOCK",
|
|
|
|
fs->lfs_ffmask);
|
|
|
|
fs->lfs_fbmask = (1 << fs->lfs_fbshift) - 1;
|
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
if (preen || reply("FIX") == 1) {
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fs->lfs_maxfilesize != maxfilesize) {
|
2001-01-05 05:02:57 +03:00
|
|
|
pwarn(
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
"INCORRECT MAXFILESIZE=%llu IN SUPERBLOCK (SHOULD BE %llu WITH BSHIFT %d)",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned long long) fs->lfs_maxfilesize,
|
2005-04-12 03:19:24 +04:00
|
|
|
(unsigned long long) maxfilesize, (int)fs->lfs_bshift);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
if (preen || reply("FIX") == 1) {
|
2005-04-12 03:19:24 +04:00
|
|
|
fs->lfs_maxfilesize = maxfilesize;
|
2000-05-23 05:48:52 +04:00
|
|
|
sbdirty();
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
if (fs->lfs_maxsymlinklen != MAXSYMLINKLEN_UFS1) {
|
2000-05-23 05:48:52 +04:00
|
|
|
pwarn("INCORRECT MAXSYMLINKLEN=%d IN SUPERBLOCK",
|
2003-03-28 11:09:52 +03:00
|
|
|
fs->lfs_maxsymlinklen);
|
2003-04-02 14:39:19 +04:00
|
|
|
fs->lfs_maxsymlinklen = MAXSYMLINKLEN_UFS1;
|
2000-05-23 05:48:52 +04:00
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
if (preen || reply("FIX") == 1) {
|
|
|
|
sbdirty();
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the Ifile; we'll be using it a lot.
|
|
|
|
* XXX If the Ifile is corrupted we are in bad shape. We need to
|
|
|
|
* XXX run through the segment headers of the entire disk to
|
|
|
|
* XXX reconstruct the inode table, then pretend all segments are
|
|
|
|
* XXX dirty while we do the rest.
|
|
|
|
*/
|
|
|
|
ivp = fs->lfs_ivnode;
|
2003-04-02 14:39:19 +04:00
|
|
|
maxino = ((VTOI(ivp)->i_ffs1_size - (fs->lfs_cleansz + fs->lfs_segtabsz)
|
2003-03-28 11:09:52 +03:00
|
|
|
* fs->lfs_bsize) / fs->lfs_bsize) * fs->lfs_ifpb;
|
|
|
|
if (debug)
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("maxino = %llu\n", (unsigned long long)maxino);
|
2003-04-02 14:39:19 +04:00
|
|
|
for (i = 0; i < VTOI(ivp)->i_ffs1_size; i += fs->lfs_bsize) {
|
2003-03-28 11:09:52 +03:00
|
|
|
bread(ivp, i >> fs->lfs_bshift, fs->lfs_bsize, NOCRED, &bp);
|
|
|
|
/* XXX check B_ERROR */
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
/*
|
|
|
|
* allocate and initialize the necessary maps
|
|
|
|
*/
|
2003-03-28 11:09:52 +03:00
|
|
|
din_table = (ufs_daddr_t *) malloc(maxino * sizeof(*din_table));
|
2005-05-24 02:17:20 +04:00
|
|
|
if (din_table == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %lu bytes for din_table\n",
|
2005-05-24 10:51:49 +04:00
|
|
|
(unsigned long) maxino * sizeof(*din_table));
|
2005-05-24 02:17:20 +04:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
memset(din_table, 0, maxino * sizeof(*din_table));
|
|
|
|
seg_table = (SEGUSE *) malloc(fs->lfs_nseg * sizeof(SEGUSE));
|
2005-05-24 02:17:20 +04:00
|
|
|
if (seg_table == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %lu bytes for seg_table\n",
|
2005-05-24 10:51:49 +04:00
|
|
|
(unsigned long) fs->lfs_nseg * sizeof(SEGUSE));
|
2005-05-24 02:17:20 +04:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
memset(seg_table, 0, fs->lfs_nseg * sizeof(SEGUSE));
|
|
|
|
/* Get segment flags */
|
|
|
|
for (i = 0; i < fs->lfs_nseg; i++) {
|
|
|
|
LFS_SEGENTRY(sup, fs, i, bp);
|
|
|
|
seg_table[i].su_flags = sup->su_flags & ~SEGUSE_ACTIVE;
|
2003-03-29 03:09:43 +03:00
|
|
|
if (preen)
|
|
|
|
seg_table[i].su_nbytes = sup->su_nbytes;
|
2003-03-28 11:09:52 +03:00
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize Ifile entry */
|
|
|
|
din_table[fs->lfs_ifile] = fs->lfs_idaddr;
|
2003-04-02 14:39:19 +04:00
|
|
|
seg_table[dtosn(fs, fs->lfs_idaddr)].su_nbytes += DINODE1_SIZE;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
#ifndef VERBOSE_BLOCKMAP
|
|
|
|
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
|
2003-03-28 11:09:52 +03:00
|
|
|
blockmap = calloc((unsigned) bmapsize, sizeof(char));
|
1999-03-18 05:02:18 +03:00
|
|
|
#else
|
2000-05-23 05:48:52 +04:00
|
|
|
bmapsize = maxfsblock * sizeof(ino_t);
|
2003-03-28 11:09:52 +03:00
|
|
|
blockmap = (ino_t *) calloc(maxfsblock, sizeof(ino_t));
|
1999-03-18 05:02:18 +03:00
|
|
|
#endif
|
|
|
|
if (blockmap == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %u bytes for blockmap\n",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned) bmapsize);
|
1999-03-18 05:02:18 +03:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
statemap = calloc((unsigned) maxino, sizeof(char));
|
1999-03-18 05:02:18 +03:00
|
|
|
if (statemap == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %u bytes for statemap\n",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned) maxino);
|
1999-03-18 05:02:18 +03:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
typemap = calloc((unsigned) maxino, sizeof(char));
|
1999-03-18 05:02:18 +03:00
|
|
|
if (typemap == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %u bytes for typemap\n",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned) maxino);
|
1999-03-18 05:02:18 +03:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
lncntp = (int16_t *) calloc((unsigned) maxino, sizeof(int16_t));
|
1999-03-18 05:02:18 +03:00
|
|
|
if (lncntp == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %lu bytes for lncntp\n",
|
2003-03-28 11:09:52 +03:00
|
|
|
(unsigned long) maxino * sizeof(int16_t));
|
1999-03-18 05:02:18 +03:00
|
|
|
goto badsblabel;
|
|
|
|
}
|
2003-03-29 03:09:43 +03:00
|
|
|
|
|
|
|
if (preen) {
|
|
|
|
n_files = fs->lfs_nfiles;
|
|
|
|
n_blks = fs->lfs_dsize - fs->lfs_bfree;
|
|
|
|
numdirs = maxino;
|
|
|
|
inplast = 0;
|
|
|
|
listmax = numdirs + 10;
|
|
|
|
inpsort = (struct inoinfo **) calloc((unsigned) listmax,
|
|
|
|
sizeof(struct inoinfo *));
|
|
|
|
inphead = (struct inoinfo **) calloc((unsigned) numdirs,
|
|
|
|
sizeof(struct inoinfo *));
|
|
|
|
if (inpsort == NULL || inphead == NULL) {
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pwarn("cannot alloc %lu bytes for inphead\n",
|
2003-03-29 03:09:43 +03:00
|
|
|
(unsigned long) numdirs * sizeof(struct inoinfo *));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
badsblabel:
|
|
|
|
ckfini(0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct disklabel *
|
2000-05-23 05:48:52 +04:00
|
|
|
getdisklabel(const char *s, int fd)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
|
|
|
static struct disklabel lab;
|
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
if (ioctl(fd, DIOCGDINFO, (char *) &lab) < 0) {
|
1999-03-18 05:02:18 +03:00
|
|
|
if (s == NULL)
|
2000-05-23 05:48:52 +04:00
|
|
|
return ((struct disklabel *) NULL);
|
1999-03-18 05:02:18 +03:00
|
|
|
pwarn("ioctl (GCINFO): %s\n", strerror(errno));
|
2000-05-16 08:55:58 +04:00
|
|
|
return NULL;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
return (&lab);
|
|
|
|
}
|