Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2



details:   https://anonhg.NetBSD.org/src/rev/d3bef54308db
branches:  trunk
changeset: 582068:d3bef54308db
user:      xtraeme <xtraeme%NetBSD.org@localhost>
date:      Wed Jun 15 18:06:19 2005 +0000

description:
Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2
for NetBSD (with different blocksizes). Utility to find
FFSv1 and FFSv2 partitions on disks, useful to recover lost
disklabels.

Reviewed by christos.

diffstat:

 distrib/sets/lists/base/mi |    3 +-
 distrib/sets/lists/man/mi  |    4 +-
 sbin/Makefile              |    6 +-
 sbin/scan_ffs/Makefile     |   12 +
 sbin/scan_ffs/scan_ffs.8   |   91 ++++++++++++++
 sbin/scan_ffs/scan_ffs.c   |  288 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 399 insertions(+), 5 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r cdc499f1904f -r d3bef54308db distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Wed Jun 15 18:01:12 2005 +0000
+++ b/distrib/sets/lists/base/mi        Wed Jun 15 18:06:19 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.555 2005/06/07 14:27:42 is Exp $
+# $NetBSD: mi,v 1.556 2005/06/15 18:06:19 xtraeme Exp $
 .                                              base-sys-root
 ./altroot                                      base-sys-root
 ./bin                                          base-sys-root
@@ -191,6 +191,7 @@
 ./sbin/rrestore                                        base-netutil-root
 ./sbin/rtsol                                   base-netutil-root       use_inet6
 ./sbin/savecore                                        base-sysutil-root
+./sbin/scan_ffs                                        base-sysutil-root
 ./sbin/scsictl                                 base-sysutil-root
 ./sbin/setkey                                  base-netutil-root
 ./sbin/shutdown                                        base-sysutil-root
diff -r cdc499f1904f -r d3bef54308db distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Wed Jun 15 18:01:12 2005 +0000
+++ b/distrib/sets/lists/man/mi Wed Jun 15 18:06:19 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.791 2005/05/31 11:39:03 christos Exp $
+# $NetBSD: mi,v 1.792 2005/06/15 18:06:19 xtraeme Exp $
 ./etc/mtree/set.man                            man-sys-root
 ./usr/share/info/am-utils.info                 man-amd-info            info
 ./usr/share/info/as.info                       man-computil-info       bfd,info
@@ -2102,6 +2102,7 @@
 ./usr/share/man/cat8/savecore.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/sbmips/MAKEDEV.0          man-obsolete            obsolete
 ./usr/share/man/cat8/sbmips/makedev.0          man-obsolete            obsolete
+./usr/share/man/cat8/scan_ffs.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/scsictl.0                 man-sysutil-catman      .cat
 ./usr/share/man/cat8/sendmail.0                        man-sendmail-catman     sendmail,.cat
 ./usr/share/man/cat8/sesd.0                    man-sysutil-catman      .cat
@@ -4334,6 +4335,7 @@
 ./usr/share/man/man8/savecore.8                        man-sysutil-man         .man
 ./usr/share/man/man8/sbmips/MAKEDEV.8          man-obsolete            obsolete
 ./usr/share/man/man8/sbmips/makedev.8          man-obsolete            obsolete
+./usr/share/man/man8/scan_ffs.8                        man-sysutil-man         .man
 ./usr/share/man/man8/scsictl.8                 man-sysutil-man         .man
 ./usr/share/man/man8/sendmail.8                        man-sendmail-man        sendmail,.man
 ./usr/share/man/man8/sesd.8                    man-sysutil-man         .man
diff -r cdc499f1904f -r d3bef54308db sbin/Makefile
--- a/sbin/Makefile     Wed Jun 15 18:01:12 2005 +0000
+++ b/sbin/Makefile     Wed Jun 15 18:06:19 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.93 2005/05/01 07:26:29 lukem Exp $
+#      $NetBSD: Makefile,v 1.94 2005/06/15 18:06:19 xtraeme Exp $
 #      @(#)Makefile    8.5 (Berkeley) 3/31/94
 
 # Not ported: XNSrouted enpload scsiformat startslip
@@ -10,8 +10,8 @@
        drvctl edlabel fastboot fdisk fsck fsirand ifconfig init ldconfig \
        lmcctl mbrlabel mknod modload modunload mount newbtconf nologin \
        pdisk ping pppoectl raidctl reboot rcorder rndctl route routed \
-       savecore scsictl shutdown slattach swapctl sysctl ttyflags umount \
-       veriexecctl vinum wdogctl wsconsctl
+       savecore scan_ffs scsictl shutdown slattach swapctl sysctl ttyflags \
+       umount veriexecctl vinum wdogctl wsconsctl
 
 # support for various file systems
 SUBDIR+= fsck_ext2fs
diff -r cdc499f1904f -r d3bef54308db sbin/scan_ffs/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/scan_ffs/Makefile    Wed Jun 15 18:06:19 2005 +0000
@@ -0,0 +1,12 @@
+# $NetBSD: Makefile,v 1.1 2005/06/15 18:06:19 xtraeme Exp $
+
+PROG=  scan_ffs
+SRCS=  scan_ffs.c
+
+MAN=   scan_ffs.8
+
+WARNS= 3
+LDADD= -lutil
+DPADD= ${LIBUTIL}
+
+.include <bsd.prog.mk>
diff -r cdc499f1904f -r d3bef54308db sbin/scan_ffs/scan_ffs.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/scan_ffs/scan_ffs.8  Wed Jun 15 18:06:19 2005 +0000
@@ -0,0 +1,91 @@
+.\"    $NetBSD: scan_ffs.8,v 1.1 2005/06/15 18:06:19 xtraeme Exp $
+.\"     OpenBSD: scan_ffs.8,v 1.13 2004/12/14 00:04:21 jmc Exp
+.\"
+.\" Copyright (c) 2005 Juan Romero Pardines
+.\" Copyright (c) 1997 Niklas Hallqvist, Tobias Weingartner
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+.\"
+.\" .TH scanffs 8
+.Dd Juny 7, 2005
+.Dt SCANFFS 8
+.Os
+.Sh NAME
+.Nm scanffs
+.Nd finding FFSv1/FFSv2 partitions on a disk
+.Sh SYNOPSIS
+.Nm scanffs
+.Op Fl lv
+.Op Fl s Ar start
+.Op Fl e Ar end
+.Ar device
+.Sh DESCRIPTION
+This program will take a raw disk device that covers the whole disk,
+and will find all possible FFSv1/FFSv2 partitions with different block
+sizes on the disk.
+It will show the filesystem type (FFSv1 or FFSv2), size and offset.
+Also it has an option to show the values with a disklabel-alike
+output.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl l
+This will make
+.Nm
+print out a string looking much like the input to disklabel.
+With a little massaging, this output can usually be used in the disklabel edit.
+.Pp
+.It Fl v
+Tell
+.Nm
+to be verbose about what it is doing, and what it has found.
+.Pp
+.It Fl s Ar start
+Tell
+.Nm
+where to start searching for filesystems.
+This makes it easier to skip swap
+partitions, or other large non-UFS/FFS partitions.
+.Pp
+.It Fl e Ar end
+Ditto for telling
+.Nm
+where to stop.
+It will default to max sectors on the disk if it wasn't specified.
+.Pp
+.It Ar device
+This specifies which device
+.Nm
+should use to scan for filesystems.
+.El
+.Sh SEE ALSO
+.Xr disklabel 8
+.Sh HISTORY
+The scan_ffs program first appeared in OpenBSD 2.3.
+.Sh AUTHORS
+Niklas Hallqvist and Tobias Weingartner for the OpenBSD Project.
+.Pp
+Juan Romero Pardines for the NetBSD Project.
+.Sh BUGS
+Currently it won't find FFSv1 partitions with fragsize/blocksize
+greater than 2048/16384, and FFSv2 partitions with fragsize/blocksize
+greater than 8192/65536.
diff -r cdc499f1904f -r d3bef54308db sbin/scan_ffs/scan_ffs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/scan_ffs/scan_ffs.c  Wed Jun 15 18:06:19 2005 +0000
@@ -0,0 +1,288 @@
+/*     $NetBSD: scan_ffs.c,v 1.1 2005/06/15 18:06:19 xtraeme Exp $     */
+/*     $OpenBSD: scan_ffs.c,v 1.11 2004/02/16 19:13:03 deraadt Exp$    */
+
+/*
+ * Copyright (c) 2005 Juan Romero Pardines
+ * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * Currently it can detect:
+ *     o FFSv1 with fragsize/blocksize: 512/4096, 1024/8192, 2048/16384.
+ *     o FFSv2 with fragsize/blocksize: 512/4096, 1024/8192, 2048/16384,
+ *                                      4096/32768, 8192/65536.
+ * TODO:
+ *     o Detect FFSv1 partitions with fsize/bsize > 2048/16384.
+ *     o Detect FFSv2 partitions with fsize/bsize > 8192/65536.
+ */
+ 
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: scan_ffs.c,v 1.1 2005/06/15 18:06:19 xtraeme Exp $");
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#include <sys/ioctl.h>
+#include <sys/fcntl.h>
+#include <ufs/ffs/fs.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <err.h>
+#include <util.h>
+
+enum { NADA, VERBOSE, LABELS };
+
+#define SBCOUNT        64 /* XXX should be configurable */
+
+static void    printpart(int, int, int);
+static void    ufsmagic(int);
+static void    usage(void) __attribute__((__noreturn__));
+static int     checkfstype(void);
+static int     ufsscan(int, daddr_t, daddr_t, int);
+
+static char    lastmount[MAXMNTLEN];
+static char    device[MAXPATHLEN];
+static const   char *fstype = NULL;
+
+static int     eflag = 0;
+static int     flags = 0;
+
+static daddr_t blk, lastblk;
+
+static struct fs *sb;
+
+static int
+checkfstype(void)
+{
+       switch (sb->fs_magic) {
+               case FS_UFS1_MAGIC:
+               case FS_UFS1_MAGIC_SWAPPED:
+                       sb->fs_size = sb->fs_old_size;
+                       fstype = "FFSv1";
+                       return 1;
+               case FS_UFS2_MAGIC:
+               case FS_UFS2_MAGIC_SWAPPED:
+                       fstype = "FFSv2";
+                       return 2;
+               default:
+                       return -1;
+       }
+}
+
+static void
+printpart(int flag, int ffsize, int n)
+{
+       
+       int fsrv = checkfstype();
+
+       if (flag == VERBOSE) {
+               (void)printf("block: %" PRIu64" "
+                       "id %x,%x size %" PRIu64"\n",
+                       blk + (n / 512), sb->fs_id[0],
+                       sb->fs_id[1], sb->fs_size);
+       } else if (flag == LABELS) {
+               (void)printf("X:  %9" PRIu64 "",
+                       (uint64_t)((off_t)sb->fs_size * sb->fs_fsize / 512));
+               if (fsrv == 1)  /* FFSv1 */
+                       (void)printf(" %9" PRIu64 "",
+                               blk + (n / 512)-(2 * SBLOCKSIZE / 512));
+               else if (fsrv == 2)     /* FFSv2 */
+                       (void)printf(" %9" PRIu64 "",
+                               blk + (n / 512)-(ffsize * SBLOCKSIZE / 512 + 128));
+               (void)printf(" 4.2BSD %6d %5d%4d # %s [%s]\n",
+                       sb->fs_fsize, sb->fs_bsize,
+                       sb->fs_old_cpg, lastmount, fstype);
+       } else {
+               printf("%s ", fstype);



Home | Main Index | Thread Index | Old Index