Source-Changes-HG archive

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

[src/trunk]: src If fs_spec starts with the special string "ROOT.", replace i...



details:   https://anonhg.NetBSD.org/src/rev/3740b2da9aec
branches:  trunk
changeset: 836248:3740b2da9aec
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Oct 06 13:09:53 2018 +0000

description:
If fs_spec starts with the special string "ROOT.", replace it with a device
path derived from the value of the kern.root_device sysctl.

diffstat:

 etc/rc.d/resize_root        |   3 ++-
 lib/libutil/getfsspecname.3 |  24 ++++++++++++++++++++++--
 lib/libutil/getfsspecname.c |  26 ++++++++++++++++++++++++--
 share/man/man5/fstab.5      |  14 ++++++++++++--
 4 files changed, 60 insertions(+), 7 deletions(-)

diffs (146 lines):

diff -r cb2e558fa842 -r 3740b2da9aec etc/rc.d/resize_root
--- a/etc/rc.d/resize_root      Sat Oct 06 13:03:55 2018 +0000
+++ b/etc/rc.d/resize_root      Sat Oct 06 13:09:53 2018 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: resize_root,v 1.3 2015/04/07 18:02:11 jmcneill Exp $
+# $NetBSD: resize_root,v 1.4 2018/10/06 13:09:53 jmcneill Exp $
 #
 
 # PROVIDE: resize_root
@@ -45,6 +45,7 @@
                # skip comment or blank line
                case "${fs_spec}" in
                \#*|'') continue ;;
+               ROOT\.*) fs_spec="/dev/$(sysctl -n kern.root_device)${fs_spec#ROOT.}" ;;
                esac
 
                # skip non-root
diff -r cb2e558fa842 -r 3740b2da9aec lib/libutil/getfsspecname.3
--- a/lib/libutil/getfsspecname.3       Sat Oct 06 13:03:55 2018 +0000
+++ b/lib/libutil/getfsspecname.3       Sat Oct 06 13:09:53 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: getfsspecname.3,v 1.5 2015/06/13 19:52:58 dholland Exp $
+.\"    $NetBSD: getfsspecname.3,v 1.6 2018/10/06 13:09:53 jmcneill Exp $
 .\"
 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd August 18, 2014
+.Dd October 6, 2018
 .Dt GETFSSPECNAME 3
 .Os
 .Sh NAME
@@ -65,6 +65,26 @@
 to
 .Fa buf
 and returned.
+.Pp
+If the
+.Fa spec
+argument starts with
+.Dq ROOT. ,
+a path in the form
+.Dq /dev/[root_device][suffix]
+is copied to
+.Fa buf ,
+where
+.Bq root_device
+is the value of the
+.Dq kern.root_device
+sysctl and
+.Bq suffix
+is the characters following
+.Dq ROOT.
+in the
+.Fa spec
+argument.
 .Sh RETURN VALUES
 On success the absolute pathname of the underlying wedge device is returned,
 or the original
diff -r cb2e558fa842 -r 3740b2da9aec lib/libutil/getfsspecname.c
--- a/lib/libutil/getfsspecname.c       Sat Oct 06 13:03:55 2018 +0000
+++ b/lib/libutil/getfsspecname.c       Sat Oct 06 13:09:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getfsspecname.c,v 1.5 2014/05/25 13:46:07 christos Exp $       */
+/*     $NetBSD: getfsspecname.c,v 1.6 2018/10/06 13:09:53 jmcneill Exp $       */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: getfsspecname.c,v 1.5 2014/05/25 13:46:07 christos Exp $");
+__RCSID("$NetBSD: getfsspecname.c,v 1.6 2018/10/06 13:09:53 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
@@ -59,6 +59,28 @@
        char *vname;
 
        p = drives = vname = NULL;
+
+       /*
+        * If the name starts with "ROOT.", replace it with "/dev/<root_device>",
+        * where <root_device> is the value of the kern.root_device sysctl. Any
+        * characters after the special "ROOT." token are appended to the end
+        * of this path.
+        */
+       if (strncasecmp(name, "ROOT.", 5) == 0 && strchr(name, ':') == NULL) {
+               static const int mib_root[] = { CTL_KERN, KERN_ROOT_DEVICE };
+               static const int mib_rootlen = __arraycount(mib_root);
+
+               strlcpy(buf, "/dev/", bufsiz);
+               len = bufsiz - 5;
+               if (sysctl(mib_root, mib_rootlen, buf + 5, &len, NULL, 0) == -1) {
+                       savee = errno;
+                       strlcpy(buf, "sysctl kern.root_device failed", bufsiz);
+                       goto out;
+               }
+               strlcat(buf, name + 5, bufsiz);
+               return buf;
+       }
+
        if (strncasecmp(name, "NAME=", 5) != 0) {
 #ifdef COMPAT_DKWEDGE
                /*
diff -r cb2e558fa842 -r 3740b2da9aec share/man/man5/fstab.5
--- a/share/man/man5/fstab.5    Sat Oct 06 13:03:55 2018 +0000
+++ b/share/man/man5/fstab.5    Sat Oct 06 13:09:53 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fstab.5,v 1.43 2015/12/21 13:15:04 ryoon Exp $
+.\"    $NetBSD: fstab.5,v 1.44 2018/10/06 13:09:53 jmcneill Exp $
 .\"
 .\" Copyright (c) 1980, 1989, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)fstab.5    8.1 (Berkeley) 6/5/93
 .\"
-.Dd December 21, 2015
+.Dd October 6, 2018
 .Dt FSTAB 5
 .Os
 .Sh NAME
@@ -91,6 +91,16 @@
 .Ar <value>
 and the device corresponding to it is selected.
 .Pp
+If the first field starts with the prefix
+.Dq ROOT.
+the prefix is replaced with
+.Dq /dev/[root_device] ,
+where
+.Bq root_device
+is the value of the
+.Dq kern.root_device
+sysctl.
+.Pp
 The second field,
 .Pq Fa fs_file ,
 describes the mount point for the file system.



Home | Main Index | Thread Index | Old Index