Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mtree Add "device" keyword, which allows the device...



details:   https://anonhg.NetBSD.org/src/rev/c6ff56f0f6b5
branches:  trunk
changeset: 515932:c6ff56f0f6b5
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue Oct 09 04:50:00 2001 +0000

description:
Add "device" keyword, which allows the device number to be specified,
to be later checked and possibly created. Uses parsing and encoding
routines from mknod(8).

diffstat:

 usr.sbin/mtree/Makefile  |  10 +++--
 usr.sbin/mtree/compare.c |  21 +++++++++++-
 usr.sbin/mtree/create.c  |   7 +++-
 usr.sbin/mtree/misc.c    |   5 +-
 usr.sbin/mtree/mtree.8   |  79 +++++++++++++++++++++++++++++++++++++++++++++--
 usr.sbin/mtree/mtree.h   |   4 +-
 usr.sbin/mtree/spec.c    |  67 ++++++++++++++++++++++++++++++++++------
 usr.sbin/mtree/verify.c  |   5 +-
 8 files changed, 170 insertions(+), 28 deletions(-)

diffs (truncated from 419 to 300 lines):

diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/Makefile
--- a/usr.sbin/mtree/Makefile   Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/Makefile   Tue Oct 09 04:50:00 2001 +0000
@@ -1,16 +1,18 @@
-#      $NetBSD: Makefile,v 1.16 2001/09/10 03:22:24 lukem Exp $
+#      $NetBSD: Makefile,v 1.17 2001/10/09 04:50:00 lukem Exp $
 #      from: @(#)Makefile      8.2 (Berkeley) 4/27/95
 
 PROG=  mtree
 #CPPFLAGS+=-DDEBUG
 MAN=   mtree.8
 SRCS=  compare.c crc.c create.c misc.c mtree.c spec.c verify.c \
-       stat_flags.c
+       stat_flags.c pack_dev.c
 
 LDADD+=        -lutil
 DPADD+=        ${LIBUTIL}
 
-CPPFLAGS+=     -I${.CURDIR}/../../bin/ls
-.PATH: ${.CURDIR}/../../usr.bin/cksum ${.CURDIR}/../../bin/ls
+CPPFLAGS+=     -I${.CURDIR}/../../bin/ls -I${.CURDIR}/../../sbin/mknod
+.PATH: ${.CURDIR}/../../usr.bin/cksum \
+       ${.CURDIR}/../../bin/ls \
+       ${.CURDIR}/../../sbin/mknod
 
 .include <bsd.prog.mk>
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/compare.c
--- a/usr.sbin/mtree/compare.c  Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/compare.c  Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compare.c,v 1.28 2001/10/04 04:51:27 lukem Exp $       */
+/*     $NetBSD: compare.c,v 1.29 2001/10/09 04:50:00 lukem Exp $       */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)compare.c  8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: compare.c,v 1.28 2001/10/04 04:51:27 lukem Exp $");
+__RCSID("$NetBSD: compare.c,v 1.29 2001/10/09 04:50:00 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -231,6 +231,23 @@
                tab = "\t";
        skip:
        }
+       if (s->flags & F_DEV &&
+           (s->type == F_BLOCK || s->type == F_CHAR) &&
+           s->st_rdev != p->fts_statp->st_rdev) {
+               LABEL;
+               (void)printf("%sdevice (%#x, %#x",
+                   tab, s->st_rdev, p->fts_statp->st_rdev);
+               if (uflag) {
+       /* XXXLUKEM: unlink first ? */
+                       if (mknod(p->fts_accpath, s->st_mode, s->st_rdev))
+                               (void)printf(", not modified: %s)\n",
+                                   strerror(errno));
+                       else
+                               (void)printf(", modified)\n");
+               } else
+                       (void)printf(")\n");
+               tab = "\t";
+       }
        if (s->flags & F_NLINK && s->type != F_DIR &&
            s->st_nlink != p->fts_statp->st_nlink) {
                LABEL;
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/create.c
--- a/usr.sbin/mtree/create.c   Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/create.c   Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: create.c,v 1.31 2001/10/04 04:51:27 lukem Exp $        */
+/*     $NetBSD: create.c,v 1.32 2001/10/09 04:50:01 lukem Exp $        */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)create.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: create.c,v 1.31 2001/10/04 04:51:27 lukem Exp $");
+__RCSID("$NetBSD: create.c,v 1.32 2001/10/09 04:50:01 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -164,6 +164,9 @@
        }
        if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
                output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS);
+       if (keys & F_DEV &&
+           (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode)))
+               output(&indent, "device=%#x", p->fts_statp->st_rdev);
        if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
                output(&indent, "nlink=%u", p->fts_statp->st_nlink);
        if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode))
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/misc.c
--- a/usr.sbin/mtree/misc.c     Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/misc.c     Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: misc.c,v 1.15 2001/10/05 13:14:56 lukem Exp $  */
+/*     $NetBSD: misc.c,v 1.16 2001/10/09 04:50:01 lukem Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: misc.c,v 1.15 2001/10/05 13:14:56 lukem Exp $");
+__RCSID("$NetBSD: misc.c,v 1.16 2001/10/09 04:50:01 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -61,6 +61,7 @@
 /* NB: the following tables must be sorted lexically. */
 static KEY keylist[] = {
        {"cksum",       F_CKSUM,        NEEDVALUE},
+       {"device",      F_DEV,          NEEDVALUE},
        {"flags",       F_FLAGS,        NEEDVALUE},
        {"gid",         F_GID,          NEEDVALUE},
        {"gname",       F_GNAME,        NEEDVALUE},
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/mtree.8
--- a/usr.sbin/mtree/mtree.8    Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/mtree.8    Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mtree.8,v 1.22 2001/10/08 00:53:30 lukem Exp $
+.\"    $NetBSD: mtree.8,v 1.23 2001/10/09 04:50:01 lukem Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\"     @(#)mtree.8    8.2 (Berkeley) 12/11/93
 .\"
-.Dd October 6, 2001
+.Dd October 9, 2001
 .Dt MTREE 8
 .Os
 .Sh NAME
@@ -213,6 +213,75 @@
 the
 .Xr cksum 1
 utility.
+.It Sy device
+The device number to use for
+.Sy block
+or
+.Sy char
+file types.
+The argument must be one of the following forms:
+.Pp
+.Bl -tag -width 4n
+.It Xo
+.Sm off
+.Ar format ,
+.Ar major ,
+.Ar minor
+.Sm on
+.Xc
+A device with
+.Ar major
+and
+.Ar minor
+fields, for an operating system specified with
+.Ar format .
+See below for valid formats.
+.It Xo
+.Sm off
+.Ar format ,
+.Ar major ,
+.Ar unit ,
+.Ar subunit
+.Sm on
+.Xc
+A device with
+.Ar major ,
+.Ar unit ,
+and
+.Ar subunit
+fields, for an operating system specified with
+.Ar format .
+(Currently this is only supported by the
+.Sy bsdos
+format.)
+.It Ar number
+Opaque number (as stored on the file system).
+.El
+.Pp
+The following values for
+.Ar format
+are recognized:
+.Sy native ,
+.Sy 386bsd ,
+.Sy 4bsd ,
+.Sy bsdos ,
+.Sy freebsd ,
+.Sy hpux ,
+.Sy isc ,
+.Sy linux ,
+.Sy netbsd ,
+.Sy osf1 ,
+.Sy sco ,
+.Sy solaris ,
+.Sy sunos ,
+.Sy svr3 ,
+.Sy svr4 ,
+and
+.Sy ultrix .
+.Pp
+See
+.Xr mknod 8
+for more details.
 .It Sy flags
 The file flags as a symbolic name.  See
 .Xr chflags 1
@@ -415,7 +484,8 @@
 .Xr stat 2 ,
 .Xr fts 3 ,
 .Xr strsvis 3 ,
-.Xr chown 8
+.Xr chown 8 ,
+.Xr mknod 8
 .Sh HISTORY
 The
 .Nm
@@ -441,7 +511,8 @@
 appeared in
 .Nx 1.4 .
 The
-.Sy tags
+.Sy device ,
+.Sy tags ,
 and
 .Sy all
 keywords,
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/mtree.h
--- a/usr.sbin/mtree/mtree.h    Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/mtree.h    Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mtree.h,v 1.14 2001/10/05 01:03:25 lukem Exp $ */
+/*     $NetBSD: mtree.h,v 1.15 2001/10/09 04:50:01 lukem Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -58,6 +58,7 @@
        gid_t   st_gid;                         /* gid */
 #define        MBITS   (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
        mode_t  st_mode;                        /* mode */
+       dev_t   st_rdev;                        /* device type */
        u_long  st_flags;                       /* flags */
        nlink_t st_nlink;                       /* link count */
        char    *md5sum;                        /* md5 checksum */
@@ -82,6 +83,7 @@
 #define        F_FLAGS 0x00010000                      /* file flags */
 #define F_MD5  0x00020000                      /* md5 check sum */
 #define F_TAGS 0x00040000                      /* tags */
+#define F_DEV  0x00080000                      /* device type */
        int     flags;                          /* items set */
 
 #define        F_BLOCK 0x001                           /* block special */
diff -r a78a9604d6d9 -r c6ff56f0f6b5 usr.sbin/mtree/spec.c
--- a/usr.sbin/mtree/spec.c     Tue Oct 09 03:18:37 2001 +0000
+++ b/usr.sbin/mtree/spec.c     Tue Oct 09 04:50:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec.c,v 1.31 2001/10/05 15:32:57 lukem Exp $  */
+/*     $NetBSD: spec.c,v 1.32 2001/10/09 04:50:01 lukem Exp $  */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -74,7 +74,7 @@
 #if 0
 static char sccsid[] = "@(#)spec.c     8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: spec.c,v 1.31 2001/10/05 15:32:57 lukem Exp $");
+__RCSID("$NetBSD: spec.c,v 1.32 2001/10/09 04:50:01 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -94,9 +94,11 @@
 
 #include "mtree.h"
 #include "extern.h"
+#include "pack_dev.h"
 
 size_t lineno;                         /* Current spec line number. */
 
+static dev_t    parsedev(char *);
 static void     set(char *, NODE *);
 static void     unset(char *, NODE *);
 
@@ -273,6 +275,9 @@
                }
                if (MATCHFLAG(F_MODE))
                        printf("mode=%#o ", cur->st_mode);
+               if (MATCHFLAG(F_DEV) &&
+                   (cur->type == F_BLOCK || cur->type == F_CHAR))
+                       printf("device=%#x ", cur->st_rdev);
                if (MATCHFLAG(F_NLINK))
                        printf("nlink=%d ", cur->st_nlink);



Home | Main Index | Thread Index | Old Index