Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Support upgrade of systems using NAME= synt...



details:   https://anonhg.NetBSD.org/src/rev/ee1f28bc3ada
branches:  trunk
changeset: 453310:ee1f28bc3ada
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Aug 07 10:08:04 2019 +0000

description:
Support upgrade of systems using NAME= syntax in /etc/fstab.

Make supported file system types dynamic - instead of hardcoding the
available types at compile time, check for available newfs_* helper
binaries in the actual install environment at runtime.

diffstat:

 usr.sbin/sysinst/arch/ews4800mips/md.h |    3 +-
 usr.sbin/sysinst/defs.h                |    3 +-
 usr.sbin/sysinst/disklabel.c           |   29 ++-
 usr.sbin/sysinst/disks.c               |  310 ++++++++++++++++++++++++++------
 usr.sbin/sysinst/gpt.c                 |   21 ++-
 usr.sbin/sysinst/partitions.h          |   14 +-
 usr.sbin/sysinst/target.c              |   26 ++-
 usr.sbin/sysinst/txtwalk.c             |    4 +-
 usr.sbin/sysinst/txtwalk.h             |   11 +-
 9 files changed, 345 insertions(+), 76 deletions(-)

diffs (truncated from 729 to 300 lines):

diff -r f0e55fe136e9 -r ee1f28bc3ada usr.sbin/sysinst/arch/ews4800mips/md.h
--- a/usr.sbin/sysinst/arch/ews4800mips/md.h    Wed Aug 07 10:01:05 2019 +0000
+++ b/usr.sbin/sysinst/arch/ews4800mips/md.h    Wed Aug 07 10:08:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.h,v 1.3 2019/06/12 06:20:20 martin Exp $    */
+/*     $NetBSD: md.h,v 1.4 2019/08/07 10:08:04 martin Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -38,7 +38,6 @@
  */
 #include <machine/disklabel.h>
 
-#define        USE_SYSVBFS
 #define        PART_BOOT       (8*MEG)
 #define        PART_BOOT_TYPE  FS_SYSVBFS
 
diff -r f0e55fe136e9 -r ee1f28bc3ada usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Wed Aug 07 10:01:05 2019 +0000
+++ b/usr.sbin/sysinst/defs.h   Wed Aug 07 10:08:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.42 2019/07/26 08:18:47 martin Exp $ */
+/*     $NetBSD: defs.h,v 1.43 2019/08/07 10:08:04 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -806,6 +806,7 @@
 int    target_symlink_exists_p(const char *);
 void   unwind_mounts(void);
 int    target_mounted(void);
+void   umount_root(void);
 
 /* from partman.c */
 #ifndef NO_PARTMAN
diff -r f0e55fe136e9 -r ee1f28bc3ada usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Wed Aug 07 10:01:05 2019 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Wed Aug 07 10:08:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.10 2019/07/26 08:18:47 martin Exp $    */
+/*     $NetBSD: disklabel.c,v 1.11 2019/08/07 10:08:04 martin Exp $    */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -1016,6 +1016,32 @@
        return parts->ptn_alignment;
 }
 
+static part_id
+disklabel_find_by_name(struct disk_partitions *arg, const char *name)
+{
+       const struct disklabel_disk_partitions *parts =
+           (const struct disklabel_disk_partitions*)arg;
+       char *sl, part;
+       ptrdiff_t n;
+       part_id pno;
+
+       sl = strrchr(name, '/');
+       if (sl == NULL)
+               return NO_PART;
+       n = sl - name;
+       if (strncmp(name, parts->l.d_packname, n) != 0)
+               return NO_PART;
+       part = name[n+1];
+       if (part < 'a')
+               return NO_PART;
+       pno = part - 'a';
+       if (pno >= parts->l.d_npartitions)
+               return NO_PART;
+       if (parts->l.d_partitions[pno].p_fstype == FS_UNUSED)
+               return NO_PART;
+       return pno;
+}
+
 static void
 disklabel_free(struct disk_partitions *arg)
 {
@@ -1034,6 +1060,7 @@
        .read_from_disk = disklabel_parts_read,
        .create_new_for_disk = disklabel_parts_new,
        .change_disk_geom = disklabel_change_geom,
+       .find_by_name = disklabel_find_by_name,
        .get_disk_pack_name = disklabel_get_disk_pack_name,
        .set_disk_pack_name = disklabel_set_disk_pack_name,
        .delete_all_partitions = disklabel_delete_all,
diff -r f0e55fe136e9 -r ee1f28bc3ada usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c  Wed Aug 07 10:01:05 2019 +0000
+++ b/usr.sbin/sysinst/disks.c  Wed Aug 07 10:08:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.46 2019/08/03 12:09:22 martin Exp $ */
+/*     $NetBSD: disks.c,v 1.47 2019/08/07 10:08:04 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -46,6 +46,7 @@
 #include <util.h>
 #include <uuid.h>
 #include <paths.h>
+#include <fstab.h>
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -80,13 +81,22 @@
        daddr_t dd_totsec;
 };
 
-static const char name_prefix[] = "NAME=";
+#define        NAME_PREFIX     "NAME="
+static const char name_prefix[] = NAME_PREFIX;
+
+/* things we could have as /sbin/newfs_* and /sbin/fsck_* */
+static const char *extern_fs_with_chk[] = {
+       "ext2fs", "lfs", "msdos", "v7fs"
+};
+
+/* things we could have as /sbin/newfs_* but not /sbin/fsck_* */
+static const char *extern_fs_newfs_only[] = {
+       "sysvbfs", "udf"
+};
 
 /* Local prototypes */
-static int foundffs(struct data *, size_t);
-#ifdef USE_SYSVBFS
-static int foundsysvbfs(struct data *, size_t);
-#endif
+static int found_fs(struct data *, size_t, const struct lookfor*);
+static int found_fs_nocheck(struct data *, size_t, const struct lookfor*);
 static int fsck_preen(const char *, const char *, bool silent);
 static void fixsb(const char *, const char *);
 
@@ -1153,20 +1163,16 @@
                        mnt_opts = "-tmsdos";
                        fsname = "msdos";
                        break;
-#ifdef USE_SYSVBFS
                case FS_SYSVBFS:
                        asprintf(&newfs, "/sbin/newfs_sysvbfs");
                        mnt_opts = "-tsysvbfs";
                        fsname = "sysvbfs";
                        break;
-#endif
-#ifdef USE_EXT2FS
                case FS_EX2FS:
                        asprintf(&newfs, "/sbin/newfs_ext2fs");
                        mnt_opts = "-text2fs";
                        fsname = "ext2fs";
                        break;
-#endif
                }
                if ((ptn->instflags & PUIINST_NEWFS) && newfs != NULL) {
                        if (ptn->fs_type == FS_MSDOS) {
@@ -1258,7 +1264,7 @@
 
                if (!get_name_and_parent(pm->diskdev, buf, parent))
                        goto done_with_disks;
-               scripting_fprintf(f, "NAME=%s\t/\tffs\trw\t\t1 1\n",
+               scripting_fprintf(f, NAME_PREFIX "%s\t/\tffs\trw\t\t1 1\n",
                    buf);
                if (!find_swap_part_on(parent, swap))
                        goto done_with_disks;
@@ -1268,7 +1274,7 @@
                res = ask_yesno(prompt);
                free(prompt);
                if (res)
-                       scripting_fprintf(f, "NAME=%s\tnone"
+                       scripting_fprintf(f, NAME_PREFIX "%s\tnone"
                            "\tswap\tsw,dp\t\t0 0\n", swap);
                goto done_with_disks;
        }
@@ -1328,12 +1334,10 @@
                        scripting_fprintf(f, "%s\t\tnone\tswap\tsw%s\t\t 0 0\n",
                                dev, dump_dev);
                        continue;
-#ifdef USE_SYSVBFS
                case FS_SYSVBFS:
                        fstype = "sysvbfs";
                        make_target_dir("/stand");
                        break;
-#endif
                default:
                        fstype = "???";
                        s = "# ";
@@ -1398,37 +1402,138 @@
        return 0;
 }
 
+static bool
+find_part_by_name(const char *name, struct disk_partitions **parts,
+    part_id *pno)
+{
+       struct pm_devs *i;
+       struct disk_partitions *ps;
+       part_id id;
+       struct disk_desc disks[MAX_DISKS];
+       int n, cnt;
+
+       if (SLIST_EMPTY(&pm_head)) {
+               /*
+                * List has not been filled, only "pm" is valid - check
+                * that first.
+                */
+               if (pm->parts->pscheme->find_by_name != NULL) {
+                       id = pm->parts->pscheme->find_by_name(pm->parts, name);
+                       if (id != NO_PART) {
+                               *pno = id;
+                               *parts = pm->parts;
+                               return true;
+                       }
+               }
+               /*
+                * Not that easy - check all other disks
+                */
+               cnt = get_disks(disks, false);
+               for (n = 0; n < cnt; n++) {
+                       if (strcmp(disks[n].dd_name, pm->diskdev) == 0)
+                               continue;
+                       ps = partitions_read_disk(disks[n].dd_name,
+                           disks[n].dd_totsec);
+                       if (ps == NULL)
+                               continue;
+                       if (ps->pscheme->find_by_name == NULL)
+                               continue;
+                       id = ps->pscheme->find_by_name(ps, name);
+                       if (id != NO_PART) {
+                               *pno = id;
+                               *parts = ps;
+                               return true;    /* XXX this leaks memory */
+                       }
+                       ps->pscheme->free(ps);
+               }
+       } else {
+               SLIST_FOREACH(i, &pm_head, l) {
+                       if (i->parts == NULL)
+                               continue;
+                       if (i->parts->pscheme->find_by_name == NULL)
+                               continue;
+                       id = i->parts->pscheme->find_by_name(i->parts, name);
+                       if (id == NO_PART)
+                               continue;
+                       *pno = id;
+                       *parts = i->parts;
+                       return true;
+               }
+       }
+
+       *pno = NO_PART;
+       *parts = NULL;
+       return false;
+}
+
 static int
 /*ARGSUSED*/
-foundffs(struct data *list, size_t num)
+process_found_fs(struct data *list, size_t num, const struct lookfor *item,
+    bool with_fsck)
 {
        int error;
-       char rbuf[PATH_MAX], buf[PATH_MAX];
-       const char *rdev, *dev;
+       char rdev[PATH_MAX], dev[PATH_MAX],
+           options[STRSIZE], tmp[STRSIZE], *op, *last;
+       const char *fsname = (const char*)item->var;
+       part_id pno;
+       struct disk_partitions *parts;
+       bool first;
 
-       if (num < 2 || strcmp(list[1].u.s_val, "/") == 0 ||
-           strstr(list[2].u.s_val, "noauto") != NULL)
+       if (num < 2 || strstr(list[2].u.s_val, "noauto") != NULL)
                return 0;
 
-       /* need the raw device for fsck_preen */
-       if (strncmp(list[0].u.s_val, name_prefix, sizeof(name_prefix)-1)
-            != 0) {
-               strcpy(rbuf, "/dev/r");
-               strlcat(rbuf, list[0].u.s_val, sizeof(rbuf));
-               rdev = rbuf;
-               strcpy(buf, "/dev/");
-               strlcat(buf, list[0].u.s_val, sizeof(buf));
-               dev = buf;
+       if ((strcmp(list[1].u.s_val, "/") == 0) && target_mounted())
+               return 0;
+
+       if (strcmp(item->head, name_prefix) == 0) {
+               /* this fstab entry uses NAME= syntax */
+               if (!find_part_by_name(list[0].u.s_val,
+                   &parts, &pno) || parts == NULL || pno == NO_PART)
+                       return 0;
+               parts->pscheme->get_part_device(parts, pno,
+                   dev, sizeof(dev), NULL, plain_name, true);
+               parts->pscheme->get_part_device(parts, pno,
+                   rdev, sizeof(rdev), NULL, raw_dev_name, true);
        } else {
-               rdev = list[0].u.s_val;
-               dev = list[0].u.s_val;
+               /* plain device name */
+               strcpy(rdev, "/dev/r");
+               strlcat(rdev, list[0].u.s_val, sizeof(rdev));
+               strcpy(dev, "/dev/");
+               strlcat(dev, list[0].u.s_val, sizeof(dev));
        }



Home | Main Index | Thread Index | Old Index