Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt PR/51230: Add the ability to set the active flag in...



details:   https://anonhg.NetBSD.org/src/rev/ed450278e86e
branches:  trunk
changeset: 345812:ed450278e86e
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 09 15:12:54 2016 +0000

description:
PR/51230: Add the ability to set the active flag in the PMBR.

diffstat:

 sbin/gpt/biosboot.c |  20 ++++++++++++++------
 sbin/gpt/create.c   |  16 ++++++++++------
 sbin/gpt/gpt.8      |  22 +++++++++++++++++-----
 sbin/gpt/gpt.c      |   8 +++++---
 sbin/gpt/gpt.h      |   2 +-
 sbin/gpt/migrate.c  |  16 ++++++++++------
 sbin/gpt/show.c     |   6 ++++--
 7 files changed, 61 insertions(+), 29 deletions(-)

diffs (truncated from 347 to 300 lines):

diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/biosboot.c
--- a/sbin/gpt/biosboot.c       Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/biosboot.c       Thu Jun 09 15:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $ */
+/*     $NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -68,7 +68,7 @@
 static int cmd_biosboot(gpt_t, int, char *[]);
 
 static const char *biosboothelp[] = {
-       "[-c bootcode] [-i index] [-L label]",
+       "[-a] [-c bootcode] [-i index] [-L label]",
 #if notyet
        "[-a alignment] [-b blocknr] [-i index] [-l label]",
        "[-s size] [-t type]",
@@ -164,7 +164,7 @@
 
 static int
 biosboot(gpt_t gpt, daddr_t start, uint64_t size, u_int entry, uint8_t *label,
-    const char *bootpath)
+    const char *bootpath, int active)
 {
        map_t mbrmap, m;
        struct mbr *mbr, *bootcode;
@@ -197,6 +197,10 @@
                sizeof(mbr->mbr_code));
        free(bootcode);
 
+       for (i = 0; i < __arraycount(mbr->mbr_part); i++)
+               if (mbr->mbr_part[i].part_typ == MBR_PTYPE_PMBR)
+                       mbr->mbr_part[i].part_flag = active ? 0x80 : 0;
+
        /*
         * Walk through the GPT and see where we can boot from
         */
@@ -255,12 +259,16 @@
        gpt_t ngpt = gpt;
        daddr_t start = 0;
        uint64_t size = 0;
+       int active = 0;
        unsigned int entry = 0;
        uint8_t *label = NULL;
        char *bootpath = NULL;
 
-       while ((ch = getopt(argc, argv, "c:i:L:")) != -1) {
+       while ((ch = getopt(argc, argv, "ac:i:L:")) != -1) {
                switch(ch) {
+               case 'a':
+                       active = 1;
+                       break;
                case 'c':
                        if (gpt_name_get(gpt, &bootpath) == -1)
                                goto usage;
@@ -295,7 +303,7 @@
                        goto cleanup;
        }
 #endif
-       if (biosboot(ngpt, start, size, entry, label, bootpath) == -1)
+       if (biosboot(ngpt, start, size, entry, label, bootpath, active) == -1)
                goto cleanup;
        if (ngpt != gpt)
                gpt_close(ngpt);
diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/create.c
--- a/sbin/gpt/create.c Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/create.c Thu Jun 09 15:12:54 2016 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: create.c,v 1.20 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.21 2016/06/09 15:12:54 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -55,7 +55,7 @@
 static int cmd_create(gpt_t, int, char *[]);
 
 static const char *createhelp[] = {
-       "[-fP] [-p partitions]",
+       "[-afP] [-p partitions]",
 };
 
 struct gpt_cmd c_create = {
@@ -69,7 +69,7 @@
 
 
 static int
-create(gpt_t gpt, u_int parts, int force, int primary_only)
+create(gpt_t gpt, u_int parts, int force, int primary_only, int active)
 {
        off_t last = gpt_last(gpt);
        map_t map;
@@ -100,7 +100,7 @@
                }
                memset(mbr, 0, sizeof(*mbr));
                mbr->mbr_sig = htole16(MBR_SIG);
-               gpt_create_pmbr_part(mbr->mbr_part, last);
+               gpt_create_pmbr_part(mbr->mbr_part, last, active);
 
                map = map_add(gpt, 0LL, 1LL, MAP_TYPE_PMBR, mbr, 1);
                if (gpt_write(gpt, map) == -1) {
@@ -125,12 +125,16 @@
 cmd_create(gpt_t gpt, int argc, char *argv[])
 {
        int ch;
+       int active = 0;
        int force = 0;
        int primary_only = 0;
        u_int parts = 128;
 
-       while ((ch = getopt(argc, argv, "fPp:")) != -1) {
+       while ((ch = getopt(argc, argv, "afPp:")) != -1) {
                switch(ch) {
+               case 'a':
+                       active = 1;
+                       break;
                case 'f':
                        force = 1;
                        break;
@@ -149,5 +153,5 @@
        if (argc != optind)
                return usage();
 
-       return create(gpt, parts, force, primary_only);
+       return create(gpt, parts, force, primary_only, active);
 }
diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/gpt.8    Thu Jun 09 15:12:54 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.45 2015/12/25 12:16:03 wiz Exp $
+.\" $NetBSD: gpt.8,v 1.46 2016/06/09 15:12:54 christos Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd December 25, 2015
+.Dd June 9, 2016
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -211,7 +211,7 @@
 The format is a plist.
 It should not be modified.
 .\" ==== biosboot ====
-.It Nm Ic biosboot Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \
+.It Nm Ic biosboot Oo Fl ac Ar bootcode Oc Oo Fl i Ar index Oc \
 Oo Fl L Ar label Oc
 The
 .Ic biosboot
@@ -220,6 +220,10 @@
 .Xr boot 8 .
 .Pp
 The
+.Fl a
+options sets the PMBR partition active.
+.Pp
+The
 .Fl c
 option allows the user to specify the filename that
 .Nm
@@ -238,7 +242,7 @@
 If there are multiple partitions with the same label, it will use the
 first one found.
 .\" ==== create ====
-.It Nm Ic create Oo Fl fP Oc Oo Fl p Ar partitions Oc
+.It Nm Ic create Oo Fl afP Oc Oo Fl p Ar partitions Oc
 The
 .Ic create
 command allows the user to create a new (empty) GPT.
@@ -252,6 +256,10 @@
 described by the MBR are lost.
 .Pp
 The
+.Fl a
+options sets the PMBR partition active.
+.Pp
+The
 .Fl P
 option tells
 .Nm
@@ -343,7 +351,7 @@
 option is used to specify the label in the command line.
 The label is assumed to be encoded in UTF-8.
 .\" ==== migrate ====
-.It Nm Ic migrate Oo Fl fs Oc Oo Fl p Ar partitions Oc
+.It Nm Ic migrate Oo Fl afs Oc Oo Fl p Ar partitions Oc
 The
 .Ic migrate
 command allows the user to migrate an MBR-based disk partitioning into a
@@ -359,6 +367,10 @@
 to be lost.
 .Pp
 The
+.Fl a
+options sets the PMBR partition active.
+.Pp
+The
 .Fl s
 option prevents migrating
 .Bx
diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/gpt.c
--- a/sbin/gpt/gpt.c    Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/gpt.c    Thu Jun 09 15:12:54 2016 +0000
@@ -35,7 +35,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: gpt.c,v 1.67 2016/01/08 18:59:01 joerg Exp $");
+__RCSID("$NetBSD: gpt.c,v 1.68 2016/06/09 15:12:54 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -336,7 +336,8 @@
                /* start is relative to the offset of the MBR itself. */
                start += lba;
                if (gpt->verbose > 2)
-                       gpt_msg(gpt, "MBR part: type=%d, start=%ju, size=%ju",
+                       gpt_msg(gpt, "MBR part: flag=%#x type=%d, start=%ju, "
+                           "size=%ju", mbr->mbr_part[i].part_flag,
                            mbr->mbr_part[i].part_typ,
                            (uintmax_t)start, (uintmax_t)size);
                if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) {
@@ -705,8 +706,9 @@
 }
 
 void
-gpt_create_pmbr_part(struct mbr_part *part, off_t last)
+gpt_create_pmbr_part(struct mbr_part *part, off_t last, int active)
 {
+       part->part_flag = active ? 0x80 : 0;
        part->part_shd = 0x00;
        part->part_ssect = 0x02;
        part->part_scyl = 0x00;
diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h    Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/gpt.h    Thu Jun 09 15:12:54 2016 +0000
@@ -92,7 +92,7 @@
 void   gpt_msg(gpt_t, const char *, ...) __printflike(2, 3);
 void   gpt_warn(gpt_t, const char *, ...) __printflike(2, 3);
 void   gpt_warnx(gpt_t, const char *, ...) __printflike(2, 3);
-void   gpt_create_pmbr_part(struct mbr_part *, off_t);
+void   gpt_create_pmbr_part(struct mbr_part *, off_t, int);
 struct gpt_ent *gpt_ent(map_t, map_t, unsigned int);
 struct gpt_ent *gpt_ent_primary(gpt_t, unsigned int);
 struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int);
diff -r b3293d32fc35 -r ed450278e86e sbin/gpt/migrate.c
--- a/sbin/gpt/migrate.c        Thu Jun 09 15:09:07 2016 +0000
+++ b/sbin/gpt/migrate.c        Thu Jun 09 15:12:54 2016 +0000
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: migrate.c,v 1.30 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: migrate.c,v 1.31 2016/06/09 15:12:54 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -81,7 +81,7 @@
 static int cmd_migrate(gpt_t, int, char *[]);
 
 static const char *migratehelp[] = {
-       "[-fs] [-p partitions]",
+       "[-afs] [-p partitions]",
 };
 
 struct gpt_cmd c_migrate = {
@@ -233,7 +233,7 @@
 }
 
 static int
-migrate(gpt_t gpt, u_int parts, int force, int slice)
+migrate(gpt_t gpt, u_int parts, int force, int slice, int active)
 {
        off_t last = gpt_last(gpt);
        map_t map;
@@ -314,7 +314,7 @@
         * Turn the MBR into a Protective MBR.
         */
        memset(mbr->mbr_part, 0, sizeof(mbr->mbr_part));
-       gpt_create_pmbr_part(mbr->mbr_part, last);
+       gpt_create_pmbr_part(mbr->mbr_part, last, active);
        if (gpt_write(gpt, map) == -1) {
                gpt_warn(gpt, "Cant write PMBR");
                return -1;



Home | Main Index | Thread Index | Old Index