2006-07-19 06:45:10 +04:00
|
|
|
/* $NetBSD: inode.c,v 1.33 2006/07/19 02:45:10 perseant Exp $ */
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2004-03-21 01:31:13 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Konrad E. Schroder <perseant@hhhh.org>.
|
1999-03-18 05:02:18 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-03-21 01:31:13 +03:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
2003-08-07 14:04:22 +04:00
|
|
|
*
|
2004-03-21 01:31:13 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2003-08-07 14:04:22 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-03-21 01:31:13 +03:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2003-08-07 14:04:22 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1999-03-18 05:02:18 +03:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-03-21 01:31:13 +03:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-03-18 05:02:18 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <sys/types.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/inode.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <ufs/ufs/dir.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#define vnode uvnode
|
1999-03-18 05:02:18 +03:00
|
|
|
#include <ufs/lfs/lfs.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
#undef vnode
|
|
|
|
|
|
|
|
#include <err.h>
|
1999-03-18 05:02:18 +03:00
|
|
|
#ifndef SMALL
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.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
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
#include "fsck.h"
|
|
|
|
#include "fsutil.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
extern SEGUSE *seg_table;
|
|
|
|
extern ufs_daddr_t *din_table;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
static int iblock(struct inodesc *, long, u_int64_t);
|
|
|
|
int blksreqd(struct lfs *, int);
|
|
|
|
int lfs_maxino(void);
|
1999-03-18 05:02:18 +03:00
|
|
|
|
|
|
|
/*
|
2003-03-28 11:09:52 +03:00
|
|
|
* Get a dinode of a given inum.
|
|
|
|
* XXX combine this function with vget.
|
1999-03-18 05:02:18 +03:00
|
|
|
*/
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode *
|
2003-03-28 11:09:52 +03:00
|
|
|
ginode(ino_t ino)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
struct uvnode *vp;
|
|
|
|
struct ubuf *bp;
|
Merge the short-lived perseant-lfsv2 branch into the trunk.
Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:
- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).
- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.
- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.
- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).
- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.
Other changes of note include:
- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.
- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
2001-07-14 00:30:18 +04:00
|
|
|
IFILE *ifp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, ino);
|
|
|
|
if (vp == NULL)
|
2000-05-23 05:48:52 +04:00
|
|
|
return NULL;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
if (din_table[ino] == 0x0) {
|
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
|
|
|
din_table[ino] = ifp->if_daddr;
|
2003-04-02 14:39:19 +04:00
|
|
|
seg_table[dtosn(fs, ifp->if_daddr)].su_nbytes += DINODE1_SIZE;
|
2003-03-28 11:09:52 +03:00
|
|
|
brelse(bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
return (VTOI(vp)->i_din.ffs1_din);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-03-28 11:09:52 +03:00
|
|
|
* Check validity of held blocks in an inode, recursing through all blocks.
|
1999-03-18 05:02:18 +03:00
|
|
|
*/
|
|
|
|
int
|
2003-04-02 14:39:19 +04:00
|
|
|
ckinode(struct ufs1_dinode *dp, struct inodesc *idesc)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
ufs_daddr_t *ap, lbn;
|
|
|
|
long ret, n, ndb, offset;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode dino;
|
2003-03-28 11:09:52 +03:00
|
|
|
u_int64_t remsize, sizepb;
|
|
|
|
mode_t mode;
|
|
|
|
char pathbuf[MAXPATHLEN + 1];
|
|
|
|
struct uvnode *vp, *thisvp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
if (idesc->id_fix != IGNORE)
|
|
|
|
idesc->id_fix = DONTKNOW;
|
|
|
|
idesc->id_entryno = 0;
|
|
|
|
idesc->id_filesize = dp->di_size;
|
|
|
|
mode = dp->di_mode & IFMT;
|
|
|
|
if (mode == IFBLK || mode == IFCHR ||
|
2003-03-28 11:09:52 +03:00
|
|
|
(mode == IFLNK && (dp->di_size < fs->lfs_maxsymlinklen ||
|
|
|
|
(fs->lfs_maxsymlinklen == 0 &&
|
|
|
|
dp->di_blocks == 0))))
|
2000-05-23 05:48:52 +04:00
|
|
|
return (KEEPON);
|
|
|
|
dino = *dp;
|
2003-03-28 11:09:52 +03:00
|
|
|
ndb = howmany(dino.di_size, fs->lfs_bsize);
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2003-07-12 20:13:38 +04:00
|
|
|
thisvp = vget(fs, idesc->id_number);
|
2003-03-28 11:09:52 +03:00
|
|
|
for (lbn = 0; lbn < NDADDR; lbn++) {
|
|
|
|
ap = dino.di_db + lbn;
|
|
|
|
if (thisvp)
|
2000-05-23 05:48:52 +04:00
|
|
|
idesc->id_numfrags =
|
2003-03-28 11:09:52 +03:00
|
|
|
numfrags(fs, VTOI(thisvp)->i_lfs_fragsize[lbn]);
|
|
|
|
else {
|
|
|
|
if (--ndb == 0 && (offset = blkoff(fs, dino.di_size)) != 0) {
|
|
|
|
idesc->id_numfrags =
|
|
|
|
numfrags(fs, fragroundup(fs, offset));
|
|
|
|
} else
|
|
|
|
idesc->id_numfrags = fs->lfs_frag;
|
|
|
|
}
|
2000-05-23 05:48:52 +04:00
|
|
|
if (*ap == 0) {
|
|
|
|
if (idesc->id_type == DATA && ndb >= 0) {
|
|
|
|
/* An empty block in a directory XXX */
|
2003-07-13 12:05:58 +04:00
|
|
|
getpathname(pathbuf, sizeof(pathbuf),
|
|
|
|
idesc->id_number, idesc->id_number);
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [1]",
|
|
|
|
pathbuf, (long long)idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (reply("ADJUST LENGTH") == 1) {
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, idesc->id_number);
|
|
|
|
dp = VTOD(vp);
|
2000-05-23 05:48:52 +04:00
|
|
|
dp->di_size = (ap - &dino.di_db[0]) *
|
2003-03-28 11:09:52 +03:00
|
|
|
fs->lfs_bsize;
|
2000-05-23 05:48:52 +04:00
|
|
|
printf(
|
2003-03-28 11:09:52 +03:00
|
|
|
"YOU MUST RERUN FSCK AFTERWARDS\n");
|
2000-05-23 05:48:52 +04:00
|
|
|
rerun = 1;
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(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
|
|
|
} else
|
|
|
|
break;
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
idesc->id_blkno = *ap;
|
|
|
|
idesc->id_lblkno = ap - &dino.di_db[0];
|
|
|
|
if (idesc->id_type == ADDR) {
|
2003-03-28 11:09:52 +03:00
|
|
|
ret = (*idesc->id_func) (idesc);
|
2000-05-23 05:48:52 +04:00
|
|
|
} else
|
|
|
|
ret = dirscan(idesc);
|
|
|
|
if (ret & STOP)
|
|
|
|
return (ret);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
idesc->id_numfrags = fs->lfs_frag;
|
|
|
|
remsize = dino.di_size - fs->lfs_bsize * NDADDR;
|
|
|
|
sizepb = fs->lfs_bsize;
|
2000-05-23 05:48:52 +04:00
|
|
|
for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
|
|
|
|
if (*ap) {
|
|
|
|
idesc->id_blkno = *ap;
|
|
|
|
ret = iblock(idesc, n, remsize);
|
|
|
|
if (ret & STOP)
|
|
|
|
return (ret);
|
|
|
|
} else {
|
|
|
|
if (idesc->id_type == DATA && remsize > 0) {
|
|
|
|
/* An empty block in a directory XXX */
|
2003-07-13 12:05:58 +04:00
|
|
|
getpathname(pathbuf, sizeof(pathbuf),
|
|
|
|
idesc->id_number, idesc->id_number);
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [2]",
|
|
|
|
pathbuf, (long long)idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (reply("ADJUST LENGTH") == 1) {
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, idesc->id_number);
|
|
|
|
dp = VTOD(vp);
|
2000-05-23 05:48:52 +04:00
|
|
|
dp->di_size -= remsize;
|
|
|
|
remsize = 0;
|
|
|
|
printf(
|
2003-03-28 11:09:52 +03:00
|
|
|
"YOU MUST RERUN FSCK AFTERWARDS\n");
|
2000-05-23 05:48:52 +04:00
|
|
|
rerun = 1;
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(VTOI(vp));
|
2000-05-23 05:48:52 +04:00
|
|
|
break;
|
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
|
|
|
|
break;
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
sizepb *= NINDIR(fs);
|
2000-05-23 05:48:52 +04:00
|
|
|
remsize -= sizepb;
|
|
|
|
}
|
|
|
|
return (KEEPON);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-28 11:09:52 +03:00
|
|
|
iblock(struct inodesc *idesc, long ilevel, u_int64_t isize)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
ufs_daddr_t *ap, *aplim;
|
|
|
|
struct ubuf *bp;
|
|
|
|
int i, n, (*func) (struct inodesc *), nif;
|
|
|
|
u_int64_t sizepb;
|
|
|
|
char pathbuf[MAXPATHLEN + 1], buf[BUFSIZ];
|
|
|
|
struct uvnode *devvp, *vp;
|
|
|
|
int diddirty = 0;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
if (idesc->id_type == ADDR) {
|
|
|
|
func = idesc->id_func;
|
2003-03-28 11:09:52 +03:00
|
|
|
n = (*func) (idesc);
|
2000-05-23 05:48:52 +04:00
|
|
|
if ((n & KEEPON) == 0)
|
|
|
|
return (n);
|
|
|
|
} else
|
|
|
|
func = dirscan;
|
2003-03-28 11:09:52 +03:00
|
|
|
if (chkrange(idesc->id_blkno, fragstofsb(fs, idesc->id_numfrags)))
|
2000-05-23 05:48:52 +04:00
|
|
|
return (SKIP);
|
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
|
|
|
bread(devvp, fsbtodb(fs, idesc->id_blkno), fs->lfs_bsize, NOCRED, &bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
ilevel--;
|
2003-03-28 11:09:52 +03:00
|
|
|
for (sizepb = fs->lfs_bsize, i = 0; i < ilevel; i++)
|
|
|
|
sizepb *= NINDIR(fs);
|
|
|
|
if (isize > sizepb * NINDIR(fs))
|
|
|
|
nif = NINDIR(fs);
|
2000-05-23 05:48:52 +04:00
|
|
|
else
|
|
|
|
nif = howmany(isize, sizepb);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (idesc->id_func == pass1check && nif < NINDIR(fs)) {
|
|
|
|
aplim = ((ufs_daddr_t *) bp->b_data) + NINDIR(fs);
|
|
|
|
for (ap = ((ufs_daddr_t *) bp->b_data) + nif; ap < aplim; ap++) {
|
2000-05-23 05:48:52 +04:00
|
|
|
if (*ap == 0)
|
|
|
|
continue;
|
2005-08-19 06:07:18 +04:00
|
|
|
(void) sprintf(buf, "PARTIALLY TRUNCATED INODE I=%llu",
|
|
|
|
(unsigned long long)idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (dofix(idesc, buf)) {
|
|
|
|
*ap = 0;
|
2003-03-28 11:09:52 +03:00
|
|
|
++diddirty;
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
aplim = ((ufs_daddr_t *) bp->b_data) + nif;
|
|
|
|
for (ap = ((ufs_daddr_t *) bp->b_data); ap < aplim; ap++) {
|
2000-05-23 05:48:52 +04:00
|
|
|
if (*ap) {
|
|
|
|
idesc->id_blkno = *ap;
|
2003-10-03 16:22:15 +04:00
|
|
|
if (ilevel == 0) {
|
|
|
|
/*
|
|
|
|
* dirscan needs lblkno.
|
|
|
|
*/
|
|
|
|
idesc->id_lblkno++;
|
2003-03-28 11:09:52 +03:00
|
|
|
n = (*func) (idesc);
|
2003-10-03 16:22:15 +04:00
|
|
|
} else {
|
2000-05-23 05:48:52 +04:00
|
|
|
n = iblock(idesc, ilevel, isize);
|
2003-10-03 16:22:15 +04:00
|
|
|
}
|
2000-05-23 05:48:52 +04:00
|
|
|
if (n & STOP) {
|
2003-03-28 11:09:52 +03:00
|
|
|
if (diddirty)
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
else
|
|
|
|
brelse(bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (idesc->id_type == DATA && isize > 0) {
|
|
|
|
/* An empty block in a directory XXX */
|
2003-07-13 12:05:58 +04:00
|
|
|
getpathname(pathbuf, sizeof(pathbuf),
|
|
|
|
idesc->id_number, idesc->id_number);
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [3]",
|
|
|
|
pathbuf, (long long)idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (reply("ADJUST LENGTH") == 1) {
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, idesc->id_number);
|
2003-04-02 14:39:19 +04:00
|
|
|
VTOI(vp)->i_ffs1_size -= isize;
|
2000-05-23 05:48:52 +04:00
|
|
|
isize = 0;
|
|
|
|
printf(
|
2003-03-28 11:09:52 +03:00
|
|
|
"YOU MUST RERUN FSCK AFTERWARDS\n");
|
2000-05-23 05:48:52 +04:00
|
|
|
rerun = 1;
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(VTOI(vp));
|
|
|
|
if (diddirty)
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
else
|
|
|
|
brelse(bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isize -= sizepb;
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (diddirty)
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
else
|
|
|
|
brelse(bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
return (KEEPON);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2005-06-08 23:09:55 +04:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
/*
|
|
|
|
* Check that a block in a legal block number.
|
|
|
|
* Return 0 if in range, 1 if out of range.
|
|
|
|
*/
|
|
|
|
int
|
2000-05-23 05:48:52 +04:00
|
|
|
chkrange(daddr_t blk, int cnt)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
if (blk < sntod(fs, 0)) {
|
Merge the short-lived perseant-lfsv2 branch into the trunk.
Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:
- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).
- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.
- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.
- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).
- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.
Other changes of note include:
- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.
- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
2001-07-14 00:30:18 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (blk > maxfsblock) {
|
|
|
|
return (1);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (blk + cnt < sntod(fs, 0)) {
|
2000-06-14 22:43:57 +04:00
|
|
|
return (1);
|
|
|
|
}
|
Merge the short-lived perseant-lfsv2 branch into the trunk.
Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:
- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).
- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.
- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.
- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).
- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.
Other changes of note include:
- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.
- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
2001-07-14 00:30:18 +04:00
|
|
|
if (blk + cnt > maxfsblock) {
|
2000-05-23 05:48:52 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2005-06-08 23:09:55 +04:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
/*
|
|
|
|
* Routines to maintain information about directory inodes.
|
|
|
|
* This is built during the first pass and used during the
|
|
|
|
* second and third passes.
|
|
|
|
*
|
|
|
|
* Enter inodes into the cache.
|
|
|
|
*/
|
|
|
|
void
|
2003-04-02 14:39:19 +04:00
|
|
|
cacheino(struct ufs1_dinode * dp, ino_t inumber)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inoinfo *inp;
|
2003-09-19 12:29:58 +04:00
|
|
|
struct inoinfo **inpp, **ninpsort;
|
2003-03-28 11:09:52 +03:00
|
|
|
unsigned int blks;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
blks = howmany(dp->di_size, fs->lfs_bsize);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (blks > NDADDR)
|
|
|
|
blks = NDADDR + NIADDR;
|
|
|
|
inp = (struct inoinfo *)
|
2003-03-28 11:09:52 +03:00
|
|
|
malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t));
|
2000-05-23 05:48:52 +04:00
|
|
|
if (inp == NULL)
|
|
|
|
return;
|
|
|
|
inpp = &inphead[inumber % numdirs];
|
|
|
|
inp->i_nexthash = *inpp;
|
|
|
|
*inpp = inp;
|
|
|
|
inp->i_child = inp->i_sibling = inp->i_parentp = 0;
|
|
|
|
if (inumber == ROOTINO)
|
|
|
|
inp->i_parent = ROOTINO;
|
|
|
|
else
|
2003-03-28 11:09:52 +03:00
|
|
|
inp->i_parent = (ino_t) 0;
|
|
|
|
inp->i_dotdot = (ino_t) 0;
|
2000-05-23 05:48:52 +04:00
|
|
|
inp->i_number = inumber;
|
|
|
|
inp->i_isize = dp->di_size;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
inp->i_numblks = blks * sizeof(ufs_daddr_t);
|
|
|
|
memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t) inp->i_numblks);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (inplast == listmax) {
|
2003-09-19 12:29:58 +04:00
|
|
|
ninpsort = (struct inoinfo **) realloc((char *) inpsort,
|
|
|
|
(unsigned) (listmax + 100) * sizeof(struct inoinfo *));
|
|
|
|
if (ninpsort == NULL)
|
2003-03-28 11:09:52 +03:00
|
|
|
err(8, "cannot increase directory list\n");
|
2003-09-19 12:29:58 +04:00
|
|
|
inpsort = ninpsort;
|
|
|
|
listmax += 100;
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
|
|
|
inpsort[inplast++] = inp;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up an inode cache structure.
|
|
|
|
*/
|
|
|
|
struct inoinfo *
|
2000-05-23 05:48:52 +04:00
|
|
|
getinoinfo(ino_t inumber)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2005-02-06 09:13:12 +03:00
|
|
|
struct inoinfo *inp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
|
|
|
|
if (inp->i_number != inumber)
|
|
|
|
continue;
|
|
|
|
return (inp);
|
|
|
|
}
|
2005-08-19 06:07:18 +04:00
|
|
|
err(8, "cannot find inode %llu\n", (unsigned long long)inumber);
|
2003-03-28 11:09:52 +03:00
|
|
|
return ((struct inoinfo *) 0);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up all the inode cache structure.
|
|
|
|
*/
|
|
|
|
void
|
2005-02-06 09:13:12 +03:00
|
|
|
inocleanup(void)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2005-02-06 09:13:12 +03:00
|
|
|
struct inoinfo **inpp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
if (inphead == NULL)
|
|
|
|
return;
|
|
|
|
for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
|
2003-03-28 11:09:52 +03:00
|
|
|
free((char *) (*inpp));
|
|
|
|
free((char *) inphead);
|
|
|
|
free((char *) inpsort);
|
2000-05-23 05:48:52 +04:00
|
|
|
inphead = inpsort = NULL;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(struct inode *ip)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
ip->i_flag |= IN_MODIFIED;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-27 06:48:28 +04:00
|
|
|
clri(struct inodesc * idesc, const char *type, int flag)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
struct uvnode *vp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
if (flag == 1) {
|
|
|
|
pwarn("%s %s", type,
|
2003-04-02 14:39:19 +04:00
|
|
|
(VTOI(vp)->i_ffs1_mode & IFMT) == IFDIR ? "DIR" : "FILE");
|
2000-05-23 05:48:52 +04:00
|
|
|
pinode(idesc->id_number);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
if (flag == 2 || preen || reply("CLEAR") == 1) {
|
|
|
|
if (preen && flag != 2)
|
2000-05-23 05:48:52 +04:00
|
|
|
printf(" (CLEARED)\n");
|
|
|
|
n_files--;
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) ckinode(VTOD(vp), idesc);
|
2004-07-19 00:51:30 +04:00
|
|
|
clearinode(idesc->id_number);
|
2000-05-23 05:48:52 +04:00
|
|
|
statemap[idesc->id_number] = USTATE;
|
2004-07-19 00:51:30 +04:00
|
|
|
vnode_destroy(vp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clearinode(ino_t inumber)
|
|
|
|
{
|
|
|
|
struct ubuf *bp;
|
|
|
|
IFILE *ifp;
|
|
|
|
daddr_t daddr;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2004-07-19 00:51:30 +04:00
|
|
|
/* Send cleared inode to the free list */
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2004-07-19 00:51:30 +04:00
|
|
|
LFS_IENTRY(ifp, fs, inumber, bp);
|
|
|
|
daddr = ifp->if_daddr;
|
2006-07-19 06:45:10 +04:00
|
|
|
if (daddr == LFS_UNUSED_DADDR) {
|
|
|
|
brelse(bp);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-19 00:51:30 +04:00
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
ifp->if_nextfree = fs->lfs_freehd;
|
|
|
|
fs->lfs_freehd = inumber;
|
|
|
|
sbdirty();
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update segment usage.
|
|
|
|
*/
|
|
|
|
if (daddr != LFS_UNUSED_DADDR) {
|
|
|
|
SEGUSE *sup;
|
|
|
|
u_int32_t oldsn = dtosn(fs, daddr);
|
|
|
|
|
|
|
|
LFS_SEGENTRY(sup, fs, oldsn, bp);
|
|
|
|
sup->su_nbytes -= DINODE1_SIZE;
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, oldsn, bp); /* Ifile */
|
2000-05-23 05:48:52 +04:00
|
|
|
}
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 11:09:52 +03:00
|
|
|
findname(struct inodesc * idesc)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2005-02-06 09:13:12 +03:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
2005-06-27 06:48:28 +04:00
|
|
|
size_t len;
|
|
|
|
char *buf;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
if (dirp->d_ino != idesc->id_parent)
|
|
|
|
return (KEEPON);
|
2005-06-27 06:48:28 +04:00
|
|
|
if ((len = dirp->d_namlen + 1) > MAXPATHLEN) {
|
|
|
|
/* Truncate it but don't overflow the buffer */
|
|
|
|
len = MAXPATHLEN;
|
|
|
|
}
|
|
|
|
/* this is namebuf with utils.h */
|
|
|
|
buf = __UNCONST(idesc->id_name);
|
|
|
|
(void)memcpy(buf, dirp->d_name, len);
|
2000-05-23 05:48:52 +04:00
|
|
|
return (STOP | FOUND);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 11:09:52 +03:00
|
|
|
findino(struct inodesc * idesc)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2005-02-06 09:13:12 +03:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
if (dirp->d_ino == 0)
|
|
|
|
return (KEEPON);
|
|
|
|
if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
|
2000-06-14 22:43:57 +04:00
|
|
|
dirp->d_ino >= ROOTINO && dirp->d_ino < maxino) {
|
2000-05-23 05:48:52 +04:00
|
|
|
idesc->id_parent = dirp->d_ino;
|
|
|
|
return (STOP | FOUND);
|
|
|
|
}
|
|
|
|
return (KEEPON);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-23 05:48:52 +04:00
|
|
|
pinode(ino_t ino)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2005-02-06 09:13:12 +03:00
|
|
|
struct ufs1_dinode *dp;
|
|
|
|
char *p;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct passwd *pw;
|
|
|
|
time_t t;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
2005-08-19 06:07:18 +04:00
|
|
|
printf(" I=%llu ", (unsigned long long)ino);
|
2000-06-14 22:43:57 +04:00
|
|
|
if (ino < ROOTINO || ino >= maxino)
|
2000-05-23 05:48:52 +04:00
|
|
|
return;
|
|
|
|
dp = ginode(ino);
|
|
|
|
if (dp) {
|
|
|
|
printf(" OWNER=");
|
1999-03-18 05:02:18 +03:00
|
|
|
#ifndef SMALL
|
2003-03-28 11:09:52 +03:00
|
|
|
if ((pw = getpwuid((int) dp->di_uid)) != 0)
|
2000-05-23 05:48:52 +04:00
|
|
|
printf("%s ", pw->pw_name);
|
|
|
|
else
|
1999-03-18 05:02:18 +03:00
|
|
|
#endif
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("%u ", (unsigned) dp->di_uid);
|
2000-05-23 05:48:52 +04:00
|
|
|
printf("MODE=%o\n", dp->di_mode);
|
|
|
|
if (preen)
|
|
|
|
printf("%s: ", cdevname());
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("SIZE=%llu ", (unsigned long long) dp->di_size);
|
2000-05-23 05:48:52 +04:00
|
|
|
t = dp->di_mtime;
|
|
|
|
p = ctime(&t);
|
|
|
|
printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
|
|
|
|
}
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-27 06:49:32 +04:00
|
|
|
blkerror(ino_t ino, const char *type, daddr_t blk)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
|
|
|
|
2005-08-19 06:07:18 +04:00
|
|
|
pfatal("%lld %s I=%llu", (long long) blk, type,
|
|
|
|
(unsigned long long)ino);
|
2000-05-23 05:48:52 +04:00
|
|
|
printf("\n");
|
|
|
|
if (exitonfail)
|
|
|
|
exit(1);
|
|
|
|
switch (statemap[ino]) {
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
case FSTATE:
|
|
|
|
statemap[ino] = FCLEAR;
|
|
|
|
return;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
case DSTATE:
|
|
|
|
statemap[ino] = DCLEAR;
|
|
|
|
return;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
case FCLEAR:
|
|
|
|
case DCLEAR:
|
|
|
|
return;
|
1999-03-18 05:02:18 +03:00
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
default:
|
2003-03-28 11:09:52 +03:00
|
|
|
err(8, "BAD STATE %d TO BLKERR\n", statemap[ino]);
|
2000-05-23 05:48:52 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2005-06-08 23:09:55 +04:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
/*
|
|
|
|
* allocate an unused inode
|
|
|
|
*/
|
|
|
|
ino_t
|
2000-05-23 05:48:52 +04:00
|
|
|
allocino(ino_t request, int type)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
ino_t ino;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode *dp;
|
2003-03-28 11:09:52 +03:00
|
|
|
time_t t;
|
|
|
|
struct uvnode *vp;
|
|
|
|
struct ubuf *bp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
if (request == 0)
|
|
|
|
request = ROOTINO;
|
|
|
|
else if (statemap[request] != USTATE)
|
|
|
|
return (0);
|
|
|
|
for (ino = request; ino < maxino; ino++)
|
|
|
|
if (statemap[ino] == USTATE)
|
|
|
|
break;
|
|
|
|
if (ino == maxino)
|
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
|
|
|
extend_ifile(fs);
|
|
|
|
|
2000-05-23 05:48:52 +04:00
|
|
|
switch (type & IFMT) {
|
|
|
|
case IFDIR:
|
|
|
|
statemap[ino] = DSTATE;
|
|
|
|
break;
|
|
|
|
case IFREG:
|
|
|
|
case IFLNK:
|
|
|
|
statemap[ino] = FSTATE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2005-06-08 23:09:55 +04:00
|
|
|
vp = lfs_valloc(fs, ino);
|
|
|
|
if (vp == NULL)
|
|
|
|
return (0);
|
2003-04-02 14:39:19 +04:00
|
|
|
dp = (VTOI(vp)->i_din.ffs1_din);
|
2003-03-28 11:09:52 +03:00
|
|
|
bp = getblk(vp, 0, fs->lfs_fsize);
|
|
|
|
VOP_BWRITE(bp);
|
2000-05-23 05:48:52 +04:00
|
|
|
dp->di_mode = type;
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) time(&t);
|
2000-05-23 05:48:52 +04:00
|
|
|
dp->di_atime = t;
|
|
|
|
dp->di_mtime = dp->di_ctime = dp->di_atime;
|
2003-03-28 11:09:52 +03:00
|
|
|
dp->di_size = fs->lfs_fsize;
|
|
|
|
dp->di_blocks = btofsb(fs, fs->lfs_fsize);
|
2000-05-23 05:48:52 +04:00
|
|
|
n_files++;
|
2003-03-28 11:09:52 +03:00
|
|
|
inodirty(VTOI(vp));
|
|
|
|
typemap[ino] = IFTODT(type);
|
2000-05-23 05:48:52 +04:00
|
|
|
return (ino);
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|
2005-06-08 23:09:55 +04:00
|
|
|
|
1999-03-18 05:02:18 +03:00
|
|
|
/*
|
|
|
|
* deallocate an inode
|
|
|
|
*/
|
|
|
|
void
|
2000-05-23 05:48:52 +04:00
|
|
|
freeino(ino_t ino)
|
1999-03-18 05:02:18 +03:00
|
|
|
{
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inodesc idesc;
|
|
|
|
struct uvnode *vp;
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
memset(&idesc, 0, sizeof(struct inodesc));
|
|
|
|
idesc.id_type = ADDR;
|
|
|
|
idesc.id_func = pass4check;
|
|
|
|
idesc.id_number = ino;
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = vget(fs, ino);
|
|
|
|
(void) ckinode(VTOD(vp), &idesc);
|
2004-07-19 00:51:30 +04:00
|
|
|
clearinode(ino);
|
2000-05-23 05:48:52 +04:00
|
|
|
statemap[ino] = USTATE;
|
2004-07-19 00:51:30 +04:00
|
|
|
vnode_destroy(vp);
|
2000-05-23 05:48:52 +04:00
|
|
|
|
|
|
|
n_files--;
|
1999-03-18 05:02:18 +03:00
|
|
|
}
|