2015-10-03 11:29:21 +03:00
|
|
|
/* $NetBSD: pass6.c,v 1.49 2015/10/03 08:29:21 dholland Exp $ */
|
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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2013-06-06 04:54:49 +04:00
|
|
|
#define VU_DIROP 0x01000000 /* XXX XXX from sys/vnode.h */
|
|
|
|
#define vnode uvnode
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <ufs/lfs/lfs.h>
|
2015-07-28 08:09:34 +03:00
|
|
|
#include <ufs/lfs/lfs_accessors.h>
|
2013-06-08 06:16:03 +04:00
|
|
|
#include <ufs/lfs/lfs_inode.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#undef vnode
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <err.h>
|
2006-09-01 23:52:48 +04:00
|
|
|
#include <signal.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-11-09 22:36:36 +03:00
|
|
|
#include <util.h>
|
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
|
|
|
#include "segwrite.h"
|
|
|
|
|
|
|
|
#include "fsck.h"
|
|
|
|
#include "extern.h"
|
|
|
|
#include "fsutil.h"
|
|
|
|
|
|
|
|
extern u_int32_t cksum(void *, size_t);
|
|
|
|
extern u_int32_t lfs_sb_cksum(struct dlfs *);
|
|
|
|
|
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
|
|
|
static int nnewblocks;
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/*
|
|
|
|
* Our own copy of lfs_update_single so we can account in seg_table
|
|
|
|
* as well as the Ifile; and so we can add the blocks to their new
|
|
|
|
* segment.
|
|
|
|
*
|
|
|
|
* Change the given block's address to ndaddr, finding its previous
|
2013-06-06 04:52:50 +04:00
|
|
|
* location using ulfs_bmaparray().
|
2003-03-28 11:09:52 +03:00
|
|
|
*
|
|
|
|
* Account for this change in the segment table.
|
|
|
|
*/
|
|
|
|
static void
|
2015-09-01 09:13:57 +03:00
|
|
|
rfw_update_single(struct uvnode *vp, daddr_t lbn, daddr_t ndaddr, size_t size)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
SEGUSE *sup;
|
|
|
|
struct ubuf *bp;
|
2013-06-06 04:52:50 +04:00
|
|
|
struct indir a[ULFS_NIADDR + 2], *ap;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inode *ip;
|
|
|
|
daddr_t daddr, ooff;
|
|
|
|
int num, error;
|
2010-02-17 02:20:30 +03:00
|
|
|
int i, osize = 0;
|
|
|
|
int frags, ofrags = 0;
|
2003-03-28 11:09:52 +03:00
|
|
|
u_int32_t oldsn, sn;
|
|
|
|
|
|
|
|
ip = VTOI(vp);
|
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
|
|
|
ip->i_flag |= IN_MODIFIED;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-06 04:52:50 +04:00
|
|
|
error = ulfs_bmaparray(fs, vp, lbn, &daddr, a, &num);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (error)
|
2013-06-06 04:52:50 +04:00
|
|
|
errx(1, "lfs_updatemeta: ulfs_bmaparray returned %d"
|
2003-03-28 11:09:52 +03:00
|
|
|
" looking up lbn %" PRId64 "\n", error, lbn);
|
|
|
|
if (daddr > 0)
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr = LFS_DBTOFSB(fs, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-18 22:18:57 +04:00
|
|
|
frags = lfs_numfrags(fs, size);
|
2003-03-28 11:09:52 +03:00
|
|
|
switch (num) {
|
|
|
|
case 0:
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_dino_getdb(fs, ip->i_din, lbn);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff <= 0)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
2003-03-28 11:09:52 +03:00
|
|
|
else {
|
|
|
|
/* possible fragment truncation or extension */
|
2013-06-18 22:18:57 +04:00
|
|
|
ofrags = lfs_numfrags(fs, ip->i_lfs_fragsize[lbn]);
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + (frags - ofrags));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setdb(fs, ip->i_din, lbn, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_dino_getib(fs, ip->i_din, a[0].in_off);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff <= 0)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
|
|
|
lfs_dino_setib(fs, ip->i_din, a[0].in_off, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ap = &a[num - 1];
|
2015-07-24 09:56:41 +03:00
|
|
|
if (bread(vp, ap->in_lbn, lfs_sb_getbsize(fs), 0, &bp))
|
2003-03-28 11:09:52 +03:00
|
|
|
errx(1, "lfs_updatemeta: bread bno %" PRId64,
|
|
|
|
ap->in_lbn);
|
|
|
|
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_iblock_get(fs, bp->b_data, ap->in_off);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff <= 0)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
|
|
|
lfs_iblock_set(fs, bp->b_data, ap->in_off, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) VOP_BWRITE(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update segment usage information, based on old size
|
|
|
|
* and location.
|
|
|
|
*/
|
|
|
|
if (daddr > 0) {
|
2013-06-18 22:18:57 +04:00
|
|
|
oldsn = lfs_dtosn(fs, daddr);
|
2013-06-06 04:52:50 +04:00
|
|
|
if (lbn >= 0 && lbn < ULFS_NDADDR)
|
2003-03-28 11:09:52 +03:00
|
|
|
osize = ip->i_lfs_fragsize[lbn];
|
|
|
|
else
|
2015-07-24 09:56:41 +03:00
|
|
|
osize = lfs_sb_getbsize(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, oldsn, bp);
|
|
|
|
seg_table[oldsn].su_nbytes -= osize;
|
|
|
|
sup->su_nbytes -= osize;
|
|
|
|
if (!(bp->b_flags & B_GATHERED))
|
|
|
|
fs->lfs_flags |= LFS_IFDIRTY;
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, oldsn, bp);
|
2013-06-18 22:18:57 +04:00
|
|
|
for (i = 0; i < lfs_btofsb(fs, osize); i++)
|
2003-03-28 11:09:52 +03:00
|
|
|
clrbmap(daddr + i);
|
|
|
|
}
|
|
|
|
|
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 block is beyond EOF, update size */
|
2015-09-01 09:08:37 +03:00
|
|
|
if (lbn >= 0 && lfs_dino_getsize(fs, ip->i_din) <= (lbn << lfs_sb_getbshift(fs))) {
|
|
|
|
lfs_dino_setsize(fs, ip->i_din, (lbn << lfs_sb_getbshift(fs)) + 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
|
|
|
}
|
|
|
|
|
2006-09-01 23:52:48 +04:00
|
|
|
/* If block frag size is too large for old EOF, update size */
|
2013-06-06 04:52:50 +04:00
|
|
|
if (lbn < ULFS_NDADDR) {
|
2006-09-01 23:52:48 +04:00
|
|
|
off_t minsize;
|
|
|
|
|
2015-07-24 09:59:31 +03:00
|
|
|
minsize = (lbn << lfs_sb_getbshift(fs));
|
2015-07-24 09:56:41 +03:00
|
|
|
minsize += (size - lfs_sb_getfsize(fs)) + 1;
|
2015-09-01 09:08:37 +03:00
|
|
|
if (lfs_dino_getsize(fs, ip->i_din) < minsize)
|
|
|
|
lfs_dino_setsize(fs, ip->i_din, minsize);
|
2006-09-01 23:52:48 +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
|
|
|
/* Count for the user */
|
|
|
|
++nnewblocks;
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Add block to its new segment */
|
2013-06-18 22:18:57 +04:00
|
|
|
sn = lfs_dtosn(fs, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
|
|
|
seg_table[sn].su_nbytes += size;
|
|
|
|
sup->su_nbytes += size;
|
|
|
|
if (!(bp->b_flags & B_GATHERED))
|
|
|
|
fs->lfs_flags |= LFS_IFDIRTY;
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, sn, bp);
|
2013-06-18 22:18:57 +04:00
|
|
|
for (i = 0; i < lfs_btofsb(fs, size); i++)
|
2006-09-01 23:52:48 +04:00
|
|
|
#ifndef VERBOSE_BLOCKMAP
|
2003-03-28 11:09:52 +03:00
|
|
|
setbmap(daddr + i);
|
2006-09-01 23:52:48 +04:00
|
|
|
#else
|
|
|
|
setbmap(daddr + i, ip->i_number);
|
|
|
|
#endif
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Check bfree accounting as well */
|
2005-06-08 23:09:55 +04:00
|
|
|
if (daddr <= 0) {
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subbfree(fs, lfs_btofsb(fs, size));
|
2003-03-28 11:09:52 +03:00
|
|
|
} else if (size != osize) {
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subbfree(fs, frags - ofrags);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that this block has a new address, and its old
|
|
|
|
* segment no longer owns it, we can forget about its
|
|
|
|
* old size.
|
|
|
|
*/
|
2013-06-06 04:52:50 +04:00
|
|
|
if (lbn >= 0 && lbn < ULFS_NDADDR)
|
2003-03-28 11:09:52 +03:00
|
|
|
ip->i_lfs_fragsize[lbn] = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the vnode from the cache, including any blocks it
|
|
|
|
* may hold. Account the blocks. Finally account the removal
|
|
|
|
* of the inode from its segment.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
remove_ino(struct uvnode *vp, ino_t ino)
|
|
|
|
{
|
|
|
|
IFILE *ifp;
|
2015-08-12 21:25:51 +03:00
|
|
|
ino_t nextfree;
|
2003-03-28 11:09:52 +03:00
|
|
|
SEGUSE *sup;
|
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
|
|
|
CLEANERINFO *cip;
|
|
|
|
struct ubuf *bp, *sbp, *cbp;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inodesc idesc;
|
2015-09-01 09:13:33 +03:00
|
|
|
daddr_t daddr;
|
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
|
|
|
if (debug)
|
|
|
|
pwarn("remove ino %d\n", (int)ino);
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
2015-08-12 21:25:51 +03:00
|
|
|
daddr = lfs_if_getdaddr(fs, ifp);
|
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 (daddr > 0) {
|
2015-08-12 21:25:51 +03:00
|
|
|
lfs_if_setdaddr(fs, ifp, 0);
|
2006-07-19 06:45:10 +04:00
|
|
|
|
2015-08-12 21:25:51 +03:00
|
|
|
LFS_GET_HEADFREE(fs, cip, cbp, &nextfree);
|
|
|
|
lfs_if_setnextfree(fs, ifp, nextfree);
|
2006-07-19 06:45:10 +04:00
|
|
|
VOP_BWRITE(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
|
|
|
LFS_PUT_HEADFREE(fs, cip, cbp, ino);
|
|
|
|
sbdirty();
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2006-07-19 06:45:10 +04:00
|
|
|
if (vp == NULL)
|
|
|
|
vp = lfs_raw_vget(fs, ino, fs->lfs_ivnode->v_fd, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-18 22:18:57 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes -= DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(sbp);
|
2015-08-12 21:28:00 +03:00
|
|
|
seg_table[lfs_dtosn(fs, daddr)].su_nbytes -= DINOSIZE(fs);
|
2006-07-19 06:45:10 +04:00
|
|
|
} else
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Do on-disk accounting */
|
|
|
|
if (vp) {
|
|
|
|
idesc.id_number = ino;
|
|
|
|
idesc.id_func = pass4check; /* Delete dinode and blocks */
|
|
|
|
idesc.id_type = ADDR;
|
|
|
|
idesc.id_lblkno = 0;
|
|
|
|
clri(&idesc, "unknown", 2); /* XXX magic number 2 */
|
2005-04-13 03:14:18 +04:00
|
|
|
/* vp has been destroyed */
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use FIP records to update blocks, if the generation number matches.
|
|
|
|
*/
|
|
|
|
static void
|
2015-09-01 09:13:57 +03:00
|
|
|
pass6harvest(daddr_t daddr, FINFO *fip)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
struct uvnode *vp;
|
|
|
|
int i;
|
|
|
|
size_t size;
|
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
vp = vget(fs, lfs_fi_getino(fs, fip));
|
2003-03-28 11:09:52 +03:00
|
|
|
if (vp && vp != fs->lfs_ivnode &&
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_getgen(fs, VTOI(vp)->i_din) == lfs_fi_getversion(fs, fip)) {
|
2015-08-12 21:27:01 +03:00
|
|
|
for (i = 0; i < lfs_fi_getnblocks(fs, fip); i++) {
|
|
|
|
size = (i == lfs_fi_getnblocks(fs, fip) - 1 ?
|
|
|
|
lfs_fi_getlastlength(fs, fip) : lfs_sb_getbsize(fs));
|
2006-09-01 23:52:48 +04:00
|
|
|
if (debug)
|
2015-08-12 21:27:01 +03:00
|
|
|
pwarn("ino %ju lbn %jd -> 0x%jx\n",
|
|
|
|
(uintmax_t)lfs_fi_getino(fs, fip),
|
|
|
|
(intmax_t)lfs_fi_getblock(fs, fip, i),
|
|
|
|
(intmax_t)daddr);
|
|
|
|
rfw_update_single(vp, lfs_fi_getblock(fs, fip, i), daddr, size);
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr += lfs_btofsb(fs, size);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check validity of blocks on roll-forward inodes.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pass6check(struct inodesc * idesc)
|
|
|
|
{
|
|
|
|
int i, sn, anyout, anynew;
|
|
|
|
|
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
|
|
|
/* Brand new blocks are always OK */
|
|
|
|
if (idesc->id_blkno == UNWRITTEN)
|
|
|
|
return KEEPON;
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Check that the blocks do not lie within clean segments. */
|
|
|
|
anyout = anynew = 0;
|
2010-02-17 02:20:30 +03:00
|
|
|
for (i = 0; i < idesc->id_numfrags; i++) {
|
2013-06-18 22:18:57 +04:00
|
|
|
sn = lfs_dtosn(fs, idesc->id_blkno + i);
|
2015-07-24 09:59:31 +03:00
|
|
|
if (sn < 0 || sn >= lfs_sb_getnseg(fs) ||
|
2003-03-28 11:09:52 +03:00
|
|
|
(seg_table[sn].su_flags & SEGUSE_DIRTY) == 0) {
|
|
|
|
anyout = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (seg_table[sn].su_flags & SEGUSE_ACTIVE) {
|
2015-07-24 09:56:41 +03:00
|
|
|
if (sn != lfs_dtosn(fs, lfs_sb_getoffset(fs)) ||
|
|
|
|
idesc->id_blkno > lfs_sb_getoffset(fs)) {
|
2003-03-28 11:09:52 +03:00
|
|
|
++anynew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!anynew) {
|
|
|
|
/* Clear so pass1check won't be surprised */
|
|
|
|
clrbmap(idesc->id_blkno + i);
|
2013-06-18 22:18:57 +04:00
|
|
|
seg_table[sn].su_nbytes -= lfs_fsbtob(fs, 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (anyout) {
|
|
|
|
blkerror(idesc->id_number, "BAD", idesc->id_blkno);
|
2015-09-01 09:15:02 +03:00
|
|
|
if (badblkcount++ >= MAXBAD) {
|
2005-08-19 06:07:18 +04:00
|
|
|
pwarn("EXCESSIVE BAD BLKS I=%llu",
|
|
|
|
(unsigned long long)idesc->id_number);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (preen)
|
|
|
|
pwarn(" (SKIPPING)\n");
|
|
|
|
else if (reply("CONTINUE") == 0)
|
2006-11-09 22:36:36 +03:00
|
|
|
err(EEXIT, "%s", "");
|
2003-03-28 11:09:52 +03:00
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pass1check(idesc);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void
|
2015-08-12 21:28:00 +03:00
|
|
|
account_indir(struct uvnode *vp, union lfs_dinode *dp, daddr_t ilbn, daddr_t daddr, int lvl)
|
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
|
|
|
{
|
|
|
|
struct ubuf *bp;
|
|
|
|
int32_t *dap, *odap, *buf, *obuf;
|
|
|
|
daddr_t lbn;
|
|
|
|
|
|
|
|
if (lvl == 0)
|
|
|
|
lbn = -ilbn;
|
|
|
|
else
|
|
|
|
lbn = ilbn + 1;
|
2015-07-24 09:56:41 +03:00
|
|
|
bread(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), lfs_sb_getbsize(fs), 0, &bp);
|
|
|
|
buf = emalloc(lfs_sb_getbsize(fs));
|
|
|
|
memcpy(buf, bp->b_data, lfs_sb_getbsize(fs));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 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
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
obuf = emalloc(lfs_sb_getbsize(fs));
|
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 (vp) {
|
2015-07-24 09:56:41 +03:00
|
|
|
bread(vp, ilbn, lfs_sb_getbsize(fs), 0, &bp);
|
|
|
|
memcpy(obuf, bp->b_data, lfs_sb_getbsize(fs));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 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
|
|
|
} else
|
2015-07-24 09:56:41 +03:00
|
|
|
memset(obuf, 0, lfs_sb_getbsize(fs));
|
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
|
|
|
|
|
|
|
for (dap = buf, odap = obuf;
|
2015-07-24 09:56:41 +03:00
|
|
|
dap < (int32_t *)((char *)buf + lfs_sb_getbsize(fs));
|
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
|
|
|
++dap, ++odap) {
|
|
|
|
if (*dap > 0 && *dap != *odap) {
|
2013-06-18 22:18:57 +04:00
|
|
|
rfw_update_single(vp, lbn, *dap, lfs_dblksize(fs, dp, lbn));
|
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 (lvl > 0)
|
|
|
|
account_indir(vp, dp, lbn, *dap, lvl - 1);
|
|
|
|
}
|
|
|
|
if (lvl == 0)
|
|
|
|
++lbn;
|
|
|
|
else if (lvl == 1)
|
2013-06-18 22:18:57 +04:00
|
|
|
lbn -= LFS_NINDIR(fs);
|
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
|
|
|
else if (lvl == 2)
|
2013-06-18 22:18:57 +04:00
|
|
|
lbn -= LFS_NINDIR(fs) * LFS_NINDIR(fs);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
free(obuf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Account block changes between new found inode and existing inode.
|
|
|
|
*/
|
|
|
|
static void
|
2015-08-12 21:28:00 +03:00
|
|
|
account_block_changes(union lfs_dinode *dp)
|
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;
|
|
|
|
daddr_t lbn, off, odaddr;
|
|
|
|
struct uvnode *vp;
|
|
|
|
struct inode *ip;
|
|
|
|
|
2015-08-12 21:28:00 +03:00
|
|
|
vp = vget(fs, lfs_dino_getinumber(fs, dp));
|
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
|
|
|
ip = (vp ? VTOI(vp) : NULL);
|
|
|
|
|
|
|
|
/* Check direct block holdings between existing and new */
|
2013-06-06 04:52:50 +04:00
|
|
|
for (i = 0; i < ULFS_NDADDR; i++) {
|
2015-09-01 09:08:37 +03:00
|
|
|
odaddr = (ip ? lfs_dino_getdb(fs, ip->i_din, i) : 0x0);
|
2015-08-12 21:28:00 +03:00
|
|
|
if (lfs_dino_getdb(fs, dp, i) > 0 && lfs_dino_getdb(fs, dp, i) != odaddr)
|
|
|
|
rfw_update_single(vp, i, lfs_dino_getdb(fs, dp, i),
|
2013-06-18 22:18:57 +04:00
|
|
|
lfs_dblksize(fs, dp, i));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* Check indirect block holdings between existing and new */
|
|
|
|
off = 0;
|
2013-06-06 04:52:50 +04:00
|
|
|
for (i = 0; i < ULFS_NIADDR; i++) {
|
2015-09-01 09:08:37 +03:00
|
|
|
odaddr = (ip ? lfs_dino_getib(fs, ip->i_din, i) : 0x0);
|
2015-08-12 21:28:00 +03:00
|
|
|
if (lfs_dino_getib(fs, dp, i) > 0 && lfs_dino_getib(fs, dp, i) != odaddr) {
|
2013-06-06 04:52:50 +04:00
|
|
|
lbn = -(ULFS_NDADDR + off + i);
|
2015-08-12 21:28:00 +03:00
|
|
|
rfw_update_single(vp, i, lfs_dino_getib(fs, dp, i), lfs_sb_getbsize(fs));
|
|
|
|
account_indir(vp, dp, lbn, lfs_dino_getib(fs, dp, i), i);
|
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 (off == 0)
|
2013-06-18 22:18:57 +04:00
|
|
|
off = LFS_NINDIR(fs);
|
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
|
|
|
else
|
2013-06-18 22:18:57 +04:00
|
|
|
off *= LFS_NINDIR(fs);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/*
|
|
|
|
* Give a previously allocated inode a new address; do segment
|
|
|
|
* accounting if necessary.
|
|
|
|
*
|
|
|
|
* Caller has ensured that this inode is not on the free list, so no
|
|
|
|
* free list accounting is done.
|
|
|
|
*/
|
|
|
|
static void
|
2015-09-01 09:13:33 +03:00
|
|
|
readdress_inode(union lfs_dinode *dp, daddr_t daddr)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
IFILE *ifp;
|
|
|
|
SEGUSE *sup;
|
|
|
|
struct ubuf *bp;
|
|
|
|
int sn;
|
2015-09-01 09:13:33 +03:00
|
|
|
daddr_t odaddr;
|
2015-08-12 21:28:00 +03:00
|
|
|
ino_t thisino = lfs_dino_getinumber(fs, dp);
|
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
|
|
|
struct uvnode *vp;
|
|
|
|
|
|
|
|
/* Recursively check all block holdings, account changes */
|
|
|
|
account_block_changes(dp);
|
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
|
|
|
/* Move ifile pointer to this location */
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_IENTRY(ifp, fs, thisino, bp);
|
2015-08-12 21:25:51 +03:00
|
|
|
odaddr = lfs_if_getdaddr(fs, ifp);
|
2006-07-19 06:45:10 +04:00
|
|
|
assert(odaddr != 0);
|
2015-08-12 21:25:51 +03:00
|
|
|
lfs_if_setdaddr(fs, ifp, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(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
|
|
|
if (debug)
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("readdress ino %ju from 0x%jx to 0x%jx mode %o nlink %d\n",
|
2015-08-12 21:28:00 +03:00
|
|
|
(uintmax_t)lfs_dino_getinumber(fs, dp),
|
2015-09-01 09:13:33 +03:00
|
|
|
(uintmax_t)odaddr,
|
|
|
|
(intmax_t)daddr,
|
2015-08-12 21:28:00 +03:00
|
|
|
(int)lfs_dino_getmode(fs, dp),
|
|
|
|
(int)lfs_dino_getnlink(fs, dp));
|
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
|
|
|
|
|
|
|
/* Copy over preexisting in-core inode, if any */
|
|
|
|
vp = vget(fs, thisino);
|
2015-08-19 23:33:29 +03:00
|
|
|
lfs_copy_dinode(fs, VTOI(vp)->i_din, dp);
|
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
|
|
|
|
|
|
|
/* Finally account the inode itself */
|
2013-06-18 22:18:57 +04:00
|
|
|
sn = lfs_dtosn(fs, odaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes -= DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
seg_table[sn].su_nbytes -= DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-18 22:18:57 +04:00
|
|
|
sn = lfs_dtosn(fs, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes += DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
seg_table[sn].su_nbytes += DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the given inode from the free list.
|
|
|
|
*/
|
|
|
|
static void
|
2015-09-01 09:15:02 +03:00
|
|
|
alloc_inode(ino_t thisino, daddr_t daddr)
|
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
|
|
|
ino_t ino, nextfree, oldhead;
|
2003-03-28 11:09:52 +03:00
|
|
|
IFILE *ifp;
|
|
|
|
SEGUSE *sup;
|
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
|
|
|
struct ubuf *bp, *cbp;
|
|
|
|
CLEANERINFO *cip;
|
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
|
|
|
if (debug)
|
2015-09-01 09:15:02 +03:00
|
|
|
pwarn("allocating ino %ju at 0x%jx\n", (uintmax_t)thisino,
|
|
|
|
(intmax_t)daddr);
|
2005-06-08 23:09:55 +04:00
|
|
|
while (thisino >= maxino) {
|
|
|
|
extend_ifile(fs);
|
|
|
|
}
|
2005-04-13 03:14:18 +04:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_IENTRY(ifp, fs, thisino, bp);
|
2015-08-12 21:25:51 +03:00
|
|
|
if (lfs_if_getdaddr(fs, ifp) != 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
|
|
|
pwarn("allocated inode %lld already allocated\n",
|
|
|
|
(long long)thisino);
|
|
|
|
}
|
2015-08-12 21:25:51 +03:00
|
|
|
nextfree = lfs_if_getnextfree(fs, ifp);
|
|
|
|
lfs_if_setnextfree(fs, ifp, 0);
|
|
|
|
lfs_if_setdaddr(fs, ifp, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(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
|
|
|
LFS_GET_HEADFREE(fs, cip, cbp, &oldhead);
|
|
|
|
if (oldhead == thisino) {
|
|
|
|
LFS_PUT_HEADFREE(fs, cip, cbp, nextfree);
|
2003-03-28 11:09:52 +03:00
|
|
|
sbdirty();
|
|
|
|
if (nextfree == 0) {
|
2005-06-08 23:09:55 +04:00
|
|
|
extend_ifile(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
} else {
|
2005-04-13 03:14:18 +04:00
|
|
|
/* Search the free list for this inode */
|
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
|
|
|
ino = oldhead;
|
2003-03-28 11:09:52 +03:00
|
|
|
while (ino) {
|
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
2015-08-12 21:25:51 +03:00
|
|
|
assert(lfs_if_getnextfree(fs, ifp) != ino);
|
|
|
|
if (lfs_if_getnextfree(fs, ifp) == thisino) {
|
|
|
|
lfs_if_setnextfree(fs, ifp, nextfree);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(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
|
|
|
if (nextfree == 0)
|
|
|
|
LFS_PUT_TAILFREE(fs, cip, cbp, ino);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
} else
|
2015-08-12 21:25:51 +03:00
|
|
|
ino = lfs_if_getnextfree(fs, ifp);
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Account for new location */
|
2013-06-18 22:18:57 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes += DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
seg_table[lfs_dtosn(fs, daddr)].su_nbytes += DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Roll forward from the last verified checkpoint.
|
|
|
|
*
|
|
|
|
* Basic strategy:
|
|
|
|
*
|
|
|
|
* Run through the summaries finding the last valid partial segment.
|
|
|
|
* Note segment numbers as we go. For each inode that we find, compare
|
|
|
|
* its generation number; if newer than old inode's (or if old inode is
|
|
|
|
* USTATE), change to that inode. Recursively look at inode blocks that
|
|
|
|
* do not have their old disk addresses. These addresses must lie in
|
|
|
|
* segments we have seen already in our roll forward.
|
|
|
|
*
|
|
|
|
* A second pass through the past-checkpoint area verifies the validity
|
|
|
|
* of these new blocks, as well as updating other blocks that do not
|
|
|
|
* have corresponding new inodes (but their generation number must match
|
|
|
|
* the old generation number).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pass6(void)
|
|
|
|
{
|
2015-09-01 09:13:33 +03:00
|
|
|
daddr_t daddr, ibdaddr, odaddr, lastgood;
|
2015-10-03 11:29:21 +03:00
|
|
|
IINFO *iip;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct uvnode *vp, *devvp;
|
|
|
|
CLEANERINFO *cip;
|
|
|
|
SEGUSE *sup;
|
|
|
|
SEGSUM *sp;
|
|
|
|
struct ubuf *bp, *ibp, *sbp, *cbp;
|
2015-08-12 21:28:00 +03:00
|
|
|
union lfs_dinode *dp;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inodesc idesc;
|
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, j, bc, hassuper;
|
2015-08-12 21:28:00 +03:00
|
|
|
unsigned k;
|
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 nnewfiles, ndelfiles, nmvfiles;
|
2006-09-01 23:52:48 +04:00
|
|
|
int sn, curseg;
|
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
|
|
|
char *ibbuf;
|
2006-09-01 23:52:48 +04:00
|
|
|
long lastserial;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2005-03-25 23:16:37 +03:00
|
|
|
devvp = fs->lfs_devvp;
|
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
|
|
|
/* If we can't roll forward because of created files, don't try */
|
|
|
|
if (no_roll_forward) {
|
|
|
|
if (debug)
|
|
|
|
pwarn("not rolling forward due to possible allocation conflict\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Find last valid partial segment */
|
|
|
|
lastgood = try_verify(fs, devvp, 0, debug);
|
2015-07-24 09:56:41 +03:00
|
|
|
if (lastgood == lfs_sb_getoffset(fs)) {
|
2003-03-28 11:09:52 +03:00
|
|
|
if (debug)
|
|
|
|
pwarn("not rolling forward, nothing to recover\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
2015-07-24 09:56:41 +03:00
|
|
|
pwarn("could roll forward from 0x%jx to 0x%jx\n",
|
|
|
|
(uintmax_t)lfs_sb_getoffset(fs), (uintmax_t)lastgood);
|
2005-04-24 00:21:03 +04:00
|
|
|
|
2006-04-17 23:05:16 +04:00
|
|
|
if (!preen && reply("ROLL FORWARD") == 0)
|
2005-04-24 00:21:03 +04:00
|
|
|
return;
|
2003-03-28 11:09:52 +03:00
|
|
|
/*
|
|
|
|
* Pass 1: find inode blocks. We ignore the Ifile inode but accept
|
|
|
|
* changes to any other inode.
|
|
|
|
*/
|
|
|
|
|
2015-07-24 09:59:31 +03:00
|
|
|
ibbuf = emalloc(lfs_sb_getibsize(fs));
|
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
|
|
|
nnewfiles = ndelfiles = nmvfiles = nnewblocks = 0;
|
2015-07-24 09:56:41 +03:00
|
|
|
daddr = lfs_sb_getoffset(fs);
|
2006-07-19 03:47:44 +04:00
|
|
|
hassuper = 0;
|
2006-09-01 23:52:48 +04:00
|
|
|
lastserial = 0;
|
2003-03-28 11:09:52 +03:00
|
|
|
while (daddr != lastgood) {
|
2013-06-18 22:18:57 +04:00
|
|
|
seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
|
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
|
2003-03-28 11:09:52 +03:00
|
|
|
sup->su_flags |= SEGUSE_DIRTY;
|
|
|
|
VOP_BWRITE(sbp);
|
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
|
|
|
|
|
|
|
/* Could be a superblock */
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr == lfs_sb_gets0addr(fs)) {
|
2006-09-01 23:52:48 +04:00
|
|
|
++hassuper;
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr += lfs_btofsb(fs, LFS_LABELPAD);
|
2006-09-01 23:52:48 +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
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr == lfs_sb_getsboff(fs, i)) {
|
2006-09-01 23:52:48 +04:00
|
|
|
++hassuper;
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr += lfs_btofsb(fs, LFS_SBPAD);
|
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
|
|
|
}
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr < lfs_sb_getsboff(fs, i))
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-01 09:13:33 +03:00
|
|
|
KASSERT(hassuper == 0 || hassuper == 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
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Read in summary block */
|
2015-07-24 09:59:31 +03:00
|
|
|
bread(devvp, LFS_FSBTODB(fs, daddr), lfs_sb_getsumsize(fs), 0, &bp);
|
2003-03-28 11:09:52 +03:00
|
|
|
sp = (SEGSUM *)bp->b_data;
|
2006-09-01 23:52:48 +04:00
|
|
|
if (debug)
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("sum at 0x%jx: ninos=%d nfinfo=%d\n",
|
|
|
|
(intmax_t)daddr, (int)lfs_ss_getninos(fs, sp),
|
2015-08-12 21:26:26 +03:00
|
|
|
(int)lfs_ss_getnfinfo(fs, sp));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* We have verified that this is a good summary. */
|
2013-06-18 22:18:57 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
|
2003-03-28 11:09:52 +03:00
|
|
|
++sup->su_nsums;
|
|
|
|
VOP_BWRITE(sbp);
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_subbfree(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
|
|
|
|
lfs_sb_adddmeta(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
sbdirty();
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr +
|
|
|
|
hassuper * lfs_btofsb(fs, LFS_SBPAD) &&
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_dtosn(fs, daddr) != lfs_dtosn(fs, lfs_sb_getoffset(fs))) {
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_subnclean(fs, 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find inodes, look at generation number. */
|
2015-08-12 21:26:26 +03:00
|
|
|
if (lfs_ss_getninos(fs, sp)) {
|
2013-06-18 22:18:57 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
|
2015-08-12 21:26:26 +03:00
|
|
|
sup->su_ninos += howmany(lfs_ss_getninos(fs, sp), LFS_INOPB(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
VOP_BWRITE(sbp);
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_sb_adddmeta(fs, lfs_btofsb(fs, howmany(lfs_ss_getninos(fs, sp),
|
2013-06-18 22:18:57 +04:00
|
|
|
LFS_INOPB(fs)) *
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_getibsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2015-10-03 11:29:21 +03:00
|
|
|
iip = SEGSUM_IINFOSTART(fs, bp->b_data);
|
2015-08-12 21:26:26 +03:00
|
|
|
for (i = 0; i < howmany(lfs_ss_getninos(fs, sp), LFS_INOPB(fs)); i++) {
|
2006-11-09 22:36:36 +03:00
|
|
|
ino_t *inums;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-18 22:18:57 +04:00
|
|
|
inums = ecalloc(LFS_INOPB(fs) + 1, sizeof(*inums));
|
2015-10-03 11:29:21 +03:00
|
|
|
ibdaddr = lfs_ii_getblock(fs, iip);
|
|
|
|
iip = NEXTLOWER_IINFO(fs, iip);
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_subbfree(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
sbdirty();
|
2015-07-24 09:59:31 +03:00
|
|
|
bread(devvp, LFS_FSBTODB(fs, ibdaddr),
|
|
|
|
lfs_sb_getibsize(fs), 0, &ibp);
|
|
|
|
memcpy(ibbuf, ibp->b_data, lfs_sb_getibsize(fs));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(ibp, 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
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
j = 0;
|
2015-08-12 21:28:00 +03:00
|
|
|
for (k = 0; k < LFS_INOPB(fs); k++) {
|
|
|
|
dp = DINO_IN_BLOCK(fs, ibbuf, k);
|
|
|
|
if (lfs_dino_getinumber(fs, dp) == 0 ||
|
2015-09-01 09:12:04 +03:00
|
|
|
lfs_dino_getinumber(fs, dp) == LFS_IFILE_INUM)
|
2003-03-28 11:09:52 +03:00
|
|
|
continue;
|
|
|
|
/* Basic sanity checks */
|
2015-08-12 21:28:00 +03:00
|
|
|
if (lfs_dino_getnlink(fs, dp) < 0
|
2006-10-16 07:21:34 +04:00
|
|
|
#if 0
|
2015-08-12 21:28:00 +03:00
|
|
|
|| lfs_dino_getinumber(fs, dp) < 0
|
|
|
|
|| lfs_dino_getsize(fs, dp) < 0
|
2006-10-16 07:21:34 +04:00
|
|
|
#endif
|
|
|
|
) {
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("BAD INODE AT 0x%jx\n",
|
|
|
|
(intmax_t)ibdaddr);
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2006-11-09 22:36:36 +03:00
|
|
|
free(inums);
|
2003-03-28 11:09:52 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-08-12 21:28:00 +03:00
|
|
|
vp = vget(fs, lfs_dino_getinumber(fs, dp));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Four cases:
|
|
|
|
* (1) Invalid inode (nlink == 0).
|
|
|
|
* If currently allocated, remove.
|
|
|
|
*/
|
2015-08-12 21:28:00 +03:00
|
|
|
if (lfs_dino_getnlink(fs, dp) == 0) {
|
|
|
|
remove_ino(vp, lfs_dino_getinumber(fs, dp));
|
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
|
|
|
++ndelfiles;
|
2003-03-28 11:09:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* (2) New valid inode, previously free.
|
|
|
|
* Nothing to do except account
|
|
|
|
* the inode itself, done after the
|
|
|
|
* loop.
|
|
|
|
*/
|
|
|
|
if (vp == NULL) {
|
2015-08-12 21:26:26 +03:00
|
|
|
if (!(lfs_ss_getflags(fs, sp) & SS_DIROP))
|
2006-09-01 23:52:48 +04:00
|
|
|
pfatal("NEW FILE IN NON-DIROP PARTIAL SEGMENT");
|
|
|
|
else {
|
2015-08-12 21:28:00 +03:00
|
|
|
inums[j++] = lfs_dino_getinumber(fs, dp);
|
2006-09-01 23:52:48 +04:00
|
|
|
nnewfiles++;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* (3) Valid new version of previously
|
|
|
|
* allocated inode. Delete old file
|
|
|
|
* and proceed as in (2).
|
|
|
|
*/
|
2015-09-01 09:08:37 +03:00
|
|
|
if (vp &&
|
|
|
|
lfs_dino_getgen(fs, VTOI(vp)->i_din)
|
|
|
|
< lfs_dino_getgen(fs, dp)) {
|
2015-08-12 21:28:00 +03:00
|
|
|
remove_ino(vp, lfs_dino_getinumber(fs, dp));
|
2015-08-12 21:26:26 +03:00
|
|
|
if (!(lfs_ss_getflags(fs, sp) & SS_DIROP))
|
2006-09-01 23:52:48 +04:00
|
|
|
pfatal("NEW FILE VERSION IN NON-DIROP PARTIAL SEGMENT");
|
|
|
|
else {
|
2015-08-12 21:28:00 +03:00
|
|
|
inums[j++] = lfs_dino_getinumber(fs, dp);
|
2006-09-01 23:52:48 +04:00
|
|
|
ndelfiles++;
|
|
|
|
nnewfiles++;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* (4) Same version of previously
|
|
|
|
* allocated inode. Move inode to
|
|
|
|
* this location, account inode change
|
|
|
|
* only. We'll pick up any new
|
|
|
|
* blocks when we do the block pass.
|
|
|
|
*/
|
2015-09-01 09:08:37 +03:00
|
|
|
if (vp &&
|
|
|
|
lfs_dino_getgen(fs, VTOI(vp)->i_din)
|
|
|
|
== lfs_dino_getgen(fs, dp)) {
|
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
|
|
|
nmvfiles++;
|
|
|
|
readdress_inode(dp, ibdaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Update with new info */
|
2015-08-12 21:28:00 +03:00
|
|
|
lfs_dino_setmode(fs, VTOD(vp), lfs_dino_getmode(fs, dp));
|
|
|
|
lfs_dino_setnlink(fs, VTOD(vp), lfs_dino_getmode(fs, dp));
|
2003-03-28 11:09:52 +03:00
|
|
|
/* XXX size is important */
|
2015-08-12 21:28:00 +03:00
|
|
|
lfs_dino_setsize(fs, VTOD(vp), lfs_dino_getsize(fs, dp));
|
|
|
|
lfs_dino_setatime(fs, VTOD(vp), lfs_dino_getatime(fs, dp));
|
|
|
|
lfs_dino_setatimensec(fs, VTOD(vp), lfs_dino_getatimensec(fs, dp));
|
|
|
|
lfs_dino_setmtime(fs, VTOD(vp), lfs_dino_getmtime(fs, dp));
|
|
|
|
lfs_dino_setmtimensec(fs, VTOD(vp), lfs_dino_getmtimensec(fs, dp));
|
|
|
|
lfs_dino_setctime(fs, VTOD(vp), lfs_dino_getctime(fs, dp));
|
|
|
|
lfs_dino_setctimensec(fs, VTOD(vp), lfs_dino_getctimensec(fs, dp));
|
|
|
|
lfs_dino_setflags(fs, VTOD(vp), lfs_dino_getflags(fs, dp));
|
|
|
|
lfs_dino_setuid(fs, VTOD(vp), lfs_dino_getuid(fs, dp));
|
|
|
|
lfs_dino_setgid(fs, VTOD(vp), lfs_dino_getgid(fs, dp));
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(VTOI(vp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j = 0; inums[j]; j++) {
|
|
|
|
alloc_inode(inums[j], ibdaddr);
|
|
|
|
vp = lfs_raw_vget(fs, inums[j],
|
|
|
|
devvp->v_fd, ibdaddr);
|
|
|
|
/* We'll get the blocks later */
|
2006-09-01 23:52:48 +04:00
|
|
|
if (debug)
|
|
|
|
pwarn("alloc ino %d nlink %d\n",
|
2015-08-12 21:28:00 +03:00
|
|
|
(int)inums[j], lfs_dino_getnlink(fs, VTOD(vp)));
|
|
|
|
|
|
|
|
for (k=0; k<ULFS_NDADDR; k++) {
|
|
|
|
lfs_dino_setdb(fs, VTOD(vp), k, 0);
|
|
|
|
}
|
|
|
|
for (k=0; k<ULFS_NIADDR; k++) {
|
|
|
|
lfs_dino_setib(fs, VTOD(vp), k, 0);
|
|
|
|
}
|
|
|
|
lfs_dino_setblocks(fs, VTOD(vp), 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2007-10-11 00:42:20 +04:00
|
|
|
vp->v_uflag |= VU_DIROP;
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(VTOI(vp));
|
|
|
|
}
|
2006-11-09 22:36:36 +03:00
|
|
|
free(inums);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bc = check_summary(fs, sp, daddr, debug, devvp, NULL);
|
|
|
|
if (bc == 0) {
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("unexpected bad seg ptr at 0x%jx with serial=%ju\n",
|
|
|
|
(intmax_t)daddr, (uintmax_t)lfs_ss_getserial(fs, sp));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
2006-09-01 23:52:48 +04:00
|
|
|
} else {
|
|
|
|
if (debug)
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("good seg ptr at 0x%jx with serial=%ju\n",
|
|
|
|
(intmax_t)daddr, (uintmax_t)lfs_ss_getserial(fs, sp));
|
2015-08-12 21:26:26 +03:00
|
|
|
lastserial = lfs_ss_getserial(fs, sp);
|
2006-09-01 23:52:48 +04:00
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
odaddr = daddr;
|
2015-07-24 09:59:31 +03:00
|
|
|
daddr += lfs_btofsb(fs, lfs_sb_getsumsize(fs) + bc);
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) ||
|
|
|
|
lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr +
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_btofsb(fs, lfs_sb_getsumsize(fs) + lfs_sb_getbsize(fs)) - 1)) {
|
2015-08-12 21:26:26 +03:00
|
|
|
daddr = lfs_ss_getnext(fs, sp);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 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
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
out:
|
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
|
|
|
free(ibbuf);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2006-09-01 23:52:48 +04:00
|
|
|
/* Set serial here, just to be sure (XXX should be right already) */
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setserial(fs, lastserial + 1);
|
2006-09-01 23:52:48 +04:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/*
|
|
|
|
* Check our new vnodes. Any blocks must lie in segments that
|
|
|
|
* we've seen before (SEGUSE_DIRTY or SEGUSE_RFW); and the rest
|
|
|
|
* of the pass 1 checks as well.
|
|
|
|
*/
|
|
|
|
memset(&idesc, 0, sizeof(struct inodesc));
|
|
|
|
idesc.id_type = ADDR;
|
|
|
|
idesc.id_func = pass6check;
|
|
|
|
idesc.id_lblkno = 0;
|
|
|
|
LIST_FOREACH(vp, &vnodelist, v_mntvnodes) {
|
2007-10-11 00:42:20 +04:00
|
|
|
if ((vp->v_uflag & VU_DIROP) == 0)
|
2003-03-29 03:09:43 +03:00
|
|
|
--n_files; /* Don't double count */
|
2003-03-28 11:09:52 +03:00
|
|
|
checkinode(VTOI(vp)->i_number, &idesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Second pass. Run through FINFO entries looking for blocks
|
|
|
|
* with the same generation number as files we've seen before.
|
|
|
|
* If they have it, pretend like we just wrote them. We don't
|
|
|
|
* do the pretend-write, though, if we've already seen them
|
|
|
|
* (the accounting would have been done for us already).
|
|
|
|
*/
|
2015-07-24 09:56:41 +03:00
|
|
|
daddr = lfs_sb_getoffset(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
while (daddr != lastgood) {
|
2013-06-18 22:18:57 +04:00
|
|
|
if (!(seg_table[lfs_dtosn(fs, daddr)].su_flags & SEGUSE_DIRTY)) {
|
|
|
|
seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY;
|
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
|
2003-03-28 11:09:52 +03:00
|
|
|
sup->su_flags |= SEGUSE_DIRTY;
|
|
|
|
VOP_BWRITE(sbp);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/* Could be a superblock */
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr == lfs_sb_gets0addr(fs))
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr += lfs_btofsb(fs, LFS_LABELPAD);
|
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
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr == lfs_sb_getsboff(fs, i)) {
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr += lfs_btofsb(fs, LFS_SBPAD);
|
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
|
|
|
}
|
2015-07-24 09:59:31 +03:00
|
|
|
if (daddr < lfs_sb_getsboff(fs, i))
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Read in summary block */
|
2015-07-24 09:59:31 +03:00
|
|
|
bread(devvp, LFS_FSBTODB(fs, daddr), lfs_sb_getsumsize(fs), 0, &bp);
|
2003-03-28 11:09:52 +03:00
|
|
|
sp = (SEGSUM *)bp->b_data;
|
|
|
|
bc = check_summary(fs, sp, daddr, debug, devvp, pass6harvest);
|
|
|
|
if (bc == 0) {
|
2015-09-01 09:13:33 +03:00
|
|
|
pwarn("unexpected bad seg ptr [2] at 0x%jx with serial=%ju\n",
|
|
|
|
(intmax_t)daddr, (uintmax_t)lfs_ss_getserial(fs, sp));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
odaddr = daddr;
|
2015-07-24 09:59:31 +03:00
|
|
|
daddr += lfs_btofsb(fs, lfs_sb_getsumsize(fs) + bc);
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs) + bc));
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) ||
|
|
|
|
lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr +
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_btofsb(fs, lfs_sb_getsumsize(fs) + lfs_sb_getbsize(fs)) - 1)) {
|
|
|
|
lfs_sb_subavail(fs, lfs_sntod(fs, lfs_dtosn(fs, daddr) + 1) - daddr);
|
2015-08-12 21:26:26 +03:00
|
|
|
daddr = lfs_ss_getnext(fs, sp);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
LFS_CLEANERINFO(cip, fs, cbp);
|
|
|
|
LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0);
|
|
|
|
bp->b_flags |= B_AGE;
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 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
|
|
|
/* Final address could also be a superblock */
|
2013-06-18 22:18:57 +04:00
|
|
|
if (lfs_sntod(fs, lfs_dtosn(fs, lastgood)) == lastgood) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (lastgood == lfs_sb_gets0addr(fs))
|
2013-06-18 22:18:57 +04:00
|
|
|
lastgood += lfs_btofsb(fs, LFS_LABELPAD);
|
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
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
2015-07-24 09:59:31 +03:00
|
|
|
if (lastgood == lfs_sb_getsboff(fs, i))
|
2013-06-18 22:18:57 +04:00
|
|
|
lastgood += lfs_btofsb(fs, LFS_SBPAD);
|
2015-07-24 09:59:31 +03:00
|
|
|
if (lastgood < lfs_sb_getsboff(fs, i))
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Update offset to point at correct location */
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setoffset(fs, lastgood);
|
|
|
|
lfs_sb_setcurseg(fs, lfs_sntod(fs, lfs_dtosn(fs, lastgood)));
|
|
|
|
for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs));;) {
|
2015-07-24 09:59:31 +03:00
|
|
|
sn = (sn + 1) % lfs_sb_getnseg(fs);
|
2006-09-01 23:52:48 +04:00
|
|
|
if (sn == curseg)
|
|
|
|
errx(1, "no clean segments");
|
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
|
|
|
if ((sup->su_flags & SEGUSE_DIRTY) == 0) {
|
|
|
|
sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
break;
|
|
|
|
}
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2006-09-01 23:52:48 +04:00
|
|
|
}
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
|
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
|
|
|
if (preen) {
|
|
|
|
if (ndelfiles)
|
|
|
|
pwarn("roll forward deleted %d file%s\n", ndelfiles,
|
|
|
|
(ndelfiles > 1 ? "s" : ""));
|
|
|
|
if (nnewfiles)
|
|
|
|
pwarn("roll forward added %d file%s\n", nnewfiles,
|
|
|
|
(nnewfiles > 1 ? "s" : ""));
|
|
|
|
if (nmvfiles)
|
|
|
|
pwarn("roll forward relocated %d inode%s\n", nmvfiles,
|
|
|
|
(nmvfiles > 1 ? "s" : ""));
|
|
|
|
if (nnewblocks)
|
|
|
|
pwarn("roll forward verified %d data block%s\n", nnewblocks,
|
|
|
|
(nnewblocks > 1 ? "s" : ""));
|
|
|
|
if (ndelfiles == 0 && nnewfiles == 0 && nmvfiles == 0 &&
|
|
|
|
nnewblocks == 0)
|
|
|
|
pwarn("roll forward produced nothing new\n");
|
|
|
|
}
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
if (!preen) {
|
|
|
|
/* Run pass 5 again (it's quick anyway). */
|
|
|
|
pwarn("** Phase 6b - Recheck Segment Block Accounting\n");
|
|
|
|
pass5();
|
|
|
|
}
|
2005-04-12 03:19:24 +04:00
|
|
|
|
|
|
|
/* Likewise for pass 0 */
|
|
|
|
if (!preen)
|
|
|
|
pwarn("** Phase 6c - Recheck Inode Free List\n");
|
|
|
|
pass0();
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|