Source-Changes-HG archive

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

[src/trunk]: src Add scan_lfs(8), utility to find LFS partitions on disk, useful



details:   https://anonhg.NetBSD.org/src/rev/7713d9fd7881
branches:  trunk
changeset: 583351:7713d9fd7881
user:      xtraeme <xtraeme%NetBSD.org@localhost>
date:      Sun Jul 31 19:26:06 2005 +0000

description:
Add scan_lfs(8), utility to find LFS partitions on disk, useful
to recover lost disklabels.

diffstat:

 distrib/sets/lists/base/mi |    3 +-
 distrib/sets/lists/man/mi  |    4 +-
 doc/CHANGES                |    3 +-
 sbin/scan_ffs/Makefile     |    6 +-
 sbin/scan_ffs/scan_ffs.c   |  293 ++++++++++++++++++++++++++++++++++----------
 sbin/scan_ffs/scan_lfs.8   |  102 +++++++++++++++
 6 files changed, 339 insertions(+), 72 deletions(-)

diffs (truncated from 632 to 300 lines):

diff -r 26912af636a4 -r 7713d9fd7881 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sun Jul 31 18:55:08 2005 +0000
+++ b/distrib/sets/lists/base/mi        Sun Jul 31 19:26:06 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.564 2005/07/31 00:22:55 wiz Exp $
+# $NetBSD: mi,v 1.565 2005/07/31 19:26:06 xtraeme Exp $
 .                                              base-sys-root
 ./altroot                                      base-sys-root
 ./bin                                          base-sys-root
@@ -192,6 +192,7 @@
 ./sbin/rtsol                                   base-netutil-root       use_inet6
 ./sbin/savecore                                        base-sysutil-root
 ./sbin/scan_ffs                                        base-sysutil-root
+./sbin/scan_lfs                                        base-sysutil-root
 ./sbin/scsictl                                 base-sysutil-root
 ./sbin/setkey                                  base-netutil-root
 ./sbin/shutdown                                        base-sysutil-root
diff -r 26912af636a4 -r 7713d9fd7881 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun Jul 31 18:55:08 2005 +0000
+++ b/distrib/sets/lists/man/mi Sun Jul 31 19:26:06 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.813 2005/07/31 18:55:08 skrll Exp $
+# $NetBSD: mi,v 1.814 2005/07/31 19:26:06 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
@@ -2127,6 +2127,7 @@
 ./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/scan_lfs.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
@@ -4380,6 +4381,7 @@
 ./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/scan_lfs.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 26912af636a4 -r 7713d9fd7881 doc/CHANGES
--- a/doc/CHANGES       Sun Jul 31 18:55:08 2005 +0000
+++ b/doc/CHANGES       Sun Jul 31 19:26:06 2005 +0000
@@ -1,4 +1,4 @@
-LIST OF CHANGES FROM LAST RELEASE:                     <$Revision: 1.500 $>
+LIST OF CHANGES FROM LAST RELEASE:                     <$Revision: 1.501 $>
 
 
 [Note: This file does not mention every change made to the NetBSD source tree.
@@ -80,3 +80,4 @@
                Useful for creation of Live CDs/DVDs. [hubertf 20050725]
        hpcmips: Add teliosio(4) driver for the Sharp Telios LCD screen and
                Battery unit. [nakayama 20050731]
+       scan_lfs(8): Program to find LFS partitions on disks [xtraeme 20050731]
diff -r 26912af636a4 -r 7713d9fd7881 sbin/scan_ffs/Makefile
--- a/sbin/scan_ffs/Makefile    Sun Jul 31 18:55:08 2005 +0000
+++ b/sbin/scan_ffs/Makefile    Sun Jul 31 19:26:06 2005 +0000
@@ -1,7 +1,9 @@
-# $NetBSD: Makefile,v 1.4 2005/06/27 01:00:06 christos Exp $
+# $NetBSD: Makefile,v 1.5 2005/07/31 19:26:06 xtraeme Exp $
 
 PROG=  scan_ffs
-MAN=   scan_ffs.8
+MAN=   scan_ffs.8 scan_lfs.8
+
+LINKS= ${BINDIR}/scan_ffs ${BINDIR}/scan_lfs
 
 LDADD= -lutil
 DPADD= ${LIBUTIL}
diff -r 26912af636a4 -r 7713d9fd7881 sbin/scan_ffs/scan_ffs.c
--- a/sbin/scan_ffs/scan_ffs.c  Sun Jul 31 18:55:08 2005 +0000
+++ b/sbin/scan_ffs/scan_ffs.c  Sun Jul 31 19:26:06 2005 +0000
@@ -1,8 +1,42 @@
-/*     $NetBSD: scan_ffs.c,v 1.4 2005/06/23 17:25:31 xtraeme Exp $     */
-/*     $OpenBSD: scan_ffs.c,v 1.11 2004/02/16 19:13:03 deraadt Exp$    */
+/* $NetBSD: scan_ffs.c,v 1.5 2005/07/31 19:26:06 xtraeme Exp $ */
 
 /*
- * Copyright (c) 2005 Juan Romero Pardines
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Juan Romero Pardines.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Juan Romero Pardines
+ *      for 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.
+ *
+ * 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.
+ */
+
+/*
  * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner
  * All rights reserved.
  *
@@ -29,27 +63,36 @@
 
 /*
  * 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.
+ *     o FFSv1 fsize/bsize: 512/4096, 1024/8192, 2048/16384.
+ *     o FFSv2 fsize/bsize: 512/4096, 1024/8192, 2048/16384,
+ *                          4096/32768, 8192/65536.
+ *     o LFSv[12] fsize/bsize: 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.
+ *
+ *     -- xtraeme --
  */
  
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: scan_ffs.c,v 1.4 2005/06/23 17:25:31 xtraeme Exp $");
+__RCSID("$NetBSD: scan_ffs.c,v 1.5 2005/07/31 19:26:06 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 <sys/queue.h>
+#include <sys/mount.h>
+
+#include <ufs/ufs/dinode.h>
+#include <ufs/lfs/lfs.h>
 #include <ufs/ffs/fs.h>
+
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -57,39 +100,61 @@
 #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 int     eflag = 0;
-static int     flags = 0;
+/* common struct for FFS/LFS */
+struct sblockinfo {
+       struct lfs      *lfs;
+       struct fs       *ffs;
+       u_int64_t       lfs_off;
+       u_int64_t       ffs_off;
+       char            lfs_path[MAXMNTLEN];
+       char            ffs_path[MAXMNTLEN];
+} sbinfo;
 
 static daddr_t blk, lastblk;
 
-static struct fs *sb;
+static int     eflag = 0;
+static int     flags = 0;
+static int     sbaddr = 0; /* counter for the LFS superblocks */
 
-static const char *fstypes[] = { "NONE", "FFSv1", "FFSv2" };
+static char    device[MAXPATHLEN];
+static const char *fstypes[] = { "NONE", "FFSv1", "FFSv2", "LFS" };
 
 #define FSTYPE_NONE    0
 #define FSTYPE_FFSV1   1
 #define FSTYPE_FFSV2   2
 
+#define SBCOUNT                64 /* may be changed */
+#define SBPASS         (SBCOUNT * SBLOCKSIZE / 512)
+
+/* This is only useful for LFS */
+
+/* first sblock address contains the correct offset */
+#define FIRST_SBLOCK_ADDRESS    1 
+/* second and third sblock address contain lfs_fsmnt[MAXMNTLEN] */
+#define SECOND_SBLOCK_ADDRESS   2
+/* last sblock address in a LFS partition */
+#define MAX_SBLOCK_ADDRESS      10
+
+enum { NADA, VERBOSE, LABELS };
+
+/* FFS functions */
+static void    ffs_printpart(int, int, int);
+static void    ffs_scan(int);
+static int     ffs_checkver(void);
+/* LFS functions */
+static void    lfs_printpart(int, int, struct sblockinfo *);
+static void    lfs_scan(int);
+/* common functions */
+static void    usage(const char *);
+static int     scan_disk(int, daddr_t, daddr_t, int);
+
 static int
-checkfstype(void)
+ffs_checkver(void)
 {
-       switch (sb->fs_magic) {
+       switch (sbinfo.ffs->fs_magic) {
                case FS_UFS1_MAGIC:
                case FS_UFS1_MAGIC_SWAPPED:
-                       sb->fs_size = sb->fs_old_size;
+                       sbinfo.ffs->fs_size = sbinfo.ffs->fs_old_size;
                        return FSTYPE_FFSV1;
                case FS_UFS2_MAGIC:
                case FS_UFS2_MAGIC_SWAPPED:
@@ -100,19 +165,22 @@
 }
 
 static void
-printpart(int flag, int ffsize, int n)
+ffs_printpart(int flag, int ffsize, int n)
 {
        
-       int fstype = checkfstype();
+       int fstype = ffs_checkver();
 
        switch (flag) {
        case 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);
+               (void)printf("block: %" PRIu64 " id %x,%x size %" PRIu64 "\n",
+                       blk + (n / 512),
+                       sbinfo.ffs->fs_id[0],
+                       sbinfo.ffs->fs_id[1], sbinfo.ffs->fs_size);
                break;
        case LABELS:
                (void)printf("X:  %9" PRIu64,
-                   (uint64_t)((off_t)sb->fs_size * sb->fs_fsize / 512));
+                       (uint64_t)((off_t)sbinfo.ffs->fs_size *
+                       sbinfo.ffs->fs_fsize / 512));
                switch (fstype) {
                case FSTYPE_FFSV1:
                        (void)printf(" %9" PRIu64,
@@ -126,9 +194,10 @@
                default:
                        break;
                }
-               (void)printf(" 4.2BSD %6d %5d%4d # %s [%s]\n",
-                       sb->fs_fsize, sb->fs_bsize,
-                       sb->fs_old_cpg, lastmount, fstypes[fstype]);
+               (void)printf(" 4.2BSD %6d %5d %8d # %s [%s]\n",
+                       sbinfo.ffs->fs_fsize, sbinfo.ffs->fs_bsize,
+                       sbinfo.ffs->fs_old_cpg, 
+                       sbinfo.ffs_path, fstypes[fstype]);
                break;
        default:
                printf("%s ", fstypes[fstype]);
@@ -146,33 +215,33 @@
                        break;
                }
                (void)printf(" size %" PRIu64 ", last mounted on %s\n",
-                   (uint64_t)((off_t)sb->fs_size * sb->fs_fsize / 512),
-                   lastmount);
+                       (uint64_t)((off_t)sbinfo.ffs->fs_size *
+                       sbinfo.ffs->fs_fsize / 512), sbinfo.ffs_path);
                break;
        }
 }
 
 static void



Home | Main Index | Thread Index | Old Index