2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2000-10-09 09:21:04 +00:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-10-09 09:21:04 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
2003-05-03 18:41:59 +00:00
|
|
|
#ifndef lint
|
2000-10-09 09:21:04 +00:00
|
|
|
static const char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
|
|
|
|
#endif /* not lint */
|
2003-05-03 18:41:59 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2000-10-09 09:21:04 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2002-12-07 21:40:31 +00:00
|
|
|
#include <sys/time.h>
|
2000-10-09 09:21:04 +00:00
|
|
|
#include <sys/types.h>
|
2001-11-17 23:48:21 +00:00
|
|
|
#include <sys/sysctl.h>
|
2011-04-29 23:00:23 +00:00
|
|
|
#include <sys/disk.h>
|
2002-06-21 06:18:05 +00:00
|
|
|
#include <sys/disklabel.h>
|
2011-04-29 23:00:23 +00:00
|
|
|
#include <sys/ioctl.h>
|
2000-10-09 09:21:04 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fstab.h>
|
2002-07-31 12:01:14 +00:00
|
|
|
#include <stdint.h>
|
2000-10-09 09:21:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-02-24 06:44:29 +00:00
|
|
|
#include <time.h>
|
2000-10-09 09:21:04 +00:00
|
|
|
#include <unistd.h>
|
2017-09-22 12:45:15 +00:00
|
|
|
#include <libufs.h>
|
2000-10-09 09:21:04 +00:00
|
|
|
|
|
|
|
#include "fsck.h"
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
int sujrecovery = 0;
|
|
|
|
|
|
|
|
static struct bufarea *allocbuf(const char *);
|
|
|
|
static void cg_write(struct bufarea *);
|
2002-12-07 21:40:31 +00:00
|
|
|
static void slowio_start(void);
|
|
|
|
static void slowio_end(void);
|
2013-02-24 06:44:29 +00:00
|
|
|
static void printIOstats(void);
|
2021-01-07 01:37:08 +00:00
|
|
|
static void prtbuf(const char *, struct bufarea *);
|
2002-12-07 21:40:31 +00:00
|
|
|
|
2013-02-24 06:44:29 +00:00
|
|
|
static long diskreads, totaldiskreads, totalreads; /* Disk cache statistics */
|
|
|
|
static struct timespec startpass, finishpass;
|
2002-12-07 21:40:31 +00:00
|
|
|
struct timeval slowio_starttime;
|
|
|
|
int slowio_delay_usec = 10000; /* Initial IO delay for background fsck */
|
|
|
|
int slowio_pollcnt;
|
2013-03-23 20:00:02 +00:00
|
|
|
static struct bufarea cgblk; /* backup buffer for cylinder group blocks */
|
2021-01-07 01:37:08 +00:00
|
|
|
static TAILQ_HEAD(bufqueue, bufarea) bufqueuehd; /* head of buffer cache LRU */
|
|
|
|
static LIST_HEAD(bufhash, bufarea) bufhashhd[HASHSIZE]; /* buffer hash list */
|
2013-02-15 01:00:48 +00:00
|
|
|
static int numbufs; /* size of buffer cache */
|
2021-01-07 01:37:08 +00:00
|
|
|
static int cachelookups; /* number of cache lookups */
|
|
|
|
static int cachereads; /* number of cache reads */
|
2013-12-30 01:16:08 +00:00
|
|
|
static int flushtries; /* number of tries to reclaim memory */
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
char *buftype[BT_NUMBUFTYPES] = BT_NAMES;
|
|
|
|
|
2013-12-30 01:16:08 +00:00
|
|
|
void
|
|
|
|
fsutilinit(void)
|
|
|
|
{
|
|
|
|
diskreads = totaldiskreads = totalreads = 0;
|
|
|
|
bzero(&startpass, sizeof(struct timespec));
|
|
|
|
bzero(&finishpass, sizeof(struct timespec));
|
|
|
|
bzero(&slowio_starttime, sizeof(struct timeval));
|
|
|
|
slowio_delay_usec = 10000;
|
|
|
|
slowio_pollcnt = 0;
|
|
|
|
flushtries = 0;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
|
|
|
|
int
|
2002-06-21 06:18:05 +00:00
|
|
|
ftypeok(union dinode *dp)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2018-03-17 12:59:55 +00:00
|
|
|
switch (DIP(dp, di_mode) & IFMT) {
|
2000-10-09 09:21:04 +00:00
|
|
|
|
2018-03-17 12:59:55 +00:00
|
|
|
case IFDIR:
|
|
|
|
case IFREG:
|
|
|
|
case IFBLK:
|
|
|
|
case IFCHR:
|
|
|
|
case IFLNK:
|
|
|
|
case IFSOCK:
|
|
|
|
case IFIFO:
|
2000-10-09 09:21:04 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (debug)
|
2002-06-21 06:18:05 +00:00
|
|
|
printf("bad file type 0%o\n", DIP(dp, di_mode));
|
2000-10-09 09:21:04 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-30 13:01:25 +00:00
|
|
|
reply(const char *question)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
int persevere;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (preen)
|
|
|
|
pfatal("INTERNAL ERROR: GOT TO reply()");
|
|
|
|
persevere = !strcmp(question, "CONTINUE");
|
|
|
|
printf("\n");
|
2001-03-21 09:48:03 +00:00
|
|
|
if (!persevere && (nflag || (fswritefd < 0 && bkgrdflag == 0))) {
|
2000-10-09 09:21:04 +00:00
|
|
|
printf("%s? no\n\n", question);
|
|
|
|
resolved = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (yflag || (persevere && nflag)) {
|
|
|
|
printf("%s? yes\n\n", question);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
printf("%s? [yn] ", question);
|
|
|
|
(void) fflush(stdout);
|
|
|
|
c = getc(stdin);
|
|
|
|
while (c != '\n' && getc(stdin) != '\n') {
|
|
|
|
if (feof(stdin)) {
|
|
|
|
resolved = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
|
|
|
|
printf("\n");
|
|
|
|
if (c == 'y' || c == 'Y')
|
|
|
|
return (1);
|
|
|
|
resolved = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up state information for an inode.
|
|
|
|
*/
|
|
|
|
struct inostat *
|
2002-03-20 22:57:10 +00:00
|
|
|
inoinfo(ino_t inum)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
static struct inostat unallocated = { USTATE, 0, 0 };
|
|
|
|
struct inostatlist *ilp;
|
|
|
|
int iloff;
|
|
|
|
|
|
|
|
if (inum > maxino)
|
2012-09-27 23:30:58 +00:00
|
|
|
errx(EEXIT, "inoinfo: inumber %ju out of range",
|
|
|
|
(uintmax_t)inum);
|
2000-10-09 09:21:04 +00:00
|
|
|
ilp = &inostathead[inum / sblock.fs_ipg];
|
|
|
|
iloff = inum % sblock.fs_ipg;
|
|
|
|
if (iloff >= ilp->il_numalloced)
|
|
|
|
return (&unallocated);
|
|
|
|
return (&ilp->il_stat[iloff]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Malloc buffers and set up cache.
|
|
|
|
*/
|
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
bufinit(void)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2021-01-07 01:37:08 +00:00
|
|
|
int i;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
2021-04-02 18:57:34 +00:00
|
|
|
if ((cgblk.b_un.b_buf = Malloc((unsigned int)sblock.fs_bsize)) == NULL)
|
2021-01-07 01:37:08 +00:00
|
|
|
errx(EEXIT, "Initial malloc(%d) failed", sblock.fs_bsize);
|
2013-02-24 06:44:29 +00:00
|
|
|
initbarea(&cgblk, BT_CYLGRP);
|
2021-01-07 01:37:08 +00:00
|
|
|
numbufs = cachelookups = cachereads = 0;
|
|
|
|
TAILQ_INIT(&bufqueuehd);
|
|
|
|
for (i = 0; i < HASHSIZE; i++)
|
|
|
|
LIST_INIT(&bufhashhd[i]);
|
2013-02-24 06:44:29 +00:00
|
|
|
for (i = 0; i < BT_NUMBUFTYPES; i++) {
|
|
|
|
readtime[i].tv_sec = totalreadtime[i].tv_sec = 0;
|
|
|
|
readtime[i].tv_nsec = totalreadtime[i].tv_nsec = 0;
|
|
|
|
readcnt[i] = totalreadcnt[i] = 0;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
static struct bufarea *
|
|
|
|
allocbuf(const char *failreason)
|
|
|
|
{
|
|
|
|
struct bufarea *bp;
|
|
|
|
char *bufp;
|
|
|
|
|
|
|
|
bp = (struct bufarea *)Malloc(sizeof(struct bufarea));
|
|
|
|
bufp = Malloc((unsigned int)sblock.fs_bsize);
|
|
|
|
if (bp == NULL || bufp == NULL) {
|
|
|
|
errx(EEXIT, "%s", failreason);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
numbufs++;
|
|
|
|
bp->b_un.b_buf = bufp;
|
|
|
|
TAILQ_INSERT_HEAD(&bufqueuehd, bp, b_list);
|
|
|
|
initbarea(bp, BT_UNKNOWN);
|
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
2013-03-23 20:00:02 +00:00
|
|
|
/*
|
|
|
|
* Manage cylinder group buffers.
|
2020-09-19 22:48:30 +00:00
|
|
|
*
|
|
|
|
* Use getblk() here rather than cgget() because the cylinder group
|
|
|
|
* may be corrupted but we want it anyway so we can fix it.
|
2013-03-23 20:00:02 +00:00
|
|
|
*/
|
|
|
|
static struct bufarea *cgbufs; /* header for cylinder group cache */
|
|
|
|
static int flushtries; /* number of tries to reclaim memory */
|
|
|
|
|
|
|
|
struct bufarea *
|
2018-01-17 06:31:21 +00:00
|
|
|
cglookup(int cg)
|
2013-03-23 20:00:02 +00:00
|
|
|
{
|
|
|
|
struct bufarea *cgbp;
|
|
|
|
struct cg *cgp;
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
if ((unsigned) cg >= sblock.fs_ncg)
|
|
|
|
errx(EEXIT, "cglookup: out of range cylinder group %d", cg);
|
2013-03-23 20:00:02 +00:00
|
|
|
if (cgbufs == NULL) {
|
2014-02-25 18:25:27 +00:00
|
|
|
cgbufs = calloc(sblock.fs_ncg, sizeof(struct bufarea));
|
2013-03-23 20:00:02 +00:00
|
|
|
if (cgbufs == NULL)
|
2021-01-07 01:37:08 +00:00
|
|
|
errx(EEXIT, "Cannot allocate cylinder group buffers");
|
2013-03-23 20:00:02 +00:00
|
|
|
}
|
|
|
|
cgbp = &cgbufs[cg];
|
|
|
|
if (cgbp->b_un.b_cg != NULL)
|
|
|
|
return (cgbp);
|
|
|
|
cgp = NULL;
|
|
|
|
if (flushtries == 0)
|
2021-01-07 01:37:08 +00:00
|
|
|
cgp = Malloc((unsigned int)sblock.fs_cgsize);
|
2013-03-23 20:00:02 +00:00
|
|
|
if (cgp == NULL) {
|
2021-01-07 01:37:08 +00:00
|
|
|
if (sujrecovery)
|
|
|
|
errx(EEXIT,"Ran out of memory during journal recovery");
|
2013-03-23 20:00:02 +00:00
|
|
|
getblk(&cgblk, cgtod(&sblock, cg), sblock.fs_cgsize);
|
|
|
|
return (&cgblk);
|
|
|
|
}
|
|
|
|
cgbp->b_un.b_cg = cgp;
|
|
|
|
initbarea(cgbp, BT_CYLGRP);
|
|
|
|
getblk(cgbp, cgtod(&sblock, cg), sblock.fs_cgsize);
|
|
|
|
return (cgbp);
|
|
|
|
}
|
|
|
|
|
2018-12-05 06:31:50 +00:00
|
|
|
/*
|
|
|
|
* Mark a cylinder group buffer as dirty.
|
|
|
|
* Update its check-hash if they are enabled.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cgdirty(struct bufarea *cgbp)
|
|
|
|
{
|
|
|
|
struct cg *cg;
|
|
|
|
|
|
|
|
cg = cgbp->b_un.b_cg;
|
|
|
|
if ((sblock.fs_metackhash & CK_CYLGRP) != 0) {
|
|
|
|
cg->cg_ckhash = 0;
|
|
|
|
cg->cg_ckhash =
|
|
|
|
calculate_crc32c(~0L, (void *)cg, sblock.fs_cgsize);
|
|
|
|
}
|
|
|
|
dirty(cgbp);
|
|
|
|
}
|
|
|
|
|
2013-03-23 20:00:02 +00:00
|
|
|
/*
|
|
|
|
* Attempt to flush a cylinder group cache entry.
|
|
|
|
* Return whether the flush was successful.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
flushentry(void)
|
|
|
|
{
|
|
|
|
struct bufarea *cgbp;
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
if (sujrecovery || flushtries == sblock.fs_ncg || cgbufs == NULL)
|
2014-02-25 18:25:27 +00:00
|
|
|
return (0);
|
2013-03-23 20:00:02 +00:00
|
|
|
cgbp = &cgbufs[flushtries++];
|
|
|
|
if (cgbp->b_un.b_cg == NULL)
|
|
|
|
return (0);
|
|
|
|
flush(fswritefd, cgbp);
|
|
|
|
free(cgbp->b_un.b_buf);
|
|
|
|
cgbp->b_un.b_buf = NULL;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
/*
|
|
|
|
* Manage a cache of directory blocks.
|
|
|
|
*/
|
|
|
|
struct bufarea *
|
2013-02-24 06:44:29 +00:00
|
|
|
getdatablk(ufs2_daddr_t blkno, long size, int type)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct bufarea *bp;
|
2021-01-07 01:37:08 +00:00
|
|
|
struct bufhash *bhdp;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
cachelookups++;
|
|
|
|
/* If out of range, return empty buffer with b_err == -1 */
|
|
|
|
if (type != BT_INODES && chkrange(blkno, size / sblock.fs_fsize)) {
|
|
|
|
blkno = -1;
|
|
|
|
type = BT_EMPTY;
|
|
|
|
}
|
|
|
|
bhdp = &bufhashhd[HASH(blkno)];
|
|
|
|
LIST_FOREACH(bp, bhdp, b_hash)
|
|
|
|
if (bp->b_bno == fsbtodb(&sblock, blkno)) {
|
|
|
|
if (debug && bp->b_size != size) {
|
|
|
|
prtbuf("getdatablk: size mismatch", bp);
|
|
|
|
pfatal("getdatablk: b_size %d != size %ld\n",
|
|
|
|
bp->b_size, size);
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
goto foundit;
|
2021-01-07 01:37:08 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Move long-term busy buffer back to the front of the LRU so we
|
|
|
|
* do not endless inspect them for recycling.
|
|
|
|
*/
|
|
|
|
bp = TAILQ_LAST(&bufqueuehd, bufqueue);
|
|
|
|
if (bp != NULL && bp->b_refcnt != 0) {
|
|
|
|
TAILQ_REMOVE(&bufqueuehd, bp, b_list);
|
|
|
|
TAILQ_INSERT_HEAD(&bufqueuehd, bp, b_list);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Allocate up to the minimum number of buffers before
|
|
|
|
* considering recycling any of them.
|
|
|
|
*/
|
|
|
|
if (size > sblock.fs_bsize)
|
|
|
|
errx(EEXIT, "Excessive buffer size %ld > %d\n", size,
|
|
|
|
sblock.fs_bsize);
|
|
|
|
if (numbufs < MINBUFS) {
|
|
|
|
bp = allocbuf("cannot create minimal buffer pool");
|
|
|
|
} else if (sujrecovery) {
|
|
|
|
/*
|
|
|
|
* SUJ recovery does not want anything written until it
|
|
|
|
* has successfully completed (so it can fail back to
|
|
|
|
* full fsck). Thus, we can only recycle clean buffers.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH_REVERSE(bp, &bufqueuehd, bufqueue, b_list)
|
|
|
|
if ((bp->b_flags & B_DIRTY) == 0 && bp->b_refcnt == 0)
|
|
|
|
break;
|
|
|
|
if (bp == NULL)
|
|
|
|
bp = allocbuf("Ran out of memory during "
|
|
|
|
"journal recovery");
|
|
|
|
else
|
|
|
|
LIST_REMOVE(bp, b_hash);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Recycle oldest non-busy buffer.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH_REVERSE(bp, &bufqueuehd, bufqueue, b_list)
|
|
|
|
if (bp->b_refcnt == 0)
|
|
|
|
break;
|
|
|
|
if (bp == NULL)
|
|
|
|
bp = allocbuf("Ran out of memory for buffers");
|
|
|
|
else
|
|
|
|
LIST_REMOVE(bp, b_hash);
|
|
|
|
}
|
|
|
|
flush(fswritefd, bp);
|
2013-02-24 06:44:29 +00:00
|
|
|
bp->b_type = type;
|
2021-01-07 01:37:08 +00:00
|
|
|
LIST_INSERT_HEAD(bhdp, bp, b_hash);
|
2000-10-09 09:21:04 +00:00
|
|
|
getblk(bp, blkno, size);
|
2021-01-07 01:37:08 +00:00
|
|
|
cachereads++;
|
2000-10-09 09:21:04 +00:00
|
|
|
/* fall through */
|
|
|
|
foundit:
|
2021-01-07 01:37:08 +00:00
|
|
|
if (debug && bp->b_type != type) {
|
|
|
|
printf("getdatablk: buffer type changed to %s",
|
|
|
|
BT_BUFTYPE(type));
|
|
|
|
prtbuf("", bp);
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&bufqueuehd, bp, b_list);
|
|
|
|
TAILQ_INSERT_HEAD(&bufqueuehd, bp, b_list);
|
|
|
|
if (bp->b_errs == 0)
|
|
|
|
bp->b_refcnt++;
|
2000-10-09 09:21:04 +00:00
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-06-21 06:18:05 +00:00
|
|
|
getblk(struct bufarea *bp, ufs2_daddr_t blk, long size)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t dblk;
|
2013-02-24 06:44:29 +00:00
|
|
|
struct timespec start, finish;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
|
|
|
dblk = fsbtodb(&sblock, blk);
|
2013-02-24 06:44:29 +00:00
|
|
|
if (bp->b_bno == dblk) {
|
|
|
|
totalreads++;
|
|
|
|
} else {
|
|
|
|
if (debug) {
|
|
|
|
readcnt[bp->b_type]++;
|
|
|
|
clock_gettime(CLOCK_REALTIME_PRECISE, &start);
|
|
|
|
}
|
2021-01-07 01:37:08 +00:00
|
|
|
if (bp->b_type != BT_EMPTY)
|
|
|
|
bp->b_errs =
|
|
|
|
blread(fsreadfd, bp->b_un.b_buf, dblk, size);
|
|
|
|
else
|
|
|
|
bp->b_errs = -1;
|
2013-02-24 06:44:29 +00:00
|
|
|
if (debug) {
|
|
|
|
clock_gettime(CLOCK_REALTIME_PRECISE, &finish);
|
Make timespecadd(3) and friends public
The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.
Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.
Bump _FreeBSD_version due to the breaking KPI change.
Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725
2018-07-30 15:46:40 +00:00
|
|
|
timespecsub(&finish, &start, &finish);
|
|
|
|
timespecadd(&readtime[bp->b_type], &finish,
|
|
|
|
&readtime[bp->b_type]);
|
2013-02-24 06:44:29 +00:00
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
bp->b_bno = dblk;
|
|
|
|
bp->b_size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
void
|
|
|
|
brelse(struct bufarea *bp)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bp->b_refcnt <= 0)
|
|
|
|
prtbuf("brelse: buffer with negative reference count", bp);
|
|
|
|
bp->b_refcnt--;
|
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
flush(int fd, struct bufarea *bp)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2021-01-07 01:37:08 +00:00
|
|
|
struct inode ip;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
if ((bp->b_flags & B_DIRTY) == 0)
|
2000-10-09 09:21:04 +00:00
|
|
|
return;
|
2021-01-07 01:37:08 +00:00
|
|
|
bp->b_flags &= ~B_DIRTY;
|
2001-03-21 09:48:03 +00:00
|
|
|
if (fswritefd < 0) {
|
|
|
|
pfatal("WRITING IN READ_ONLY MODE.\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
if (bp->b_errs != 0)
|
2002-07-30 13:01:25 +00:00
|
|
|
pfatal("WRITING %sZERO'ED BLOCK %lld TO DISK\n",
|
2000-10-09 09:21:04 +00:00
|
|
|
(bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
|
2002-07-30 13:01:25 +00:00
|
|
|
(long long)bp->b_bno);
|
2000-10-09 09:21:04 +00:00
|
|
|
bp->b_errs = 0;
|
2018-01-24 23:57:40 +00:00
|
|
|
/*
|
|
|
|
* Write using the appropriate function.
|
|
|
|
*/
|
|
|
|
switch (bp->b_type) {
|
|
|
|
case BT_SUPERBLK:
|
|
|
|
if (bp != &sblk)
|
2018-01-25 08:36:19 +00:00
|
|
|
pfatal("BUFFER %p DOES NOT MATCH SBLK %p\n",
|
|
|
|
bp, &sblk);
|
2018-12-05 06:31:50 +00:00
|
|
|
if (sbput(fd, bp->b_un.b_fs, 0) == 0)
|
2018-01-26 00:58:32 +00:00
|
|
|
fsmodified = 1;
|
2018-01-24 23:57:40 +00:00
|
|
|
break;
|
|
|
|
case BT_CYLGRP:
|
2021-01-07 01:37:08 +00:00
|
|
|
if (sujrecovery)
|
|
|
|
cg_write(bp);
|
2020-09-19 22:48:30 +00:00
|
|
|
if (cgput(fswritefd, &sblock, bp->b_un.b_cg) == 0)
|
2018-01-24 23:57:40 +00:00
|
|
|
fsmodified = 1;
|
|
|
|
break;
|
2021-01-07 01:37:08 +00:00
|
|
|
case BT_INODES:
|
|
|
|
if (debug && sblock.fs_magic == FS_UFS2_MAGIC) {
|
|
|
|
struct ufs2_dinode *dp = bp->b_un.b_dinode2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < INOPB(&sblock); dp++, i++) {
|
|
|
|
if (ffs_verify_dinode_ckhash(&sblock, dp) == 0)
|
|
|
|
continue;
|
|
|
|
pwarn("flush: INODE CHECK-HASH FAILED");
|
|
|
|
ip.i_bp = bp;
|
|
|
|
ip.i_dp = (union dinode *)dp;
|
|
|
|
ip.i_number = bp->b_index + i;
|
|
|
|
prtinode(&ip);
|
|
|
|
if (preen || reply("FIX") != 0) {
|
|
|
|
if (preen)
|
|
|
|
printf(" (FIXED)\n");
|
|
|
|
ffs_update_dinode_ckhash(&sblock, dp);
|
|
|
|
inodirty(&ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
2018-01-24 23:57:40 +00:00
|
|
|
default:
|
|
|
|
blwrite(fd, bp->b_un.b_buf, bp->b_bno, bp->b_size);
|
|
|
|
break;
|
2000-10-09 09:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
/*
|
|
|
|
* Journaled soft updates does not maintain cylinder group summary
|
|
|
|
* information during cleanup, so this routine recalculates the summary
|
|
|
|
* information and updates the superblock summary in preparation for
|
|
|
|
* writing out the cylinder group.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cg_write(struct bufarea *bp)
|
|
|
|
{
|
|
|
|
ufs1_daddr_t fragno, cgbno, maxbno;
|
|
|
|
u_int8_t *blksfree;
|
|
|
|
struct cg *cgp;
|
|
|
|
int blk;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix the frag and cluster summary.
|
|
|
|
*/
|
|
|
|
cgp = bp->b_un.b_cg;
|
|
|
|
cgp->cg_cs.cs_nbfree = 0;
|
|
|
|
cgp->cg_cs.cs_nffree = 0;
|
|
|
|
bzero(&cgp->cg_frsum, sizeof(cgp->cg_frsum));
|
|
|
|
maxbno = fragstoblks(&sblock, sblock.fs_fpg);
|
|
|
|
if (sblock.fs_contigsumsize > 0) {
|
|
|
|
for (i = 1; i <= sblock.fs_contigsumsize; i++)
|
|
|
|
cg_clustersum(cgp)[i] = 0;
|
|
|
|
bzero(cg_clustersfree(cgp), howmany(maxbno, CHAR_BIT));
|
|
|
|
}
|
|
|
|
blksfree = cg_blksfree(cgp);
|
|
|
|
for (cgbno = 0; cgbno < maxbno; cgbno++) {
|
|
|
|
if (ffs_isfreeblock(&sblock, blksfree, cgbno))
|
|
|
|
continue;
|
|
|
|
if (ffs_isblock(&sblock, blksfree, cgbno)) {
|
|
|
|
ffs_clusteracct(&sblock, cgp, cgbno, 1);
|
|
|
|
cgp->cg_cs.cs_nbfree++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fragno = blkstofrags(&sblock, cgbno);
|
|
|
|
blk = blkmap(&sblock, blksfree, fragno);
|
|
|
|
ffs_fragacct(&sblock, blk, cgp->cg_frsum, 1);
|
|
|
|
for (i = 0; i < sblock.fs_frag; i++)
|
|
|
|
if (isset(blksfree, fragno + i))
|
|
|
|
cgp->cg_cs.cs_nffree++;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Update the superblock cg summary from our now correct values
|
|
|
|
* before writing the block.
|
|
|
|
*/
|
|
|
|
sblock.fs_cs(&sblock, cgp->cg_cgx) = cgp->cg_cs;
|
|
|
|
}
|
|
|
|
|
2001-03-21 09:48:03 +00:00
|
|
|
void
|
2002-07-30 13:01:25 +00:00
|
|
|
rwerror(const char *mesg, ufs2_daddr_t blk)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
|
2001-04-24 22:38:08 +00:00
|
|
|
if (bkgrdcheck)
|
|
|
|
exit(EEXIT);
|
2000-10-09 09:21:04 +00:00
|
|
|
if (preen == 0)
|
|
|
|
printf("\n");
|
2001-11-17 23:48:21 +00:00
|
|
|
pfatal("CANNOT %s: %ld", mesg, (long)blk);
|
2000-10-09 09:21:04 +00:00
|
|
|
if (reply("CONTINUE") == 0)
|
|
|
|
exit(EEXIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
ckfini(int markclean)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct bufarea *bp, *nbp;
|
2021-04-02 18:57:34 +00:00
|
|
|
struct inoinfo *inp, *ninp;
|
|
|
|
int ofsmodified, cnt, cg, i;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
2001-03-21 09:48:03 +00:00
|
|
|
if (bkgrdflag) {
|
|
|
|
unlink(snapname);
|
|
|
|
if ((!(sblock.fs_flags & FS_UNCLEAN)) != markclean) {
|
|
|
|
cmd.value = FS_UNCLEAN;
|
|
|
|
cmd.size = markclean ? -1 : 1;
|
|
|
|
if (sysctlbyname("vfs.ffs.setflags", 0, 0,
|
|
|
|
&cmd, sizeof cmd) == -1)
|
2003-08-01 11:31:19 +00:00
|
|
|
rwerror("SET FILE SYSTEM FLAGS", FS_UNCLEAN);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (!preen) {
|
|
|
|
printf("\n***** FILE SYSTEM MARKED %s *****\n",
|
|
|
|
markclean ? "CLEAN" : "DIRTY");
|
|
|
|
if (!markclean)
|
|
|
|
rerun = 1;
|
|
|
|
}
|
|
|
|
} else if (!preen && !markclean) {
|
|
|
|
printf("\n***** FILE SYSTEM STILL DIRTY *****\n");
|
|
|
|
rerun = 1;
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 20:53:52 +00:00
|
|
|
if (debug && cachelookups > 0)
|
2021-01-07 01:37:08 +00:00
|
|
|
printf("cache with %d buffers missed %d of %d (%d%%)\n",
|
|
|
|
numbufs, cachereads, cachelookups,
|
|
|
|
(int)(cachereads * 100 / cachelookups));
|
2000-10-09 09:21:04 +00:00
|
|
|
if (fswritefd < 0) {
|
|
|
|
(void)close(fsreadfd);
|
|
|
|
return;
|
|
|
|
}
|
2021-01-07 01:37:08 +00:00
|
|
|
/*
|
|
|
|
* To remain idempotent with partial truncations the buffers
|
|
|
|
* must be flushed in this order:
|
|
|
|
* 1) cylinder groups (bitmaps)
|
|
|
|
* 2) indirect, directory, external attribute, and data blocks
|
|
|
|
* 3) inode blocks
|
|
|
|
* 4) superblock
|
|
|
|
* This ordering preserves access to the modified pointers
|
|
|
|
* until they are freed.
|
|
|
|
*/
|
|
|
|
/* Step 1: cylinder groups */
|
|
|
|
if (debug)
|
|
|
|
printf("Flush Cylinder groups\n");
|
|
|
|
if (cgbufs != NULL) {
|
|
|
|
for (cnt = 0; cnt < sblock.fs_ncg; cnt++) {
|
|
|
|
if (cgbufs[cnt].b_un.b_cg == NULL)
|
|
|
|
continue;
|
|
|
|
flush(fswritefd, &cgbufs[cnt]);
|
|
|
|
free(cgbufs[cnt].b_un.b_cg);
|
|
|
|
}
|
|
|
|
free(cgbufs);
|
2021-04-02 18:57:34 +00:00
|
|
|
cgbufs = NULL;
|
2000-10-09 09:21:04 +00:00
|
|
|
}
|
|
|
|
flush(fswritefd, &cgblk);
|
|
|
|
free(cgblk.b_un.b_buf);
|
2021-04-02 18:57:34 +00:00
|
|
|
cgblk.b_un.b_buf = NULL;
|
2013-02-15 01:00:48 +00:00
|
|
|
cnt = 0;
|
2021-01-07 01:37:08 +00:00
|
|
|
/* Step 2: indirect, directory, external attribute, and data blocks */
|
|
|
|
if (debug)
|
|
|
|
printf("Flush indirect, directory, external attribute, "
|
|
|
|
"and data blocks\n");
|
2021-04-02 18:57:34 +00:00
|
|
|
if (pdirbp != NULL) {
|
2021-01-07 01:37:08 +00:00
|
|
|
brelse(pdirbp);
|
2021-04-02 18:57:34 +00:00
|
|
|
pdirbp = NULL;
|
|
|
|
}
|
2021-01-07 01:37:08 +00:00
|
|
|
TAILQ_FOREACH_REVERSE_SAFE(bp, &bufqueuehd, bufqueue, b_list, nbp) {
|
|
|
|
switch (bp->b_type) {
|
|
|
|
/* These should not be in the buffer cache list */
|
|
|
|
case BT_UNKNOWN:
|
|
|
|
case BT_SUPERBLK:
|
|
|
|
case BT_CYLGRP:
|
|
|
|
default:
|
|
|
|
prtbuf("ckfini: improper buffer type on cache list",bp);
|
|
|
|
continue;
|
|
|
|
/* These are the ones to flush in this step */
|
|
|
|
case BT_EMPTY:
|
|
|
|
if (bp->b_bno >= 0)
|
|
|
|
pfatal("Unused BT_EMPTY buffer for block %jd\n",
|
|
|
|
(intmax_t)bp->b_bno);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case BT_LEVEL1:
|
|
|
|
case BT_LEVEL2:
|
|
|
|
case BT_LEVEL3:
|
|
|
|
case BT_EXTATTR:
|
|
|
|
case BT_DIRDATA:
|
|
|
|
case BT_DATA:
|
|
|
|
break;
|
|
|
|
/* These are the ones to flush in the next step */
|
|
|
|
case BT_INODES:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (debug && bp->b_refcnt != 0) {
|
|
|
|
prtbuf("ckfini: clearing in-use buffer", bp);
|
|
|
|
pfatal("ckfini: clearing in-use buffer\n");
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&bufqueuehd, bp, b_list);
|
|
|
|
cnt++;
|
|
|
|
flush(fswritefd, bp);
|
|
|
|
free(bp->b_un.b_buf);
|
|
|
|
free((char *)bp);
|
|
|
|
}
|
|
|
|
/* Step 3: inode blocks */
|
|
|
|
if (debug)
|
|
|
|
printf("Flush inode blocks\n");
|
2021-04-02 18:57:34 +00:00
|
|
|
if (icachebp != NULL) {
|
2021-01-07 01:37:08 +00:00
|
|
|
brelse(icachebp);
|
2021-04-02 18:57:34 +00:00
|
|
|
icachebp = NULL;
|
|
|
|
}
|
2021-01-07 01:37:08 +00:00
|
|
|
TAILQ_FOREACH_REVERSE_SAFE(bp, &bufqueuehd, bufqueue, b_list, nbp) {
|
|
|
|
if (debug && bp->b_refcnt != 0) {
|
|
|
|
prtbuf("ckfini: clearing in-use buffer", bp);
|
|
|
|
pfatal("ckfini: clearing in-use buffer\n");
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&bufqueuehd, bp, b_list);
|
2000-10-09 09:21:04 +00:00
|
|
|
cnt++;
|
|
|
|
flush(fswritefd, bp);
|
|
|
|
free(bp->b_un.b_buf);
|
|
|
|
free((char *)bp);
|
|
|
|
}
|
2013-02-15 01:00:48 +00:00
|
|
|
if (numbufs != cnt)
|
|
|
|
errx(EEXIT, "panic: lost %d buffers", numbufs - cnt);
|
2021-01-07 01:37:08 +00:00
|
|
|
/* Step 4: superblock */
|
|
|
|
if (debug)
|
|
|
|
printf("Flush the superblock\n");
|
|
|
|
flush(fswritefd, &sblk);
|
|
|
|
if (havesb && cursnapshot == 0 && sblock.fs_magic == FS_UFS2_MAGIC &&
|
|
|
|
sblk.b_bno != sblock.fs_sblockloc / dev_bsize &&
|
|
|
|
!preen && reply("UPDATE STANDARD SUPERBLOCK")) {
|
|
|
|
/* Change the write destination to standard superblock */
|
|
|
|
sblock.fs_sblockactualloc = sblock.fs_sblockloc;
|
|
|
|
sblk.b_bno = sblock.fs_sblockloc / dev_bsize;
|
|
|
|
sbdirty();
|
|
|
|
flush(fswritefd, &sblk);
|
2013-03-23 20:00:02 +00:00
|
|
|
}
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot == 0 && sblock.fs_clean != markclean) {
|
2002-10-19 05:36:48 +00:00
|
|
|
if ((sblock.fs_clean = markclean) != 0) {
|
2001-04-16 22:22:21 +00:00
|
|
|
sblock.fs_flags &= ~(FS_UNCLEAN | FS_NEEDSFSCK);
|
2002-10-19 05:36:48 +00:00
|
|
|
sblock.fs_pendingblocks = 0;
|
|
|
|
sblock.fs_pendinginodes = 0;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
sbdirty();
|
|
|
|
ofsmodified = fsmodified;
|
|
|
|
flush(fswritefd, &sblk);
|
|
|
|
fsmodified = ofsmodified;
|
|
|
|
if (!preen) {
|
|
|
|
printf("\n***** FILE SYSTEM MARKED %s *****\n",
|
|
|
|
markclean ? "CLEAN" : "DIRTY");
|
|
|
|
if (!markclean)
|
|
|
|
rerun = 1;
|
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
} else if (!preen) {
|
|
|
|
if (markclean) {
|
|
|
|
printf("\n***** FILE SYSTEM IS CLEAN *****\n");
|
|
|
|
} else {
|
|
|
|
printf("\n***** FILE SYSTEM STILL DIRTY *****\n");
|
|
|
|
rerun = 1;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
}
|
2021-04-02 18:57:34 +00:00
|
|
|
/*
|
|
|
|
* Free allocated tracking structures.
|
|
|
|
*/
|
|
|
|
if (blockmap != NULL)
|
|
|
|
free(blockmap);
|
|
|
|
blockmap = NULL;
|
|
|
|
if (inostathead != NULL) {
|
|
|
|
for (cg = 0; cg < sblock.fs_ncg; cg++)
|
|
|
|
if (inostathead[cg].il_stat != NULL)
|
|
|
|
free((char *)inostathead[cg].il_stat);
|
|
|
|
free(inostathead);
|
|
|
|
}
|
|
|
|
inostathead = NULL;
|
|
|
|
if (inpsort != NULL)
|
|
|
|
free(inpsort);
|
|
|
|
inpsort = NULL;
|
|
|
|
if (inphead != NULL) {
|
|
|
|
for (i = 0; i < dirhash; i++) {
|
|
|
|
for (inp = inphead[i]; inp != NULL; inp = ninp) {
|
|
|
|
ninp = inp->i_nexthash;
|
|
|
|
free(inp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(inphead);
|
|
|
|
}
|
|
|
|
inphead = NULL;
|
2021-01-07 01:37:08 +00:00
|
|
|
finalIOstats();
|
2000-10-09 09:21:04 +00:00
|
|
|
(void)close(fsreadfd);
|
|
|
|
(void)close(fswritefd);
|
|
|
|
}
|
|
|
|
|
2013-02-24 06:44:29 +00:00
|
|
|
/*
|
|
|
|
* Print out I/O statistics.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
IOstats(char *what)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (debug == 0)
|
|
|
|
return;
|
|
|
|
if (diskreads == 0) {
|
|
|
|
printf("%s: no I/O\n\n", what);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (startpass.tv_sec == 0)
|
|
|
|
startpass = startprog;
|
|
|
|
printf("%s: I/O statistics\n", what);
|
|
|
|
printIOstats();
|
|
|
|
totaldiskreads += diskreads;
|
|
|
|
diskreads = 0;
|
|
|
|
for (i = 0; i < BT_NUMBUFTYPES; i++) {
|
Make timespecadd(3) and friends public
The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.
Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.
Bump _FreeBSD_version due to the breaking KPI change.
Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725
2018-07-30 15:46:40 +00:00
|
|
|
timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]);
|
2013-02-24 06:44:29 +00:00
|
|
|
totalreadcnt[i] += readcnt[i];
|
|
|
|
readtime[i].tv_sec = readtime[i].tv_nsec = 0;
|
|
|
|
readcnt[i] = 0;
|
|
|
|
}
|
|
|
|
clock_gettime(CLOCK_REALTIME_PRECISE, &startpass);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
finalIOstats(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (debug == 0)
|
|
|
|
return;
|
|
|
|
printf("Final I/O statistics\n");
|
|
|
|
totaldiskreads += diskreads;
|
|
|
|
diskreads = totaldiskreads;
|
|
|
|
startpass = startprog;
|
|
|
|
for (i = 0; i < BT_NUMBUFTYPES; i++) {
|
Make timespecadd(3) and friends public
The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.
Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.
Bump _FreeBSD_version due to the breaking KPI change.
Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725
2018-07-30 15:46:40 +00:00
|
|
|
timespecadd(&totalreadtime[i], &readtime[i], &totalreadtime[i]);
|
2013-02-24 06:44:29 +00:00
|
|
|
totalreadcnt[i] += readcnt[i];
|
|
|
|
readtime[i] = totalreadtime[i];
|
|
|
|
readcnt[i] = totalreadcnt[i];
|
|
|
|
}
|
|
|
|
printIOstats();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printIOstats(void)
|
|
|
|
{
|
|
|
|
long long msec, totalmsec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_REALTIME_PRECISE, &finishpass);
|
Make timespecadd(3) and friends public
The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.
Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.
Bump _FreeBSD_version due to the breaking KPI change.
Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725
2018-07-30 15:46:40 +00:00
|
|
|
timespecsub(&finishpass, &startpass, &finishpass);
|
2013-03-24 22:37:10 +00:00
|
|
|
printf("Running time: %jd.%03ld sec\n",
|
2013-03-24 10:41:29 +00:00
|
|
|
(intmax_t)finishpass.tv_sec, finishpass.tv_nsec / 1000000);
|
2013-02-24 06:44:29 +00:00
|
|
|
printf("buffer reads by type:\n");
|
|
|
|
for (totalmsec = 0, i = 0; i < BT_NUMBUFTYPES; i++)
|
|
|
|
totalmsec += readtime[i].tv_sec * 1000 +
|
|
|
|
readtime[i].tv_nsec / 1000000;
|
|
|
|
if (totalmsec == 0)
|
|
|
|
totalmsec = 1;
|
|
|
|
for (i = 0; i < BT_NUMBUFTYPES; i++) {
|
|
|
|
if (readcnt[i] == 0)
|
|
|
|
continue;
|
2013-03-24 22:37:10 +00:00
|
|
|
msec =
|
|
|
|
readtime[i].tv_sec * 1000 + readtime[i].tv_nsec / 1000000;
|
2013-03-24 10:41:29 +00:00
|
|
|
printf("%21s:%8ld %2ld.%ld%% %4jd.%03ld sec %2lld.%lld%%\n",
|
2013-02-24 06:44:29 +00:00
|
|
|
buftype[i], readcnt[i], readcnt[i] * 100 / diskreads,
|
2013-03-23 20:00:02 +00:00
|
|
|
(readcnt[i] * 1000 / diskreads) % 10,
|
2013-03-24 10:41:29 +00:00
|
|
|
(intmax_t)readtime[i].tv_sec, readtime[i].tv_nsec / 1000000,
|
2013-02-24 06:44:29 +00:00
|
|
|
msec * 100 / totalmsec, (msec * 1000 / totalmsec) % 10);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
int
|
2006-10-31 22:06:56 +00:00
|
|
|
blread(int fd, char *buf, ufs2_daddr_t blk, long size)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
int i, errs;
|
|
|
|
off_t offset;
|
|
|
|
|
|
|
|
offset = blk;
|
|
|
|
offset *= dev_bsize;
|
2002-12-07 21:40:31 +00:00
|
|
|
if (bkgrdflag)
|
|
|
|
slowio_start();
|
2013-02-24 06:44:29 +00:00
|
|
|
totalreads++;
|
|
|
|
diskreads++;
|
2018-12-15 11:36:20 +00:00
|
|
|
if (pread(fd, buf, (int)size, offset) == size) {
|
2002-12-07 21:40:31 +00:00
|
|
|
if (bkgrdflag)
|
|
|
|
slowio_end();
|
2000-10-09 09:21:04 +00:00
|
|
|
return (0);
|
2002-12-07 21:40:31 +00:00
|
|
|
}
|
2013-07-30 22:57:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is handled specially here instead of in rwerror because
|
|
|
|
* rwerror is used for all sorts of errors, not just true read/write
|
|
|
|
* errors. It should be refactored and fixed.
|
|
|
|
*/
|
|
|
|
if (surrender) {
|
|
|
|
pfatal("CANNOT READ_BLK: %ld", (long)blk);
|
|
|
|
errx(EEXIT, "ABORTING DUE TO READ ERRORS");
|
|
|
|
} else
|
|
|
|
rwerror("READ BLK", blk);
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
errs = 0;
|
|
|
|
memset(buf, 0, (size_t)size);
|
|
|
|
printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
|
|
|
|
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
|
2018-12-15 11:36:20 +00:00
|
|
|
if (pread(fd, cp, (int)secsize, offset + i) != secsize) {
|
2000-10-09 09:21:04 +00:00
|
|
|
if (secsize != dev_bsize && dev_bsize != 1)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf(" %jd (%jd),",
|
|
|
|
(intmax_t)(blk * dev_bsize + i) / secsize,
|
|
|
|
(intmax_t)blk + i / dev_bsize);
|
2000-10-09 09:21:04 +00:00
|
|
|
else
|
2002-07-31 12:01:14 +00:00
|
|
|
printf(" %jd,", (intmax_t)blk + i / dev_bsize);
|
2000-10-09 09:21:04 +00:00
|
|
|
errs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
if (errs)
|
|
|
|
resolved = 0;
|
|
|
|
return (errs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-12 15:36:44 +00:00
|
|
|
blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *cp;
|
|
|
|
off_t offset;
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
offset = blk;
|
|
|
|
offset *= dev_bsize;
|
2018-12-15 11:36:20 +00:00
|
|
|
if (pwrite(fd, buf, size, offset) == size) {
|
2000-10-09 09:21:04 +00:00
|
|
|
fsmodified = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolved = 0;
|
2001-03-21 09:48:03 +00:00
|
|
|
rwerror("WRITE BLK", blk);
|
2000-10-09 09:21:04 +00:00
|
|
|
printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
|
|
|
|
for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
|
2018-12-15 11:36:20 +00:00
|
|
|
if (pwrite(fd, cp, dev_bsize, offset + i) != dev_bsize)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf(" %jd,", (intmax_t)blk + i / dev_bsize);
|
2000-10-09 09:21:04 +00:00
|
|
|
printf("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-29 23:00:23 +00:00
|
|
|
void
|
|
|
|
blerase(int fd, ufs2_daddr_t blk, long size)
|
|
|
|
{
|
|
|
|
off_t ioarg[2];
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
ioarg[0] = blk * dev_bsize;
|
|
|
|
ioarg[1] = size;
|
|
|
|
ioctl(fd, DIOCGDELETE, ioarg);
|
|
|
|
/* we don't really care if we succeed or not */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-20 07:19:58 +00:00
|
|
|
/*
|
|
|
|
* Fill a contiguous region with all-zeroes. Note ZEROBUFSIZE is by
|
|
|
|
* definition a multiple of dev_bsize.
|
|
|
|
*/
|
2013-04-29 20:13:09 +00:00
|
|
|
void
|
|
|
|
blzero(int fd, ufs2_daddr_t blk, long size)
|
|
|
|
{
|
|
|
|
static char *zero;
|
|
|
|
off_t offset, len;
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
if (zero == NULL) {
|
2013-08-20 07:19:58 +00:00
|
|
|
zero = calloc(ZEROBUFSIZE, 1);
|
2013-04-29 20:13:09 +00:00
|
|
|
if (zero == NULL)
|
|
|
|
errx(EEXIT, "cannot allocate buffer pool");
|
|
|
|
}
|
|
|
|
offset = blk * dev_bsize;
|
|
|
|
if (lseek(fd, offset, 0) < 0)
|
|
|
|
rwerror("SEEK BLK", blk);
|
|
|
|
while (size > 0) {
|
2016-05-02 01:28:21 +00:00
|
|
|
len = MIN(ZEROBUFSIZE, size);
|
2013-04-29 20:13:09 +00:00
|
|
|
if (write(fd, zero, len) != len)
|
|
|
|
rwerror("WRITE BLK", blk);
|
|
|
|
blk += len / dev_bsize;
|
|
|
|
size -= len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-10 23:49:23 +00:00
|
|
|
/*
|
2009-02-04 01:02:56 +00:00
|
|
|
* Verify cylinder group's magic number and other parameters. If the
|
|
|
|
* test fails, offer an option to rebuild the whole cylinder group.
|
2008-04-10 23:49:23 +00:00
|
|
|
*/
|
2009-02-04 01:02:56 +00:00
|
|
|
int
|
2021-01-07 01:37:08 +00:00
|
|
|
check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild)
|
2008-04-10 23:49:23 +00:00
|
|
|
{
|
2013-03-23 20:00:02 +00:00
|
|
|
struct cg *cgp = cgbp->b_un.b_cg;
|
2021-01-07 01:37:08 +00:00
|
|
|
uint32_t cghash, calchash;
|
2021-04-27 01:42:48 +00:00
|
|
|
static int prevfailcg = -1;
|
2008-04-10 23:49:23 +00:00
|
|
|
|
2009-02-04 01:02:56 +00:00
|
|
|
/*
|
|
|
|
* Extended cylinder group checks.
|
|
|
|
*/
|
2021-01-07 01:37:08 +00:00
|
|
|
calchash = cgp->cg_ckhash;
|
2021-03-12 06:44:33 +00:00
|
|
|
if ((sblock.fs_metackhash & CK_CYLGRP) != 0 &&
|
|
|
|
(ckhashadd & CK_CYLGRP) == 0) {
|
2021-01-07 01:37:08 +00:00
|
|
|
cghash = cgp->cg_ckhash;
|
|
|
|
cgp->cg_ckhash = 0;
|
|
|
|
calchash = calculate_crc32c(~0L, (void *)cgp, sblock.fs_cgsize);
|
|
|
|
cgp->cg_ckhash = cghash;
|
|
|
|
}
|
|
|
|
if (cgp->cg_ckhash == calchash &&
|
|
|
|
cg_chkmagic(cgp) &&
|
|
|
|
cgp->cg_cgx == cg &&
|
2009-02-04 01:02:56 +00:00
|
|
|
((sblock.fs_magic == FS_UFS1_MAGIC &&
|
|
|
|
cgp->cg_old_niblk == sblock.fs_ipg &&
|
|
|
|
cgp->cg_ndblk <= sblock.fs_fpg &&
|
2010-01-07 00:17:36 +00:00
|
|
|
cgp->cg_old_ncyl <= sblock.fs_old_cpg) ||
|
2009-02-04 01:02:56 +00:00
|
|
|
(sblock.fs_magic == FS_UFS2_MAGIC &&
|
|
|
|
cgp->cg_niblk == sblock.fs_ipg &&
|
|
|
|
cgp->cg_ndblk <= sblock.fs_fpg &&
|
|
|
|
cgp->cg_initediblk <= sblock.fs_ipg))) {
|
|
|
|
return (1);
|
|
|
|
}
|
2021-04-27 01:42:48 +00:00
|
|
|
if (prevfailcg == cg)
|
|
|
|
return (0);
|
|
|
|
prevfailcg = cg;
|
2021-01-07 01:37:08 +00:00
|
|
|
pfatal("CYLINDER GROUP %d: INTEGRITY CHECK FAILED", cg);
|
2021-04-27 01:42:48 +00:00
|
|
|
if (!request_rebuild) {
|
|
|
|
printf("\n");
|
2021-01-07 01:37:08 +00:00
|
|
|
return (0);
|
2021-04-27 01:42:48 +00:00
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
if (!reply("REBUILD CYLINDER GROUP")) {
|
|
|
|
printf("YOU WILL NEED TO RERUN FSCK.\n");
|
|
|
|
rerun = 1;
|
|
|
|
return (1);
|
2008-04-10 23:49:23 +00:00
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
/*
|
|
|
|
* Zero out the cylinder group and then initialize critical fields.
|
|
|
|
* Bit maps and summaries will be recalculated by later passes.
|
|
|
|
*/
|
|
|
|
memset(cgp, 0, (size_t)sblock.fs_cgsize);
|
|
|
|
cgp->cg_magic = CG_MAGIC;
|
|
|
|
cgp->cg_cgx = cg;
|
|
|
|
cgp->cg_niblk = sblock.fs_ipg;
|
2016-05-02 01:28:21 +00:00
|
|
|
cgp->cg_initediblk = MIN(sblock.fs_ipg, 2 * INOPB(&sblock));
|
2009-02-04 01:02:56 +00:00
|
|
|
if (cgbase(&sblock, cg) + sblock.fs_fpg < sblock.fs_size)
|
|
|
|
cgp->cg_ndblk = sblock.fs_fpg;
|
|
|
|
else
|
|
|
|
cgp->cg_ndblk = sblock.fs_size - cgbase(&sblock, cg);
|
|
|
|
cgp->cg_iusedoff = &cgp->cg_space[0] - (u_char *)(&cgp->cg_firstfield);
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC) {
|
|
|
|
cgp->cg_niblk = 0;
|
|
|
|
cgp->cg_initediblk = 0;
|
|
|
|
cgp->cg_old_ncyl = sblock.fs_old_cpg;
|
|
|
|
cgp->cg_old_niblk = sblock.fs_ipg;
|
|
|
|
cgp->cg_old_btotoff = cgp->cg_iusedoff;
|
|
|
|
cgp->cg_old_boff = cgp->cg_old_btotoff +
|
|
|
|
sblock.fs_old_cpg * sizeof(int32_t);
|
|
|
|
cgp->cg_iusedoff = cgp->cg_old_boff +
|
|
|
|
sblock.fs_old_cpg * sizeof(u_int16_t);
|
|
|
|
}
|
|
|
|
cgp->cg_freeoff = cgp->cg_iusedoff + howmany(sblock.fs_ipg, CHAR_BIT);
|
|
|
|
cgp->cg_nextfreeoff = cgp->cg_freeoff + howmany(sblock.fs_fpg,CHAR_BIT);
|
|
|
|
if (sblock.fs_contigsumsize > 0) {
|
|
|
|
cgp->cg_nclusterblks = cgp->cg_ndblk / sblock.fs_frag;
|
|
|
|
cgp->cg_clustersumoff =
|
|
|
|
roundup(cgp->cg_nextfreeoff, sizeof(u_int32_t));
|
|
|
|
cgp->cg_clustersumoff -= sizeof(u_int32_t);
|
|
|
|
cgp->cg_clusteroff = cgp->cg_clustersumoff +
|
|
|
|
(sblock.fs_contigsumsize + 1) * sizeof(u_int32_t);
|
|
|
|
cgp->cg_nextfreeoff = cgp->cg_clusteroff +
|
|
|
|
howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
|
|
|
|
}
|
2018-12-05 06:31:50 +00:00
|
|
|
cgdirty(cgbp);
|
2009-02-04 01:02:56 +00:00
|
|
|
return (0);
|
2008-04-10 23:49:23 +00:00
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
/*
|
|
|
|
* allocate a data block with the specified number of fragments
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t
|
2002-03-20 22:57:10 +00:00
|
|
|
allocblk(long frags)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
int i, j, k, cg, baseblk;
|
2013-03-23 20:00:02 +00:00
|
|
|
struct bufarea *cgbp;
|
|
|
|
struct cg *cgp;
|
2000-10-09 09:21:04 +00:00
|
|
|
|
|
|
|
if (frags <= 0 || frags > sblock.fs_frag)
|
|
|
|
return (0);
|
|
|
|
for (i = 0; i < maxfsblock - sblock.fs_frag; i += sblock.fs_frag) {
|
|
|
|
for (j = 0; j <= sblock.fs_frag - frags; j++) {
|
|
|
|
if (testbmap(i + j))
|
|
|
|
continue;
|
|
|
|
for (k = 1; k < frags; k++)
|
|
|
|
if (testbmap(i + j + k))
|
|
|
|
break;
|
|
|
|
if (k < frags) {
|
|
|
|
j += k;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cg = dtog(&sblock, i + j);
|
2018-01-17 06:31:21 +00:00
|
|
|
cgbp = cglookup(cg);
|
2013-03-23 20:00:02 +00:00
|
|
|
cgp = cgbp->b_un.b_cg;
|
2021-04-26 23:47:27 +00:00
|
|
|
if (!check_cgmagic(cg, cgbp, 0)) {
|
|
|
|
i = (cg + 1) * sblock.fs_fpg - sblock.fs_frag;
|
|
|
|
continue;
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
baseblk = dtogd(&sblock, i + j);
|
|
|
|
for (k = 0; k < frags; k++) {
|
|
|
|
setbmap(i + j + k);
|
|
|
|
clrbit(cg_blksfree(cgp), baseblk + k);
|
|
|
|
}
|
|
|
|
n_blks += frags;
|
|
|
|
if (frags == sblock.fs_frag)
|
|
|
|
cgp->cg_cs.cs_nbfree--;
|
|
|
|
else
|
|
|
|
cgp->cg_cs.cs_nffree -= frags;
|
2018-12-05 06:31:50 +00:00
|
|
|
cgdirty(cgbp);
|
2000-10-09 09:21:04 +00:00
|
|
|
return (i + j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-12-18 23:28:27 +00:00
|
|
|
* Slow down IO so as to leave some disk bandwidth for other processes
|
2000-10-09 09:21:04 +00:00
|
|
|
*/
|
|
|
|
void
|
2002-12-07 21:40:31 +00:00
|
|
|
slowio_start()
|
|
|
|
{
|
|
|
|
|
2004-05-18 19:51:41 +00:00
|
|
|
/* Delay one in every 8 operations */
|
2002-12-07 21:40:31 +00:00
|
|
|
slowio_pollcnt = (slowio_pollcnt + 1) & 7;
|
|
|
|
if (slowio_pollcnt == 0) {
|
|
|
|
gettimeofday(&slowio_starttime, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
slowio_end()
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int delay_usec;
|
|
|
|
|
|
|
|
if (slowio_pollcnt != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Update the slowdown interval. */
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
delay_usec = (tv.tv_sec - slowio_starttime.tv_sec) * 1000000 +
|
|
|
|
(tv.tv_usec - slowio_starttime.tv_usec);
|
|
|
|
if (delay_usec < 64)
|
|
|
|
delay_usec = 64;
|
2004-05-18 19:51:41 +00:00
|
|
|
if (delay_usec > 2500000)
|
|
|
|
delay_usec = 2500000;
|
2002-12-07 21:40:31 +00:00
|
|
|
slowio_delay_usec = (slowio_delay_usec * 63 + delay_usec) >> 6;
|
2004-05-18 19:51:41 +00:00
|
|
|
/* delay by 8 times the average IO delay */
|
|
|
|
if (slowio_delay_usec > 64)
|
|
|
|
usleep(slowio_delay_usec * 8);
|
2002-12-07 21:40:31 +00:00
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
/*
|
|
|
|
* Find a pathname
|
|
|
|
*/
|
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
getpathname(char *namebuf, ino_t curdir, ino_t ino)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
int len;
|
2002-03-20 17:55:10 +00:00
|
|
|
char *cp;
|
2021-01-07 01:37:08 +00:00
|
|
|
struct inode ip;
|
2000-10-09 09:21:04 +00:00
|
|
|
struct inodesc idesc;
|
|
|
|
static int busy = 0;
|
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
if (curdir == ino && ino == UFS_ROOTINO) {
|
2000-10-09 09:21:04 +00:00
|
|
|
(void)strcpy(namebuf, "/");
|
|
|
|
return;
|
|
|
|
}
|
2004-10-08 20:44:47 +00:00
|
|
|
if (busy || !INO_IS_DVALID(curdir)) {
|
2000-10-09 09:21:04 +00:00
|
|
|
(void)strcpy(namebuf, "?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
busy = 1;
|
|
|
|
memset(&idesc, 0, sizeof(struct inodesc));
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
cp = &namebuf[MAXPATHLEN - 1];
|
|
|
|
*cp = '\0';
|
|
|
|
if (curdir != ino) {
|
|
|
|
idesc.id_parent = curdir;
|
|
|
|
goto namelookup;
|
|
|
|
}
|
2017-02-15 19:50:26 +00:00
|
|
|
while (ino != UFS_ROOTINO) {
|
2000-10-09 09:21:04 +00:00
|
|
|
idesc.id_number = ino;
|
|
|
|
idesc.id_func = findino;
|
2002-07-30 13:01:25 +00:00
|
|
|
idesc.id_name = strdup("..");
|
2021-01-07 01:37:08 +00:00
|
|
|
ginode(ino, &ip);
|
|
|
|
if ((ckinode(ip.i_dp, &idesc) & FOUND) == 0) {
|
|
|
|
irelse(&ip);
|
2000-10-09 09:21:04 +00:00
|
|
|
break;
|
2021-01-07 01:37:08 +00:00
|
|
|
}
|
|
|
|
irelse(&ip);
|
2000-10-09 09:21:04 +00:00
|
|
|
namelookup:
|
|
|
|
idesc.id_number = idesc.id_parent;
|
|
|
|
idesc.id_parent = ino;
|
|
|
|
idesc.id_func = findname;
|
|
|
|
idesc.id_name = namebuf;
|
2021-01-07 01:37:08 +00:00
|
|
|
ginode(idesc.id_number, &ip);
|
|
|
|
if ((ckinode(ip.i_dp, &idesc) & FOUND) == 0) {
|
|
|
|
irelse(&ip);
|
2000-10-09 09:21:04 +00:00
|
|
|
break;
|
2021-01-07 01:37:08 +00:00
|
|
|
}
|
|
|
|
irelse(&ip);
|
2000-10-09 09:21:04 +00:00
|
|
|
len = strlen(namebuf);
|
|
|
|
cp -= len;
|
|
|
|
memmove(cp, namebuf, (size_t)len);
|
|
|
|
*--cp = '/';
|
2017-02-09 17:47:01 +00:00
|
|
|
if (cp < &namebuf[UFS_MAXNAMLEN])
|
2000-10-09 09:21:04 +00:00
|
|
|
break;
|
|
|
|
ino = idesc.id_number;
|
|
|
|
}
|
|
|
|
busy = 0;
|
2017-02-15 19:50:26 +00:00
|
|
|
if (ino != UFS_ROOTINO)
|
2000-10-09 09:21:04 +00:00
|
|
|
*--cp = '?';
|
|
|
|
memmove(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 13:01:25 +00:00
|
|
|
catch(int sig __unused)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2002-05-12 23:44:15 +00:00
|
|
|
|
|
|
|
ckfini(0);
|
2000-10-09 09:21:04 +00:00
|
|
|
exit(12);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When preening, allow a single quit to signal
|
2002-08-21 18:11:48 +00:00
|
|
|
* a special exit after file system checks complete
|
2000-10-09 09:21:04 +00:00
|
|
|
* so that reboot sequence may be interrupted.
|
|
|
|
*/
|
|
|
|
void
|
2002-07-30 13:01:25 +00:00
|
|
|
catchquit(int sig __unused)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
2002-08-21 18:11:48 +00:00
|
|
|
printf("returning to single-user after file system check\n");
|
2000-10-09 09:21:04 +00:00
|
|
|
returntosingle = 1;
|
|
|
|
(void)signal(SIGQUIT, SIG_DFL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* determine whether an inode should be fixed.
|
|
|
|
*/
|
|
|
|
int
|
2002-07-30 13:01:25 +00:00
|
|
|
dofix(struct inodesc *idesc, const char *msg)
|
2000-10-09 09:21:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (idesc->id_fix) {
|
|
|
|
|
|
|
|
case DONTKNOW:
|
|
|
|
if (idesc->id_type == DATA)
|
|
|
|
direrror(idesc->id_number, msg);
|
|
|
|
else
|
2001-08-19 08:19:37 +00:00
|
|
|
pwarn("%s", msg);
|
2000-10-09 09:21:04 +00:00
|
|
|
if (preen) {
|
|
|
|
printf(" (SALVAGED)\n");
|
|
|
|
idesc->id_fix = FIX;
|
|
|
|
return (ALTERED);
|
|
|
|
}
|
|
|
|
if (reply("SALVAGE") == 0) {
|
|
|
|
idesc->id_fix = NOFIX;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
idesc->id_fix = FIX;
|
|
|
|
return (ALTERED);
|
|
|
|
|
|
|
|
case FIX:
|
|
|
|
return (ALTERED);
|
|
|
|
|
|
|
|
case NOFIX:
|
|
|
|
case IGNORE:
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
default:
|
|
|
|
errx(EEXIT, "UNKNOWN INODESC FIX MODE %d", idesc->id_fix);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
/*
|
|
|
|
* Print details about a buffer.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
prtbuf(const char *msg, struct bufarea *bp)
|
|
|
|
{
|
|
|
|
|
2021-01-08 19:28:30 +00:00
|
|
|
printf("%s: bp %p, type %s, bno %jd, size %d, refcnt %d, flags %s, "
|
|
|
|
"index %jd\n", msg, bp, BT_BUFTYPE(bp->b_type), (intmax_t) bp->b_bno,
|
2021-01-07 01:37:08 +00:00
|
|
|
bp->b_size, bp->b_refcnt, bp->b_flags & B_DIRTY ? "dirty" : "clean",
|
2021-01-08 19:28:30 +00:00
|
|
|
(intmax_t) bp->b_index);
|
2021-01-07 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2000-10-09 09:21:04 +00:00
|
|
|
/*
|
2012-01-07 16:09:33 +00:00
|
|
|
* An unexpected inconsistency occurred.
|
2002-08-21 18:11:48 +00:00
|
|
|
* Die if preening or file system is running with soft dependency protocol,
|
2000-10-09 09:21:04 +00:00
|
|
|
* otherwise just print message and continue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pfatal(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (!preen) {
|
2001-04-24 22:38:08 +00:00
|
|
|
(void)vfprintf(stdout, fmt, ap);
|
2000-10-09 09:21:04 +00:00
|
|
|
va_end(ap);
|
|
|
|
if (usedsoftdep)
|
2001-04-24 22:38:08 +00:00
|
|
|
(void)fprintf(stdout,
|
2000-10-09 09:21:04 +00:00
|
|
|
"\nUNEXPECTED SOFT UPDATE INCONSISTENCY\n");
|
2001-04-16 22:22:21 +00:00
|
|
|
/*
|
|
|
|
* Force foreground fsck to clean up inconsistency.
|
|
|
|
*/
|
|
|
|
if (bkgrdflag) {
|
|
|
|
cmd.value = FS_NEEDSFSCK;
|
|
|
|
cmd.size = 1;
|
|
|
|
if (sysctlbyname("vfs.ffs.setflags", 0, 0,
|
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
pwarn("CANNOT SET FS_NEEDSFSCK FLAG\n");
|
2001-04-24 22:38:08 +00:00
|
|
|
fprintf(stdout, "CANNOT RUN IN BACKGROUND\n");
|
2001-04-16 22:22:21 +00:00
|
|
|
ckfini(0);
|
|
|
|
exit(EEXIT);
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cdevname == NULL)
|
2002-07-30 13:01:25 +00:00
|
|
|
cdevname = strdup("fsck");
|
2001-04-24 22:38:08 +00:00
|
|
|
(void)fprintf(stdout, "%s: ", cdevname);
|
|
|
|
(void)vfprintf(stdout, fmt, ap);
|
|
|
|
(void)fprintf(stdout,
|
2000-10-09 09:21:04 +00:00
|
|
|
"\n%s: UNEXPECTED%sINCONSISTENCY; RUN fsck MANUALLY.\n",
|
|
|
|
cdevname, usedsoftdep ? " SOFT UPDATE " : " ");
|
2001-04-16 22:22:21 +00:00
|
|
|
/*
|
|
|
|
* Force foreground fsck to clean up inconsistency.
|
|
|
|
*/
|
|
|
|
if (bkgrdflag) {
|
|
|
|
cmd.value = FS_NEEDSFSCK;
|
|
|
|
cmd.size = 1;
|
|
|
|
if (sysctlbyname("vfs.ffs.setflags", 0, 0,
|
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
pwarn("CANNOT SET FS_NEEDSFSCK FLAG\n");
|
|
|
|
}
|
2000-10-09 09:21:04 +00:00
|
|
|
ckfini(0);
|
|
|
|
exit(EEXIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pwarn just prints a message when not preening or running soft dependency
|
|
|
|
* protocol, or a warning (preceded by filename) when preening.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pwarn(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if (preen)
|
2001-04-24 22:38:08 +00:00
|
|
|
(void)fprintf(stdout, "%s: ", cdevname);
|
|
|
|
(void)vfprintf(stdout, fmt, ap);
|
2000-10-09 09:21:04 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stub for routines from kernel.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
panic(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
pfatal("INTERNAL INCONSISTENCY:");
|
2001-04-24 22:38:08 +00:00
|
|
|
(void)vfprintf(stdout, fmt, ap);
|
2000-10-09 09:21:04 +00:00
|
|
|
va_end(ap);
|
|
|
|
exit(EEXIT);
|
|
|
|
}
|