Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add -x option which allows to run `fsck_msdos -n' on a snaps...
details: https://anonhg.NetBSD.org/src/rev/90b23632dff5
branches: trunk
changeset: 753821:90b23632dff5
user: hannken <hannken%NetBSD.org@localhost>
date: Sun Apr 11 08:23:51 2010 +0000
description:
Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.
While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().
Reviewed by: Manuel Bouyer <bouyer%netbsd.org@localhost>
diffstat:
doc/CHANGES | 4 +-
sbin/dump/snapshot.c | 48 ++++++++++++++++++++++++-----
sbin/fsck_ffs/main.c | 69 ++-----------------------------------------
sbin/fsck_msdos/Makefile | 9 +++--
sbin/fsck_msdos/fsck_msdos.8 | 17 +++++++++-
sbin/fsck_msdos/main.c | 35 ++++++++++++++++++---
6 files changed, 95 insertions(+), 87 deletions(-)
diffs (truncated from 380 to 300 lines):
diff -r d7a6181f7b5b -r 90b23632dff5 doc/CHANGES
--- a/doc/CHANGES Sun Apr 11 06:50:30 2010 +0000
+++ b/doc/CHANGES Sun Apr 11 08:23:51 2010 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1379 $>
+# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1380 $>
#
#
# [Note: This file does not mention every change made to the NetBSD source tree.
@@ -581,3 +581,5 @@
agp(4): Add support for the Intel 82855GM AGP port. [jakllsch 20100404]
acpi(4): Updated ACPICA to 20100121. [jruoho 20100408]
fss(4): Add snapshot support for MSDOS file systems. [hannken 20100409]
+ fsck_msdos(8): add -x option which allows to run fsck_msdos -n on
+ a snapshot of a live file system. [hannken 20100411]
diff -r d7a6181f7b5b -r 90b23632dff5 sbin/dump/snapshot.c
--- a/sbin/dump/snapshot.c Sun Apr 11 06:50:30 2010 +0000
+++ b/sbin/dump/snapshot.c Sun Apr 11 08:23:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: snapshot.c,v 1.4 2008/04/28 20:23:08 martin Exp $ */
+/* $NetBSD: snapshot.c,v 1.5 2010/04/11 08:23:51 hannken Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -54,25 +54,51 @@
* snapshot device path.
*/
int
-snap_open(char *mountpoint, char *backup, time_t *snap_date, char **snap_dev)
+snap_open(char *file, char *backup, time_t *snap_date, char **snap_dev)
{
- int i, fd, israw, fsinternal, dounlink, flags;
- char path[MAXPATHLEN], fss_dev[14];
+ int i, n, fd, israw, fsinternal, dounlink, flags;
+ char path[MAXPATHLEN], fss_dev[14], *cp;
dev_t mountdev;
struct fss_set fss;
struct fss_get fsg;
struct stat sb;
- struct statvfs fsb;
+ struct statvfs *mntbuf, *fs, fsb;
dounlink = 0;
fd = -1;
+ mntbuf = NULL;
- fss.fss_mount = mountpoint;
+ /*
+ * Lookup the mount point. `file' is either a directory or a raw
+ * character device.
+ */
+ if (lstat(file, &sb) < 0)
+ goto fail;
+ fss.fss_mount = NULL;
+ if (S_ISCHR(sb.st_mode)) {
+ if ((cp = strrchr(file, '/')) == NULL || cp[1] != 'r') {
+ errno = EINVAL;
+ goto fail;
+ }
+ snprintf(path, sizeof(path), "%.*s/%s",
+ (int)(cp - file), file, cp + 2);
+ n = getmntinfo(&mntbuf, MNT_NOWAIT);
+ for (fs = mntbuf, i = 0; i < n; i++, fs++) {
+ if (strcmp(fs->f_mntfromname, path) == 0) {
+ fss.fss_mount = fs->f_mntonname;
+ if (stat(fss.fss_mount, &sb) < 0)
+ goto fail;
+ break;
+ }
+ }
+ } else if (S_ISDIR(sb.st_mode))
+ fss.fss_mount = file;
+ if (fss.fss_mount == NULL) {
+ errno = EINVAL;
+ goto fail;
+ }
fss.fss_bstore = backup ? backup : fss.fss_mount;
fss.fss_csize = 0;
-
- if (stat(fss.fss_mount, &sb) < 0)
- goto fail;
mountdev = sb.st_dev;
/*
@@ -153,12 +179,16 @@
goto fail;
}
+ if (mntbuf)
+ free(mntbuf);
if (snap_date != NULL)
*snap_date = fsg.fsg_time.tv_sec;
return fd;
}
fail:
+ if (mntbuf)
+ free(mntbuf);
if (dounlink)
unlink(fss.fss_bstore);
if (fd >= 0)
diff -r d7a6181f7b5b -r 90b23632dff5 sbin/fsck_ffs/main.c
--- a/sbin/fsck_ffs/main.c Sun Apr 11 06:50:30 2010 +0000
+++ b/sbin/fsck_ffs/main.c Sun Apr 11 08:23:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.75 2010/01/07 01:39:56 christos Exp $ */
+/* $NetBSD: main.c,v 1.76 2010/04/11 08:23:51 hannken Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
#else
-__RCSID("$NetBSD: main.c,v 1.75 2010/01/07 01:39:56 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.76 2010/04/11 08:23:51 hannken Exp $");
#endif
#endif /* not lint */
@@ -76,7 +76,6 @@
static int argtoi(int, const char *, const char *, int);
static int checkfilesys(const char *, const char *, int);
static void usage(void);
-static char *get_snap_device(char *);
int
main(int argc, char *argv[])
@@ -223,23 +222,17 @@
pfatal("Can't check %s\n", *argv);
if (snap_backup || snap_internal) {
- char *mpt;
char *snap_dev;
int snapfd;
- mpt = get_snap_device(*argv);
- if (mpt == NULL)
- goto next;
- snapfd = snap_open(mpt, snap_backup, NULL, &snap_dev);
+ snapfd = snap_open(*argv, snap_backup, NULL, &snap_dev);
if (snapfd < 0) {
- warn("can't take snapshot of %s", mpt);
- free(mpt);
+ warn("can't take snapshot of %s", *argv);
goto next;
}
nret = checkfilesys(blockcheck(snap_dev), path, 0);
if (ret < nret)
ret = nret;
- free(mpt);
close(snapfd);
} else {
nret = checkfilesys(path, path, 0);
@@ -512,57 +505,3 @@
getprogname());
exit(FSCK_EXIT_USAGE);
}
-
-static
-char *get_snap_device(char *file)
-{
- char *mountpoint = NULL;
- struct statvfs *mntbuf, *fs, fsbuf;
- struct stat sb;
-
- /* find the mount point */
- if (lstat(file, &sb) == -1) {
- warn("can't stat %s", file);
- return NULL;
- }
- if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
- int mntbufc, i;
- if ((mntbufc = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
- pfatal("can't get mount list: %s\n", strerror(errno));
- for (fs = mntbuf, i = 0;
- i < mntbufc; i++, fs++) {
- if (strcmp(fs->f_fstypename, "ufs") != 0 &&
- strcmp(fs->f_fstypename, "ffs") != 0)
- continue;
- if (fs->f_flag & ST_RDONLY) {
- warnx("Cannot use -x or -X "
- "on read-only filesystem");
- free(mntbuf);
- return NULL;
- }
- if (strcmp(fs->f_mntfromname, unrawname(file)) == 0) {
- mountpoint = strdup(fs->f_mntonname);
- free(mntbuf);
- return mountpoint;
- }
- }
- warnx("Cannot use -x or -X on unmounted device");
- free(mntbuf);
- return NULL;
- }
- if (S_ISDIR(sb.st_mode)) {
- if (statvfs(file, &fsbuf) == -1)
- pfatal("can't statvfs %s: %s\n", file, strerror(errno));
- if (strcmp(fsbuf.f_mntonname, file))
- pfatal("%s is not a mount point\n", file);
- if (fsbuf.f_flag & ST_RDONLY) {
- warnx("Cannot use -x or -X "
- "on read-only filesystem");
- return NULL;
- }
- mountpoint = strdup(file);
- return mountpoint;
- }
- pfatal("%s is not a mount point\n", file);
- return NULL;
-}
diff -r d7a6181f7b5b -r 90b23632dff5 sbin/fsck_msdos/Makefile
--- a/sbin/fsck_msdos/Makefile Sun Apr 11 06:50:30 2010 +0000
+++ b/sbin/fsck_msdos/Makefile Sun Apr 11 08:23:51 2010 +0000
@@ -1,14 +1,15 @@
-# $NetBSD: Makefile,v 1.11 2006/08/26 18:14:28 christos Exp $
+# $NetBSD: Makefile,v 1.12 2010/04/11 08:23:52 hannken Exp $
.include <bsd.own.mk>
PROG= fsck_msdos
MAN= fsck_msdos.8
-SRCS= main.c check.c boot.c fat.c dir.c fsutil.c
+SRCS= main.c check.c boot.c fat.c dir.c fsutil.c snapshot.c
FSCK= ${NETBSDSRCDIR}/sbin/fsck
-CPPFLAGS+= -I${FSCK}
-.PATH: ${FSCK}
+DUMP= ${NETBSDSRCDIR}/sbin/dump
+CPPFLAGS+= -I${FSCK} -I${DUMP}
+.PATH: ${FSCK} ${DUMP}
LDADD+=-lutil
DPADD+=${LIBUTIL}
diff -r d7a6181f7b5b -r 90b23632dff5 sbin/fsck_msdos/fsck_msdos.8
--- a/sbin/fsck_msdos/fsck_msdos.8 Sun Apr 11 06:50:30 2010 +0000
+++ b/sbin/fsck_msdos/fsck_msdos.8 Sun Apr 11 08:23:51 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: fsck_msdos.8,v 1.15 2008/06/13 20:46:09 martin Exp $
+.\" $NetBSD: fsck_msdos.8,v 1.16 2010/04/11 08:23:52 hannken Exp $
.\"
.\" Copyright (C) 1995 Wolfgang Solfrank
.\" Copyright (c) 1995 Martin Husemann
@@ -24,7 +24,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\"
-.Dd August 13, 1995
+.Dd April 11, 2010
.Dt FSCK_MSDOS 8
.Os
.Sh NAME
@@ -37,6 +37,7 @@
.Ar filesystem ...
.Nm
.Op Fl fny
+.Op Fl x Ar snap-backup
.Ar filesystem ...
.Sh DESCRIPTION
The
@@ -86,6 +87,17 @@
.Dq CONTINUE? .
.It Fl p
Preen the specified filesystems.
+.It Fl x Ar snap-backup
+Use a snapshot with
+.Ar snap-backup
+as backup to check a read-write mounted filesystem. Must be used with
+.Fl n .
+See
+.Xr fss 4
+for more details.
+The point is to check an internally-consistent version of the
+filesystem to find out if it is damaged; on failure one should unmount
+the filesystem and repair it.
.It Fl y
Causes
.Nm
@@ -94,6 +106,7 @@
.Sh SEE ALSO
.Xr fsck 8 ,
.Xr fsck_ffs 8 ,
+.Xr fss 4 ,
.Xr mount_msdos 8
.Sh BUGS
.Nm
diff -r d7a6181f7b5b -r 90b23632dff5 sbin/fsck_msdos/main.c
--- a/sbin/fsck_msdos/main.c Sun Apr 11 06:50:30 2010 +0000
+++ b/sbin/fsck_msdos/main.c Sun Apr 11 08:23:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.21 2008/06/13 20:46:09 martin Exp $ */
+/* $NetBSD: main.c,v 1.22 2010/04/11 08:23:52 hannken Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank
@@ -28,18 +28,20 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.21 2008/06/13 20:46:09 martin Exp $");
Home |
Main Index |
Thread Index |
Old Index