CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Sun Dec 13 21:55:25 UTC 2020 Modified Files: src/sbin/gpt: recover.c Log Message: PR/55875 - Valentin -- "gpt recover -r" does nothing Delete do nothing undocumented option, that was there from initial import. No idea what it was intended to do and there is no longer an "upstream". To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/recover.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.18 src/sbin/gpt/recover.c:1.19 --- src/sbin/gpt/recover.c:1.18 Tue Jul 3 03:41:24 2018 +++ src/sbin/gpt/recover.c Sun Dec 13 21:55:25 2020 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.18 2018/07/03 03:41:24 jnemeth Exp $"); +__RCSID("$NetBSD: recover.c,v 1.19 2020/12/13 21:55:25 jnemeth Exp $"); #endif #include @@ -149,7 +149,7 @@ recover_gpt_tbl(gpt_t gpt, int type, off } static int -recover(gpt_t gpt, int recoverable) +recover(gpt_t gpt) { off_t last = gpt_last(gpt); map_t map; @@ -233,13 +233,9 @@ static int cmd_recover(gpt_t gpt, int argc, char *argv[]) { int ch; - int recoverable = 0; while ((ch = getopt(argc, argv, "r")) != -1) { switch(ch) { - case 'r': - recoverable = 1; - break; default: return usage(); } @@ -248,5 +244,5 @@ cmd_recover(gpt_t gpt, int argc, char *a if (argc != optind) return usage(); - return recover(gpt, recoverable); + return recover(gpt); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Mon Jul 27 20:54:18 UTC 2020 Modified Files: src/sbin/gpt: gpt.8 Log Message: catch up with source rename of fbsd-zfs -> zfs To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.73 src/sbin/gpt/gpt.8:1.74 --- src/sbin/gpt/gpt.8:1.73 Sun May 24 16:59:16 2020 +++ src/sbin/gpt/gpt.8 Mon Jul 27 16:54:18 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.73 2020/05/24 20:59:16 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.74 2020/07/27 20:54:18 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 May 24, 2020 +.Dd July 27, 2020 .Dt GPT 8 .Os .Sh NAME @@ -203,8 +203,9 @@ UFS/UFS2 .It Cm fbsd-vinum .Fx vinum -.It Cm fbsd-zfs -.Fx +.It Cm zfs +.Fx , +.Nx ZFS .It Cm linux-data Linux data
CVS commit: src/sbin/gpt
Module Name:src Committed By: thorpej Date: Mon Jun 8 22:52:09 UTC 2020 Modified Files: src/sbin/gpt: backup.c Log Message: When we add "entries", "index", and "sector_size" values to the dictionary, add them as signed valaues, rather than unsigned (which is how we keep them in memory). This causes them be serialized in base-10 (rather than base-16, which is the default for unsigned). This behavior is documented in prop_number(3). Fixes t_gpt::backup_2part unit test. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/backup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.19 src/sbin/gpt/backup.c:1.20 --- src/sbin/gpt/backup.c:1.19 Sun Jun 7 05:42:25 2020 +++ src/sbin/gpt/backup.c Mon Jun 8 22:52:09 2020 @@ -33,13 +33,15 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.19 2020/06/07 05:42:25 thorpej Exp $"); +__RCSID("$NetBSD: backup.c,v 1.20 2020/06/08 22:52:09 thorpej Exp $"); #endif #include #include +#include #include +#include #include #include #include @@ -80,7 +82,8 @@ store_mbr(gpt_t gpt, unsigned int i, con mbr_dict = prop_dictionary_create(); PROP_ERR(mbr_dict); - PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i)); + assert(i <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(mbr_dict, "index", (int)i)); PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag)); PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head", par->part_shd)); @@ -127,8 +130,9 @@ store_gpt(gpt_t gpt, const struct gpt_hd le32toh(hdr->hdr_revision))); gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid); PROP_ERR(prop_dictionary_set_string(*type_dict, "guid", buf)); - PROP_ERR(prop_dictionary_set_uint(*type_dict, "entries", - le32toh(hdr->hdr_entries))); + assert(le32toh(hdr->hdr_entries) <= INT32_MAX); + PROP_ERR(prop_dictionary_set_int32(*type_dict, "entries", + (int32_t)le32toh(hdr->hdr_entries))); return 0; cleanup: if (*type_dict) @@ -161,7 +165,8 @@ store_tbl(gpt_t gpt, const map_t m, prop m->map_size * gpt->secsz; i++, ent++) { gpt_dict = prop_dictionary_create(); PROP_ERR(gpt_dict); - PROP_ERR(prop_dictionary_set_uint(gpt_dict, "index", i)); + assert(i <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(gpt_dict, "index", (int)i)); gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_type); PROP_ERR(prop_dictionary_set_string(gpt_dict, "type", buf)); gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_guid); @@ -206,7 +211,9 @@ backup(gpt_t gpt, const char *outfile) props = prop_dictionary_create(); PROP_ERR(props); - PROP_ERR(prop_dictionary_set_uint(props, "sector_size", gpt->secsz)); + assert(gpt->secsz <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(props, "sector_size", + (int)gpt->secsz)); m = map_first(gpt); while (m != NULL) { switch (m->map_type) {
CVS commit: src/sbin/gpt
Module Name:src Committed By: thorpej Date: Sun Jun 7 05:42:25 UTC 2020 Modified Files: src/sbin/gpt: backup.c restore.c Log Message: Update for proplib(3) API changes. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/backup.c cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/restore.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.18 src/sbin/gpt/backup.c:1.19 --- src/sbin/gpt/backup.c:1.18 Thu Sep 7 10:23:33 2017 +++ src/sbin/gpt/backup.c Sun Jun 7 05:42:25 2020 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.18 2017/09/07 10:23:33 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.19 2020/06/07 05:42:25 thorpej Exp $"); #endif #include @@ -68,79 +68,46 @@ struct gpt_cmd c_backup = { #define PROP_ERR(x) if (!(x)) goto cleanup -#define prop_uint(a) prop_number_create_unsigned_integer(a) - static int store_mbr(gpt_t gpt, unsigned int i, const struct mbr *mbr, prop_array_t *mbr_array) { prop_dictionary_t mbr_dict; - prop_number_t propnum; const struct mbr_part *par = >mbr_part[i]; - bool rc; if (mbr->mbr_part[i].part_typ == MBR_PTYPE_UNUSED) return 0; mbr_dict = prop_dictionary_create(); PROP_ERR(mbr_dict); - propnum = prop_number_create_integer(i); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "index", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_flag); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "flag", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_shd); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "start_head", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_ssect); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "start_sector", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_scyl); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "start_cylinder", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_typ); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "type", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_ehd); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "end_head", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_esect); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "end_sector", propnum); - PROP_ERR(rc); - propnum = prop_uint(par->part_ecyl); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "end_cylinder", propnum); - PROP_ERR(rc); - propnum = prop_uint(le16toh(par->part_start_lo)); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "lba_start_low", propnum); - PROP_ERR(rc); - propnum = prop_uint(le16toh(par->part_start_hi)); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "lba_start_high", propnum); - PROP_ERR(rc); - propnum = prop_uint(le16toh(par->part_size_lo)); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "lba_size_low", propnum); - PROP_ERR(rc); - propnum = prop_uint(le16toh(par->part_size_hi)); - PROP_ERR(propnum); - rc = prop_dictionary_set(mbr_dict, "lba_size_high", propnum); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head", + par->part_shd)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_sector", + par->part_ssect)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_cylinder", + par->part_scyl)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "type", par->part_typ)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_head", par->part_ehd)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_sector", + par->part_esect)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_cylinder", + par->part_ecyl)); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_low", + le16toh(par->part_start_lo))); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_high", + le16toh(par->part_start_hi))); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_low", + le16toh(par->part_size_lo))); + PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_high", + le16toh(par->part_size_hi))); + if (*mbr_array == NULL) { *mbr_array = prop_array_create(); PROP_ERR(*mbr_array); } - rc = prop_array_add(*mbr_array, mbr_dict); - PROP_ERR(rc); + PROP_ERR(prop_array_add_and_rel(*mbr_array, mbr_dict)); return 0; cleanup: if (mbr_dict) @@ -152,26 +119,16 @@ cleanup: static int store_gpt(gpt_t gpt, const struct gpt_hdr *hdr, prop_dictionary_t *type_dict) { - prop_number_t propnum; - prop_string_t propstr; char buf[128]; - bool rc; *type_dict = prop_dictionary_create(); PROP_ERR(type_dict); - propnum = prop_uint(le32toh(hdr->hdr_revision)); - PROP_ERR(propnum); -
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Sun May 24 20:59:16 UTC 2020 Modified Files: src/sbin/gpt: gpt.8 Log Message: Fix typo in macro. Sort option descriptions. To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.72 src/sbin/gpt/gpt.8:1.73 --- src/sbin/gpt/gpt.8:1.72 Sun May 24 18:42:20 2020 +++ src/sbin/gpt/gpt.8 Sun May 24 20:59:16 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.72 2020/05/24 18:42:20 jmcneill Exp $ +.\" $NetBSD: gpt.8,v 1.73 2020/05/24 20:59:16 wiz Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -34,7 +34,7 @@ .Nd GUID partition table maintenance utility .Sh SYNOPSIS .Nm -.Op Fl Hnrqv +.Op Fl Hnqrv .Op Fl m Ar mediasize .Op Fl s Ar sectorsize .Op Fl T Ar timestamp @@ -79,12 +79,12 @@ change the behaviour that is applicable Not all commands use all default settings, so some general options may not have an effect on all commands. .Bl -tag -width +.It Fl H +Ignore existing MBR (Hybrid MBR/GPT mode). .It Fl m Ar mediasize Override the default media size for the device (obtained from the kernel if possible) or defaulting to the file size for plain files. -.If Fl H -Ignore existing MBR (Hybrid MBR/GPT mode). .It Fl n Do not update the wedge information that .Nm @@ -92,15 +92,15 @@ changed. You need to use the .Xr dkctl 8 command manually update the device's wedge configuration if you do that. +.It Fl q +Do not print error messages. +This is not implemented completely yet. .It Fl r Open the device for reading only. .Nm Currently this option is primarily useful for the .Ic show command, but the intent is to use it to implement dry-run behaviour. -.It Fl q -Do not print error messages. -This is not implemented completely yet. .It Fl s Ar sectorsize Override the default sector size for the device (obtained from the kernel if possible) or
CVS commit: src/sbin/gpt
Module Name:src Committed By: jmcneill Date: Sun May 24 18:42:20 UTC 2020 Modified Files: src/sbin/gpt: gpt.8 gpt.c gpt.h main.c Log Message: Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode). To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.81 -r1.82 src/sbin/gpt/gpt.c cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/gpt.h cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.71 src/sbin/gpt/gpt.8:1.72 --- src/sbin/gpt/gpt.8:1.71 Sun May 24 14:42:44 2020 +++ src/sbin/gpt/gpt.8 Sun May 24 18:42:20 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.71 2020/05/24 14:42:44 jmcneill Exp $ +.\" $NetBSD: gpt.8,v 1.72 2020/05/24 18:42:20 jmcneill Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -34,7 +34,7 @@ .Nd GUID partition table maintenance utility .Sh SYNOPSIS .Nm -.Op Fl nrqv +.Op Fl Hnrqv .Op Fl m Ar mediasize .Op Fl s Ar sectorsize .Op Fl T Ar timestamp @@ -83,6 +83,8 @@ have an effect on all commands. Override the default media size for the device (obtained from the kernel if possible) or defaulting to the file size for plain files. +.If Fl H +Ignore existing MBR (Hybrid MBR/GPT mode). .It Fl n Do not update the wedge information that .Nm Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.81 src/sbin/gpt/gpt.c:1.82 --- src/sbin/gpt/gpt.c:1.81 Fri Oct 11 23:04:52 2019 +++ src/sbin/gpt/gpt.c Sun May 24 18:42:20 2020 @@ -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.81 2019/10/11 23:04:52 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.82 2020/05/24 18:42:20 jmcneill Exp $"); #endif #include @@ -311,7 +311,7 @@ gpt_mbr(gpt_t gpt, off_t lba, unsigned i continue; if (mbr->mbr_part[i].part_typ == MBR_PTYPE_PMBR) pmbr++; - else + else if ((gpt->flags & GPT_HYBRID) == 0) break; } if (pmbr && i == 4 && lba == 0) { Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.41 src/sbin/gpt/gpt.h:1.42 --- src/sbin/gpt/gpt.h:1.41 Sun Jun 30 11:38:16 2019 +++ src/sbin/gpt/gpt.h Sun May 24 18:42:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gpt.h,v 1.41 2019/06/30 11:38:16 sevan Exp $ */ +/* $NetBSD: gpt.h,v 1.42 2020/05/24 18:42:20 jmcneill Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -84,6 +84,7 @@ gpt_t gpt_open(const char *, int, int, o #define GPT_FILE 0x10 #define GPT_TIMESTAMP 0x20 #define GPT_SYNC 0x40 +#define GPT_HYBRID 0x80 #define GPT_OPTDEV 0x8000 void* gpt_read(gpt_t, off_t, size_t); Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.13 src/sbin/gpt/main.c:1.14 --- src/sbin/gpt/main.c:1.13 Tue Jun 25 04:53:40 2019 +++ src/sbin/gpt/main.c Sun May 24 18:42:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $ */ +/* $NetBSD: main.c,v 1.14 2020/05/24 18:42:20 jmcneill Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.13 2019/06/25 04:53:40 jnemeth Exp $"); +__RCSID("$NetBSD: main.c,v 1.14 2020/05/24 18:42:20 jmcneill Exp $"); #endif #include @@ -185,8 +185,11 @@ main(int argc, char *argv[]) #endif /* Get the generic options */ - while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "m:nqrs:T:v")) != -1) { + while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "Hm:nqrs:T:v")) != -1) { switch(ch) { + case 'H': + flags |= GPT_HYBRID; + break; case 'm': if (mediasz > 0) usage();
CVS commit: src/sbin/gpt
Module Name:src Committed By: jmcneill Date: Sun May 24 14:42:44 UTC 2020 Modified Files: src/sbin/gpt: gpt.8 map.c resize.c resizedisk.c Log Message: Exit gracefully when auto-expanding a partition and it is already the correct size. Add a -q flag to "resize" and "resizedisk" commands to skip printing warnings in the already resize paths. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/map.c cvs rdiff -u -r1.24 -r1.25 src/sbin/gpt/resize.c cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.70 src/sbin/gpt/gpt.8:1.71 --- src/sbin/gpt/gpt.8:1.70 Fri Jul 26 07:22:05 2019 +++ src/sbin/gpt/gpt.8 Sun May 24 14:42:44 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.70 2019/07/26 07:22:05 martin Exp $ +.\" $NetBSD: gpt.8,v 1.71 2020/05/24 14:42:44 jmcneill 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 July 26, 2019 +.Dd May 24, 2020 .Dt GPT 8 .Os .Sh NAME @@ -470,7 +470,7 @@ Partitions are removed by clearing the p No other information is changed. .\" resize .It Nm Ic resize Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc Oo Fl a Ar alignment Oc \ -Oo Fl s Ar size Oc +Oo Fl s Ar size Oc Oo Fl q Oc The .Ic resize command allows the user to resize a partition. @@ -500,8 +500,12 @@ If the .Fl a option is specified then the size will be adjusted to be a multiple of alignment if possible. +If the +.Fl q +option is specified then the utility will not print output when a +resize is not required. .\" resizedisk -.It Nm Ic resizedisk Oo Fl s Ar size Oc +.It Nm Ic resizedisk Oo Fl s Ar size Oc Oo Fl q Oc The .Ic resizedisk command allows the user to resize a disk. @@ -537,6 +541,10 @@ Using the .Fl s option allows you to move the backup copy prior to resizing the medium. This is primarily useful when shrinking the medium. +If the +.Fl q +option is specified then the utility will not print output when a +resize is not required. .\" restore .It Nm Ic restore Oo Fl F Oc Oo Fl i Ar infile Oc The Index: src/sbin/gpt/map.c diff -u src/sbin/gpt/map.c:1.14 src/sbin/gpt/map.c:1.15 --- src/sbin/gpt/map.c:1.14 Wed Apr 11 07:14:23 2018 +++ src/sbin/gpt/map.c Sun May 24 14:42:44 2020 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/map.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: map.c,v 1.14 2018/04/11 07:14:23 mrg Exp $"); +__RCSID("$NetBSD: map.c,v 1.15 2020/05/24 14:42:44 jmcneill Exp $"); #endif #include @@ -280,7 +280,10 @@ map_resize(gpt_t gpt, map_t m, off_t siz prevsize = m->map_size; size = ((m->map_size + n->map_size) / alignment) * alignment; - if (size <= prevsize) { + if (size == prevsize) { +m->map_size = size; +return size; + } else if (size < prevsize) { gpt_warnx(gpt, "Can't coalesce %ju <= %ju", (uintmax_t)prevsize, (uintmax_t)size); return -1; Index: src/sbin/gpt/resize.c diff -u src/sbin/gpt/resize.c:1.24 src/sbin/gpt/resize.c:1.25 --- src/sbin/gpt/resize.c:1.24 Sun Mar 24 13:31:00 2019 +++ src/sbin/gpt/resize.c Sun May 24 14:42:44 2020 @@ -33,12 +33,13 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resize.c,v 1.24 2019/03/24 13:31:00 martin Exp $"); +__RCSID("$NetBSD: resize.c,v 1.25 2020/05/24 14:42:44 jmcneill Exp $"); #endif #include #include +#include #include #include #include @@ -52,7 +53,7 @@ __RCSID("$NetBSD: resize.c,v 1.24 2019/0 static int cmd_resize(gpt_t, int, char *[]); static const char *resizehelp[] = { - "[-i index | -b blocknr] [-a alignment] [-s size]", + "[-i index | -b blocknr] [-a alignment] [-s size] [-q]", }; struct gpt_cmd c_resize = { @@ -65,13 +66,13 @@ struct gpt_cmd c_resize = { #define usage() gpt_usage(NULL, _resize) static int -resize(gpt_t gpt, u_int entry, off_t alignment, off_t sectors, off_t size) +resize(gpt_t gpt, u_int entry, off_t alignment, off_t sectors, off_t size, bool quiet) { map_t map; struct gpt_hdr *hdr; struct gpt_ent *ent; unsigned int i; - off_t alignsecs, newsize; + off_t alignsecs, newsize, oldsize; uint64_t end; @@ -101,14 +102,25 @@ resize(gpt_t gpt, u_int entry, off_t ali if (alignment == 0 || (alignment > 0 && sectors % alignsecs == 0)) { /* nothing to do */ - gpt_warnx(gpt, "partition does not need resizing"); + if (!quiet) +gpt_warnx(gpt, +"partition does not need resizing"); return 0; } + oldsize = map->map_size; newsize = map_resize(gpt, map, sectors, alignsecs); if (newsize == -1) return -1; + if (oldsize == newsize) { +
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Mon Mar 30 10:41:53 UTC 2020 Modified Files: src/sbin/gpt: gpt_uuid.c Log Message: Now that we use the same UUID for ZFS as FreeBSD, drop the FreeBSD marker from the description. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/gpt_uuid.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt_uuid.c diff -u src/sbin/gpt/gpt_uuid.c:1.18 src/sbin/gpt/gpt_uuid.c:1.19 --- src/sbin/gpt/gpt_uuid.c:1.18 Tue Jun 25 04:25:11 2019 +++ src/sbin/gpt/gpt_uuid.c Mon Mar 30 10:41:53 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $ */ +/* $NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: gpt_uuid.c,v 1.18 2019/06/25 04:25:11 jnemeth Exp $"); +__RCSID("$NetBSD: gpt_uuid.c,v 1.19 2020/03/30 10:41:53 martin Exp $"); #endif #include @@ -73,7 +73,7 @@ static const struct { { GPT_ENT_TYPE_FREEBSD_SWAP, "fbsd-swap", "FreeBSD swap" }, { GPT_ENT_TYPE_FREEBSD_UFS, "fbsd-ufs", "FreeBSD UFS/UFS2" }, { GPT_ENT_TYPE_FREEBSD_VINUM, "fbsd-vinum", "FreeBSD vinum" }, - { GPT_ENT_TYPE_FREEBSD_ZFS, "fbsd-zfs", "FreeBSD ZFS" }, + { GPT_ENT_TYPE_FREEBSD_ZFS, "zfs", "ZFS" }, { GPT_ENT_TYPE_LINUX_DATA, "linux-data", "Linux data" }, { GPT_ENT_TYPE_LINUX_RAID, "linux-raid", "Linux RAID" }, { GPT_ENT_TYPE_LINUX_SWAP, "linux-swap", "Linux swap" },
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Thu Apr 4 14:03:40 UTC 2019 Modified Files: src/sbin/gpt: destroy.c Log Message: PR bin/54088: make "destroy" remove the protective MBR too. We could make this optional if someone comes up with a good reason to leave it intact. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/destroy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/destroy.c diff -u src/sbin/gpt/destroy.c:1.11 src/sbin/gpt/destroy.c:1.12 --- src/sbin/gpt/destroy.c:1.11 Thu Apr 4 13:58:20 2019 +++ src/sbin/gpt/destroy.c Thu Apr 4 14:03:40 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: destroy.c,v 1.11 2019/04/04 13:58:20 martin Exp $"); +__RCSID("$NetBSD: destroy.c,v 1.12 2019/04/04 14:03:40 martin Exp $"); #endif #include @@ -68,10 +68,11 @@ struct gpt_cmd c_destroy = { static int destroy(gpt_t gpt, int force, int recoverable) { - map_t pri_hdr, sec_hdr; + map_t pri_hdr, sec_hdr, pmbr; pri_hdr = map_find(gpt, MAP_TYPE_PRI_GPT_HDR); sec_hdr = map_find(gpt, MAP_TYPE_SEC_GPT_HDR); + pmbr = map_find(gpt, MAP_TYPE_PMBR); if (pri_hdr == NULL && sec_hdr == NULL) { gpt_warnx(gpt, "Device doesn't contain a GPT"); @@ -99,6 +100,14 @@ destroy(gpt_t gpt, int force, int recove } } + if (!recoverable && pmbr != NULL) { + memset(pmbr->map_data, 0, gpt->secsz); + if (gpt_write(gpt, pmbr) == -1) { + gpt_warnx(gpt, "Error deleting PMBR"); + return -1; + } + } + return 0; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Thu Apr 4 13:58:20 UTC 2019 Modified Files: src/sbin/gpt: destroy.c Log Message: Ignore -f with the "destroy" command completely (it was effectively ignored already, so no functional change). Leave it as valid option for compatibility. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/destroy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/destroy.c diff -u src/sbin/gpt/destroy.c:1.10 src/sbin/gpt/destroy.c:1.11 --- src/sbin/gpt/destroy.c:1.10 Thu Dec 3 01:07:28 2015 +++ src/sbin/gpt/destroy.c Thu Apr 4 13:58:20 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/destroy.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: destroy.c,v 1.10 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: destroy.c,v 1.11 2019/04/04 13:58:20 martin Exp $"); #endif #include @@ -52,7 +52,7 @@ __RCSID("$NetBSD: destroy.c,v 1.10 2015/ static int cmd_destroy(gpt_t, int, char *[]); static const char *destroyhelp[] = { - "[-rf]", + "[-r]", }; struct gpt_cmd c_destroy = { @@ -107,12 +107,10 @@ cmd_destroy(gpt_t gpt, int argc, char *a { int ch; int recoverable = 0; - int force = 0; while ((ch = getopt(argc, argv, "fr")) != -1) { switch(ch) { case 'f': - force = 1; break; case 'r': recoverable = 1; @@ -125,5 +123,5 @@ cmd_destroy(gpt_t gpt, int argc, char *a if (argc != optind) return usage(); - return destroy(gpt, force, recoverable); + return destroy(gpt, 0, recoverable); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Thu Apr 4 13:55:40 UTC 2019 Modified Files: src/sbin/gpt: biosboot.c gpt.8 Log Message: Allow specifying the partition via -b startsec for the biosboot cmd. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.67 -r1.68 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.30 src/sbin/gpt/biosboot.c:1.31 --- src/sbin/gpt/biosboot.c:1.30 Thu Sep 7 10:23:33 2017 +++ src/sbin/gpt/biosboot.c Thu Apr 4 13:55:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.31 2019/04/04 13:55:40 martin Exp $"); #endif #include @@ -72,7 +72,7 @@ __RCSID("$NetBSD: biosboot.c,v 1.30 2017 static int cmd_biosboot(gpt_t, int, char *[]); static const char *biosboothelp[] = { - "[-A] [-c bootcode] [-i index] [-L label]", + "[-A] [-c bootcode] [-i index] [-L label] [-b startsec]", #if notyet "[-a alignment] [-b blocknr] [-i index] [-l label]", "[-s size] [-t type]", @@ -230,6 +230,10 @@ biosboot(gpt_t gpt, daddr_t start, uint6 if (entry < 1 && label == NULL && size > 0 && m->map_start == start && m->map_size == (off_t)size) break; + /* next could be start sector specified by -b option */ + if (entry < 1 && label == NULL && size == 0 && + m->map_start == start) + break; } if (m == NULL) { @@ -270,7 +274,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * uint8_t *label = NULL; char *bootpath = NULL; - while ((ch = getopt(argc, argv, "Ac:i:L:")) != -1) { + while ((ch = getopt(argc, argv, "Ac:i:L:b:")) != -1) { switch(ch) { case 'A': active = 1; @@ -287,6 +291,10 @@ cmd_biosboot(gpt_t gpt, int argc, char * if (gpt_name_get(gpt, ) == -1) goto usage; break; + case 'b': + if (gpt_human_get(gpt, ) == -1) +goto usage; + break; default: goto usage; } Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.67 src/sbin/gpt/gpt.8:1.68 --- src/sbin/gpt/gpt.8:1.67 Tue Mar 26 14:55:02 2019 +++ src/sbin/gpt/gpt.8 Thu Apr 4 13:55:40 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.67 2019/03/26 14:55:02 martin Exp $ +.\" $NetBSD: gpt.8,v 1.68 2019/04/04 13:55:40 martin 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 March 26, 2019 +.Dd April 4, 2019 .Dt GPT 8 .Os .Sh NAME @@ -249,8 +249,8 @@ command. The format is a plist. It should not be modified. .\" biosboot -.It Nm Ic biosboot Oo Fl A Oc Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \ -Oo Fl L Ar label Oc +.It Nm Ic biosboot Oo Fl A Oc Oo Fl c Ar bootcode Oc Oo Fl b Ar startsec Oc \ +Oo Fl i Ar index Oc Oo Fl L Ar label Oc The .Ic biosboot command allows the user to configure the partition that contains the @@ -279,6 +279,9 @@ The option selects the partition by label. If there are multiple partitions with the same label, the first one found will be used. +The +.Fl b +options selects the partition by start block. .\" create .It Nm Ic create Oo Fl AfP Oc Oo Fl p Ar partitions Oc The
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Tue Mar 26 14:55:02 UTC 2019 Modified Files: src/sbin/gpt: gpt.8 unset.c Log Message: Allow -b to specify a partition for "gpt unset" as well. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/unset.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.66 src/sbin/gpt/gpt.8:1.67 --- src/sbin/gpt/gpt.8:1.66 Mon Mar 25 20:15:49 2019 +++ src/sbin/gpt/gpt.8 Tue Mar 26 14:55:02 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.66 2019/03/25 20:15:49 martin Exp $ +.\" $NetBSD: gpt.8,v 1.67 2019/03/26 14:55:02 martin 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 March 25, 2019 +.Dd March 26, 2019 .Dt GPT 8 .Os .Sh NAME @@ -653,7 +653,7 @@ The .Fl l flag lists available types. .\" unset -.It Nm Ic unset Fl a Ar attribute Fl i Ar index +.It Nm Ic unset Fl a Ar attribute Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc .It Nm Ic unset Fl l The .Ic unset @@ -664,8 +664,11 @@ flag lists all available attributes. The .Fl a option specifies which attributes to unset and may be specified more than once. +Alternatively a comma separated list of attributes can be used. The .Fl i +or the +.Fl b option specifies which entry to update. The possible attributes are .Do biosboot Dc , Index: src/sbin/gpt/unset.c diff -u src/sbin/gpt/unset.c:1.14 src/sbin/gpt/unset.c:1.15 --- src/sbin/gpt/unset.c:1.14 Mon Mar 19 09:06:20 2018 +++ src/sbin/gpt/unset.c Tue Mar 26 14:55:02 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: unset.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $"); +__RCSID("$NetBSD: unset.c,v 1.15 2019/03/26 14:55:02 martin Exp $"); #endif #include @@ -53,6 +53,7 @@ static int cmd_unset(gpt_t, int, char *[ static const char *unsethelp[] = { "-a attribute -i index", + "-a attribute -b startsec", "-l", }; @@ -71,13 +72,19 @@ cmd_unset(gpt_t gpt, int argc, char *arg int ch; unsigned int entry = 0; uint64_t attributes = 0; + off_t start = 0; + map_t m; - while ((ch = getopt(argc, argv, "a:i:l")) != -1) { + while ((ch = getopt(argc, argv, "a:b:i:l")) != -1) { switch(ch) { case 'a': if (gpt == NULL || gpt_attr_get(gpt, ) == -1) return usage(); break; + case 'b': + if (gpt == NULL || gpt_human_get(gpt, ) == -1) +return usage(); + break; case 'i': if (gpt == NULL || gpt_uint_get(gpt, ) == -1) return usage(); @@ -90,6 +97,18 @@ cmd_unset(gpt_t gpt, int argc, char *arg } } + if (start > 0) { + for (m = map_first(gpt); m != NULL; m = m->map_next) { + if (m->map_type != MAP_TYPE_GPT_PART || + m->map_index < 1) +continue; + if (start != m->map_start) +continue; + entry = m->map_index; + break; + } + } + if (gpt == NULL || argc != optind) return usage();
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Tue Mar 26 11:23:55 UTC 2019 Modified Files: src/sbin/gpt: show.c Log Message: When displaying a single partition (gpt show -i ...) display offset and size in sectors (instead of the totally confusing bytes), followed by the humanized byte offset/size. This makes the numbers match the "gpt show" or "gpt show -a" output. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.43 src/sbin/gpt/show.c:1.44 --- src/sbin/gpt/show.c:1.43 Sun Mar 24 13:45:35 2019 +++ src/sbin/gpt/show.c Tue Mar 26 11:23:55 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.43 2019/03/24 13:45:35 martin Exp $"); +__RCSID("$NetBSD: show.c,v 1.44 2019/03/26 11:23:55 martin Exp $"); #endif #include @@ -186,6 +186,24 @@ show(gpt_t gpt, int xshow) return 0; } +static void +gpt_show_sec_num(const char *prompt, int64_t secsize, off_t num) +{ +#ifdef HN_AUTOSCALE + char human_num[5]; + if (humanize_number(human_num, sizeof(human_num), + (int64_t)num*secsize, + "", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0) + human_num[0] = '\0'; +#endif + printf("%s: %" PRIu64, prompt, (uint64_t)num); +#ifdef HN_AUTOSCALE + if (human_num[0] != '\0') + printf(" (%s)", human_num); +#endif + printf("\n"); +} + static int show_one(gpt_t gpt, unsigned int entry) { @@ -204,8 +222,8 @@ show_one(gpt_t gpt, unsigned int entry) ent = m->map_data; printf("Details for index %d:\n", entry); - gpt_show_num("Start", (uintmax_t)(m->map_start * gpt->secsz)); - gpt_show_num("Size", (uintmax_t)(m->map_size * gpt->secsz)); + gpt_show_sec_num("Start", gpt->secsz, m->map_start); + gpt_show_sec_num("Size", gpt->secsz, m->map_size); gpt_uuid_snprintf(s1, sizeof(s1), "%s", ent->ent_type); gpt_uuid_snprintf(s2, sizeof(s2), "%d", ent->ent_type);
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Mon Mar 25 20:15:49 UTC 2019 Modified Files: src/sbin/gpt: gpt.8 set.c Log Message: Allow -b startsec to specify the partition to change for the set subcommand as well. Add another option, -N, as a quick way to remove all attributes. To generate a diff of this commit: cvs rdiff -u -r1.65 -r1.66 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/set.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.65 src/sbin/gpt/gpt.8:1.66 --- src/sbin/gpt/gpt.8:1.65 Sun Mar 24 13:45:35 2019 +++ src/sbin/gpt/gpt.8 Mon Mar 25 20:15:49 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $ +.\" $NetBSD: gpt.8,v 1.66 2019/03/25 20:15:49 martin 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 March 24, 2019 +.Dd March 25, 2019 .Dt GPT 8 .Os .Sh NAME @@ -555,7 +555,8 @@ the partitions fit, as will automatically adjust. However, the new disk must use the same sector size as the old disk. .\" set -.It Nm Ic set Fl a Ar attribute Fl i Ar index +.It Nm Ic set Oo Fl a Ar attribute Oc Oo Fl N Oc Oo Fl i Ar index Oc \ +Oo Fl b Ar startsec Oc .It Nm Ic set Fl l The .Ic set @@ -567,9 +568,16 @@ The .Fl a option specifies which attributes to set and may be specified more than once, or the attributes can be comma-separated. +If the +.Fl N +option and no +.Fl a +option are specified, all attributes are removed. The .Fl i -option specifies which entry to update. +or the +.Fl b +option specify which entry to update. The possible attributes are .Do biosboot Dc , .Do bootme Dc , Index: src/sbin/gpt/set.c diff -u src/sbin/gpt/set.c:1.14 src/sbin/gpt/set.c:1.15 --- src/sbin/gpt/set.c:1.14 Mon Mar 19 09:06:20 2018 +++ src/sbin/gpt/set.c Mon Mar 25 20:15:49 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: set.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $"); +__RCSID("$NetBSD: set.c,v 1.15 2019/03/25 20:15:49 martin Exp $"); #endif #include @@ -52,7 +52,8 @@ __RCSID("$NetBSD: set.c,v 1.14 2018/03/1 static int cmd_set(gpt_t, int, char *[]); static const char *sethelp[] = { - "-a attribute -i index", + "-a attribute [-i index] [-b startsec]", + "-N [-i index] [-b startsec]", "-l", }; @@ -70,14 +71,20 @@ cmd_set(gpt_t gpt, int argc, char *argv[ { int ch; unsigned int entry = 0; - uint64_t attributes = 0; + uint64_t attributes = 0, clear = 0; + off_t start = 0; + map_t m; - while ((ch = getopt(argc, argv, "a:i:l")) != -1) { + while ((ch = getopt(argc, argv, "a:b:i:lN")) != -1) { switch(ch) { case 'a': if (gpt == NULL || gpt_attr_get(gpt, ) == -1) return usage(); break; + case 'b': + if (gpt == NULL || gpt_human_get(gpt, ) == -1) +return usage(); + break; case 'i': if (gpt == NULL || gpt_uint_get(gpt, ) == -1) return usage(); @@ -85,13 +92,28 @@ cmd_set(gpt_t gpt, int argc, char *argv[ case 'l': gpt_attr_help("\t"); return 0; + case 'N': + clear = ~clear; + break; default: return usage(); } } - if (gpt == NULL || argc != optind) + if (start > 0) { + for (m = map_first(gpt); m != NULL; m = m->map_next) { + if (m->map_type != MAP_TYPE_GPT_PART || + m->map_index < 1) +continue; + if (start != m->map_start) +continue; + entry = m->map_index; + break; + } + } + + if (gpt == NULL || argc != optind || (attributes != 0 && clear != 0)) return usage(); - return gpt_attr_update(gpt, entry, attributes, 0); + return gpt_attr_update(gpt, entry, attributes, clear); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Sun Mar 24 13:45:35 UTC 2019 Modified Files: src/sbin/gpt: gpt.8 show.c Log Message: Make the "show" subcommand accept -b startsec to identify a partition (very usefull for scripts and other robotic callers). To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.64 src/sbin/gpt/gpt.8:1.65 --- src/sbin/gpt/gpt.8:1.64 Sun Mar 24 13:31:00 2019 +++ src/sbin/gpt/gpt.8 Sun Mar 24 13:45:35 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin Exp $ +.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -466,7 +466,7 @@ See above for a description of these opt Partitions are removed by clearing the partition type. No other information is changed. .\" resize -.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \ +.It Nm Ic resize Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc Oo Fl a Ar alignment Oc \ Oo Fl s Ar size Oc The .Ic resize @@ -592,7 +592,7 @@ They may be used by .Nx in the future. .\" show -.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc +.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc The .Ic show command displays the current partitioning on the listed devices and gives @@ -611,6 +611,8 @@ option the GPT partition type is display user friendly form. With the .Fl i +or the +.Fl b option, all the details of a particular GPT partition will be displayed. The format of this display is subject to change. With the Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.42 src/sbin/gpt/show.c:1.43 --- src/sbin/gpt/show.c:1.42 Sun Mar 3 03:20:42 2019 +++ src/sbin/gpt/show.c Sun Mar 24 13:45:35 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.42 2019/03/03 03:20:42 jnemeth Exp $"); +__RCSID("$NetBSD: show.c,v 1.43 2019/03/24 13:45:35 martin Exp $"); #endif #include @@ -317,8 +317,10 @@ cmd_show(gpt_t gpt, int argc, char *argv int ch; int xshow = 0; unsigned int entry = 0; + off_t start = 0; + map_t m; - while ((ch = getopt(argc, argv, "gi:lua")) != -1) { + while ((ch = getopt(argc, argv, "gi:b:lua")) != -1) { switch(ch) { case 'a': xshow |= SHOW_ALL; @@ -330,6 +332,10 @@ cmd_show(gpt_t gpt, int argc, char *argv if (gpt_uint_get(gpt, ) == -1) return usage(); break; + case 'b': + if (gpt_human_get(gpt, ) == -1) +return usage(); + break; case 'l': xshow |= SHOW_LABEL; break; @@ -350,5 +356,17 @@ cmd_show(gpt_t gpt, int argc, char *argv if (xshow & SHOW_ALL) return show_all(gpt); + if (start > 0) { + for (m = map_first(gpt); m != NULL; m = m->map_next) { + if (m->map_type != MAP_TYPE_GPT_PART || + m->map_index < 1) +continue; + if (start != m->map_start) +continue; + entry = m->map_index; + break; + } + } + return entry > 0 ? show_one(gpt, entry) : show(gpt, xshow); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Sun Mar 24 13:31:00 UTC 2019 Modified Files: src/sbin/gpt: gpt.8 resize.c Log Message: Add support for specifying the partition to resize via -b startsec (similar to label and other subcommands). Do not fully add gpt_find functionality here, as resizing multiple partitions in one go does not make sense. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.23 -r1.24 src/sbin/gpt/resize.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.63 src/sbin/gpt/gpt.8:1.64 --- src/sbin/gpt/gpt.8:1.63 Tue May 1 21:16:02 2018 +++ src/sbin/gpt/gpt.8 Sun Mar 24 13:31:00 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.63 2018/05/01 21:16:02 kre Exp $ +.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin 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 May 1, 2018 +.Dd March 24, 2019 .Dt GPT 8 .Os .Sh NAME @@ -466,7 +466,7 @@ See above for a description of these opt Partitions are removed by clearing the partition type. No other information is changed. .\" resize -.It Nm Ic resize Fl i Ar index Oo Fl a Ar alignment Oc \ +.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \ Oo Fl s Ar size Oc The .Ic resize Index: src/sbin/gpt/resize.c diff -u src/sbin/gpt/resize.c:1.23 src/sbin/gpt/resize.c:1.24 --- src/sbin/gpt/resize.c:1.23 Tue Jul 3 03:41:24 2018 +++ src/sbin/gpt/resize.c Sun Mar 24 13:31:00 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resize.c,v 1.23 2018/07/03 03:41:24 jnemeth Exp $"); +__RCSID("$NetBSD: resize.c,v 1.24 2019/03/24 13:31:00 martin Exp $"); #endif #include @@ -52,7 +52,7 @@ __RCSID("$NetBSD: resize.c,v 1.23 2018/0 static int cmd_resize(gpt_t, int, char *[]); static const char *resizehelp[] = { - "-i index [-a alignment] [-s size]", + "[-i index | -b blocknr] [-a alignment] [-s size]", }; struct gpt_cmd c_resize = { @@ -131,17 +131,32 @@ static int cmd_resize(gpt_t gpt, int argc, char *argv[]) { int ch; - off_t alignment = 0, sectors, size = 0; + off_t alignment = 0, sectors, start = 0, size = 0; unsigned int entry = 0; + map_t m; - while ((ch = getopt(argc, argv, GPT_AIS)) != -1) { - if (gpt_add_ais(gpt, , , , ch) == -1) + while ((ch = getopt(argc, argv, GPT_AIS "b:")) != -1) { + if (ch == 'b') + gpt_human_get(gpt, ); + else if (gpt_add_ais(gpt, , , , ch) == -1) return usage(); } if (argc != optind) return usage(); + if (start > 0) { + for (m = map_first(gpt); m != NULL; m = m->map_next) { + if (m->map_type != MAP_TYPE_GPT_PART || + m->map_index < 1) +continue; + if (start != m->map_start) +continue; + entry = m->map_index; + break; + } + } + if ((sectors = gpt_check_ais(gpt, alignment, entry, size)) == -1) return -1;
CVS commit: src/sbin/gpt
Module Name:src Committed By: mlelstv Date: Thu Mar 14 10:26:10 UTC 2019 Modified Files: src/sbin/gpt: header.c Log Message: print little-endian header fields correctly. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/header.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/header.c diff -u src/sbin/gpt/header.c:1.9 src/sbin/gpt/header.c:1.10 --- src/sbin/gpt/header.c:1.9 Tue May 1 08:17:13 2018 +++ src/sbin/gpt/header.c Thu Mar 14 10:26:10 2019 @@ -33,7 +33,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: header.c,v 1.9 2018/05/01 08:17:13 martin Exp $"); +__RCSID("$NetBSD: header.c,v 1.10 2019/03/14 10:26:10 mlelstv Exp $"); #endif #include @@ -90,11 +90,11 @@ header(gpt_t gpt) revision = le32toh(hdr->hdr_revision); printf("- GPT Header Revision: %u.%u\n", revision >> 16, revision & 0x); - gpt_show_num("- First Data Sector", hdr->hdr_lba_start); - gpt_show_num("- Last Data Sector", hdr->hdr_lba_end); + gpt_show_num("- First Data Sector", le64toh(hdr->hdr_lba_start)); + gpt_show_num("- Last Data Sector", le64toh(hdr->hdr_lba_end)); gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid); printf("- Media GUID: %s\n", buf); - printf("- Number of GPT Entries: %u\n", hdr->hdr_entries); + printf("- Number of GPT Entries: %u\n", le32toh(hdr->hdr_entries)); return 0; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Sun Mar 3 03:20:43 UTC 2019 Modified Files: src/sbin/gpt: show.c Log Message: Make it clear when displaying data from the MBR. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.41 src/sbin/gpt/show.c:1.42 --- src/sbin/gpt/show.c:1.41 Thu Sep 7 10:23:33 2017 +++ src/sbin/gpt/show.c Sun Mar 3 03:20:42 2019 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.41 2017/09/07 10:23:33 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.42 2019/03/03 03:20:42 jnemeth Exp $"); #endif #include @@ -344,6 +344,9 @@ cmd_show(gpt_t gpt, int argc, char *argv if (argc != optind) return usage(); + if (map_find(gpt, MAP_TYPE_PRI_GPT_HDR) == NULL) + printf("GPT not found, displaying data from MBR.\n\n"); + if (xshow & SHOW_ALL) return show_all(gpt);
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Sun Mar 3 02:28:14 UTC 2019 Modified Files: src/sbin/gpt: migrate.c Log Message: add some more FAT file system types To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sbin/gpt/migrate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.34 src/sbin/gpt/migrate.c:1.35 --- src/sbin/gpt/migrate.c:1.34 Sun Feb 10 10:35:51 2019 +++ src/sbin/gpt/migrate.c Sun Mar 3 02:28:14 2019 @@ -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.34 2019/02/10 10:35:51 martin Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.35 2019/03/03 02:28:14 jnemeth Exp $"); #endif #include @@ -289,13 +289,20 @@ migrate(gpt_t gpt, u_int parts, int forc type = GPT_TYPE_EFI; break; - case MBR_PTYPE_NTFS: case MBR_PTYPE_FAT12: case MBR_PTYPE_FAT16S: case MBR_PTYPE_FAT16B: + case MBR_PTYPE_NTFS: case MBR_PTYPE_FAT32: case MBR_PTYPE_FAT32L: case MBR_PTYPE_FAT16L: + case MBR_PTYPE_OS2_DOS12: + case MBR_PTYPE_OS2_DOS16S: + case MBR_PTYPE_OS2_DOS16B: + case MBR_PTYPE_OS2_IFS: + case MBR_PTYPE_HID_FAT32: + case MBR_PTYPE_HID_FAT32_LBA: + case MBR_PTYPE_HID_FAT16_LBA: type = GPT_TYPE_MS_BASIC_DATA; break;
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Sun Feb 10 10:35:51 UTC 2019 Modified Files: src/sbin/gpt: migrate.c Log Message: Make "gpt migrate" work for disks with FAT32 and NTFS partitions To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/sbin/gpt/migrate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.33 src/sbin/gpt/migrate.c:1.34 --- src/sbin/gpt/migrate.c:1.33 Tue Jul 3 03:41:24 2018 +++ src/sbin/gpt/migrate.c Sun Feb 10 10:35:51 2019 @@ -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.33 2018/07/03 03:41:24 jnemeth Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.34 2019/02/10 10:35:51 martin Exp $"); #endif #include @@ -289,6 +289,16 @@ migrate(gpt_t gpt, u_int parts, int forc type = GPT_TYPE_EFI; break; + case MBR_PTYPE_NTFS: + case MBR_PTYPE_FAT12: + case MBR_PTYPE_FAT16S: + case MBR_PTYPE_FAT16B: + case MBR_PTYPE_FAT32: + case MBR_PTYPE_FAT32L: + case MBR_PTYPE_FAT16L: + type = GPT_TYPE_MS_BASIC_DATA; + break; + default: if (!force) { gpt_warnx(gpt, "unknown partition type (%d)",
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Sun Jan 27 13:16:05 UTC 2019 Modified Files: src/sbin/gpt: gpt.c Log Message: Fix three MBR extended partition related bugs: 1) when walking an extended MBR chain, do not assign duplicate indices 2) the pointer to the next MBR may be any of the MBR_PTYPE_EXT* variants 3) the ext MBR chain links are relative to the primary extended partition, unlike the contained partitions which are relative to the extended MBR block address. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.76 src/sbin/gpt/gpt.c:1.77 --- src/sbin/gpt/gpt.c:1.76 Sun Oct 14 20:10:49 2018 +++ src/sbin/gpt/gpt.c Sun Jan 27 13:16:05 2019 @@ -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.76 2018/10/14 20:10:49 mlelstv Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.77 2019/01/27 13:16:05 martin Exp $"); #endif #include @@ -279,7 +279,7 @@ gpt_write(gpt_t gpt, map_t map) } static int -gpt_mbr(gpt_t gpt, off_t lba) +gpt_mbr(gpt_t gpt, off_t lba, unsigned int *next_index, off_t ext_offset) { struct mbr *mbr; map_t m, p; @@ -345,20 +345,22 @@ gpt_mbr(gpt_t gpt, off_t lba) (uintmax_t)lba); continue; } - /* start is relative to the offset of the MBR itself. */ - start += lba; if (gpt->verbose > 2) 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) { + if (!MBR_IS_EXTENDED(mbr->mbr_part[i].part_typ)) { + start += lba; m = map_add(gpt, start, size, MAP_TYPE_MBR_PART, p, 0); if (m == NULL) return -1; - m->map_index = i + 1; + m->map_index = *next_index; + (*next_index)++; } else { - if (gpt_mbr(gpt, start) == -1) + start += ext_offset; + if (gpt_mbr(gpt, start, next_index, + ext_offset ? ext_offset : start) == -1) return -1; } } @@ -479,7 +481,7 @@ gpt_open(const char *dev, int flags, int int mode, found; off_t devsz; gpt_t gpt; - + unsigned int index; if ((gpt = calloc(1, sizeof(*gpt))) == NULL) { if (!(flags & GPT_QUIET)) @@ -567,7 +569,8 @@ gpt_open(const char *dev, int flags, int if (map_init(gpt, devsz) == -1) goto close; - if (gpt_mbr(gpt, 0LL) == -1) + index = 1; + if (gpt_mbr(gpt, 0LL, , 0U) == -1) goto close; if ((found = gpt_gpt(gpt, 1LL, 1)) == -1) goto close;
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Thu Dec 20 14:58:10 UTC 2018 Modified Files: src/sbin/gpt: gpt_uuid.c gpt_uuid.h Log Message: Add a query function (for external code) to enumerate the know guids. Add recently added VMware GUIDs to the internal enum type. Fix some short names (bogus + duplicate). To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/gpt_uuid.c cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/gpt_uuid.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt_uuid.c diff -u src/sbin/gpt/gpt_uuid.c:1.16 src/sbin/gpt/gpt_uuid.c:1.17 --- src/sbin/gpt/gpt_uuid.c:1.16 Tue Nov 6 04:04:33 2018 +++ src/sbin/gpt/gpt_uuid.c Thu Dec 20 14:58:10 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $ */ +/* $NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: gpt_uuid.c,v 1.16 2018/11/06 04:04:33 mrg Exp $"); +__RCSID("$NetBSD: gpt_uuid.c,v 1.17 2018/12/20 14:58:10 martin Exp $"); #endif #include @@ -87,9 +87,9 @@ static const struct { { GPT_ENT_TYPE_NETBSD_RAIDFRAME, "raid", "NetBSD RAIDFrame component" }, { GPT_ENT_TYPE_NETBSD_SWAP, "swap", "NetBSD swap" }, - { GPT_ENT_TYPE_VMWARE_VMKCORE, "swap", "VMware VMkernel core dump" }, - { GPT_ENT_TYPE_VMWARE_VMFS, "swap", "VMware VMFS" }, - { GPT_ENT_TYPE_VMWARE_RESERVED, "swap", "VMware reserved" }, + { GPT_ENT_TYPE_VMWARE_VMKCORE, "vmcore", "VMware VMkernel core dump" }, + { GPT_ENT_TYPE_VMWARE_VMFS, "vmfs", "VMware VMFS" }, + { GPT_ENT_TYPE_VMWARE_RESERVED, "vmresered", "VMware reserved" }, }; static void @@ -234,6 +234,23 @@ gpt_uuid_parse(const char *s, gpt_uuid_t return 0; } +size_t +gpt_uuid_query( +void (*func)(const char *uuid, const char *short_name, const char *desc)) +{ + size_t i; + char buf[64]; + + if (func != NULL) { + for (i = 0; i < __arraycount(gpt_nv); i++) { + gpt_uuid_numeric(buf, sizeof(buf), _nv[i].u); + (*func)(buf, gpt_nv[i].n, gpt_nv[i].d); + } + } + return __arraycount(gpt_nv); +} + +#ifndef GPT_UUID_QUERY_ONLY void gpt_uuid_help(const char *prefix) { @@ -323,3 +340,4 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t gpt_dce_to_uuid(, t); return 0; } +#endif Index: src/sbin/gpt/gpt_uuid.h diff -u src/sbin/gpt/gpt_uuid.h:1.7 src/sbin/gpt/gpt_uuid.h:1.8 --- src/sbin/gpt/gpt_uuid.h:1.7 Sun Dec 6 04:27:05 2015 +++ src/sbin/gpt/gpt_uuid.h Thu Dec 20 14:58:10 2018 @@ -67,7 +67,10 @@ typedef enum { GPT_TYPE_NETBSD_FFS, GPT_TYPE_NETBSD_LFS, GPT_TYPE_NETBSD_RAIDFRAME, - GPT_TYPE_NETBSD_SWAP + GPT_TYPE_NETBSD_SWAP, + GPT_TYPE_VMWARE_VMKCORE, + GPT_TYPE_VMWARE_VMFS, + GPT_TYPE_VMWARE_RESERVED } gpt_type_t; typedef uint8_t gpt_uuid_t[16]; @@ -98,6 +101,10 @@ int gpt_uuid_parse(const char *, gpt_uui struct gpt; int gpt_uuid_generate(struct gpt *, gpt_uuid_t); +/* returns number of entries, callback func may be NULL */ +size_t gpt_uuid_query( +void (*func)(const char *uuid, const char *short_name, const char *desc)); + void gpt_uuid_help(const char *); __END_DECLS
CVS commit: src/sbin/gpt
Module Name:src Committed By: mlelstv Date: Sun Oct 14 20:10:49 UTC 2018 Modified Files: src/sbin/gpt: gpt.c Log Message: When changing entries skip those that do not match the -L option. Should fix PR 53668. To generate a diff of this commit: cvs rdiff -u -r1.75 -r1.76 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.75 src/sbin/gpt/gpt.c:1.76 --- src/sbin/gpt/gpt.c:1.75 Tue Jul 3 03:41:23 2018 +++ src/sbin/gpt/gpt.c Sun Oct 14 20:10:49 2018 @@ -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.75 2018/07/03 03:41:23 jnemeth Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.76 2018/10/14 20:10:49 mlelstv Exp $"); #endif #include @@ -1043,7 +1043,7 @@ gpt_change_ent(gpt_t gpt, const struct g utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name), utfbuf, __arraycount(utfbuf)); - if (strcmp((char *)find->label, (char *)utfbuf) == 0) + if (strcmp((char *)find->label, (char *)utfbuf) != 0) continue; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: sevan Date: Mon Aug 27 15:50:39 UTC 2018 Modified Files: src/sbin/gpt: main.c Log Message: Add the -T flag to usage() To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.11 src/sbin/gpt/main.c:1.12 --- src/sbin/gpt/main.c:1.11 Mon Mar 19 09:06:20 2018 +++ src/sbin/gpt/main.c Mon Aug 27 15:50:39 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $ */ +/* $NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $"); +__RCSID("$NetBSD: main.c,v 1.12 2018/08/27 15:50:39 sevan Exp $"); #endif #include @@ -105,7 +105,7 @@ usage(void) { const char *p = getprogname(); const char *f = - "[-nrqv] [-m mediasize] [-s sectorsize]"; + "[-nrqv] [-m mediasize] [-s sectorsize] [-T timestamp]"; size_t i; if (strcmp(p, "gpt") == 0)
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Tue Jul 3 03:41:24 UTC 2018 Modified Files: src/sbin/gpt: add.c gpt.c gpt.h label.c migrate.c recover.c remove.c resize.c restore.c type.c Log Message: Not all things that write to the disk do something that dk(4) will be interested in. Let individual commands decide if ioctl(DIOCMWEDGES) should be done. I was conservative and set the flag on any command that might create/modify/delete partitions in any way. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/add.c cvs rdiff -u -r1.74 -r1.75 src/sbin/gpt/gpt.c cvs rdiff -u -r1.37 -r1.38 src/sbin/gpt/gpt.h cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/label.c cvs rdiff -u -r1.32 -r1.33 src/sbin/gpt/migrate.c cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/recover.c src/sbin/gpt/restore.c cvs rdiff -u -r1.21 -r1.22 src/sbin/gpt/remove.c cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/resize.c cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/type.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.43 src/sbin/gpt/add.c:1.44 --- src/sbin/gpt/add.c:1.43 Tue Dec 29 16:45:04 2015 +++ src/sbin/gpt/add.c Tue Jul 3 03:41:23 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.43 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.44 2018/07/03 03:41:23 jnemeth Exp $"); #endif #include @@ -62,7 +62,7 @@ struct gpt_cmd c_add = { "add", cmd_add, addhelp, __arraycount(addhelp), - 0, + GPT_SYNC, }; #define usage() gpt_usage(NULL, _add) Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.74 src/sbin/gpt/gpt.c:1.75 --- src/sbin/gpt/gpt.c:1.74 Tue Feb 13 00:34:11 2018 +++ src/sbin/gpt/gpt.c Tue Jul 3 03:41:23 2018 @@ -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.74 2018/02/13 00:34:11 sevan Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.75 2018/07/03 03:41:23 jnemeth Exp $"); #endif #include @@ -587,7 +587,7 @@ void gpt_close(gpt_t gpt) { - if (!(gpt->flags & GPT_MODIFIED)) + if (!(gpt->flags & GPT_MODIFIED) || !(gpt->flags & GPT_SYNC)) goto out; if (!(gpt->flags & GPT_NOSYNC)) { Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.37 src/sbin/gpt/gpt.h:1.38 --- src/sbin/gpt/gpt.h:1.37 Mon Mar 19 09:06:20 2018 +++ src/sbin/gpt/gpt.h Tue Jul 3 03:41:23 2018 @@ -81,6 +81,7 @@ gpt_t gpt_open(const char *, int, int, o #define GPT_NOSYNC 0x08 #define GPT_FILE 0x10 #define GPT_TIMESTAMP 0x20 +#define GPT_SYNC 0x40 #define GPT_OPTDEV 0x8000 void* gpt_read(gpt_t, off_t, size_t); Index: src/sbin/gpt/label.c diff -u src/sbin/gpt/label.c:1.28 src/sbin/gpt/label.c:1.29 --- src/sbin/gpt/label.c:1.28 Fri Dec 4 01:47:48 2015 +++ src/sbin/gpt/label.c Tue Jul 3 03:41:24 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: label.c,v 1.28 2015/12/04 01:47:48 christos Exp $"); +__RCSID("$NetBSD: label.c,v 1.29 2018/07/03 03:41:24 jnemeth Exp $"); #endif #include @@ -62,7 +62,7 @@ struct gpt_cmd c_label = { "label", cmd_label, labelhelp, __arraycount(labelhelp), - 0, + GPT_SYNC, }; #define usage() gpt_usage(NULL, _label) Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.32 src/sbin/gpt/migrate.c:1.33 --- src/sbin/gpt/migrate.c:1.32 Thu Jun 9 19:04:43 2016 +++ src/sbin/gpt/migrate.c Tue Jul 3 03:41:24 2018 @@ -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.32 2016/06/09 19:04:43 christos Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.33 2018/07/03 03:41:24 jnemeth Exp $"); #endif #include @@ -88,7 +88,7 @@ struct gpt_cmd c_migrate = { "migrate", cmd_migrate, migratehelp, __arraycount(migratehelp), - 0, + GPT_SYNC, }; #define usage() gpt_usage(NULL, _migrate) Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.17 src/sbin/gpt/recover.c:1.18 --- src/sbin/gpt/recover.c:1.17 Wed Mar 22 19:59:16 2017 +++ src/sbin/gpt/recover.c Tue Jul 3 03:41:24 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.17 2017/03/22 19:59:16 martin Exp $"); +__RCSID("$NetBSD: recover.c,v 1.18 2018/07/03 03:41:24 jnemeth Exp $"); #endif #include @@ -59,7 +59,7 @@ struct gpt_cmd c_recover = { "recover", cmd_recover, recoverhelp, __arraycount(recoverhelp), - 0, + GPT_SYNC, }; #define usage() gpt_usage(NULL, _recover) Index: src/sbin/gpt/restore.c diff -u src/sbin/gpt/restore.c:1.17 src/sbin/gpt/restore.c:1.18 --- src/sbin/gpt/restore.c:1.17 Thu Sep 7 10:23:33
CVS commit: src/sbin/gpt
Module Name:src Committed By: kre Date: Tue May 1 21:16:02 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 Log Message: Spello. (it is "existence"). ispell also says that we should s/parseable/parsable/ but I'm not sure about that one, so I left it. I also left a correct spelling that no-one has bothered to mangle! To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.62 src/sbin/gpt/gpt.8:1.63 --- src/sbin/gpt/gpt.8:1.62 Tue May 1 21:04:01 2018 +++ src/sbin/gpt/gpt.8 Tue May 1 21:16:02 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.62 2018/05/01 21:04:01 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.63 2018/05/01 21:16:02 kre Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -683,7 +683,7 @@ The .Nm command exits with a failure status (1) when the header command is used and no GPT header is found. -This can be used to check for the existance of a GPT in shell scripts. +This can be used to check for the existence of a GPT in shell scripts. .Sh EXAMPLES .Bd -literal nas# gpt show wd3
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Tue May 1 21:04:01 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 Log Message: Bump date for new EXIT STATUS section. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.61 src/sbin/gpt/gpt.8:1.62 --- src/sbin/gpt/gpt.8:1.61 Tue May 1 21:03:37 2018 +++ src/sbin/gpt/gpt.8 Tue May 1 21:04:01 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.61 2018/05/01 21:03:37 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.62 2018/05/01 21:04:01 wiz 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 March 5, 2018 +.Dd May 1, 2018 .Dt GPT 8 .Os .Sh NAME
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Tue May 1 21:03:37 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 Log Message: Sort sections. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.60 src/sbin/gpt/gpt.8:1.61 --- src/sbin/gpt/gpt.8:1.60 Tue May 1 08:17:13 2018 +++ src/sbin/gpt/gpt.8 Tue May 1 21:03:37 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.60 2018/05/01 08:17:13 martin Exp $ +.\" $NetBSD: gpt.8,v 1.61 2018/05/01 21:03:37 wiz Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -678,6 +678,12 @@ They may be used by .Nx code in the future. .El +.Sh EXIT STATUS +The +.Nm +command exits with a failure status (1) when the header command +is used and no GPT header is found. +This can be used to check for the existance of a GPT in shell scripts. .Sh EXAMPLES .Bd -literal nas# gpt show wd3 @@ -735,12 +741,6 @@ xotica# installboot /dev/rdk0 /usr/mdec/ xotica# mount /dev/dk0 /mnt xotica# cp /usr/mdec/boot /mnt .Ed -.Sh EXIT STATUS -The -.Nm -command exits with a failure status (1) when the header command -is used and no GPT header is found. -This can be used to check for the existance of a GPT in shell scripts. .Sh SEE ALSO .Xr boot 8 , .Xr dkctl 8 ,
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Tue May 1 08:17:13 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 header.c Log Message: Make the "gpt header" command return EXIT_FAILURE when no GPT is present. This helps sysinst to tell a GPT labeled disk from others. Very lazy version of a change proposed by kre. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.8 -r1.9 src/sbin/gpt/header.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.59 src/sbin/gpt/gpt.8:1.60 --- src/sbin/gpt/gpt.8:1.59 Wed Apr 11 07:13:18 2018 +++ src/sbin/gpt/gpt.8 Tue May 1 08:17:13 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.59 2018/04/11 07:13:18 mrg Exp $ +.\" $NetBSD: gpt.8,v 1.60 2018/05/01 08:17:13 martin Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -735,6 +735,12 @@ xotica# installboot /dev/rdk0 /usr/mdec/ xotica# mount /dev/dk0 /mnt xotica# cp /usr/mdec/boot /mnt .Ed +.Sh EXIT STATUS +The +.Nm +command exits with a failure status (1) when the header command +is used and no GPT header is found. +This can be used to check for the existance of a GPT in shell scripts. .Sh SEE ALSO .Xr boot 8 , .Xr dkctl 8 , Index: src/sbin/gpt/header.c diff -u src/sbin/gpt/header.c:1.8 src/sbin/gpt/header.c:1.9 --- src/sbin/gpt/header.c:1.8 Thu Dec 24 17:35:57 2015 +++ src/sbin/gpt/header.c Tue May 1 08:17:13 2018 @@ -33,7 +33,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: header.c,v 1.8 2015/12/24 17:35:57 martin Exp $"); +__RCSID("$NetBSD: header.c,v 1.9 2018/05/01 08:17:13 martin Exp $"); #endif #include @@ -83,7 +83,7 @@ header(gpt_t gpt) map = map_find(gpt, MAP_TYPE_PRI_GPT_HDR); if (map == NULL) { printf("- GPT Header not found\n"); - return 0; + return -1; } hdr = map->map_data;
CVS commit: src/sbin/gpt
Module Name:src Committed By: mrg Date: Wed Apr 11 07:14:23 UTC 2018 Modified Files: src/sbin/gpt: map.c Log Message: if a new map entry doesn't fit, be more verbose about the sizes. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/map.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/map.c diff -u src/sbin/gpt/map.c:1.13 src/sbin/gpt/map.c:1.14 --- src/sbin/gpt/map.c:1.13 Thu Dec 3 21:30:54 2015 +++ src/sbin/gpt/map.c Wed Apr 11 07:14:23 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/map.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: map.c,v 1.13 2015/12/03 21:30:54 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.14 2018/04/11 07:14:23 mrg Exp $"); #endif #include @@ -117,7 +117,10 @@ map_add(gpt_t gpt, off_t start, off_t si if (n->map_start + n->map_size < start + size) { if (!(gpt->flags & GPT_QUIET)) - gpt_warnx(gpt, "map entry doesn't fit media"); + gpt_warnx(gpt, "map entry doesn't fit media: " + "new start + new size < start + size\n" + "(%jx + %jx < %jx + %jx)", + n->map_start, n->map_size, start, size); return NULL; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: mrg Date: Wed Apr 11 07:13:18 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 Log Message: add information about how to boot from gpt. mostly taken from the wiki. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.58 src/sbin/gpt/gpt.8:1.59 --- src/sbin/gpt/gpt.8:1.58 Mon Mar 19 09:06:20 2018 +++ src/sbin/gpt/gpt.8 Wed Apr 11 07:13:18 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.58 2018/03/19 09:06:20 mlelstv Exp $ +.\" $NetBSD: gpt.8,v 1.59 2018/04/11 07:13:18 mrg 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 January 15, 2018 +.Dd March 5, 2018 .Dt GPT 8 .Os .Sh NAME @@ -716,6 +716,25 @@ nas# gpt show -l wd3 3907029167 1 Sec GPT header nas# .Ed +.Pp +Booting from GPT on an BIOS system. +This creates a bootable partition that can be manually installed to. +Note that +.Xr sysinst 8 +does not yet properly support this setup. +.Bd -literal +xotica# gpt create wd1 +xotica# gpt add -b 1024 -l bootroot -t ffs -s 1g wd1 +/dev/rwd1: Partition 1 added: 49f48d5a-b10e-11dc-b99b-0019d1879648 1024 2097152 +xotica ~# dmesg | tail -2 +wd1: GPT GUID: 660e0630-0a3f-47c0-bc52-c88bcec79392 +dk0 at wd1: "bootroot", 2097152 blocks at 1024, type: ffs +xotica# gpt biosboot -L bootroot wd1 +xotica# newfs dk0 +xotica# installboot /dev/rdk0 /usr/mdec/bootxx_ffsv1 +xotica# mount /dev/dk0 /mnt +xotica# cp /usr/mdec/boot /mnt +.Ed .Sh SEE ALSO .Xr boot 8 , .Xr dkctl 8 , @@ -723,7 +742,7 @@ nas# .Xr installboot 8 , .Xr mount 8 , .Xr newfs 8 , -.Xr swapon 8 +.Xr swapctl 8 .Sh HISTORY The .Nm
CVS commit: src/sbin/gpt
Module Name:src Committed By: mlelstv Date: Mon Mar 19 09:06:21 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 gpt.h main.c set.c type.c unset.c Log Message: Check device parameter to avoid segfaults. Agument synopsis for -l option. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.36 -r1.37 src/sbin/gpt/gpt.h cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/main.c cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/set.c src/sbin/gpt/type.c \ src/sbin/gpt/unset.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.57 src/sbin/gpt/gpt.8:1.58 --- src/sbin/gpt/gpt.8:1.57 Mon Jan 15 12:20:47 2018 +++ src/sbin/gpt/gpt.8 Mon Mar 19 09:06:20 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.57 2018/01/15 12:20:47 sborrill Exp $ +.\" $NetBSD: gpt.8,v 1.58 2018/03/19 09:06:20 mlelstv Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -41,6 +41,15 @@ .Ar command .Op Ar command_options .Ar device +.Nm +.Ar set +.Fl l +.Nm +.Ar unset +.Fl l +.Nm +.Ar type +.Fl l .Sh DESCRIPTION The .Nm Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.36 src/sbin/gpt/gpt.h:1.37 --- src/sbin/gpt/gpt.h:1.36 Wed Sep 6 18:17:18 2017 +++ src/sbin/gpt/gpt.h Mon Mar 19 09:06:20 2018 @@ -81,6 +81,7 @@ gpt_t gpt_open(const char *, int, int, o #define GPT_NOSYNC 0x08 #define GPT_FILE 0x10 #define GPT_TIMESTAMP 0x20 +#define GPT_OPTDEV 0x8000 void* gpt_read(gpt_t, off_t, size_t); off_t gpt_last(gpt_t); Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.10 src/sbin/gpt/main.c:1.11 --- src/sbin/gpt/main.c:1.10 Thu Feb 16 22:40:19 2017 +++ src/sbin/gpt/main.c Mon Mar 19 09:06:20 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $ */ +/* $NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $"); #endif #include @@ -241,6 +241,9 @@ main(int argc, char *argv[]) if (gpt == NULL) return EXIT_FAILURE; } else { + if ((cmdsw[i]->flags & GPT_OPTDEV) == 0) + errx(EXIT_FAILURE, + "Command %s needs a device parameter", cmd); argc++; gpt = NULL; } Index: src/sbin/gpt/set.c diff -u src/sbin/gpt/set.c:1.13 src/sbin/gpt/set.c:1.14 --- src/sbin/gpt/set.c:1.13 Tue Dec 29 16:45:04 2015 +++ src/sbin/gpt/set.c Mon Mar 19 09:06:20 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: set.c,v 1.13 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: set.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $"); #endif #include @@ -60,7 +60,7 @@ struct gpt_cmd c_set = { "set", cmd_set, sethelp, __arraycount(sethelp), - 0, + GPT_OPTDEV, }; #define usage() gpt_usage(NULL, _set) @@ -75,11 +75,11 @@ cmd_set(gpt_t gpt, int argc, char *argv[ while ((ch = getopt(argc, argv, "a:i:l")) != -1) { switch(ch) { case 'a': - if (gpt_attr_get(gpt, ) == -1) + if (gpt == NULL || gpt_attr_get(gpt, ) == -1) return usage(); break; case 'i': - if (gpt_uint_get(gpt, ) == -1) + if (gpt == NULL || gpt_uint_get(gpt, ) == -1) return usage(); break; case 'l': @@ -90,7 +90,7 @@ cmd_set(gpt_t gpt, int argc, char *argv[ } } - if (argc != optind) + if (gpt == NULL || argc != optind) return usage(); return gpt_attr_update(gpt, entry, attributes, 0); Index: src/sbin/gpt/type.c diff -u src/sbin/gpt/type.c:1.13 src/sbin/gpt/type.c:1.14 --- src/sbin/gpt/type.c:1.13 Sun Dec 6 00:39:26 2015 +++ src/sbin/gpt/type.c Mon Mar 19 09:06:20 2018 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: type.c,v 1.13 2015/12/06 00:39:26 christos Exp $"); +__RCSID("$NetBSD: type.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $"); #endif #include @@ -61,7 +61,7 @@ struct gpt_cmd c_type = { "type", cmd_type, typehelp, __arraycount(typehelp), - 0, + GPT_OPTDEV, }; #define usage() gpt_usage(NULL, _type) @@ -91,17 +91,17 @@ cmd_type(gpt_t gpt, int argc, char *argv gpt_uuid_help("\t"); return 0; case 'T': - if (gpt_uuid_get(gpt, ) == -1) + if (gpt == NULL || gpt_uuid_get(gpt, ) == -1) return -1; break; default: - if (gpt_add_find(gpt, , ch) == -1) + if (gpt == NULL || gpt_add_find(gpt, , ch) == -1) return usage(); break; } } - if (gpt_uuid_is_nil(newtype) || argc != optind) + if (gpt == NULL || gpt_uuid_is_nil(newtype) || argc != optind) return usage(); return gpt_change_ent(gpt, , change, ); Index: src/sbin/gpt/unset.c diff -u src/sbin/gpt/unset.c:1.13 src/sbin/gpt/unset.c:1.14 ---
CVS commit: src/sbin/gpt
Module Name:src Committed By: sevan Date: Tue Feb 13 00:34:11 UTC 2018 Modified Files: src/sbin/gpt: gpt.c Log Message: Spelling To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.73 src/sbin/gpt/gpt.c:1.74 --- src/sbin/gpt/gpt.c:1.73 Thu Sep 7 10:23:33 2017 +++ src/sbin/gpt/gpt.c Tue Feb 13 00:34:11 2018 @@ -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.73 2017/09/07 10:23:33 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.74 2018/02/13 00:34:11 sevan Exp $"); #endif #include @@ -1165,7 +1165,7 @@ gpt_attr_get(gpt_t gpt, uint64_t *attrib if (strcmp(gpt_attr[i].name, ptr) == 0) break; if (i == __arraycount(gpt_attr)) { - gpt_warnx(gpt, "Unregognized attribute `%s'", ptr); + gpt_warnx(gpt, "Unrecognized attribute `%s'", ptr); rv = -1; } else *attributes |= gpt_attr[i].mask;
CVS commit: src/sbin/gpt
Module Name:src Committed By: sborrill Date: Mon Jan 15 12:20:47 UTC 2018 Modified Files: src/sbin/gpt: gpt.8 Log Message: Explain what suffixes are accepted when specifying a size. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.56 src/sbin/gpt/gpt.8:1.57 --- src/sbin/gpt/gpt.8:1.56 Tue Oct 3 06:55:04 2017 +++ src/sbin/gpt/gpt.8 Mon Jan 15 12:20:47 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.56 2017/10/03 06:55:04 mlelstv Exp $ +.\" $NetBSD: gpt.8,v 1.57 2018/01/15 12:20:47 sborrill 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 August 3, 2017 +.Dd January 15, 2018 .Dt GPT 8 .Os .Sh NAME @@ -154,6 +154,15 @@ or .Sq S then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. +Accepted suffix units are +.Sq b +to denote bytes, +.Sq k +to denote kilobytes, +.Sq m +to denote megabytes and +.Sq g +to denote gigabytes. The minimum size is 1 sector. .Pp The @@ -465,6 +474,15 @@ or .Sq S then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. +Accepted suffix units are +.Sq b +to denote bytes, +.Sq k +to denote kilobytes, +.Sq m +to denote megabytes and +.Sq g +to denote gigabytes. The minimum size is 1 sector. If the .Fl a @@ -494,6 +512,15 @@ or .Sq S then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. +Accepted suffix units are +.Sq b +to denote bytes, +.Sq k +to denote kilobytes, +.Sq m +to denote megabytes and +.Sq g +to denote gigabytes. Using the .Fl s option allows you to move the backup copy prior to resizing the medium.
CVS commit: src/sbin/gpt
Module Name:src Committed By: mlelstv Date: Tue Oct 3 06:55:04 UTC 2017 Modified Files: src/sbin/gpt: gpt.8 Log Message: clarify that alignment is the number of bytes to align to. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.55 src/sbin/gpt/gpt.8:1.56 --- src/sbin/gpt/gpt.8:1.55 Sat Aug 5 20:21:08 2017 +++ src/sbin/gpt/gpt.8 Tue Oct 3 06:55:04 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.55 2017/08/05 20:21:08 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.56 2017/10/03 06:55:04 mlelstv Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -123,7 +123,8 @@ The command-specific options can be used The .Fl a Ar alignment option allows the user to specify an alignment for the start and size. -The alignment may have a suffix to indicate its magnitude. +The alignment is given in bytes and may have a suffix to indicate its +magnitude. .Nm will attempt to align the partition. .Pp
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Sep 7 10:23:33 UTC 2017 Modified Files: src/sbin/gpt: backup.c biosboot.c gpt.c restore.c show.c Log Message: use __arraycount To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/backup.c cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.72 -r1.73 src/sbin/gpt/gpt.c cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/restore.c cvs rdiff -u -r1.40 -r1.41 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.17 src/sbin/gpt/backup.c:1.18 --- src/sbin/gpt/backup.c:1.17 Wed Sep 6 14:17:18 2017 +++ src/sbin/gpt/backup.c Thu Sep 7 06:23:33 2017 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.17 2017/09/06 18:17:18 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.18 2017/09/07 10:23:33 christos Exp $"); #endif #include @@ -231,8 +231,8 @@ store_tbl(gpt_t gpt, const map_t m, prop PROP_ERR(propnum); rc = prop_dictionary_set(gpt_dict, "attributes", propnum); PROP_ERR(rc); - utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), utfbuf, - sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name), + utfbuf, __arraycount(utfbuf)); if (utfbuf[0] != '\0') { propstr = prop_string_create_cstring((char *)utfbuf); PROP_ERR(propstr); Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.29 src/sbin/gpt/biosboot.c:1.30 --- src/sbin/gpt/biosboot.c:1.29 Wed Sep 6 14:17:18 2017 +++ src/sbin/gpt/biosboot.c Thu Sep 7 06:23:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.29 2017/09/06 18:17:18 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.29 2017/09/06 18:17:18 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.30 2017/09/07 10:23:33 christos Exp $"); #endif #include @@ -219,8 +219,9 @@ biosboot(gpt_t gpt, daddr_t start, uint6 break; if (label != NULL) { - utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), - utfbuf, sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, + __arraycount(ent->ent_name), utfbuf, + __arraycount(utfbuf)); if (strcmp((char *)label, (char *)utfbuf) == 0) break; } Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.72 src/sbin/gpt/gpt.c:1.73 --- src/sbin/gpt/gpt.c:1.72 Wed Sep 6 14:17:18 2017 +++ src/sbin/gpt/gpt.c Thu Sep 7 06:23:33 2017 @@ -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.72 2017/09/06 18:17:18 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.73 2017/09/07 10:23:33 christos Exp $"); #endif #include @@ -1040,8 +1040,9 @@ gpt_change_ent(gpt_t gpt, const struct g ent = gpt_ent_primary(gpt, i); if (find->label != NULL) { - utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), - utfbuf, sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, + __arraycount(ent->ent_name), + utfbuf, __arraycount(utfbuf)); if (strcmp((char *)find->label, (char *)utfbuf) == 0) continue; } Index: src/sbin/gpt/restore.c diff -u src/sbin/gpt/restore.c:1.16 src/sbin/gpt/restore.c:1.17 --- src/sbin/gpt/restore.c:1.16 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/restore.c Thu Sep 7 06:23:33 2017 @@ -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: restore.c,v 1.16 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: restore.c,v 1.17 2017/09/07 10:23:33 christos Exp $"); #endif #include @@ -178,7 +178,7 @@ restore_ent(gpt_t gpt, prop_dictionary_t if (propstr != NULL) { s = prop_string_cstring_nocopy(propstr); utf8_to_utf16((const uint8_t *)s, ent.ent_name, - __arraycount(ent.ent_name)); + __arraycount(ent.ent_name)); } propnum = prop_dictionary_get(gpt_dict, "index"); PROP_ERR(propnum); Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.40 src/sbin/gpt/show.c:1.41 --- src/sbin/gpt/show.c:1.40 Wed Sep 6 14:17:18 2017 +++ src/sbin/gpt/show.c Thu Sep 7 06:23:33 2017 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.40 2017/09/06 18:17:18 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.41 2017/09/07 10:23:33 christos Exp $"); #endif #include @@ -129,8 +129,9 @@ print_part_type(int map_type, int flags, printf("GPT part "); ent = map_data; if (flags & SHOW_LABEL) { - utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), - utfbuf, sizeof(utfbuf)); +
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Sep 6 18:17:18 UTC 2017 Modified Files: src/sbin/gpt: backup.c biosboot.c gpt.c gpt.h show.c Log Message: - make sure that the utf16 string is padded with 0's where needed. - since the utf16 string is not 0 terminated, pass the size of the string. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/backup.c cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.71 -r1.72 src/sbin/gpt/gpt.c cvs rdiff -u -r1.35 -r1.36 src/sbin/gpt/gpt.h cvs rdiff -u -r1.39 -r1.40 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.16 src/sbin/gpt/backup.c:1.17 --- src/sbin/gpt/backup.c:1.16 Thu Dec 3 16:40:32 2015 +++ src/sbin/gpt/backup.c Wed Sep 6 14:17:18 2017 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.16 2015/12/03 21:40:32 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.17 2017/09/06 18:17:18 christos Exp $"); #endif #include @@ -231,7 +231,8 @@ store_tbl(gpt_t gpt, const map_t m, prop PROP_ERR(propnum); rc = prop_dictionary_set(gpt_dict, "attributes", propnum); PROP_ERR(rc); - utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), utfbuf, + sizeof(utfbuf)); if (utfbuf[0] != '\0') { propstr = prop_string_create_cstring((char *)utfbuf); PROP_ERR(propstr); Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.28 src/sbin/gpt/biosboot.c:1.29 --- src/sbin/gpt/biosboot.c:1.28 Mon Jul 3 02:44:58 2017 +++ src/sbin/gpt/biosboot.c Wed Sep 6 14:17:18 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.28 2017/07/03 06:44:58 mrg Exp $ */ +/* $NetBSD: biosboot.c,v 1.29 2017/09/06 18:17:18 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.28 2017/07/03 06:44:58 mrg Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.29 2017/09/06 18:17:18 christos Exp $"); #endif #include @@ -219,7 +219,8 @@ biosboot(gpt_t gpt, daddr_t start, uint6 break; if (label != NULL) { - utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), + utfbuf, sizeof(utfbuf)); if (strcmp((char *)label, (char *)utfbuf) == 0) break; } Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.71 src/sbin/gpt/gpt.c:1.72 --- src/sbin/gpt/gpt.c:1.71 Tue Sep 5 14:30:46 2017 +++ src/sbin/gpt/gpt.c Wed Sep 6 14:17:18 2017 @@ -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.71 2017/09/05 18:30:46 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.72 2017/09/06 18:17:18 christos Exp $"); #endif #include @@ -121,16 +121,22 @@ crc32(const void *buf, size_t size) return crc ^ ~0U; } +/* + * Produce a NUL-terminated utf-8 string from the non-NUL-terminated + * utf16 string. + */ void -utf16_to_utf8(const uint16_t *s16, uint8_t *s8, size_t s8len) +utf16_to_utf8(const uint16_t *s16, size_t s16len, uint8_t *s8, size_t s8len) { - size_t s8idx, s16idx, s16len; + size_t s8idx, s16idx; uint32_t utfchar; unsigned int c; - s16len = 0; - while (s16[s16len++] != 0) - continue; + for (s16idx = 0; s16idx < s16len; s16idx++) + if (s16[s16idx] == 0) + break; + + s16len = s16idx; s8idx = s16idx = 0; while (s16idx < s16len) { utfchar = le16toh(s16[s16idx++]); @@ -168,6 +174,10 @@ utf16_to_utf8(const uint16_t *s16, uint8 s8[s8idx] = 0; } +/* + * Produce a non-NUL-terminated utf-16 string from the NUL-terminated + * utf8 string. + */ void utf8_to_utf16(const uint8_t *s8, uint16_t *s16, size_t s16len) { @@ -228,6 +238,9 @@ utf8_to_utf16(const uint8_t *s8, uint16_ } } } while (c != 0); + + while (s16idx < s16len) + s16[s16idx++] = 0; } void * @@ -1027,7 +1040,8 @@ gpt_change_ent(gpt_t gpt, const struct g ent = gpt_ent_primary(gpt, i); if (find->label != NULL) { - utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf)); + utf16_to_utf8(ent->ent_name, sizeof(ent->ent_name), + utfbuf, sizeof(utfbuf)); if (strcmp((char *)find->label, (char *)utfbuf) == 0) continue; } Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.35 src/sbin/gpt/gpt.h:1.36 --- src/sbin/gpt/gpt.h:1.35 Thu Feb 16 17:40:19 2017 +++ src/sbin/gpt/gpt.h Wed Sep 6 14:17:18 2017 @@ -99,7 +99,7 @@ struct gpt_ent *gpt_ent_primary(gpt_t, u struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int); int gpt_usage(const char *, const struct gpt_cmd *); -void utf16_to_utf8(const uint16_t *, uint8_t *, size_t); +void utf16_to_utf8(const uint16_t *, size_t, uint8_t *, size_t); void utf8_to_utf16(const uint8_t *,
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Tue Sep 5 18:30:46 UTC 2017 Modified Files: src/sbin/gpt: gpt.c Log Message: PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name. XXX: pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.70 src/sbin/gpt/gpt.c:1.71 --- src/sbin/gpt/gpt.c:1.70 Wed Feb 15 22:32:17 2017 +++ src/sbin/gpt/gpt.c Tue Sep 5 14:30:46 2017 @@ -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.70 2017/02/16 03:32:17 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.71 2017/09/05 18:30:46 christos Exp $"); #endif #include @@ -224,7 +224,6 @@ utf8_to_utf16(const uint8_t *s8, uint16_ } else s16[s16idx++] = htole16((uint16_t)utfchar); if (s16idx == s16len) { -s16[--s16idx] = 0; return; } }
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Sat Aug 5 20:21:08 UTC 2017 Modified Files: src/sbin/gpt: gpt.8 Log Message: Use Fx/Nx. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.54 src/sbin/gpt/gpt.8:1.55 --- src/sbin/gpt/gpt.8:1.54 Fri Aug 4 02:43:56 2017 +++ src/sbin/gpt/gpt.8 Sat Aug 5 20:21:08 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.54 2017/08/04 02:43:56 kre Exp $ +.\" $NetBSD: gpt.8,v 1.55 2017/08/05 20:21:08 wiz Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -171,15 +171,20 @@ BIOS Boot .It Cm efi EFI System .It Cm fbsd-legacy -FreeBSD legacy +.Fx +legacy .It Cm fbsd-swap -FreeBSD swap +.Fx +swap .It Cm fbsd-ufs -FreeBSD UFS/UFS2 +.Fx +UFS/UFS2 .It Cm fbsd-vinum -FreeBSD vinum +.Fx +vinum .It Cm fbsd-zfs -FreeBSD ZFS +.Fx +ZFS .It Cm linux-data Linux data .It Cm linux-raid @@ -193,17 +198,23 @@ Windows basic data .It Cm windows-reserved Windows reserved .It Cm ccd -NetBSD ccd component +.Nx +ccd component .It Cm cgd -NetBSD Cryptographic Disk +.Nx +Cryptographic Disk .It Cm ffs -NetBSD FFSv1/FFSv2 +.Nx +FFSv1/FFSv2 .It Cm lfs -NetBSD LFS +.Nx +LFS .It Cm raid -NetBSD RAIDFrame component +.Nx +RAIDFrame component .It Cm swap -NetBSD swap +.Nx +swap .El as aliases for the most commonly used partition types. .\" backup
CVS commit: src/sbin/gpt
Module Name:src Committed By: kre Date: Fri Aug 4 02:43:56 UTC 2017 Modified Files: src/sbin/gpt: gpt.8 Log Message: Fix a typo, and make a couple of minor wording improvements. I resisted the (very weak) impulse to Americanise some spellings ... To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.53 src/sbin/gpt/gpt.8:1.54 --- src/sbin/gpt/gpt.8:1.53 Thu Aug 3 14:39:31 2017 +++ src/sbin/gpt/gpt.8 Fri Aug 4 02:43:56 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.53 2017/08/03 14:39:31 msaitoh Exp $ +.\" $NetBSD: gpt.8,v 1.54 2017/08/04 02:43:56 kre Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -247,8 +247,8 @@ bootstrap code, as installed via The .Fl L option selects the partition by label. -If there are multiple partitions with the same label, it will use the -first one found. +If there are multiple partitions with the same label, the +first one found will be used. .\" create .It Nm Ic create Oo Fl AfP Oc Oo Fl p Ar partitions Oc The @@ -534,16 +534,15 @@ by legacy BIOS boot code. See the .Ic biosboot command for more information. -The bootme flag is used to indicate which partiotion should be booted +The bootme flag is used to indicate which partition should be booted by UEFI boot code. The other attributes are for compatibility with .Fx -and are not currently used by any -.Nx -code. +and are not currently used by +.Nx . They may be used by .Nx -code in the future. +in the future. .\" show .It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc The
CVS commit: src/sbin/gpt
Module Name:src Committed By: msaitoh Date: Thu Aug 3 14:39:31 UTC 2017 Modified Files: src/sbin/gpt: gpt.8 Log Message: Add note about bootme flag: The bootme flag is used to indicate which partiotion should be booted by UEFI boot code. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.52 src/sbin/gpt/gpt.8:1.53 --- src/sbin/gpt/gpt.8:1.52 Thu Feb 16 03:32:17 2017 +++ src/sbin/gpt/gpt.8 Thu Aug 3 14:39:31 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.52 2017/02/16 03:32:17 christos Exp $ +.\" $NetBSD: gpt.8,v 1.53 2017/08/03 14:39:31 msaitoh 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 February 15, 2017 +.Dd August 3, 2017 .Dt GPT 8 .Os .Sh NAME @@ -534,6 +534,8 @@ by legacy BIOS boot code. See the .Ic biosboot command for more information. +The bootme flag is used to indicate which partiotion should be booted +by UEFI boot code. The other attributes are for compatibility with .Fx and are not currently used by any
CVS commit: src/sbin/gpt
Module Name:src Committed By: mrg Date: Mon Jul 3 06:44:58 UTC 2017 Modified Files: src/sbin/gpt: biosboot.c Log Message: only do wedges if not the tools version. fixes build on netbsd-4, and any other place that might have the same ioctl name while having something not quite right (in this case, cpuid_t in headers not working properly..) XXX: pullup-8 To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/gpt/biosboot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.27 src/sbin/gpt/biosboot.c:1.28 --- src/sbin/gpt/biosboot.c:1.27 Thu Feb 16 03:32:17 2017 +++ src/sbin/gpt/biosboot.c Mon Jul 3 06:44:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.27 2017/02/16 03:32:17 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.28 2017/07/03 06:44:58 mrg Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,18 +37,22 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.27 2017/02/16 03:32:17 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.28 2017/07/03 06:44:58 mrg Exp $"); #endif #include #include #include -#ifdef DIOCGWEDGEINFO -#include -#endif #include #include +#if defined(DIOCGWEDGEINFO) && !defined(HAVE_NBTOOL_CONFIG_H) +#define USE_WEDGES +#endif +#ifdef USE_WEDGES +#include +#endif + #include #include #include @@ -252,7 +256,7 @@ biosboot(gpt_t gpt, daddr_t start, uint6 static int cmd_biosboot(gpt_t gpt, int argc, char *argv[]) { -#ifdef DIOCGWEDGEINFO +#ifdef USE_WEDGES struct dkwedge_info dkw; #endif int ch; @@ -289,7 +293,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * if (argc != optind) return usage(); -#ifdef DIOCGWEDGEINFO +#ifdef USE_WEDGES if ((gpt->sb.st_mode & S_IFMT) != S_IFREG && ioctl(gpt->fd, DIOCGWEDGEINFO, ) != -1) { if (entry > 0)
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Wed Mar 22 19:59:16 UTC 2017 Modified Files: src/sbin/gpt: recover.c Log Message: Add missing endianes swap to make the "recover" command work on big endian machines. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/recover.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.16 src/sbin/gpt/recover.c:1.17 --- src/sbin/gpt/recover.c:1.16 Sun Jun 12 12:48:32 2016 +++ src/sbin/gpt/recover.c Wed Mar 22 19:59:16 2017 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.16 2016/06/12 12:48:32 jnemeth Exp $"); +__RCSID("$NetBSD: recover.c,v 1.17 2017/03/22 19:59:16 martin Exp $"); #endif #include @@ -177,7 +177,7 @@ recover(gpt_t gpt, int recoverable) } if (gpt->gpt != NULL && - ((struct gpt_hdr *)(gpt->gpt->map_data))->hdr_lba_alt != + le64toh(((struct gpt_hdr *)(gpt->gpt->map_data))->hdr_lba_alt) != (uint64_t)last) { gpt_warnx(gpt, "Media size has changed, please use " "'%s resizedisk'", getprogname());
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Feb 16 22:40:19 UTC 2017 Modified Files: src/sbin/gpt: gpt.h gpt_uuid.c main.c Log Message: allow 0 timestamp To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sbin/gpt/gpt.h cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/gpt_uuid.c cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.34 src/sbin/gpt/gpt.h:1.35 --- src/sbin/gpt/gpt.h:1.34 Wed Feb 15 22:32:17 2017 +++ src/sbin/gpt/gpt.h Thu Feb 16 17:40:19 2017 @@ -80,6 +80,7 @@ gpt_t gpt_open(const char *, int, int, o #define GPT_QUIET 0x04 #define GPT_NOSYNC 0x08 #define GPT_FILE 0x10 +#define GPT_TIMESTAMP 0x20 void* gpt_read(gpt_t, off_t, size_t); off_t gpt_last(gpt_t); Index: src/sbin/gpt/gpt_uuid.c diff -u src/sbin/gpt/gpt_uuid.c:1.14 src/sbin/gpt/gpt_uuid.c:1.15 --- src/sbin/gpt/gpt_uuid.c:1.14 Wed Feb 15 22:32:17 2017 +++ src/sbin/gpt/gpt_uuid.c Thu Feb 16 17:40:19 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: gpt_uuid.c,v 1.14 2017/02/16 03:32:17 christos Exp $ */ +/* $NetBSD: gpt_uuid.c,v 1.15 2017/02/16 22:40:19 christos Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: gpt_uuid.c,v 1.14 2017/02/16 03:32:17 christos Exp $"); +__RCSID("$NetBSD: gpt_uuid.c,v 1.15 2017/02/16 22:40:19 christos Exp $"); #endif #include @@ -301,10 +301,10 @@ gpt_uuid_generate(gpt_t gpt, gpt_uuid_t { int rv; struct dce_uuid u; - if (gpt->timestamp == 0) - rv = gpt_uuid_random(gpt, , sizeof(u)); - else + if (gpt->flags & GPT_TIMESTAMP) rv = gpt_uuid_tstamp(gpt, , sizeof(u)); + else + rv = gpt_uuid_random(gpt, , sizeof(u)); if (rv == -1) return -1; Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.9 src/sbin/gpt/main.c:1.10 --- src/sbin/gpt/main.c:1.9 Wed Feb 15 22:32:17 2017 +++ src/sbin/gpt/main.c Thu Feb 16 17:40:19 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.9 2017/02/16 03:32:17 christos Exp $ */ +/* $NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.9 2017/02/16 03:32:17 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $"); #endif #include @@ -206,6 +206,7 @@ main(int argc, char *argv[]) usage(); break; case 'T': + flags |= GPT_TIMESTAMP; timestamp = get_tstamp(optarg); break; case 'v':
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Feb 16 03:32:17 UTC 2017 Modified Files: src/sbin/gpt: biosboot.c gpt.8 gpt.c gpt.h gpt_private.h gpt_uuid.c main.c Log Message: Add -T timestamp for reproducible builds. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.51 -r1.52 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.69 -r1.70 src/sbin/gpt/gpt.c cvs rdiff -u -r1.33 -r1.34 src/sbin/gpt/gpt.h cvs rdiff -u -r1.1 -r1.2 src/sbin/gpt/gpt_private.h cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/gpt_uuid.c cvs rdiff -u -r1.8 -r1.9 src/sbin/gpt/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.26 src/sbin/gpt/biosboot.c:1.27 --- src/sbin/gpt/biosboot.c:1.26 Thu Jun 9 15:04:43 2016 +++ src/sbin/gpt/biosboot.c Wed Feb 15 22:32:17 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.26 2016/06/09 19:04:43 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.27 2017/02/16 03:32:17 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.26 2016/06/09 19:04:43 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.27 2017/02/16 03:32:17 christos Exp $"); #endif #include @@ -298,7 +298,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * start = dkw.dkw_offset; size = dkw.dkw_size; ngpt = gpt_open(dkw.dkw_parent, gpt->flags, gpt->verbose, - gpt->mediasz, gpt->secsz); + gpt->mediasz, gpt->secsz, gpt->timestamp); if (ngpt == NULL) goto cleanup; } Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.51 src/sbin/gpt/gpt.8:1.52 --- src/sbin/gpt/gpt.8:1.51 Fri Jan 27 05:21:16 2017 +++ src/sbin/gpt/gpt.8 Wed Feb 15 22:32:17 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.51 2017/01/27 10:21:16 abhinav Exp $ +.\" $NetBSD: gpt.8,v 1.52 2017/02/16 03:32:17 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 November 1, 2016 +.Dd February 15, 2017 .Dt GPT 8 .Os .Sh NAME @@ -37,6 +37,7 @@ .Op Fl nrqv .Op Fl m Ar mediasize .Op Fl s Ar sectorsize +.Op Fl T Ar timestamp .Ar command .Op Ar command_options .Ar device @@ -94,6 +95,13 @@ Override the default sector size for the from the kernel if possible) or .Dv 512 for plain files. +.It Fl T Ar timestamp +Specify a timestamp to be used for uuid generation so that uuids +are not random and can be consistent for reproducible builds. +The timestamp can be a pathname, where the timestamps are derived from +that file, a parseable date for parsedate(3) (this option is not +yet available in the tools build), or an integer value interpreted +as the number of seconds from the Epoch. .It Fl v Controls the verbosity level. The level increases with every occurrence of this option. Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.69 src/sbin/gpt/gpt.c:1.70 --- src/sbin/gpt/gpt.c:1.69 Sat Sep 24 09:40:55 2016 +++ src/sbin/gpt/gpt.c Wed Feb 15 22:32:17 2017 @@ -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.69 2016/09/24 13:40:55 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.70 2017/02/16 03:32:17 christos Exp $"); #endif #include @@ -461,7 +461,8 @@ gpt_gpt(gpt_t gpt, off_t lba, int found) } gpt_t -gpt_open(const char *dev, int flags, int verbose, off_t mediasz, u_int secsz) +gpt_open(const char *dev, int flags, int verbose, off_t mediasz, u_int secsz, +time_t timestamp) { int mode, found; off_t devsz; @@ -477,6 +478,7 @@ gpt_open(const char *dev, int flags, int gpt->verbose = verbose; gpt->mediasz = mediasz; gpt->secsz = secsz; + gpt->timestamp = timestamp; mode = (gpt->flags & GPT_READONLY) ? O_RDONLY : O_RDWR|O_EXCL; Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.33 src/sbin/gpt/gpt.h:1.34 --- src/sbin/gpt/gpt.h:1.33 Thu Jun 9 11:12:54 2016 +++ src/sbin/gpt/gpt.h Wed Feb 15 22:32:17 2017 @@ -74,7 +74,7 @@ struct gpt_cmd { uint32_t crc32(const void *, size_t); void gpt_close(gpt_t); int gpt_gpt(gpt_t, off_t, int); -gpt_t gpt_open(const char *, int, int, off_t, u_int); +gpt_t gpt_open(const char *, int, int, off_t, u_int, time_t); #define GPT_READONLY 0x01 #define GPT_MODIFIED 0x02 #define GPT_QUIET 0x04 Index: src/sbin/gpt/gpt_private.h diff -u src/sbin/gpt/gpt_private.h:1.1 src/sbin/gpt/gpt_private.h:1.2 --- src/sbin/gpt/gpt_private.h:1.1 Tue Dec 1 04:05:33 2015 +++ src/sbin/gpt/gpt_private.h Wed Feb 15 22:32:17 2017 @@ -41,5 +41,6 @@ struct gpt { struct map *tbl, *lbt, *gpt, *tpg; u_int secsz; off_t mediasz; + time_t timestamp; struct stat sb; }; Index: src/sbin/gpt/gpt_uuid.c diff -u src/sbin/gpt/gpt_uuid.c:1.13
CVS commit: src/sbin/gpt
Module Name:src Committed By: aymeric Date: Sun Feb 12 16:54:06 UTC 2017 Modified Files: src/sbin/gpt: main.c Log Message: Make gpt(8) work when compiled on a glibc-based OS. This restores the ability to build amd64 install-image's under Linux. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/main.c diff -u src/sbin/gpt/main.c:1.7 src/sbin/gpt/main.c:1.8 --- src/sbin/gpt/main.c:1.7 Tue Dec 29 16:45:04 2015 +++ src/sbin/gpt/main.c Sun Feb 12 16:54:06 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $ */ +/* $NetBSD: main.c,v 1.8 2017/02/12 16:54:06 aymeric Exp $ */ /*- * Copyright (c) 2002 Marcel Moolenaar @@ -34,7 +34,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: main.c,v 1.7 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.8 2017/02/12 16:54:06 aymeric Exp $"); #endif #include @@ -145,8 +145,14 @@ main(int argc, char *argv[]) dev = argv[--argc]; } +#ifdef __GLIBC__ +#define GETOPT_BE_POSIX "+" +#else +#define GETOPT_BE_POSIX "" +#endif + /* Get the generic options */ - while ((ch = getopt(argc, argv, "m:nqrs:v")) != -1) { + while ((ch = getopt(argc, argv, GETOPT_BE_POSIX "m:nqrs:v")) != -1) { switch(ch) { case 'm': if (mediasz > 0)
CVS commit: src/sbin/gpt
Module Name:src Committed By: abhinav Date: Fri Jan 27 10:21:16 UTC 2017 Modified Files: src/sbin/gpt: gpt.8 Log Message: Fix spelling of partition. To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.50 src/sbin/gpt/gpt.8:1.51 --- src/sbin/gpt/gpt.8:1.50 Tue Nov 1 16:15:51 2016 +++ src/sbin/gpt/gpt.8 Fri Jan 27 10:21:16 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.50 2016/11/01 16:15:51 jdolecek Exp $ +.\" $NetBSD: gpt.8,v 1.51 2017/01/27 10:21:16 abhinav Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -638,7 +638,7 @@ nas# gpt show wd3 3907029167 1 Sec GPT header nas# gpt add -s 10486224 -t swap -i 1 wd3 nas# gpt label -i 1 -l swap_1 wd3 -parition 1 on rwd3d labeled swap_1 +partition 1 on rwd3d labeled swap_1 nas# gpt show wd3 startsize index contents 0 1 PMBR
CVS commit: src/sbin/gpt
Module Name:src Committed By: jdolecek Date: Tue Nov 1 16:15:51 UTC 2016 Modified Files: src/sbin/gpt: gpt.8 Log Message: remove dup line To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.49 src/sbin/gpt/gpt.8:1.50 --- src/sbin/gpt/gpt.8:1.49 Sun Sep 11 21:38:16 2016 +++ src/sbin/gpt/gpt.8 Tue Nov 1 16:15:51 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.49 2016/09/11 21:38:16 sevan Exp $ +.\" $NetBSD: gpt.8,v 1.50 2016/11/01 16:15:51 jdolecek 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 September 11, 2016 +.Dd November 1, 2016 .Dt GPT 8 .Os .Sh NAME @@ -571,7 +571,6 @@ The order of precedence for the options .\" type .It Nm Ic type Oo Fl a Oc Fl T Ar newtype .It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \ -.It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \ Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc \ Fl T Ar newtype .It Nm Ic type Fl l
CVS commit: src/sbin/gpt
Module Name:src Committed By: kre Date: Wed Oct 5 03:06:24 UTC 2016 Modified Files: src/sbin/gpt: show.c Log Message: Avoiding having parameter name shadow its own function's name. Strictly this shouldnt be (and hasn't been for almost a year) a problem, but there are compilers that warn about locals shadowing globals (which this is/was) and it is easy to avoid, so ...No functinal difference. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.38 src/sbin/gpt/show.c:1.39 --- src/sbin/gpt/show.c:1.38 Thu Jun 9 17:43:36 2016 +++ src/sbin/gpt/show.c Wed Oct 5 03:06:24 2016 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.38 2016/06/09 17:43:36 kre Exp $"); +__RCSID("$NetBSD: show.c,v 1.39 2016/10/05 03:06:24 kre Exp $"); #endif #include @@ -158,7 +158,7 @@ print_part_type(int map_type, int flags, } static int -show(gpt_t gpt, int show) +show(gpt_t gpt, int xshow) { map_t m; @@ -178,7 +178,7 @@ show(gpt_t gpt, int show) printf(" "); putchar(' '); putchar(' '); - print_part_type(m->map_type, show, m->map_data, m->map_start); + print_part_type(m->map_type, xshow, m->map_data, m->map_start); putchar('\n'); m = m->map_next; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Sat Sep 24 13:40:55 UTC 2016 Modified Files: src/sbin/gpt: gpt.c Log Message: say that you need to destroy it first. To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.68 src/sbin/gpt/gpt.c:1.69 --- src/sbin/gpt/gpt.c:1.68 Thu Jun 9 11:12:54 2016 +++ src/sbin/gpt/gpt.c Sat Sep 24 09:40:55 2016 @@ -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.68 2016/06/09 15:12:54 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.69 2016/09/24 13:40:55 christos Exp $"); #endif #include @@ -795,7 +795,8 @@ gpt_create(gpt_t gpt, off_t last, u_int if (map_find(gpt, MAP_TYPE_PRI_GPT_HDR) != NULL || map_find(gpt, MAP_TYPE_SEC_GPT_HDR) != NULL) { - gpt_warnx(gpt, "Device already contains a GPT"); + gpt_warnx(gpt, "Device already contains a GPT, " + "destroy it first"); return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Sep 23 19:36:50 UTC 2016 Modified Files: src/sbin/gpt: create.c Log Message: PR/51497: Clare: Allow gpt -p create to work. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/create.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.22 src/sbin/gpt/create.c:1.23 --- src/sbin/gpt/create.c:1.22 Thu Jun 9 15:04:43 2016 +++ src/sbin/gpt/create.c Fri Sep 23 15:36:50 2016 @@ -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.22 2016/06/09 19:04:43 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.23 2016/09/23 19:36:50 christos Exp $"); #endif #include @@ -128,7 +128,7 @@ cmd_create(gpt_t gpt, int argc, char *ar int active = 0; int force = 0; int primary_only = 0; - u_int parts = 128; + u_int parts = 0; while ((ch = getopt(argc, argv, "AfPp:")) != -1) { switch(ch) { @@ -149,6 +149,8 @@ cmd_create(gpt_t gpt, int argc, char *ar return usage(); } } + if (parts == 0) + parts = 128; if (argc != optind) return usage();
CVS commit: src/sbin/gpt
Module Name:src Committed By: sevan Date: Sun Sep 11 21:38:16 UTC 2016 Modified Files: src/sbin/gpt: gpt.8 Log Message: Document the version gpt first appeared. Replace contractions. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.48 src/sbin/gpt/gpt.8:1.49 --- src/sbin/gpt/gpt.8:1.48 Thu Jun 9 19:04:43 2016 +++ src/sbin/gpt/gpt.8 Sun Sep 11 21:38:16 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.48 2016/06/09 19:04:43 christos Exp $ +.\" $NetBSD: gpt.8,v 1.49 2016/09/11 21:38:16 sevan 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 June 9, 2016 +.Dd September 11, 2016 .Dt GPT 8 .Os .Sh NAME @@ -74,7 +74,7 @@ Override the default media size for the from the kernel if possible) or defaulting to the file size for plain files. .It Fl n -Don't update the wedge information that +Do not update the wedge information that .Nm changed. You need to use the @@ -87,7 +87,7 @@ Currently this option is primarily usefu .Ic show command, but the intent is to use it to implement dry-run behaviour. .It Fl q -Don't print error messages. +Do not print error messages. This is not implemented completely yet. .It Fl s Ar sectorsize Override the default sector size for the device (obtained @@ -378,7 +378,7 @@ disk labels into GPT partitions by creat the GPT equivalent of a slice. Note that the .Fl s -option isn't applicable to +option is not applicable to .Nx partitions. .Pp @@ -403,7 +403,7 @@ See the option for the size of the GPT partition table. By default, just about all devices have a minimum of 62 sectors free at the -beginning of the device, but don't have any free space at the end. +beginning of the device, but do not have any free space at the end. For the default GPT partition table size on a 512 byte sector size device, 33 sectors at the end of the device would need to be freed. .\" recover @@ -674,6 +674,9 @@ The utility appeared in .Fx 5.0 for ia64. +.Nm +utility first appeared in +.Nx 5.0 . .Sh BUGS The development of the .Nm
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Sun Jun 12 12:48:33 UTC 2016 Modified Files: src/sbin/gpt: recover.c Log Message: - fix setting of hdr_lba_alt which was broken in revision 1.10 on 2015/12/2 - switch to using gpt_last - PR/51230 -- recreate the PMBR if it was lost To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/recover.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.15 src/sbin/gpt/recover.c:1.16 --- src/sbin/gpt/recover.c:1.15 Fri Dec 4 16:46:24 2015 +++ src/sbin/gpt/recover.c Sun Jun 12 12:48:32 2016 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.15 2015/12/04 16:46:24 christos Exp $"); +__RCSID("$NetBSD: recover.c,v 1.16 2016/06/12 12:48:32 jnemeth Exp $"); #endif #include @@ -68,7 +68,7 @@ static int recover_gpt_hdr(gpt_t gpt, int type, off_t last) { const char *name, *origname; - map_t *dgpt, dtbl, sgpt, stbl; + map_t *dgpt, dtbl, sgpt, stbl __unused; struct gpt_hdr *hdr; if (gpt_add_hdr(gpt, type, last) == -1) @@ -99,7 +99,7 @@ recover_gpt_hdr(gpt_t gpt, int type, off memcpy((*dgpt)->map_data, sgpt->map_data, gpt->secsz); hdr = (*dgpt)->map_data; hdr->hdr_lba_self = htole64((uint64_t)(*dgpt)->map_start); - hdr->hdr_lba_alt = htole64((uint64_t)stbl->map_start); + hdr->hdr_lba_alt = htole64((uint64_t)sgpt->map_start); hdr->hdr_lba_table = htole64((uint64_t)dtbl->map_start); hdr->hdr_crc_self = 0; hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size))); @@ -151,7 +151,9 @@ recover_gpt_tbl(gpt_t gpt, int type, off static int recover(gpt_t gpt, int recoverable) { - uint64_t last; + off_t last = gpt_last(gpt); + map_t map; + struct mbr *mbr; if (map_find(gpt, MAP_TYPE_MBR) != NULL) { gpt_warnx(gpt, "Device contains an MBR"); @@ -174,10 +176,9 @@ recover(gpt_t gpt, int recoverable) return -1; } - last = (uint64_t)(gpt->mediasz / gpt->secsz - 1LL); - if (gpt->gpt != NULL && - ((struct gpt_hdr *)(gpt->gpt->map_data))->hdr_lba_alt != last) { + ((struct gpt_hdr *)(gpt->gpt->map_data))->hdr_lba_alt != + (uint64_t)last) { gpt_warnx(gpt, "Media size has changed, please use " "'%s resizedisk'", getprogname()); return -1; @@ -185,7 +186,7 @@ recover(gpt_t gpt, int recoverable) if (gpt->tbl != NULL && gpt->lbt == NULL) { if (recover_gpt_tbl(gpt, MAP_TYPE_SEC_GPT_TBL, - (off_t)last - gpt->tbl->map_size) == -1) + last - gpt->tbl->map_size) == -1) return -1; } else if (gpt->tbl == NULL && gpt->lbt != NULL) { if (recover_gpt_tbl(gpt, MAP_TYPE_PRI_GPT_TBL, 2LL) == -1) @@ -193,13 +194,38 @@ recover(gpt_t gpt, int recoverable) } if (gpt->gpt != NULL && gpt->tpg == NULL) { - if (recover_gpt_hdr(gpt, MAP_TYPE_SEC_GPT_HDR, - (off_t)last) == -1) + if (recover_gpt_hdr(gpt, MAP_TYPE_SEC_GPT_HDR, last) == -1) return -1; } else if (gpt->gpt == NULL && gpt->tpg != NULL) { if (recover_gpt_hdr(gpt, MAP_TYPE_PRI_GPT_HDR, 1LL) == -1) return -1; } + + /* + * Create PMBR if it doesn't already exist. + */ + if (map_find(gpt, MAP_TYPE_PMBR) == NULL) { + if (map_free(gpt, 0LL, 1LL) == 0) { + gpt_warnx(gpt, "No room for the PMBR"); + return -1; + } + mbr = gpt_read(gpt, 0LL, 1); + if (mbr == NULL) { + gpt_warnx(gpt, "Error reading MBR"); + return -1; + } + memset(mbr, 0, sizeof(*mbr)); + mbr->mbr_sig = htole16(MBR_SIG); + gpt_create_pmbr_part(mbr->mbr_part, last, 0); + + map = map_add(gpt, 0LL, 1LL, MAP_TYPE_PMBR, mbr, 1); + if (gpt_write(gpt, map) == -1) { + gpt_warn(gpt, "Can't write PMBR"); + return -1; + } + gpt_msg(gpt, + "Recreated PMBR (you may need to rerun 'gpt biosboot'"); + } return 0; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Jun 9 19:04:43 UTC 2016 Modified Files: src/sbin/gpt: biosboot.c create.c gpt.8 migrate.c Log Message: Rename 'a' to set the active PMBR flag to 'A' To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.21 -r1.22 src/sbin/gpt/create.c cvs rdiff -u -r1.47 -r1.48 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.31 -r1.32 src/sbin/gpt/migrate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.25 src/sbin/gpt/biosboot.c:1.26 --- src/sbin/gpt/biosboot.c:1.25 Thu Jun 9 11:12:54 2016 +++ src/sbin/gpt/biosboot.c Thu Jun 9 15:04:43 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.26 2016/06/09 19:04:43 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.26 2016/06/09 19:04:43 christos Exp $"); #endif #include @@ -68,7 +68,7 @@ __RCSID("$NetBSD: biosboot.c,v 1.25 2016 static int cmd_biosboot(gpt_t, int, char *[]); static const char *biosboothelp[] = { - "[-a] [-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]", @@ -264,9 +264,9 @@ cmd_biosboot(gpt_t gpt, int argc, char * uint8_t *label = NULL; char *bootpath = NULL; - while ((ch = getopt(argc, argv, "ac:i:L:")) != -1) { + while ((ch = getopt(argc, argv, "Ac:i:L:")) != -1) { switch(ch) { - case 'a': + case 'A': active = 1; break; case 'c': Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.21 src/sbin/gpt/create.c:1.22 --- src/sbin/gpt/create.c:1.21 Thu Jun 9 11:12:54 2016 +++ src/sbin/gpt/create.c Thu Jun 9 15:04:43 2016 @@ -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.21 2016/06/09 15:12:54 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.22 2016/06/09 19:04:43 christos Exp $"); #endif #include @@ -55,7 +55,7 @@ __RCSID("$NetBSD: create.c,v 1.21 2016/0 static int cmd_create(gpt_t, int, char *[]); static const char *createhelp[] = { - "[-afP] [-p partitions]", + "[-AfP] [-p partitions]", }; struct gpt_cmd c_create = { @@ -130,9 +130,9 @@ cmd_create(gpt_t gpt, int argc, char *ar int primary_only = 0; u_int parts = 128; - while ((ch = getopt(argc, argv, "afPp:")) != -1) { + while ((ch = getopt(argc, argv, "AfPp:")) != -1) { switch(ch) { - case 'a': + case 'A': active = 1; break; case 'f': Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.47 src/sbin/gpt/gpt.8:1.48 --- src/sbin/gpt/gpt.8:1.47 Thu Jun 9 12:48:14 2016 +++ src/sbin/gpt/gpt.8 Thu Jun 9 15:04:43 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.47 2016/06/09 16:48:14 kre Exp $ +.\" $NetBSD: gpt.8,v 1.48 2016/06/09 19:04:43 christos Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -211,7 +211,7 @@ command. The format is a plist. It should not be modified. .\" biosboot -.It Nm Ic biosboot Oo Fl a Oc Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \ +.It Nm Ic biosboot Oo Fl A Oc Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \ Oo Fl L Ar label Oc The .Ic biosboot @@ -220,7 +220,7 @@ primary bootstrap program, used during .Xr boot 8 . .Pp The -.Fl a +.Fl A options sets the PMBR partition active. .Pp The @@ -242,7 +242,7 @@ option selects the partition by label. If there are multiple partitions with the same label, it will use the first one found. .\" create -.It Nm Ic create Oo Fl afP 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. @@ -256,7 +256,7 @@ option is specified, an existing MBR is described by the MBR are lost. .Pp The -.Fl a +.Fl A options sets the PMBR partition active. .Pp The @@ -351,7 +351,7 @@ The 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 afs 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 @@ -367,7 +367,7 @@ option will cause unknown partitions to to be lost. .Pp The -.Fl a +.Fl A options sets the PMBR partition active. .Pp The Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.31 src/sbin/gpt/migrate.c:1.32 --- src/sbin/gpt/migrate.c:1.31 Thu Jun 9 11:12:54 2016 +++ src/sbin/gpt/migrate.c Thu Jun 9 15:04:43 2016 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD:
CVS commit: src/sbin/gpt
Module Name:src Committed By: kre Date: Thu Jun 9 17:43:36 UTC 2016 Modified Files: src/sbin/gpt: show.c Log Message: Make "gpt show" add an "(active)" annotation to the PMBR output line when it has been marked active for legacy (non UEFI) booting. This was (kind of obviously) intended by the previous commit, but... To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.37 src/sbin/gpt/show.c:1.38 --- src/sbin/gpt/show.c:1.37 Thu Jun 9 15:12:54 2016 +++ src/sbin/gpt/show.c Thu Jun 9 17:43:36 2016 @@ -33,9 +33,10 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.37 2016/06/09 15:12:54 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.38 2016/06/09 17:43:36 kre Exp $"); #endif +#include #include #include @@ -45,6 +46,7 @@ __RCSID("$NetBSD: show.c,v 1.37 2016/06/ #include #include + #include "map.h" #include "gpt.h" #include "gpt_private.h" @@ -144,6 +146,10 @@ print_part_type(int map_type, int flags, break; case MAP_TYPE_PMBR: printf("PMBR"); + mbr = map_data; + if (mbr->mbr_part[0].part_typ == MBR_PTYPE_PMBR && + mbr->mbr_part[0].part_flag == 0x80) + printf(" (active)"); break; default: printf("Unknown %#x", map_type);
CVS commit: src/sbin/gpt
Module Name:src Committed By: kre Date: Thu Jun 9 16:48:14 UTC 2016 Modified Files: src/sbin/gpt: gpt.8 Log Message: Fix rendering of biosboot command synopsis. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.46 src/sbin/gpt/gpt.8:1.47 --- src/sbin/gpt/gpt.8:1.46 Thu Jun 9 15:12:54 2016 +++ src/sbin/gpt/gpt.8 Thu Jun 9 16:48:14 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.46 2016/06/09 15:12:54 christos Exp $ +.\" $NetBSD: gpt.8,v 1.47 2016/06/09 16:48:14 kre Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -211,7 +211,7 @@ command. The format is a plist. It should not be modified. .\" biosboot -.It Nm Ic biosboot Oo Fl ac Ar bootcode Oc Oo Fl i Ar index Oc \ +.It Nm Ic biosboot Oo Fl a Oc Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \ Oo Fl L Ar label Oc The .Ic biosboot
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Jun 9 15:12:54 UTC 2016 Modified Files: src/sbin/gpt: biosboot.c create.c gpt.8 gpt.c gpt.h migrate.c show.c Log Message: PR/51230: Add the ability to set the active flag in the PMBR. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.20 -r1.21 src/sbin/gpt/create.c cvs rdiff -u -r1.45 -r1.46 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.67 -r1.68 src/sbin/gpt/gpt.c cvs rdiff -u -r1.32 -r1.33 src/sbin/gpt/gpt.h cvs rdiff -u -r1.30 -r1.31 src/sbin/gpt/migrate.c cvs rdiff -u -r1.36 -r1.37 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.24 src/sbin/gpt/biosboot.c:1.25 --- src/sbin/gpt/biosboot.c:1.24 Tue Dec 29 11:45:04 2015 +++ src/sbin/gpt/biosboot.c Thu Jun 9 11:12:54 2016 @@ -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 #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 @@ -68,7 +68,7 @@ __RCSID("$NetBSD: biosboot.c,v 1.24 2015 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 @@ set_bootable(gpt_t gpt, map_t map, map_t 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 @@ biosboot(gpt_t gpt, daddr_t start, uint6 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 @@ cmd_biosboot(gpt_t gpt, int argc, char * 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, ) == -1) goto usage; @@ -295,7 +303,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * 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); Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.20 src/sbin/gpt/create.c:1.21 --- src/sbin/gpt/create.c:1.20 Tue Dec 29 11:45:04 2015 +++ src/sbin/gpt/create.c Thu Jun 9 11:12:54 2016 @@ -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 @@ -55,7 +55,7 @@ __RCSID("$NetBSD: create.c,v 1.20 2015/1 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 @@ struct gpt_cmd c_create = { 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 @@ create(gpt_t gpt, u_int parts, int force } 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 @@ static int 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 @@ cmd_create(gpt_t gpt, int argc, char *ar if (argc != optind) return usage(); - return create(gpt, parts, force, primary_only); + return create(gpt, parts, force, primary_only, active); } Index: src/sbin/gpt/gpt.8 diff -u
CVS commit: src/sbin/gpt
Module Name:src Committed By: dholland Date: Tue May 31 02:29:54 UTC 2016 Modified Files: src/sbin/gpt: show.c Log Message: PR 50756 David Binderman: avoid running off the end of an array in case thing we're looking for isn't there. Which is probably impossible, but that's not obvious. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.35 src/sbin/gpt/show.c:1.36 --- src/sbin/gpt/show.c:1.35 Tue Dec 29 16:45:04 2015 +++ src/sbin/gpt/show.c Tue May 31 02:29:54 2016 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.35 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.36 2016/05/31 02:29:54 dholland Exp $"); #endif #include @@ -114,7 +114,12 @@ print_part_type(int map_type, int flags, if (map_start == p->map_start + start) break; } - printf("%d", mbr->mbr_part[i].part_typ); + if (i == 4) { + /* wasn't there */ + printf("[partition not found?]"); + } else { + printf("%d", mbr->mbr_part[i].part_typ); + } break; case MAP_TYPE_GPT_PART: printf("GPT part ");
CVS commit: src/sbin/gpt
Module Name:src Committed By: joerg Date: Fri Jan 8 18:59:01 UTC 2016 Modified Files: src/sbin/gpt: gpt.c Log Message: gpt_vwarnx is printf-like. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.66 src/sbin/gpt/gpt.c:1.67 --- src/sbin/gpt/gpt.c:1.66 Tue Dec 29 16:45:04 2015 +++ src/sbin/gpt/gpt.c Fri Jan 8 18:59:01 2016 @@ -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.66 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.67 2016/01/08 18:59:01 joerg Exp $"); #endif #include @@ -592,6 +592,7 @@ out: close(gpt->fd); } +__printflike(2, 0) static void gpt_vwarnx(gpt_t gpt, const char *fmt, va_list ap, const char *e) {
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Tue Dec 29 16:45:04 UTC 2015 Modified Files: src/sbin/gpt: add.c biosboot.c create.c gpt.c gpt.h main.c migrate.c set.c show.c unset.c Log Message: - add more informational messages - handle case where last argument is an option not a device (set -l) To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/add.c cvs rdiff -u -r1.23 -r1.24 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/create.c cvs rdiff -u -r1.65 -r1.66 src/sbin/gpt/gpt.c cvs rdiff -u -r1.31 -r1.32 src/sbin/gpt/gpt.h cvs rdiff -u -r1.6 -r1.7 src/sbin/gpt/main.c cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/migrate.c cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/set.c src/sbin/gpt/unset.c cvs rdiff -u -r1.34 -r1.35 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.42 src/sbin/gpt/add.c:1.43 --- src/sbin/gpt/add.c:1.42 Thu Dec 3 16:46:22 2015 +++ src/sbin/gpt/add.c Tue Dec 29 11:45:04 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.42 2015/12/03 21:46:22 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.43 2015/12/29 16:45:04 christos Exp $"); #endif #include @@ -167,7 +167,7 @@ cmd_add(gpt_t gpt, int argc, char *argv[ while ((ch = getopt(argc, argv, GPT_AIS "b:l:t:")) != -1) { switch(ch) { case 'b': - if (gpt_human_get() == -1) + if (gpt_human_get(gpt, ) == -1) goto usage; break; case 'l': Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.23 src/sbin/gpt/biosboot.c:1.24 --- src/sbin/gpt/biosboot.c:1.23 Thu Dec 3 16:49:51 2015 +++ src/sbin/gpt/biosboot.c Tue Dec 29 11:45:04 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $"); #endif #include @@ -266,7 +266,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * goto usage; break; case 'i': - if (gpt_uint_get() == -1) + if (gpt_uint_get(gpt, ) == -1) goto usage; break; case 'L': Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.19 src/sbin/gpt/create.c:1.20 --- src/sbin/gpt/create.c:1.19 Thu Dec 3 16:30:54 2015 +++ src/sbin/gpt/create.c Tue Dec 29 11:45:04 2015 @@ -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.19 2015/12/03 21:30:54 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.20 2015/12/29 16:45:04 christos Exp $"); #endif #include @@ -138,7 +138,7 @@ cmd_create(gpt_t gpt, int argc, char *ar primary_only = 1; break; case 'p': - if (gpt_uint_get() == -1) + if (gpt_uint_get(gpt, ) == -1) return -1; break; default: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.65 src/sbin/gpt/gpt.c:1.66 --- src/sbin/gpt/gpt.c:1.65 Sat Dec 26 08:12:16 2015 +++ src/sbin/gpt/gpt.c Tue Dec 29 11:45:04 2015 @@ -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.65 2015/12/26 13:12:16 jnemeth Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.66 2015/12/29 16:45:04 christos Exp $"); #endif #include @@ -592,34 +592,39 @@ out: close(gpt->fd); } +static void +gpt_vwarnx(gpt_t gpt, const char *fmt, va_list ap, const char *e) +{ + if (gpt && (gpt->flags & GPT_QUIET)) + return; + fprintf(stderr, "%s: ", getprogname()); + if (gpt) + fprintf(stderr, "%s: ", gpt->device_name); + vfprintf(stderr, fmt, ap); + if (e) + fprintf(stderr, " (%s)\n", e); + else + fputc('\n', stderr); +} + void gpt_warnx(gpt_t gpt, const char *fmt, ...) { va_list ap; - if (gpt->flags & GPT_QUIET) - return; - fprintf(stderr, "%s: %s: ", getprogname(), gpt->device_name); va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + gpt_vwarnx(gpt, fmt, ap, NULL); va_end(ap); - fprintf(stderr, "\n"); } void gpt_warn(gpt_t gpt, const char *fmt, ...) { va_list ap; - int e = errno; - if (gpt->flags & GPT_QUIET) - return; - fprintf(stderr, "%s: %s: ", getprogname(), gpt->device_name); va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + gpt_vwarnx(gpt, fmt, ap, strerror(errno)); va_end(ap); - fprintf(stderr, " (%s)\n", strerror(e)); - errno = e; } void @@ -627,9 +632,10 @@ gpt_msg(gpt_t gpt, const char *fmt, ...) { va_list ap; - if (gpt->flags & GPT_QUIET) + if (gpt && (gpt->flags & GPT_QUIET)) return; - printf("%s: ", gpt->device_name); + if (gpt) + printf("%s: ",
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Sat Dec 26 13:12:17 UTC 2015 Modified Files: src/sbin/gpt: gpt.c Log Message: pretty up attribute display a bit To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.64 src/sbin/gpt/gpt.c:1.65 --- src/sbin/gpt/gpt.c:1.64 Sun Dec 6 00:39:26 2015 +++ src/sbin/gpt/gpt.c Sat Dec 26 13:12:16 2015 @@ -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.64 2015/12/06 00:39:26 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.65 2015/12/26 13:12:16 jnemeth Exp $"); #endif #include @@ -1154,7 +1154,7 @@ gpt_attr_list(char *buf, size_t len, uin for (i = 0; i < __arraycount(gpt_attr); i++) if (attributes & gpt_attr[i].mask) { - strlcat(buf, buf[0] ? "," : "", len); + strlcat(buf, buf[0] ? ", " : "", len); strlcat(buf, gpt_attr[i].name, len); } return buf;
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Sat Dec 26 13:08:45 UTC 2015 Modified Files: src/sbin/gpt: show.c Log Message: Improve "show -a" display: split human readable Type: field from the Type-GUID to avoid wrapping in the common case; add a human readable Size: display. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.33 src/sbin/gpt/show.c:1.34 --- src/sbin/gpt/show.c:1.33 Fri Dec 25 12:16:03 2015 +++ src/sbin/gpt/show.c Sat Dec 26 13:08:45 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.33 2015/12/25 12:16:03 wiz Exp $"); +__RCSID("$NetBSD: show.c,v 1.34 2015/12/26 13:08:45 martin Exp $"); #endif #include @@ -222,6 +222,9 @@ show_all(gpt_t gpt) map_t m; struct gpt_ent *ent; char s1[128], s2[128]; +#ifdef HN_AUTOSCALE + char human_num[8]; +#endif uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1]; #define PFX " " @@ -247,11 +250,27 @@ show_all(gpt_t gpt) gpt_uuid_snprintf(s2, sizeof(s2), "%d", ent->ent_type); if (strcmp(s1, s2) == 0) strlcpy(s1, "unknown", sizeof(s1)); - printf(PFX "Type: %s (%s)\n", s1, s2); + printf(PFX "Type: %s\n", s1); + printf(PFX "TypeID: %s\n", s2); gpt_uuid_snprintf(s2, sizeof(s1), "%d", ent->ent_guid); printf(PFX "GUID: %s\n", s2); + printf(PFX "Size: "); +#ifdef HN_AUTOSCALE + if (humanize_number(human_num, sizeof(human_num), + (int64_t)(m->map_size * gpt->secsz), + "", HN_AUTOSCALE, HN_B) < 0) { +#endif +printf("%ju", +(int64_t)(m->map_size * gpt->secsz)); +#ifdef HN_AUTOSCALE + } else { +printf("%s", human_num); + } +#endif + putchar('\n'); + utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf)); printf(PFX "Label: %s\n", (char *)utfbuf);
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Fri Dec 25 10:59:56 UTC 2015 Modified Files: src/sbin/gpt: gpt.8 show.c Log Message: Add a -a flag to the show command, so we can display the full GPT with all information in one go. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.31 -r1.32 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.43 src/sbin/gpt/gpt.8:1.44 --- src/sbin/gpt/gpt.8:1.43 Sun Dec 6 09:36:57 2015 +++ src/sbin/gpt/gpt.8 Fri Dec 25 10:59:56 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.43 2015/12/06 09:36:57 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.44 2015/12/25 10:59:56 martin 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 6, 2015 +.Dd December 25, 2015 .Dt GPT 8 .Os .Sh NAME @@ -523,7 +523,7 @@ They may be used by .Nx code in the future. .\" show -.It Nm Ic show Oo Fl glu Oc Oo Fl i Ar index Oc +.It Nm Ic show Oo Fl glu Oc Oo Fl i Ar index Oc Oo Fl a Oc The .Ic show command displays the current partitioning on the listed devices and gives @@ -544,8 +544,14 @@ With the .Fl i option, all the details of a particular GPT partition will be displayed. The format of this display is subject to change. +With the +.Fl a +option, all information for all GPT partitions (just like with +.Fl i Ar index ) +will be printed. None of the options have any effect on non-GPT partitions. The order of precedence for the options are: +.Fl a , .Fl i , .Fl l , .Fl g , Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.31 src/sbin/gpt/show.c:1.32 --- src/sbin/gpt/show.c:1.31 Sun Dec 6 00:39:26 2015 +++ src/sbin/gpt/show.c Fri Dec 25 10:59:56 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.31 2015/12/06 00:39:26 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.32 2015/12/25 10:59:56 martin Exp $"); #endif #include @@ -52,12 +52,13 @@ __RCSID("$NetBSD: show.c,v 1.31 2015/12/ static int cmd_show(gpt_t, int, char *[]); static const char *showhelp[] = { - "[-glu] [-i index]", + "[-glu] [-i index] [-a]", }; #define SHOW_UUID 1 #define SHOW_GUID 2 #define SHOW_LABEL 4 +#define SHOW_ALL 8 struct gpt_cmd c_show = { "show", @@ -68,17 +69,86 @@ struct gpt_cmd c_show = { #define usage() gpt_usage(NULL, _show) -static int -show(gpt_t gpt, int show) +static void +print_part_type(int map_type, int flags, void *map_data, off_t map_start) { off_t start; - map_t m, p; + map_t p; struct mbr *mbr; struct gpt_ent *ent; unsigned int i; char buf[128], *b = buf; uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1]; + switch (map_type) { + case MAP_TYPE_UNUSED: + printf("Unused"); + break; + case MAP_TYPE_MBR: + if (map_start != 0) + printf("Extended "); + printf("MBR"); + break; + case MAP_TYPE_PRI_GPT_HDR: + printf("Pri GPT header"); + break; + case MAP_TYPE_SEC_GPT_HDR: + printf("Sec GPT header"); + break; + case MAP_TYPE_PRI_GPT_TBL: + printf("Pri GPT table"); + break; + case MAP_TYPE_SEC_GPT_TBL: + printf("Sec GPT table"); + break; + case MAP_TYPE_MBR_PART: + p = map_data; + if (p->map_start != 0) + printf("Extended "); + printf("MBR part "); + mbr = p->map_data; + for (i = 0; i < 4; i++) { + start = le16toh(mbr->mbr_part[i].part_start_hi); + start = (start << 16) + + le16toh(mbr->mbr_part[i].part_start_lo); + if (map_start == p->map_start + start) +break; + } + printf("%d", mbr->mbr_part[i].part_typ); + break; + case MAP_TYPE_GPT_PART: + printf("GPT part "); + ent = map_data; + if (flags & SHOW_LABEL) { + utf16_to_utf8(ent->ent_name, utfbuf, + sizeof(utfbuf)); + b = (char *)utfbuf; + } else if (flags & SHOW_GUID) { + gpt_uuid_snprintf( buf, sizeof(buf), "%d", + ent->ent_guid); + } else if (flags & SHOW_UUID) { + gpt_uuid_snprintf(buf, sizeof(buf), + "%d", ent->ent_type); + } else { + gpt_uuid_snprintf(buf, sizeof(buf), "%ls", + ent->ent_type); + } + printf("- %s", b); + break; + case MAP_TYPE_PMBR: + printf("PMBR"); + break; + default: + printf("Unknown %#x", map_type); + break; + } +} + +static int +show(gpt_t gpt, int show) +{ + map_t m; + printf(" %*s", gpt->lbawidth, "start"); printf(" %*s", gpt->lbawidth, "size"); printf(" index contents\n"); @@ -95,68 +165,7 @@ show(gpt_t gpt, int show) printf(" "); putchar(' '); putchar(' '); - switch (m->map_type) { - case MAP_TYPE_UNUSED: - printf("Unused"); - break; - case MAP_TYPE_MBR: - if (m->map_start != 0) -printf("Extended "); - printf("MBR"); - break; - case MAP_TYPE_PRI_GPT_HDR: - printf("Pri GPT
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Fri Dec 25 12:16:03 UTC 2015 Modified Files: src/sbin/gpt: gpt.8 show.c Log Message: Simplify usage for gpt show. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.32 -r1.33 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.44 src/sbin/gpt/gpt.8:1.45 --- src/sbin/gpt/gpt.8:1.44 Fri Dec 25 10:59:56 2015 +++ src/sbin/gpt/gpt.8 Fri Dec 25 12:16:03 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.44 2015/12/25 10:59:56 martin Exp $ +.\" $NetBSD: gpt.8,v 1.45 2015/12/25 12:16:03 wiz Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -523,7 +523,7 @@ They may be used by .Nx code in the future. .\" show -.It Nm Ic show Oo Fl glu Oc Oo Fl i Ar index Oc Oo Fl a Oc +.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc The .Ic show command displays the current partitioning on the listed devices and gives Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.32 src/sbin/gpt/show.c:1.33 --- src/sbin/gpt/show.c:1.32 Fri Dec 25 10:59:56 2015 +++ src/sbin/gpt/show.c Fri Dec 25 12:16:03 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.32 2015/12/25 10:59:56 martin Exp $"); +__RCSID("$NetBSD: show.c,v 1.33 2015/12/25 12:16:03 wiz Exp $"); #endif #include @@ -52,7 +52,7 @@ __RCSID("$NetBSD: show.c,v 1.32 2015/12/ static int cmd_show(gpt_t, int, char *[]); static const char *showhelp[] = { - "[-glu] [-i index] [-a]", + "[-aglu] [-i index]", }; #define SHOW_UUID 1
CVS commit: src/sbin/gpt
Module Name:src Committed By: martin Date: Thu Dec 24 17:35:57 UTC 2015 Modified Files: src/sbin/gpt: header.c Log Message: Fix output in an error case To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/header.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/header.c diff -u src/sbin/gpt/header.c:1.7 src/sbin/gpt/header.c:1.8 --- src/sbin/gpt/header.c:1.7 Thu Dec 3 02:02:43 2015 +++ src/sbin/gpt/header.c Thu Dec 24 17:35:57 2015 @@ -33,7 +33,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: header.c,v 1.7 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: header.c,v 1.8 2015/12/24 17:35:57 martin Exp $"); #endif #include @@ -82,7 +82,7 @@ header(gpt_t gpt) map = map_find(gpt, MAP_TYPE_PRI_GPT_HDR); if (map == NULL) { - printf("- GPT Header not found"); + printf("- GPT Header not found\n"); return 0; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Sun Dec 6 04:27:05 UTC 2015 Modified Files: src/sbin/gpt: gpt_uuid.h migrate.c Log Message: remove more duplicated code. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sbin/gpt/gpt_uuid.h cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/migrate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt_uuid.h diff -u src/sbin/gpt/gpt_uuid.h:1.6 src/sbin/gpt/gpt_uuid.h:1.7 --- src/sbin/gpt/gpt_uuid.h:1.6 Sat Dec 5 19:39:26 2015 +++ src/sbin/gpt/gpt_uuid.h Sat Dec 5 23:27:05 2015 @@ -46,6 +46,7 @@ // Must match the array in gpt_uuid.c typedef enum { + GPT_TYPE_INVALID = -1, GPT_TYPE_APPLE_HFS = 0, GPT_TYPE_APPLE_UFS, GPT_TYPE_BIOS, Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.28 src/sbin/gpt/migrate.c:1.29 --- src/sbin/gpt/migrate.c:1.28 Sat Dec 5 13:46:08 2015 +++ src/sbin/gpt/migrate.c Sat Dec 5 23:27:05 2015 @@ -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.28 2015/12/05 18:46:08 christos Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.29 2015/12/06 04:27:05 christos Exp $"); #endif #include @@ -118,86 +118,58 @@ mbrptypename(u_int t) return buf; } -static struct gpt_ent * -migrate_disklabel(gpt_t gpt, off_t start, struct gpt_ent *ent) +static gpt_type_t +freebsd_fstype_to_gpt_type(gpt_t gpt, u_int i, u_int fstype) { - char *buf; - struct disklabel *dl; - off_t ofs, rawofs; - int i; - - buf = gpt_read(gpt, start + LABELSECTOR, 1); - if (buf == NULL) { - gpt_warn(gpt, "Error reading label"); - return NULL; - } - dl = (void*)(buf + LABELOFFSET); - - if (le32toh(dl->d_magic) != DISKMAGIC || - le32toh(dl->d_magic2) != DISKMAGIC) { - gpt_warnx(gpt, "FreeBSD slice without disklabel"); - free(buf); - return (ent); - } - - rawofs = le32toh(dl->d_partitions[RAW_PART].p_offset) * - le32toh(dl->d_secsize); - for (i = 0; i < le16toh(dl->d_npartitions); i++) { - if (dl->d_partitions[i].p_fstype == FS_UNUSED) - continue; - ofs = le32toh(dl->d_partitions[i].p_offset) * - le32toh(dl->d_secsize); - if (ofs < rawofs) - rawofs = 0; + switch (fstype) { + case FS_UNUSED: + return GPT_TYPE_INVALID; + case FS_SWAP: + return GPT_TYPE_FREEBSD_SWAP; + case FS_BSDFFS: + return GPT_TYPE_FREEBSD_UFS; + case FREEBSD_FS_VINUM: + return GPT_TYPE_FREEBSD_VINUM; + case FREEBSD_FS_ZFS: + return GPT_TYPE_FREEBSD_ZFS; + default: + gpt_warnx(gpt, "Unknown FreeBSD partition (%d)", fstype); + return GPT_TYPE_INVALID; } - rawofs /= gpt->secsz; - - for (i = 0; i < le16toh(dl->d_npartitions); i++) { - switch (dl->d_partitions[i].p_fstype) { - case FS_UNUSED: - continue; - case FS_SWAP: { - gpt_uuid_create(GPT_TYPE_FREEBSD_SWAP, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); - break; - } - case FS_BSDFFS: { - gpt_uuid_create(GPT_TYPE_FREEBSD_UFS, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); - break; - } - case FREEBSD_FS_VINUM: { - gpt_uuid_create(GPT_TYPE_FREEBSD_VINUM, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); - break; - } - case FREEBSD_FS_ZFS: { - gpt_uuid_create(GPT_TYPE_FREEBSD_ZFS, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); - break; - } - default: - gpt_warnx(gpt, "Unknown FreeBSD partition (%d)", - dl->d_partitions[i].p_fstype); - continue; - } +} - ofs = (le32toh(dl->d_partitions[i].p_offset) * - le32toh(dl->d_secsize)) / gpt->secsz; - ofs = (ofs > 0) ? ofs - rawofs : 0; - ent->ent_lba_start = htole64((uint64_t)(start + ofs)); - ent->ent_lba_end = htole64((uint64_t)(start + ofs + - (off_t)le32toh((uint64_t)dl->d_partitions[i].p_size) - - 1LL)); - ent++; +static gpt_type_t +netbsd_fstype_to_gpt_type(gpt_t gpt, u_int i, u_int fstype) +{ + switch (fstype) { + case FS_UNUSED: + return GPT_TYPE_INVALID; + case FS_HFS: + return GPT_TYPE_APPLE_HFS; + case FS_EX2FS: + return GPT_TYPE_LINUX_DATA; + case FS_SWAP: + return GPT_TYPE_NETBSD_SWAP; + case FS_BSDFFS: + return GPT_TYPE_NETBSD_FFS; + case FS_BSDLFS: + return GPT_TYPE_NETBSD_LFS; + case FS_RAID: + return GPT_TYPE_NETBSD_RAIDFRAME; + case FS_CCD: + return GPT_TYPE_NETBSD_CCD; + case FS_CGD: + return GPT_TYPE_NETBSD_CGD; + default: + gpt_warnx(gpt, "Partition %u unknown type %s, " + "using \"Microsoft Basic Data\"", i, fstypename(fstype)); + return GPT_TYPE_MS_BASIC_DATA; } - - free(buf); - return ent; } -static struct gpt_ent* -migrate_netbsd_disklabel(gpt_t gpt, off_t start, struct gpt_ent *ent) +static struct gpt_ent * +migrate_disklabel(gpt_t gpt, off_t start, struct gpt_ent *ent, +gpt_type_t (*convert)(gpt_t, u_int, u_int)) { char *buf; struct disklabel *dl; @@ -214,7 +186,7 @@ migrate_netbsd_disklabel(gpt_t gpt, off_ if (le32toh(dl->d_magic) != DISKMAGIC ||
CVS commit: src/sbin/gpt
Module Name:src Committed By: wiz Date: Sun Dec 6 09:36:58 UTC 2015 Modified Files: src/sbin/gpt: gpt.8 Log Message: Bump date for previous. Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.42 src/sbin/gpt/gpt.8:1.43 --- src/sbin/gpt/gpt.8:1.42 Sun Dec 6 00:39:26 2015 +++ src/sbin/gpt/gpt.8 Sun Dec 6 09:36:57 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.42 2015/12/06 00:39:26 christos Exp $ +.\" $NetBSD: gpt.8,v 1.43 2015/12/06 09:36:57 wiz 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 November 30, 2015 +.Dd December 6, 2015 .Dt GPT 8 .Os .Sh NAME @@ -570,7 +570,7 @@ The flag lists available types. .\" unset .It Nm Ic unset Fl a Ar attribute Fl i Ar index -.It Nm Ic unset Fl l +.It Nm Ic unset Fl l The .Ic unset command unsets various partition attributes.
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Sun Dec 6 00:39:26 UTC 2015 Modified Files: src/sbin/gpt: gpt.8 gpt.c gpt.h gpt_uuid.c gpt_uuid.h set.c show.c type.c unset.c Log Message: Add listing commands for type, set and unset. Add help and formatting for set and unset. Change show to print all the attribute info in one line. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/gpt.8 cvs rdiff -u -r1.63 -r1.64 src/sbin/gpt/gpt.c cvs rdiff -u -r1.30 -r1.31 src/sbin/gpt/gpt.h src/sbin/gpt/show.c cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/gpt_uuid.c src/sbin/gpt/type.c cvs rdiff -u -r1.5 -r1.6 src/sbin/gpt/gpt_uuid.h cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/set.c src/sbin/gpt/unset.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.41 src/sbin/gpt/gpt.8:1.42 --- src/sbin/gpt/gpt.8:1.41 Wed Dec 2 07:36:53 2015 +++ src/sbin/gpt/gpt.8 Sat Dec 5 19:39:26 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.41 2015/12/02 12:36:53 christos Exp $ +.\" $NetBSD: gpt.8,v 1.42 2015/12/06 00:39:26 christos Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -488,26 +488,33 @@ will automatically adjust. However, the new disk must use the same sector size as the old disk. .\" set .It Nm Ic set Fl a Ar attribute Fl i Ar index +.It Nm Ic set Fl l The .Ic set command sets various partition attributes. The +.Fl l +flag lists all available attributes. +The .Fl a -option specifies which attributes to set and may be specified more than once. +option specifies which attributes to set and may be specified more than once, +or the attributes can be comma-separated. The .Fl i option specifies which entry to update. The possible attributes are .Do biosboot Dc , .Do bootme Dc , -.Do bootonce Dc , and -.Do bootfailed Dc . +.Do bootonce Dc , +.Do bootfailed Dc , +.Do noblockio Dc , and +.Do required Dc . The biosboot flag is used to indicate which partition should be booted by legacy BIOS boot code. See the .Ic biosboot command for more information. -The other three attributes are for compatibility with +The other attributes are for compatibility with .Fx and are not currently used by any .Nx @@ -546,8 +553,10 @@ The order of precedence for the options .\" type .It Nm Ic type Oo Fl a Oc Fl T Ar newtype .It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \ +.It Nm Ic type Oo Fl b Ar blocknr Oc Oo Fl i Ar index Oc \ Oo Fl L Ar label Oc Oo Fl s Ar sectors Oc Oo Fl t Ar type Oc \ Fl T Ar newtype +.It Nm Ic type Fl l The .Ic type command allows the user to change the type of any and all partitions @@ -556,12 +565,19 @@ It uses the same selection options as th .Ic label command. See above for a description of these options. +The +.Fl l +flag lists available types. .\" unset .It Nm Ic unset Fl a Ar attribute Fl i Ar index +.It Nm Ic unset Fl l The .Ic unset command unsets various partition attributes. The +.Fl l +flag lists all available attributes. +The .Fl a option specifies which attributes to unset and may be specified more than once. The @@ -570,14 +586,16 @@ option specifies which entry to update. The possible attributes are .Do biosboot Dc , .Do bootme Dc , -.Do bootonce Dc , and -.Do bootfailed Dc . +.Do bootonce Dc , +.Do bootfailed Dc , +.Do noblockio Dc , and +.Do required Dc . The biosboot flag is used to indicate which partition should be booted by legacy BIOS boot code. See the .Ic biosboot command for more information. -The other three attributes are for compatibility with +The other attributes are for compatibility with .Fx and are not currently used by any .Nx Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.63 src/sbin/gpt/gpt.c:1.64 --- src/sbin/gpt/gpt.c:1.63 Fri Dec 4 11:46:24 2015 +++ src/sbin/gpt/gpt.c Sat Dec 5 19:39:26 2015 @@ -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.63 2015/12/04 16:46:24 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.64 2015/12/06 00:39:26 christos Exp $"); #endif #include @@ -1076,21 +1076,90 @@ gpt_check_ais(gpt_t gpt, off_t alignment return size / gpt->secsz; return 0; } + +static const struct nvd { + const char *name; + uint64_t mask; + const char *description; +} gpt_attr[] = { + { + "biosboot", + GPT_ENT_ATTR_LEGACY_BIOS_BOOTABLE, + "Legacy BIOS boot partition", + }, + { + "bootme", + GPT_ENT_ATTR_BOOTME, + "Bootable partition", + }, + { + "bootfailed", + GPT_ENT_ATTR_BOOTFAILED, + "Partition that marked bootonce failed to boot", + }, + { + "bootonce", + GPT_ENT_ATTR_BOOTONCE, + "Attempt to boot this partition only once", + }, + { + "noblockio", + GPT_ENT_ATTR_NO_BLOCK_IO_PROTOCOL, + "UEFI won't recognize file system for block I/O", + }, + { +
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Sat Dec 5 18:46:08 UTC 2015 Modified Files: src/sbin/gpt: migrate.c Log Message: Add debugging and more to migration To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/gpt/migrate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.27 src/sbin/gpt/migrate.c:1.28 --- src/sbin/gpt/migrate.c:1.27 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/migrate.c Sat Dec 5 13:46:08 2015 @@ -33,11 +33,13 @@ __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.27 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.28 2015/12/05 18:46:08 christos Exp $"); #endif #include #include +#define FSTYPENAMES +#define MBRPTYPENAMES #ifdef HAVE_NBTOOL_CONFIG_H #include #include @@ -91,6 +93,31 @@ struct gpt_cmd c_migrate = { #define usage() gpt_usage(NULL, _migrate) +static const char * +fstypename(u_int t) +{ + static char buf[64]; + if (t >= __arraycount(fstypenames)) { + snprintf(buf, sizeof(buf), "*%u*", t); + return buf; + } + return fstypenames[t]; +} + +static const char * +mbrptypename(u_int t) +{ + static char buf[64]; + size_t i; + + for (i = 0; i < __arraycount(mbr_ptypes); i++) + if ((u_int)mbr_ptypes[i].id == t) + return mbr_ptypes[i].name; + + snprintf(buf, sizeof(buf), "*%u*", t); + return buf; +} + static struct gpt_ent * migrate_disklabel(gpt_t gpt, off_t start, struct gpt_ent *ent) { @@ -175,7 +202,8 @@ migrate_netbsd_disklabel(gpt_t gpt, off_ char *buf; struct disklabel *dl; off_t ofs, rawofs; - int i; + unsigned int i; + gpt_type_t type; buf = gpt_read(gpt, start + LABELSECTOR, 1); if (buf == NULL) { @@ -201,48 +229,53 @@ migrate_netbsd_disklabel(gpt_t gpt, off_ if (ofs < rawofs) rawofs = 0; } + if (gpt->verbose > 1) + gpt_msg(gpt, "rawofs=%ju", (uintmax_t)rawofs); rawofs /= gpt->secsz; for (i = 0; i < le16toh(dl->d_npartitions); i++) { + if (gpt->verbose > 1) + gpt_msg(gpt, "Disklabel partition %u type %s", i, + fstypename(dl->d_partitions[i].p_fstype)); + switch (dl->d_partitions[i].p_fstype) { case FS_UNUSED: continue; - case FS_SWAP: { - gpt_uuid_create(GPT_TYPE_NETBSD_SWAP, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_HFS: + type = GPT_TYPE_APPLE_HFS; break; - } - case FS_BSDFFS: { - gpt_uuid_create(GPT_TYPE_NETBSD_FFS, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_EX2FS: + type = GPT_TYPE_LINUX_DATA; break; - } - case FS_BSDLFS: { - gpt_uuid_create(GPT_TYPE_NETBSD_LFS, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_SWAP: + type = GPT_TYPE_NETBSD_SWAP; break; - } - case FS_RAID: { - gpt_uuid_create(GPT_TYPE_NETBSD_RAIDFRAME, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_BSDFFS: + type = GPT_TYPE_NETBSD_FFS; break; - } - case FS_CCD: { - gpt_uuid_create(GPT_TYPE_NETBSD_CCD, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_BSDLFS: + type = GPT_TYPE_NETBSD_LFS; break; - } - case FS_CGD: { - gpt_uuid_create(GPT_TYPE_NETBSD_CGD, ent->ent_type, - ent->ent_name, sizeof(ent->ent_name)); + case FS_RAID: + type = GPT_TYPE_NETBSD_RAIDFRAME; + break; + case FS_CCD: + type = GPT_TYPE_NETBSD_CCD; + break; + case FS_CGD: + type = GPT_TYPE_NETBSD_CGD; break; - } default: - gpt_warnx(gpt, "Unknown NetBSD partition (%d)", - dl->d_partitions[i].p_fstype); - continue; + gpt_warnx(gpt, "Partition %u unknown type %s, " + "using \"Microsoft Basic Data\"", i, + fstypename(dl->d_partitions[i].p_fstype)); + type = GPT_TYPE_MS_BASIC_DATA; + break; } + gpt_uuid_create(type, ent->ent_type, + ent->ent_name, sizeof(ent->ent_name)); + ofs = (le32toh(dl->d_partitions[i].p_offset) * le32toh(dl->d_secsize)) / gpt->secsz; ofs = (ofs > 0) ? ofs - rawofs : 0; @@ -269,7 +302,7 @@ migrate(gpt_t gpt, u_int parts, int forc map = map_find(gpt, MAP_TYPE_MBR); if (map == NULL || map->map_start != 0) { - gpt_warnx(gpt, "No partitions to convert"); + gpt_warnx(gpt, "No MBR in disk to convert"); return -1; } @@ -287,6 +320,9 @@ migrate(gpt_t gpt, u_int parts, int forc size = le16toh(mbr->mbr_part[i].part_size_hi); size = (size << 16) + le16toh(mbr->mbr_part[i].part_size_lo); + if (gpt->verbose > 1) + gpt_msg(gpt, "MBR partition %u type %s", i, + mbrptypename(mbr->mbr_part[i].part_typ)); switch (mbr->mbr_part[i].part_typ) { case MBR_PTYPE_UNUSED: continue;
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 16:54:28 UTC 2015 Modified Files: src/sbin/gpt: resize.c Log Message: Kill newline To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sbin/gpt/resize.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/resize.c diff -u src/sbin/gpt/resize.c:1.21 src/sbin/gpt/resize.c:1.22 --- src/sbin/gpt/resize.c:1.21 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/resize.c Fri Dec 4 11:54:28 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resize.c,v 1.21 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: resize.c,v 1.22 2015/12/04 16:54:28 christos Exp $"); #endif #include @@ -121,7 +121,7 @@ resize(gpt_t gpt, u_int entry, off_t ali if (gpt_write_backup(gpt) == -1) return -1; - gpt_msg(gpt, "Partition %d resized: %" PRIu64 " %" PRIu64 "\n", entry, + gpt_msg(gpt, "Partition %d resized: %" PRIu64 " %" PRIu64, entry, map->map_start, newsize); return 0;
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 16:46:24 UTC 2015 Modified Files: src/sbin/gpt: gpt.c gpt.h recover.c resizedisk.c Log Message: Fix resizedisk. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/sbin/gpt/gpt.c cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/gpt.h cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/recover.c cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.62 src/sbin/gpt/gpt.c:1.63 --- src/sbin/gpt/gpt.c:1.62 Thu Dec 3 20:46:32 2015 +++ src/sbin/gpt/gpt.c Fri Dec 4 11:46:24 2015 @@ -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.62 2015/12/04 01:46:32 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.63 2015/12/04 16:46:24 christos Exp $"); #endif #include @@ -829,16 +829,8 @@ gpt_create(gpt_t gpt, off_t last, u_int blocks--; /* Number of blocks in the GPT table. */ - if ((p = calloc(1, gpt->secsz)) == NULL) { - gpt_warnx(gpt, "Can't allocate the primary GPT"); - return -1; - } - if ((gpt->gpt = map_add(gpt, 1LL, 1LL, - MAP_TYPE_PRI_GPT_HDR, p, 1)) == NULL) { - free(p); - gpt_warnx(gpt, "Can't add the primary GPT"); + if (gpt_add_hdr(gpt, MAP_TYPE_PRI_GPT_HDR, 1) == -1) return -1; - } if ((p = calloc((size_t)blocks, gpt->secsz)) == NULL) { gpt_warnx(gpt, "Can't allocate the primary GPT table"); @@ -885,16 +877,8 @@ gpt_create(gpt_t gpt, off_t last, u_int if (primary_only) return last; - if ((p = calloc(1, gpt->secsz)) == NULL) { - gpt_warnx(gpt, "Can't allocate the secondary GPT"); + if (gpt_add_hdr(gpt, MAP_TYPE_SEC_GPT_HDR, last) == -1) return -1; - } - - if ((gpt->tpg = map_add(gpt, last, 1LL, - MAP_TYPE_SEC_GPT_HDR, p, 1)) == NULL) { - gpt_warnx(gpt, "Can't add the secondary GPT"); - return -1; - } if ((gpt->lbt = map_add(gpt, last - blocks, blocks, MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data, 0)) == NULL) { @@ -1202,3 +1186,38 @@ gpt_show_num(const char *prompt, uintmax #endif printf("\n"); } + +int +gpt_add_hdr(gpt_t gpt, int type, off_t loc) +{ + void *p; + map_t *t; + const char *msg; + + switch (type) { + case MAP_TYPE_PRI_GPT_HDR: + t = >gpt; + msg = "primary"; + break; + case MAP_TYPE_SEC_GPT_HDR: + t = >tpg; + msg = "secondary"; + break; + default: + gpt_warnx(gpt, "Unknown GPT header type %d", type); + return -1; + } + + if ((p = calloc(1, gpt->secsz)) == NULL) { + gpt_warn(gpt, "Error allocating %s GPT header", msg); + return -1; + } + + *t = map_add(gpt, loc, 1LL, type, p, 1); + if (*t == NULL) { + gpt_warn(gpt, "Error adding %s GPT header", msg); + free(p); + return -1; + } + return 0; +} Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.29 src/sbin/gpt/gpt.h:1.30 --- src/sbin/gpt/gpt.h:1.29 Thu Dec 3 20:46:32 2015 +++ src/sbin/gpt/gpt.h Fri Dec 4 11:46:24 2015 @@ -125,6 +125,7 @@ int gpt_uint_get(u_int *); int gpt_human_get(off_t *); int gpt_uuid_get(gpt_t, gpt_uuid_t *); int gpt_name_get(gpt_t, void *); +int gpt_add_hdr(gpt_t, int, off_t); void gpt_show_num(const char *, uintmax_t); #endif /* _GPT_H_ */ Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.14 src/sbin/gpt/recover.c:1.15 --- src/sbin/gpt/recover.c:1.14 Thu Dec 3 16:30:54 2015 +++ src/sbin/gpt/recover.c Fri Dec 4 11:46:24 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.14 2015/12/03 21:30:54 christos Exp $"); +__RCSID("$NetBSD: recover.c,v 1.15 2015/12/04 16:46:24 christos Exp $"); #endif #include @@ -68,10 +68,12 @@ static int recover_gpt_hdr(gpt_t gpt, int type, off_t last) { const char *name, *origname; - void *p; map_t *dgpt, dtbl, sgpt, stbl; struct gpt_hdr *hdr; + if (gpt_add_hdr(gpt, type, last) == -1) + return -1; + switch (type) { case MAP_TYPE_PRI_GPT_HDR: dgpt = >gpt; @@ -94,14 +96,6 @@ recover_gpt_hdr(gpt_t gpt, int type, off return -1; } - if ((p = calloc(1, gpt->secsz)) == NULL) { - gpt_warn(gpt, "Cannot allocate %s GPT header", name); - return -1; - } - if ((*dgpt = map_add(gpt, last, 1LL, type, p, 1)) == NULL) { - gpt_warnx(gpt, "Cannot add %s GPT header", name); - return -1; - } memcpy((*dgpt)->map_data, sgpt->map_data, gpt->secsz); hdr = (*dgpt)->map_data; hdr->hdr_lba_self = htole64((uint64_t)(*dgpt)->map_start); Index: src/sbin/gpt/resizedisk.c diff -u src/sbin/gpt/resizedisk.c:1.15 src/sbin/gpt/resizedisk.c:1.16 --- src/sbin/gpt/resizedisk.c:1.15 Thu Dec 3 16:30:54 2015 +++ src/sbin/gpt/resizedisk.c Fri Dec 4 11:46:24 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resizedisk.c,v 1.15 2015/12/03
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 21:39:18 UTC 2015 Modified Files: src/sbin/gpt: resizedisk.c Log Message: type confusion To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/resizedisk.c diff -u src/sbin/gpt/resizedisk.c:1.16 src/sbin/gpt/resizedisk.c:1.17 --- src/sbin/gpt/resizedisk.c:1.16 Fri Dec 4 11:46:24 2015 +++ src/sbin/gpt/resizedisk.c Fri Dec 4 16:39:18 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resizedisk.c,v 1.16 2015/12/04 16:46:24 christos Exp $"); +__RCSID("$NetBSD: resizedisk.c,v 1.17 2015/12/04 21:39:18 christos Exp $"); #endif #include @@ -272,7 +272,7 @@ cmd_resizedisk(gpt_t gpt, int argc, char return -1; if (--sector == 0) { - gpt_warnx(gpt, "New size %ju too small", (uintptr_t)size); + gpt_warnx(gpt, "New size %ju too small", (uintmax_t)size); return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:30:54 UTC 2015 Modified Files: src/sbin/gpt: create.c gpt.c map.c map.h recover.c resizedisk.c Log Message: CID 1341556: Don't leak map info To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/create.c cvs rdiff -u -r1.60 -r1.61 src/sbin/gpt/gpt.c cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/map.c cvs rdiff -u -r1.5 -r1.6 src/sbin/gpt/map.h cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/recover.c cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.18 src/sbin/gpt/create.c:1.19 --- src/sbin/gpt/create.c:1.18 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/create.c Thu Dec 3 16:30:54 2015 @@ -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.18 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.19 2015/12/03 21:30:54 christos Exp $"); #endif #include @@ -102,7 +102,7 @@ create(gpt_t gpt, u_int parts, int force mbr->mbr_sig = htole16(MBR_SIG); gpt_create_pmbr_part(mbr->mbr_part, last); - map = map_add(gpt, 0LL, 1LL, MAP_TYPE_PMBR, mbr); + map = map_add(gpt, 0LL, 1LL, MAP_TYPE_PMBR, mbr, 1); if (gpt_write(gpt, map) == -1) { gpt_warn(gpt, "Can't write PMBR"); return -1; Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.60 src/sbin/gpt/gpt.c:1.61 --- src/sbin/gpt/gpt.c:1.60 Wed Dec 2 21:16:00 2015 +++ src/sbin/gpt/gpt.c Thu Dec 3 16:30:54 2015 @@ -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.60 2015/12/03 02:16:00 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.61 2015/12/03 21:30:54 christos Exp $"); #endif #include @@ -308,7 +308,7 @@ gpt_mbr(gpt_t gpt, off_t lba) (uintmax_t)lba); else if (gpt->verbose > 1) gpt_msg(gpt, "PMBR at sector %ju", (uintmax_t)lba); - p = map_add(gpt, lba, 1LL, MAP_TYPE_PMBR, mbr); + p = map_add(gpt, lba, 1LL, MAP_TYPE_PMBR, mbr, 1); goto out; } if (pmbr) @@ -316,7 +316,7 @@ gpt_mbr(gpt_t gpt, off_t lba) else if (gpt->verbose > 1) gpt_msg(gpt, "MBR at sector %ju", (uintmax_t)lba); - p = map_add(gpt, lba, 1LL, MAP_TYPE_MBR, mbr); + p = map_add(gpt, lba, 1LL, MAP_TYPE_MBR, mbr, 1); if (p == NULL) goto out; @@ -340,8 +340,7 @@ gpt_mbr(gpt_t gpt, off_t lba) mbr->mbr_part[i].part_typ, (uintmax_t)start, (uintmax_t)size); if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) { - // XXX: map add with non-allocated memory - m = map_add(gpt, start, size, MAP_TYPE_MBR_PART, p); + m = map_add(gpt, start, size, MAP_TYPE_MBR_PART, p, 0); if (m == NULL) return -1; m->map_index = i + 1; @@ -415,13 +414,13 @@ gpt_gpt(gpt_t gpt, off_t lba, int found) (lba == 1) ? "Pri" : "Sec", (uintmax_t)lba); m = map_add(gpt, lba, 1, (lba == 1) - ? MAP_TYPE_PRI_GPT_HDR : MAP_TYPE_SEC_GPT_HDR, hdr); + ? MAP_TYPE_PRI_GPT_HDR : MAP_TYPE_SEC_GPT_HDR, hdr, 1); if (m == NULL) return (-1); m = map_add(gpt, (off_t)le64toh((uint64_t)hdr->hdr_lba_table), (off_t)blocks, - lba == 1 ? MAP_TYPE_PRI_GPT_TBL : MAP_TYPE_SEC_GPT_TBL, p); + lba == 1 ? MAP_TYPE_PRI_GPT_TBL : MAP_TYPE_SEC_GPT_TBL, p, 1); if (m == NULL) return (-1); @@ -444,9 +443,8 @@ gpt_gpt(gpt_t gpt, off_t lba, int found) (uintmax_t)le64toh(ent->ent_lba_start), (uintmax_t)size); } - // XXX: map add with not allocated memory. m = map_add(gpt, (off_t)le64toh((uint64_t)ent->ent_lba_start), - size, MAP_TYPE_GPT_PART, ent); + size, MAP_TYPE_GPT_PART, ent, 0); if (m == NULL) return (-1); m->map_index = i + 1; @@ -835,7 +833,7 @@ gpt_create(gpt_t gpt, off_t last, u_int return -1; } if ((gpt->gpt = map_add(gpt, 1LL, 1LL, - MAP_TYPE_PRI_GPT_HDR, p)) == NULL) { + MAP_TYPE_PRI_GPT_HDR, p, 1)) == NULL) { free(p); gpt_warnx(gpt, "Can't add the primary GPT"); return -1; @@ -846,7 +844,7 @@ gpt_create(gpt_t gpt, off_t last, u_int return -1; } if ((gpt->tbl = map_add(gpt, 2LL, blocks, - MAP_TYPE_PRI_GPT_TBL, p)) == NULL) { + MAP_TYPE_PRI_GPT_TBL, p, 1)) == NULL) { free(p); gpt_warnx(gpt, "Can't add the primary GPT table"); return -1; @@ -892,13 +890,13 @@ gpt_create(gpt_t gpt, off_t last, u_int } if ((gpt->tpg = map_add(gpt, last, 1LL, - MAP_TYPE_SEC_GPT_HDR, p)) == NULL) { + MAP_TYPE_SEC_GPT_HDR, p, 1)) == NULL) { gpt_warnx(gpt, "Can't add the secondary GPT"); return -1; } if ((gpt->lbt = map_add(gpt, last - blocks, blocks, - MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data)) == NULL) { + MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data, 0)) == NULL) { gpt_warnx(gpt, "Can't add the secondary GPT table");
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 20:58:08 UTC 2015 Modified Files: src/sbin/gpt: add.c Log Message: CID 1341548: Check error returns To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/sbin/gpt/add.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.39 src/sbin/gpt/add.c:1.40 --- src/sbin/gpt/add.c:1.39 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/add.c Thu Dec 3 15:58:08 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.39 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.40 2015/12/03 20:58:08 christos Exp $"); #endif #include @@ -139,11 +139,13 @@ add(gpt_t gpt, off_t alignment, off_t bl } ent_set(ent, map, type, name); - gpt_write_primary(gpt); + if (gpt_write_primary(gpt) == -1) + return -1; ent = gpt_ent_backup(gpt, i); ent_set(ent, map, type, name); - gpt_write_backup(gpt); + if (gpt_write_backup(gpt) == -1) + return -1; gpt_uuid_snprintf(buf, sizeof(buf), "%d", type); gpt_msg(gpt, "Partition %d added: %s %" PRIu64 " %" PRIu64, i + 1,
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:51:02 UTC 2015 Modified Files: src/sbin/gpt: label.c Log Message: CID 1341564: Arg memory leak To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sbin/gpt/label.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/label.c diff -u src/sbin/gpt/label.c:1.26 src/sbin/gpt/label.c:1.27 --- src/sbin/gpt/label.c:1.26 Thu Dec 3 16:48:12 2015 +++ src/sbin/gpt/label.c Thu Dec 3 16:51:02 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: label.c,v 1.26 2015/12/03 21:48:12 christos Exp $"); +__RCSID("$NetBSD: label.c,v 1.27 2015/12/03 21:51:02 christos Exp $"); #endif #include @@ -135,21 +135,24 @@ cmd_label(gpt_t gpt, int argc, char *arg switch(ch) { case 'f': if (name_from_file(gpt, ) == -1) -return usage(); +goto usage; break; case 'l': if (gpt_name_get(gpt, ) == -1) -return usage(); +goto usage; break; default: if (gpt_add_find(gpt, , ch) == -1) -return usage(); +goto usage; break; } } if (name == NULL || argc != optind) - return usage(); + goto usage; return gpt_change_ent(gpt, , change, name); +usage: + free(name); + return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:40:32 UTC 2015 Modified Files: src/sbin/gpt: backup.c Log Message: CID 1341558: Fix proplib memory leaks To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/backup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.15 src/sbin/gpt/backup.c:1.16 --- src/sbin/gpt/backup.c:1.15 Wed Dec 2 23:39:41 2015 +++ src/sbin/gpt/backup.c Thu Dec 3 16:40:32 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.15 2015/12/03 04:39:41 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.16 2015/12/03 21:40:32 christos Exp $"); #endif #include @@ -66,10 +66,7 @@ struct gpt_cmd c_backup = { #define usage() gpt_usage(NULL, _backup) -#define PROP_ERR(x) if (!(x)) { \ - gpt_warnx(gpt, "proplib failure"); \ - return -1;\ - } +#define PROP_ERR(x) if (!(x)) goto cleanup #define prop_uint(a) prop_number_create_unsigned_integer(a) @@ -145,6 +142,11 @@ store_mbr(gpt_t gpt, unsigned int i, con rc = prop_array_add(*mbr_array, mbr_dict); PROP_ERR(rc); return 0; +cleanup: + if (mbr_dict) + prop_object_release(mbr_dict); + gpt_warnx(gpt, "proplib failure"); + return -1; } static int @@ -171,6 +173,10 @@ store_gpt(gpt_t gpt, const struct gpt_hd rc = prop_dictionary_set(*type_dict, "entries", propnum); PROP_ERR(rc); return 0; +cleanup: + if (*type_dict) + prop_object_release(*type_dict); + return -1; } static int @@ -186,12 +192,15 @@ store_tbl(gpt_t gpt, const map_t m, prop uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1]; bool rc; + *type_dict = NULL; + + gpt_array = prop_array_create(); + PROP_ERR(gpt_array); + *type_dict = prop_dictionary_create(); PROP_ERR(*type_dict); ent = m->map_data; - gpt_array = prop_array_create(); - PROP_ERR(gpt_array); for (i = 1, ent = m->map_data; (const char *)ent < (const char *)(m->map_data) + m->map_size * gpt->secsz; i++, ent++) { @@ -236,6 +245,12 @@ store_tbl(gpt_t gpt, const map_t m, prop PROP_ERR(rc); prop_object_release(gpt_array); return 0; +cleanup: + if (*type_dict) + prop_object_release(*type_dict); + if (gpt_array) + prop_object_release(gpt_array); + return -1; } static int @@ -274,7 +289,7 @@ backup(gpt_t gpt, const char *outfile) mbr_array = NULL; for (i = 0; i < 4; i++) { if (store_mbr(gpt, i, mbr, _array) == -1) - return -1; + goto cleanup; } if (mbr_array != NULL) { rc = prop_dictionary_set(type_dict, @@ -288,7 +303,7 @@ backup(gpt_t gpt, const char *outfile) break; case MAP_TYPE_PRI_GPT_HDR: if (store_gpt(gpt, m->map_data, _dict) == -1) -return -1; +goto cleanup; rc = prop_dictionary_set(props, "GPT_HDR", type_dict); PROP_ERR(rc); @@ -296,7 +311,7 @@ backup(gpt_t gpt, const char *outfile) break; case MAP_TYPE_PRI_GPT_TBL: if (store_tbl(gpt, m, _dict) == -1) -return -1; +goto cleanup; rc = prop_dictionary_set(props, "GPT_TBL", type_dict); PROP_ERR(rc); prop_object_release(type_dict); @@ -310,13 +325,18 @@ backup(gpt_t gpt, const char *outfile) fp = strcmp(outfile, "-") == 0 ? stdout : fopen(outfile, "w"); if (fp == NULL) { gpt_warn(gpt, "Can't open `%s'", outfile); - return -1; + free(propext); + goto cleanup; } fputs(propext, fp); if (fp != stdout) fclose(fp); free(propext); return 0; +cleanup: + if (props) + prop_object_release(props); + return -1; } static int
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:46:22 UTC 2015 Modified Files: src/sbin/gpt: add.c Log Message: CID 1341561: Argument memory leak To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sbin/gpt/add.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.41 src/sbin/gpt/add.c:1.42 --- src/sbin/gpt/add.c:1.41 Thu Dec 3 16:43:25 2015 +++ src/sbin/gpt/add.c Thu Dec 3 16:46:22 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.41 2015/12/03 21:43:25 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.42 2015/12/03 21:46:22 christos Exp $"); #endif #include @@ -200,10 +200,9 @@ cmd_add(gpt_t gpt, int argc, char *argv[ goto cleanup; return add(gpt, alignment, block, sectors, size, entry, name, type); +usage: + return usage(); cleanup: free(name); return -1; -usage: - free(name); - return usage(); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:48:12 UTC 2015 Modified Files: src/sbin/gpt: label.c Log Message: CID 1341563: fix leak To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/gpt/label.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/label.c diff -u src/sbin/gpt/label.c:1.25 src/sbin/gpt/label.c:1.26 --- src/sbin/gpt/label.c:1.25 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/label.c Thu Dec 3 16:48:12 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: label.c,v 1.25 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: label.c,v 1.26 2015/12/03 21:48:12 christos Exp $"); #endif #include @@ -98,13 +98,12 @@ name_from_file(gpt_t gpt, void *v) if ((*name = malloc(maxlen)) == NULL) { gpt_warn(gpt, "Can't copy string"); - return -1; + goto cleanup; } len = fread(*name, 1, maxlen - 1, f); if (ferror(f)) { - free(*name); gpt_warn(gpt, "Can't label from `%s'", fn); - return -1; + goto cleanup; } if (f != stdin) fclose(f); @@ -114,6 +113,11 @@ name_from_file(gpt_t gpt, void *v) if (p != NULL) *p = '\0'; return 0; +cleanup: + free(*name); + if (f != stdin) + fclose(f); + return -1; } static int
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:49:51 UTC 2015 Modified Files: src/sbin/gpt: biosboot.c Log Message: more leak To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sbin/gpt/biosboot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.22 src/sbin/gpt/biosboot.c:1.23 --- src/sbin/gpt/biosboot.c:1.22 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/biosboot.c Thu Dec 3 16:49:51 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.23 2015/12/03 21:49:51 christos Exp $"); #endif #include @@ -257,24 +257,24 @@ cmd_biosboot(gpt_t gpt, int argc, char * uint64_t size = 0; unsigned int entry = 0; uint8_t *label = NULL; - const char *bootpath = NULL; + char *bootpath = NULL; while ((ch = getopt(argc, argv, "c:i:L:")) != -1) { switch(ch) { case 'c': if (gpt_name_get(gpt, ) == -1) -return usage(); +goto usage; break; case 'i': if (gpt_uint_get() == -1) -return usage(); +goto usage; break; case 'L': if (gpt_name_get(gpt, ) == -1) -return usage(); +goto usage; break; default: - return usage(); + goto usage; } } @@ -286,18 +286,26 @@ cmd_biosboot(gpt_t gpt, int argc, char * ioctl(gpt->fd, DIOCGWEDGEINFO, ) != -1) { if (entry > 0) /* wedges and indexes are mutually exclusive */ - return usage(); + goto usage; start = dkw.dkw_offset; size = dkw.dkw_size; ngpt = gpt_open(dkw.dkw_parent, gpt->flags, gpt->verbose, gpt->mediasz, gpt->secsz); if (ngpt == NULL) - return -1; + goto cleanup; } #endif - biosboot(ngpt, start, size, entry, label, bootpath); + if (biosboot(ngpt, start, size, entry, label, bootpath) == -1) + goto cleanup; if (ngpt != gpt) gpt_close(ngpt); - return 0; +usage: + usage(); +cleanup: + if (ngpt != gpt) + gpt_close(ngpt); + free(bootpath); + free(label); + return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 21:43:25 UTC 2015 Modified Files: src/sbin/gpt: add.c Log Message: CID 1341560: Free arg. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sbin/gpt/add.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.40 src/sbin/gpt/add.c:1.41 --- src/sbin/gpt/add.c:1.40 Thu Dec 3 15:58:08 2015 +++ src/sbin/gpt/add.c Thu Dec 3 16:43:25 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.40 2015/12/03 20:58:08 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.41 2015/12/03 21:43:25 christos Exp $"); #endif #include @@ -168,20 +168,20 @@ cmd_add(gpt_t gpt, int argc, char *argv[ switch(ch) { case 'b': if (gpt_human_get() == -1) -return usage(); +goto usage; break; case 'l': if (gpt_name_get(gpt, ) == -1) -return usage(); +goto usage; break; case 't': if (gpt_uuid_get(gpt, ) == -1) -return usage(); +goto usage; break; default: if (gpt_add_ais(gpt, , , , ch) == -1) -return usage(); +goto usage; break; } } @@ -194,10 +194,16 @@ cmd_add(gpt_t gpt, int argc, char *argv[ gpt_uuid_create(GPT_TYPE_NETBSD_FFS, type, NULL, 0); if (optind != argc) - return usage(); + goto cleanup; if ((sectors = gpt_check_ais(gpt, alignment, ~0U, size)) == -1) - return -1; + goto cleanup; return add(gpt, alignment, block, sectors, size, entry, name, type); +cleanup: + free(name); + return -1; +usage: + free(name); + return usage(); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 01:47:48 UTC 2015 Modified Files: src/sbin/gpt: label.c Log Message: put back usage from kre To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/gpt/label.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/label.c diff -u src/sbin/gpt/label.c:1.27 src/sbin/gpt/label.c:1.28 --- src/sbin/gpt/label.c:1.27 Thu Dec 3 16:51:02 2015 +++ src/sbin/gpt/label.c Thu Dec 3 20:47:48 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: label.c,v 1.27 2015/12/03 21:51:02 christos Exp $"); +__RCSID("$NetBSD: label.c,v 1.28 2015/12/04 01:47:48 christos Exp $"); #endif #include @@ -153,6 +153,7 @@ cmd_label(gpt_t gpt, int argc, char *arg return gpt_change_ent(gpt, , change, name); usage: + usage(); free(name); return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 01:46:32 UTC 2015 Modified Files: src/sbin/gpt: gpt.c gpt.h Log Message: don't print dkctl message for files fix typo To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/sbin/gpt/gpt.c cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/gpt.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.61 src/sbin/gpt/gpt.c:1.62 --- src/sbin/gpt/gpt.c:1.61 Thu Dec 3 16:30:54 2015 +++ src/sbin/gpt/gpt.c Thu Dec 3 20:46:32 2015 @@ -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.61 2015/12/03 21:30:54 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.62 2015/12/04 01:46:32 christos Exp $"); #endif #include @@ -518,6 +518,7 @@ gpt_open(const char *dev, int flags, int } } } else { + gpt->flags |= GPT_FILE; if (gpt->secsz == 0) gpt->secsz = 512; /* Fixed size for files. */ if (gpt->mediasz == 0) { @@ -538,7 +539,7 @@ gpt_open(const char *dev, int flags, int */ devsz = gpt->mediasz / gpt->secsz; if (devsz < 6) { - gpt_warnx(gpt, "Need 6 sectorso, we have %ju", + gpt_warnx(gpt, "Need 6 sectors, we have %ju", (uintmax_t)devsz); goto close; } @@ -583,8 +584,9 @@ gpt_close(gpt_t gpt) goto out; #endif } - gpt_msg(gpt, "You need to run \"dkctl %s makewedges\"" - " for the changes to take effect\n", gpt->device_name); + if (!(gpt->flags & GPT_FILE)) + gpt_msg(gpt, "You need to run \"dkctl %s makewedges\"" + " for the changes to take effect\n", gpt->device_name); out: close(gpt->fd); @@ -715,7 +717,6 @@ gpt_create_pmbr_part(struct mbr_part *pa } } - struct gpt_ent * gpt_ent(map_t map, map_t tbl, unsigned int i) { Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.28 src/sbin/gpt/gpt.h:1.29 --- src/sbin/gpt/gpt.h:1.28 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/gpt.h Thu Dec 3 20:46:32 2015 @@ -75,10 +75,11 @@ uint32_t crc32(const void *, size_t); void gpt_close(gpt_t); int gpt_gpt(gpt_t, off_t, int); gpt_t gpt_open(const char *, int, int, off_t, u_int); -#define GPT_READONLY 1 -#define GPT_MODIFIED 2 -#define GPT_QUIET 4 -#define GPT_NOSYNC 8 +#define GPT_READONLY 0x01 +#define GPT_MODIFIED 0x02 +#define GPT_QUIET 0x04 +#define GPT_NOSYNC 0x08 +#define GPT_FILE 0x10 void* gpt_read(gpt_t, off_t, size_t); off_t gpt_last(gpt_t);
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Fri Dec 4 01:46:12 UTC 2015 Modified Files: src/sbin/gpt: show.c Log Message: fix label printing. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.29 src/sbin/gpt/show.c:1.30 --- src/sbin/gpt/show.c:1.29 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/show.c Thu Dec 3 20:46:12 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.29 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: show.c,v 1.30 2015/12/04 01:46:12 christos Exp $"); #endif #include @@ -137,7 +137,7 @@ show(gpt_t gpt, int show) if (show & SHOW_LABEL) { utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf)); -b = (char *)buf; +b = (char *)utfbuf; } else if (show & SHOW_GUID) { gpt_uuid_snprintf( buf, sizeof(buf), "%d", ent->ent_guid);
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 20:09:54 UTC 2015 Modified Files: src/sbin/gpt: resizedisk.c Log Message: check allocations To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/resizedisk.c diff -u src/sbin/gpt/resizedisk.c:1.10 src/sbin/gpt/resizedisk.c:1.11 --- src/sbin/gpt/resizedisk.c:1.10 Tue Dec 1 14:25:24 2015 +++ src/sbin/gpt/resizedisk.c Wed Dec 2 15:09:54 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resizedisk.c,v 1.10 2015/12/01 19:25:24 christos Exp $"); +__RCSID("$NetBSD: resizedisk.c,v 1.11 2015/12/02 20:09:54 christos Exp $"); #endif #include @@ -87,6 +87,7 @@ resizedisk(gpt_t gpt) struct mbr *mbr; off_t last, oldloc, newloc, lastdata, gpt_size; int i; + void *p; last = gpt->mediasz / gpt->secsz - 1; lastdata = 0; @@ -174,10 +175,26 @@ resizedisk(gpt_t gpt) newloc = sector; else newloc = last; - gpt->tpg = map_add(gpt, newloc, 1LL, MAP_TYPE_SEC_GPT_HDR, - calloc(1, gpt->secsz)); + if ((p = calloc(1, gpt->secsz)) == NULL) { + gpt_warn(gpt, "Error allocating secondary GPT"); + return -1; + } + if (gpt->lbt == NULL) { + gpt_warn(gpt, "Error adding secondary GPT"); + return -1; + } + gpt->tpg = map_add(gpt, newloc, 1LL, MAP_TYPE_SEC_GPT_HDR, p); + if (gpt->lbt == NULL) { + gpt_warn(gpt, "Error adding secondary GPT"); + return -1; + } + // XXX: map add with non-allocated memory gpt->lbt = map_add(gpt, newloc - gpt_size, gpt_size, MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data); + if (gpt->lbt == NULL) { + gpt_warn(gpt, "Error adding secondary GPT table"); + return -1; + } memcpy(gpt->tpg->map_data, gpt->gpt->map_data, gpt->secsz); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 20:41:10 UTC 2015 Modified Files: src/sbin/gpt: recover.c Log Message: merge duplicated code and check allocations. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/recover.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.9 src/sbin/gpt/recover.c:1.10 --- src/sbin/gpt/recover.c:1.9 Tue Dec 1 11:32:19 2015 +++ src/sbin/gpt/recover.c Wed Dec 2 15:41:10 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.9 2015/12/01 16:32:19 christos Exp $"); +__RCSID("$NetBSD: recover.c,v 1.10 2015/12/02 20:41:10 christos Exp $"); #endif #include @@ -67,10 +67,100 @@ struct gpt_cmd c_recover = { #define usage() gpt_usage(NULL, _recover) static int +recover_gpt_hdr(gpt_t gpt, int type, off_t last) +{ + const char *name, *origname; + void *p; + map_t *dgpt, dtbl, sgpt, stbl; + struct gpt_hdr *hdr; + + switch (type) { + case MAP_TYPE_PRI_GPT_HDR: + dgpt = >gpt; + dtbl = gpt->tbl; + sgpt = gpt->tpg; + stbl = gpt->lbt; + origname = "secondary"; + name = "primary"; + break; + case MAP_TYPE_SEC_GPT_HDR: + dgpt = >tpg; + dtbl = gpt->lbt; + sgpt = gpt->gpt; + stbl = gpt->tbl; + origname = "primary"; + name = "secondary"; + break; + default: + gpt_warn(gpt, "Bad table type %d", type); + return -1; + } + + if ((p = calloc(1, gpt->secsz)) == NULL) { + gpt_warn(gpt, "Cannot allocate %s GPT header", name); + return -1; + } + if ((*dgpt = map_add(gpt, last, 1LL, type, p)) == NULL) { + gpt_warnx(gpt, "Cannot add %s GPT header", name); + return -1; + } + memcpy((*dgpt)->map_data, sgpt->map_data, gpt->secsz); + hdr = (*dgpt)->map_data; + hdr->hdr_lba_self = htole64((*dgpt)->map_start); + hdr->hdr_lba_alt = htole64(stbl->map_start); + hdr->hdr_lba_table = htole64(dtbl->map_start); + hdr->hdr_crc_self = 0; + hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size))); + if (gpt_write(gpt, *dgpt) == -1) { + gpt_warnx(gpt, "Writing %s GPT header failed", name); + return -1; + } + gpt_msg(gpt, "Recovered %s GPT header from %s", name, origname); + return 0; +} + +static int +recover_gpt_tbl(gpt_t gpt, int type, off_t start) +{ + const char *name, *origname; + map_t *dtbl, stbl; + + switch (type) { + case MAP_TYPE_PRI_GPT_TBL: + dtbl = >tbl; + stbl = gpt->lbt; + origname = "secondary"; + name = "primary"; + break; + case MAP_TYPE_SEC_GPT_TBL: + dtbl = >lbt; + stbl = gpt->tbl; + origname = "primary"; + name = "secondary"; + break; + default: + gpt_warn(gpt, "Bad table type %d", type); + return -1; + } + + // XXX: non allocated memory + *dtbl = map_add(gpt, start, stbl->map_size, type, stbl->map_data); + if (*dtbl == NULL) { + gpt_warnx(gpt, "Adding %s GPT table failed", name); + return -1; + } + if (gpt_write(gpt, *dtbl) == -1) { + gpt_warnx(gpt, "Writing %s GPT table failed", name); + return -1; + } + gpt_msg(gpt, "Recovered %s GPT table from %s", name, origname); + return 0; +} + +static int recover(gpt_t gpt) { uint64_t last; - struct gpt_hdr *hdr; if (map_find(gpt, MAP_TYPE_MBR) != NULL) { gpt_warnx(gpt, "Device contains an MBR"); @@ -103,70 +193,20 @@ recover(gpt_t gpt) } if (gpt->tbl != NULL && gpt->lbt == NULL) { - gpt->lbt = map_add(gpt, last - gpt->tbl->map_size, - gpt->tbl->map_size, MAP_TYPE_SEC_GPT_TBL, - gpt->tbl->map_data); - if (gpt->lbt == NULL) { - gpt_warnx(gpt, "Adding secondary GPT table failed"); - return -1; - } - if (gpt_write(gpt, gpt->lbt) == -1) { - gpt_warnx(gpt, "Writing secondary GPT table failed"); + if (recover_gpt_tbl(gpt, MAP_TYPE_SEC_GPT_TBL, + last - gpt->tbl->map_size) == -1) return -1; - } - gpt_msg(gpt, "Recovered secondary GPT table from primary"); } else if (gpt->tbl == NULL && gpt->lbt != NULL) { - gpt->tbl = map_add(gpt, 2LL, gpt->lbt->map_size, - MAP_TYPE_PRI_GPT_TBL, gpt->lbt->map_data); - if (gpt->tbl == NULL) { - gpt_warnx(gpt, "Adding primary GPT table failed"); - return -1; - } - if (gpt_write(gpt, gpt->tbl) == -1) { - gpt_warnx(gpt, "Writing primary GPT table failed"); + if (recover_gpt_tbl(gpt, MAP_TYPE_PRI_GPT_TBL, 2LL) == -1) return -1; - } - gpt_msg(gpt, "Recovered primary GPT table from secondary"); } if (gpt->gpt != NULL && gpt->tpg == NULL) { - gpt->tpg = map_add(gpt, last, 1LL, MAP_TYPE_SEC_GPT_HDR, - calloc(1, gpt->secsz)); - if (gpt->tpg == NULL) { - gpt_warnx(gpt, "Adding secondary GPT header failed"); - return -1; - } - memcpy(gpt->tpg->map_data, gpt->gpt->map_data, gpt->secsz); - hdr = gpt->tpg->map_data; - hdr->hdr_lba_self = htole64(gpt->tpg->map_start); - hdr->hdr_lba_alt = htole64(gpt->gpt->map_start); - hdr->hdr_lba_table = htole64(gpt->lbt->map_start); - hdr->hdr_crc_self
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 20:42:07 UTC 2015 Modified Files: src/sbin/gpt: recover.c Log Message: don't hard-code the program name To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/recover.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/recover.c diff -u src/sbin/gpt/recover.c:1.10 src/sbin/gpt/recover.c:1.11 --- src/sbin/gpt/recover.c:1.10 Wed Dec 2 15:41:10 2015 +++ src/sbin/gpt/recover.c Wed Dec 2 15:42:07 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/recover.c,v 1.8 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: recover.c,v 1.10 2015/12/02 20:41:10 christos Exp $"); +__RCSID("$NetBSD: recover.c,v 1.11 2015/12/02 20:42:07 christos Exp $"); #endif #include @@ -188,7 +188,7 @@ recover(gpt_t gpt) if (gpt->gpt != NULL && ((struct gpt_hdr *)(gpt->gpt->map_data))->hdr_lba_alt != last) { gpt_warnx(gpt, "Media size has changed, please use " - "'gpt resizedisk'"); + "'%s resizedisk'", getprogname()); return -1; }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 20:01:44 UTC 2015 Modified Files: src/sbin/gpt: gpt.c map.c map.h resize.c Log Message: - check errors from map allocation - make map_resize return -1 instead of 0, and handle errors locally explaining what's going wrong To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/sbin/gpt/gpt.c cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/map.c cvs rdiff -u -r1.4 -r1.5 src/sbin/gpt/map.h cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/resize.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.56 src/sbin/gpt/gpt.c:1.57 --- src/sbin/gpt/gpt.c:1.56 Wed Dec 2 07:20:52 2015 +++ src/sbin/gpt/gpt.c Wed Dec 2 15:01:44 2015 @@ -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.56 2015/12/02 12:20:52 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.57 2015/12/02 20:01:44 christos Exp $"); #endif #include @@ -547,7 +547,8 @@ gpt_open(const char *dev, int flags, int (uintmax_t)gpt->mediasz, gpt->secsz, (uintmax_t)devsz); } - map_init(gpt, devsz); + if (map_init(gpt, devsz) == -1) + goto close; if (gpt_mbr(gpt, 0LL) == -1) goto close; Index: src/sbin/gpt/map.c diff -u src/sbin/gpt/map.c:1.11 src/sbin/gpt/map.c:1.12 --- src/sbin/gpt/map.c:1.11 Tue Dec 1 04:05:33 2015 +++ src/sbin/gpt/map.c Wed Dec 2 15:01:44 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/map.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: map.c,v 1.11 2015/12/01 09:05:33 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.12 2015/12/02 20:01:44 christos Exp $"); #endif #include @@ -52,14 +52,14 @@ mkmap(off_t start, off_t size, int type) m = calloc(1, sizeof(*m)); if (m == NULL) - return (NULL); + return NULL; m->map_start = start; m->map_size = size; m->map_next = m->map_prev = NULL; m->map_type = type; m->map_index = 0; m->map_data = NULL; - return (m); + return m; } static const char *maptypes[] = { @@ -101,13 +101,13 @@ map_add(gpt_t gpt, off_t start, off_t si if (n == NULL) { if (!(gpt->flags & GPT_QUIET)) gpt_warnx(gpt, "Can't find map"); - return (NULL); + return NULL; } if (n->map_start + n->map_size < start + size) { if (!(gpt->flags & GPT_QUIET)) gpt_warnx(gpt, "map entry doesn't fit media"); - return (NULL); + return NULL; } if (n->map_start == start && n->map_size == size) { @@ -115,13 +115,14 @@ map_add(gpt_t gpt, off_t start, off_t si if (n->map_type != MAP_TYPE_MBR_PART || type != MAP_TYPE_GPT_PART) { if (!(gpt->flags & GPT_QUIET)) - gpt_warnx(gpt, "partition(%ju,%ju) mirrored", + gpt_warnx(gpt, + "partition(%ju,%ju) mirrored", (uintmax_t)start, (uintmax_t)size); } } n->map_type = type; n->map_data = data; - return (n); + return n; } if (n->map_type != MAP_TYPE_UNUSED) { @@ -129,14 +130,14 @@ map_add(gpt_t gpt, off_t start, off_t si type != MAP_TYPE_GPT_PART) { gpt_warnx(gpt, "bogus map current=%s new=%s", map_type(n->map_type), map_type(type)); - return (NULL); + return NULL; } n->map_type = MAP_TYPE_UNUSED; } m = mkmap(start, size, type); if (m == NULL) - return (NULL); + goto oomem; m->map_data = data; @@ -160,6 +161,8 @@ map_add(gpt_t gpt, off_t start, off_t si p->map_size -= size; } else { p = mkmap(n->map_start, start - n->map_start, n->map_type); + if (p == NULL) + goto oomem; n->map_start += p->map_size + m->map_size; n->map_size -= (p->map_size + m->map_size); p->map_prev = n->map_prev; @@ -173,7 +176,10 @@ map_add(gpt_t gpt, off_t start, off_t si gpt->mediamap = p; } - return (m); + return m; +oomem: + gpt_warn(gpt, "Can't create map"); + return NULL; } map_t @@ -193,7 +199,7 @@ map_alloc(gpt_t gpt, off_t start, off_t if (m->map_type != MAP_TYPE_UNUSED || m->map_start < 2) continue; if (start != 0 && m->map_start > start) - return (NULL); + return NULL; if (start != 0) delta = start - m->map_start; @@ -232,12 +238,20 @@ map_resize(gpt_t gpt, map_t m, off_t siz if (size < 0 || alignment < 0) { gpt_warnx(gpt, "negative size or alignment"); - return 0; + return -1; } - if (size == 0 && alignment == 0) { - if (n == NULL || n->map_type != MAP_TYPE_UNUSED) - return 0; - else { + /* Size == 0 means delete, if the next map is unused */ + if (size == 0) { + if (n == NULL) { + // XXX: we could just turn the map to UNUSED! + gpt_warnx(gpt, "Can't delete, next map is not found"); + return -1; + } + if (n->map_type != MAP_TYPE_UNUSED) { + gpt_warnx(gpt, "Can't delete, next map is in use"); + return -1; + } + if (alignment == 0) { size = m->map_size + n->map_size; m->map_size = size; m->map_next =
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 20:09:33 UTC 2015 Modified Files: src/sbin/gpt: gpt.c Log Message: annotate map additions with non-allocated memory. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.57 src/sbin/gpt/gpt.c:1.58 --- src/sbin/gpt/gpt.c:1.57 Wed Dec 2 15:01:44 2015 +++ src/sbin/gpt/gpt.c Wed Dec 2 15:09:33 2015 @@ -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.57 2015/12/02 20:01:44 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.58 2015/12/02 20:09:33 christos Exp $"); #endif #include @@ -340,6 +340,7 @@ gpt_mbr(gpt_t gpt, off_t lba) mbr->mbr_part[i].part_typ, (uintmax_t)start, (uintmax_t)size); if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) { + // XXX: map add with non-allocated memory m = map_add(gpt, start, size, MAP_TYPE_MBR_PART, p); if (m == NULL) return -1; @@ -442,6 +443,7 @@ gpt_gpt(gpt_t gpt, off_t lba, int found) (uintmax_t)le64toh(ent->ent_lba_start), (uintmax_t)size); } + // XXX: map add with not allocated memory. m = map_add(gpt, le64toh(ent->ent_lba_start), size, MAP_TYPE_GPT_PART, ent); if (m == NULL)
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 01:07:28 UTC 2015 Modified Files: src/sbin/gpt: add.c backup.c biosboot.c create.c destroy.c header.c label.c main.c migrate.c recover.c remove.c resize.c resizedisk.c restore.c set.c show.c type.c unset.c Log Message: eliminate static globals so that commands can be re-used. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sbin/gpt/add.c cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/backup.c cvs rdiff -u -r1.20 -r1.21 src/sbin/gpt/biosboot.c src/sbin/gpt/remove.c cvs rdiff -u -r1.16 -r1.17 src/sbin/gpt/create.c cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/destroy.c src/sbin/gpt/set.c \ src/sbin/gpt/unset.c cvs rdiff -u -r1.5 -r1.6 src/sbin/gpt/header.c cvs rdiff -u -r1.24 -r1.25 src/sbin/gpt/label.c cvs rdiff -u -r1.4 -r1.5 src/sbin/gpt/main.c cvs rdiff -u -r1.25 -r1.26 src/sbin/gpt/migrate.c cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/recover.c src/sbin/gpt/resizedisk.c \ src/sbin/gpt/type.c cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/resize.c cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/restore.c cvs rdiff -u -r1.27 -r1.28 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.37 src/sbin/gpt/add.c:1.38 --- src/sbin/gpt/add.c:1.37 Wed Dec 2 06:20:34 2015 +++ src/sbin/gpt/add.c Wed Dec 2 20:07:28 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.37 2015/12/02 11:20:34 jnemeth Exp $"); +__RCSID("$NetBSD: add.c,v 1.38 2015/12/03 01:07:28 christos Exp $"); #endif #include @@ -51,15 +51,11 @@ __RCSID("$NetBSD: add.c,v 1.37 2015/12/0 #include "gpt.h" #include "gpt_private.h" -static gpt_uuid_t type; -static off_t alignment, block, sectors, size; -static unsigned int entry; -static uint8_t *name; static int cmd_add(gpt_t, int, char *[]); static const char *addhelp[] = { -"[-a alignment] [-b blocknr] [-i index] [-l label]", -"[-s size] [-t type]", + "[-a alignment] [-b blocknr] [-i index] [-l label]", + "[-s size] [-t type]", }; struct gpt_cmd c_add = { @@ -84,7 +80,8 @@ ent_set(struct gpt_ent *ent, const map_t } static int -add(gpt_t gpt) +add(gpt_t gpt, off_t alignment, off_t block, off_t sectors, off_t size, +u_int entry, uint8_t *name, gpt_uuid_t type) { map_t map; struct gpt_hdr *hdr; @@ -157,6 +154,12 @@ static int cmd_add(gpt_t gpt, int argc, char *argv[]) { int ch; + off_t alignment = 0, block = 0, sectors = 0, size = 0; + unsigned int entry = 0; + uint8_t *name = NULL; + gpt_uuid_t type; + + gpt_uuid_copy(type, gpt_uuid_nil); while ((ch = getopt(argc, argv, GPT_AIS "b:l:t:")) != -1) { switch(ch) { @@ -193,5 +196,5 @@ cmd_add(gpt_t gpt, int argc, char *argv[ if ((sectors = gpt_check_ais(gpt, alignment, ~0, size)) == -1) return -1; - return add(gpt); + return add(gpt, alignment, block, sectors, size, entry, name, type); } Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.13 src/sbin/gpt/backup.c:1.14 --- src/sbin/gpt/backup.c:1.13 Wed Dec 2 07:36:53 2015 +++ src/sbin/gpt/backup.c Wed Dec 2 20:07:28 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.14 2015/12/03 01:07:28 christos Exp $"); #endif #include @@ -51,10 +51,8 @@ __RCSID("$NetBSD: backup.c,v 1.13 2015/1 #include "gpt.h" #include "gpt_private.h" -static const char *outfile = "/dev/stdout"; - static const char *backuphelp[] = { -"[-o outfile]", + "[-o outfile]", }; static int cmd_backup(gpt_t, int, char *[]); @@ -241,7 +239,7 @@ store_tbl(gpt_t gpt, const map_t m, prop } static int -backup(gpt_t gpt) +backup(gpt_t gpt, const char *outfile) { map_t m; struct mbr *mbr; @@ -309,12 +307,14 @@ backup(gpt_t gpt) propext = prop_dictionary_externalize(props); PROP_ERR(propext); prop_object_release(props); - if ((fp = fopen(outfile, "w")) == NULL) { + fp = strcmp(outfile, "-") == 0 ? stdout : fopen(outfile, "w"); + if (fp == NULL) { gpt_warn(gpt, "Can't open `%s'", outfile); return -1; } fputs(propext, fp); - fclose(fp); + if (fp != stdin) + fclose(fp); free(propext); return 0; } @@ -323,6 +323,7 @@ static int cmd_backup(gpt_t gpt, int argc, char *argv[]) { int ch; + const char *outfile = "-"; while ((ch = getopt(argc, argv, "o:")) != -1) { switch(ch) { @@ -336,5 +337,5 @@ cmd_backup(gpt_t gpt, int argc, char *ar if (argc != optind) return usage(); - return backup(gpt); + return backup(gpt, outfile); } Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.20 src/sbin/gpt/biosboot.c:1.21 --- src/sbin/gpt/biosboot.c:1.20 Wed Dec 2 07:24:02 2015 +++
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 01:16:21 UTC 2015 Modified Files: src/sbin/gpt: resize.c Log Message: remove extra assignment To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/resize.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/resize.c diff -u src/sbin/gpt/resize.c:1.19 src/sbin/gpt/resize.c:1.20 --- src/sbin/gpt/resize.c:1.19 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/resize.c Wed Dec 2 20:16:21 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resize.c,v 1.19 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: resize.c,v 1.20 2015/12/03 01:16:21 christos Exp $"); #endif #include @@ -77,8 +77,6 @@ resize(gpt_t gpt, u_int entry, off_t ali if ((hdr = gpt_hdr(gpt)) == NULL) return -1; - ent = NULL; - i = entry - 1; ent = gpt_ent_primary(gpt, i); if (gpt_uuid_is_nil(ent->ent_type)) {
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 04:39:41 UTC 2015 Modified Files: src/sbin/gpt: backup.c Log Message: compare to stdout, thanks kre To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sbin/gpt/backup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.14 src/sbin/gpt/backup.c:1.15 --- src/sbin/gpt/backup.c:1.14 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/backup.c Wed Dec 2 23:39:41 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.14 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.15 2015/12/03 04:39:41 christos Exp $"); #endif #include @@ -313,7 +313,7 @@ backup(gpt_t gpt, const char *outfile) return -1; } fputs(propext, fp); - if (fp != stdin) + if (fp != stdout) fclose(fp); free(propext); return 0;
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Wed Dec 2 10:19:58 UTC 2015 Modified Files: src/sbin/gpt: gpt.c Log Message: - dereferencing NULL is generally bad, found by visual inspection - automatically set nosync when opening a file to avoid spurious errors To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.54 src/sbin/gpt/gpt.c:1.55 --- src/sbin/gpt/gpt.c:1.54 Wed Dec 2 04:17:25 2015 +++ src/sbin/gpt/gpt.c Wed Dec 2 10:19:58 2015 @@ -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.54 2015/12/02 04:17:25 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.55 2015/12/02 10:19:58 jnemeth Exp $"); #endif #include @@ -467,7 +467,7 @@ gpt_open(const char *dev, int flags, int if ((gpt = calloc(1, sizeof(*gpt))) == NULL) { - if (!(gpt->flags & GPT_QUIET)) + if (!(flags & GPT_QUIET)) warn("Cannot allocate `%s'", dev); return NULL; } @@ -525,6 +525,7 @@ gpt_open(const char *dev, int flags, int goto close; } gpt->mediasz = gpt->sb.st_size; + gpt->flags |= GPT_NOSYNC; } }
CVS commit: src/sbin/gpt
Module Name:src Committed By: jnemeth Date: Wed Dec 2 11:20:34 UTC 2015 Modified Files: src/sbin/gpt: add.c Log Message: hrmm... i386devel: {245} ./gpt add -b 1000 -s 1000 disk Segmentation fault (core dumped) Where's my flyswatter? ...zzzap To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/sbin/gpt/add.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.36 src/sbin/gpt/add.c:1.37 --- src/sbin/gpt/add.c:1.36 Wed Dec 2 04:07:11 2015 +++ src/sbin/gpt/add.c Wed Dec 2 11:20:34 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.36 2015/12/02 04:07:11 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.37 2015/12/02 11:20:34 jnemeth Exp $"); #endif #include @@ -158,7 +158,7 @@ cmd_add(gpt_t gpt, int argc, char *argv[ { int ch; - while ((ch = getopt(argc, argv, GPT_AIS "bl:t:")) != -1) { + while ((ch = getopt(argc, argv, GPT_AIS "b:l:t:")) != -1) { switch(ch) { case 'b': if (gpt_human_get() == -1)
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 12:20:52 UTC 2015 Modified Files: src/sbin/gpt: gpt.c Log Message: Always set NOSYNC if regular file, even if we got the size from the command line. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.55 src/sbin/gpt/gpt.c:1.56 --- src/sbin/gpt/gpt.c:1.55 Wed Dec 2 05:19:58 2015 +++ src/sbin/gpt/gpt.c Wed Dec 2 07:20:52 2015 @@ -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.55 2015/12/02 10:19:58 jnemeth Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.56 2015/12/02 12:20:52 christos Exp $"); #endif #include @@ -525,8 +525,8 @@ gpt_open(const char *dev, int flags, int goto close; } gpt->mediasz = gpt->sb.st_size; - gpt->flags |= GPT_NOSYNC; } + gpt->flags |= GPT_NOSYNC; } /*
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 12:36:53 UTC 2015 Modified Files: src/sbin/gpt: backup.c gpt.8 restore.c Log Message: Allow backup and restore to operate on files. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/backup.c src/sbin/gpt/restore.c cvs rdiff -u -r1.40 -r1.41 src/sbin/gpt/gpt.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.12 src/sbin/gpt/backup.c:1.13 --- src/sbin/gpt/backup.c:1.12 Tue Dec 1 23:06:47 2015 +++ src/sbin/gpt/backup.c Wed Dec 2 07:36:53 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.12 2015/12/02 04:06:47 christos Exp $"); +__RCSID("$NetBSD: backup.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); #endif #include @@ -51,9 +51,10 @@ __RCSID("$NetBSD: backup.c,v 1.12 2015/1 #include "gpt.h" #include "gpt_private.h" +static const char *outfile = "/dev/stdout"; static const char *backuphelp[] = { -"", +"[-o outfile]", }; static int cmd_backup(gpt_t, int, char *[]); @@ -251,6 +252,7 @@ backup(gpt_t gpt) prop_number_t propnum; char *propext; bool rc; + FILE *fp; props = prop_dictionary_create(); PROP_ERR(props); @@ -307,7 +309,12 @@ backup(gpt_t gpt) propext = prop_dictionary_externalize(props); PROP_ERR(propext); prop_object_release(props); - fputs(propext, stdout); + if ((fp = fopen(outfile, "w")) == NULL) { + gpt_warn(gpt, "Can't open `%s'", outfile); + return -1; + } + fputs(propext, fp); + fclose(fp); free(propext); return 0; } @@ -315,6 +322,17 @@ backup(gpt_t gpt) static int cmd_backup(gpt_t gpt, int argc, char *argv[]) { + int ch; + + while ((ch = getopt(argc, argv, "o:")) != -1) { + switch(ch) { + case 'o': + outfile = optarg; + break; + default: + return usage(); + } + } if (argc != optind) return usage(); Index: src/sbin/gpt/restore.c diff -u src/sbin/gpt/restore.c:1.12 src/sbin/gpt/restore.c:1.13 --- src/sbin/gpt/restore.c:1.12 Tue Dec 1 23:07:11 2015 +++ src/sbin/gpt/restore.c Wed Dec 2 07:36:53 2015 @@ -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: restore.c,v 1.12 2015/12/02 04:07:11 christos Exp $"); +__RCSID("$NetBSD: restore.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); #endif #include @@ -57,9 +57,11 @@ static int force; static int cmd_restore(gpt_t, int, char *[]); static const char *restorehelp[] = { -"[-F]", +"[-F] [-i ]", }; +static const char *infile = "/dev/stdin"; + struct gpt_cmd c_restore = { "restore", cmd_restore, @@ -113,7 +115,7 @@ restore(gpt_t gpt) map->map_type = MAP_TYPE_UNUSED; } - props = prop_dictionary_internalize_from_file("/dev/stdin"); + props = prop_dictionary_internalize_from_file(infile); if (props == NULL) { gpt_warnx(gpt, "Unable to read/parse backup file"); return -1; @@ -396,8 +398,11 @@ cmd_restore(gpt_t gpt, int argc, char *a { int ch; - while ((ch = getopt(argc, argv, "F")) != -1) { + while ((ch = getopt(argc, argv, "Fi:")) != -1) { switch(ch) { + case 'i': + infile = optarg; + break; case 'F': force = 1; break; Index: src/sbin/gpt/gpt.8 diff -u src/sbin/gpt/gpt.8:1.40 src/sbin/gpt/gpt.8:1.41 --- src/sbin/gpt/gpt.8:1.40 Tue Dec 1 17:49:25 2015 +++ src/sbin/gpt/gpt.8 Wed Dec 2 07:36:53 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.40 2015/12/01 22:49:25 christos Exp $ +.\" $NetBSD: gpt.8,v 1.41 2015/12/02 12:36:53 christos Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -199,11 +199,13 @@ NetBSD swap .El as aliases for the most commonly used partition types. .\" backup -.It Nm Ic backup +.It Nm Ic backup Oo Fl o Ar outfile Oc The .Ic backup command dumps the MBR or (PMBR) and GPT partition tables to standard -output in a format to be used by the +output or to a file specified by the +.Ar outfile +argument in a format to be used by the .Ic restore command. The format is a plist. @@ -465,14 +467,16 @@ Using the option allows you to move the backup copy prior to resizing the medium. This is primarily useful when shrinking the medium. .\" restore -.It Nm Ic restore Oo Fl F Oc +.It Nm Ic restore Oo Fl F Oc Oo Fl i Ar infile Oc The .Ic restore command restores a partition table that was previously saved using the .Ic backup command. -The partition table is read from standard input and is expected to be in -the format of a plist. +The partition table is read from standard input or a file specified in +the +.Ar infile +argument and is expected to be in the format of a plist. It assumes an empty disk. The .Fl F
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 12:24:02 UTC 2015 Modified Files: src/sbin/gpt: biosboot.c Log Message: don't advertise stuff we don't support. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/biosboot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.19 src/sbin/gpt/biosboot.c:1.20 --- src/sbin/gpt/biosboot.c:1.19 Tue Dec 1 23:07:11 2015 +++ src/sbin/gpt/biosboot.c Wed Dec 2 07:24:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.19 2015/12/02 04:07:11 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.20 2015/12/02 12:24:02 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.19 2015/12/02 04:07:11 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.20 2015/12/02 12:24:02 christos Exp $"); #endif #include @@ -76,8 +76,10 @@ static int cmd_biosboot(gpt_t, int, char static const char *biosboothelp[] = { "[-c bootcode] [-i index] [-L label]", +#if notyet "[-a alignment] [-b blocknr] [-i index] [-l label]", "[-s size] [-t type]", +#endif }; struct gpt_cmd c_biosboot = {
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Wed Dec 2 22:32:04 UTC 2015 Modified Files: src/sbin/gpt: restore.c Log Message: - factor out into smaller separate functions - fix signed/unsigned confusion - do proper write checks - fix some memory leaks To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/restore.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/restore.c diff -u src/sbin/gpt/restore.c:1.13 src/sbin/gpt/restore.c:1.14 --- src/sbin/gpt/restore.c:1.13 Wed Dec 2 07:36:53 2015 +++ src/sbin/gpt/restore.c Wed Dec 2 17:32:04 2015 @@ -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: restore.c,v 1.13 2015/12/02 12:36:53 christos Exp $"); +__RCSID("$NetBSD: restore.c,v 1.14 2015/12/02 22:32:04 christos Exp $"); #endif #include @@ -76,6 +76,124 @@ struct gpt_cmd c_restore = { return -1;\ } +#define prop_uint(a) prop_number_unsigned_integer_value(a) + +static int +restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last) +{ + unsigned int i; + prop_number_t propnum; + struct mbr_part *part; + + propnum = prop_dictionary_get(mbr_dict, "index"); + PROP_ERR(propnum); + + i = prop_number_integer_value(propnum); + propnum = prop_dictionary_get(mbr_dict, "flag"); + PROP_ERR(propnum); + part = >mbr_part[i]; + + part->part_flag = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "start_head"); + PROP_ERR(propnum); + part->part_shd = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "start_sector"); + PROP_ERR(propnum); + part->part_ssect = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "start_cylinder"); + PROP_ERR(propnum); + part->part_scyl = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "type"); + PROP_ERR(propnum); + part->part_typ = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "end_head"); + PROP_ERR(propnum); + part->part_ehd = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "end_sector"); + PROP_ERR(propnum); + part->part_esect = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "end_cylinder"); + PROP_ERR(propnum); + part->part_ecyl = prop_uint(propnum); + propnum = prop_dictionary_get(mbr_dict, "lba_start_low"); + PROP_ERR(propnum); + part->part_start_lo = htole16(prop_uint(propnum)); + propnum = prop_dictionary_get(mbr_dict, "lba_start_high"); + PROP_ERR(propnum); + part->part_start_hi = htole16(prop_uint(propnum)); + /* adjust PMBR size to size of device */ + if (part->part_typ == MBR_PTYPE_PMBR) { + if (last > 0x) { + mbr->mbr_part[0].part_size_lo = htole16(0x); + mbr->mbr_part[0].part_size_hi = htole16(0x); + } else { + mbr->mbr_part[0].part_size_lo = htole16(last); + mbr->mbr_part[0].part_size_hi = htole16(last >> 16); + } + } else { + propnum = prop_dictionary_get(mbr_dict, "lba_size_low"); + PROP_ERR(propnum); + part->part_size_lo = htole16(prop_uint(propnum)); + propnum = prop_dictionary_get(mbr_dict, "lba_size_high"); + PROP_ERR(propnum); + part->part_size_hi = htole16(prop_uint(propnum)); + } + return 0; +} + +static int +restore_ent(gpt_t gpt, prop_dictionary_t gpt_dict, void *secbuf, u_int gpt_size, +u_int entries) +{ + unsigned int i; + struct gpt_ent ent; + const char *s; + prop_string_t propstr; + prop_number_t propnum; + + memset(, 0, sizeof(ent)); + propstr = prop_dictionary_get(gpt_dict, "type"); + PROP_ERR(propstr); + s = prop_string_cstring_nocopy(propstr); + if (gpt_uuid_parse(s, ent.ent_type) != 0) { + gpt_warnx(gpt, "%s: not able to convert to an UUID", s); + return -1; + } + propstr = prop_dictionary_get(gpt_dict, "guid"); + PROP_ERR(propstr); + s = prop_string_cstring_nocopy(propstr); + if (gpt_uuid_parse(s, ent.ent_guid) != 0) { + gpt_warnx(gpt, "%s: not able to convert to an UUID", s); + return -1; + } + propnum = prop_dictionary_get(gpt_dict, "start"); + PROP_ERR(propnum); + ent.ent_lba_start = htole64(prop_uint(propnum)); + propnum = prop_dictionary_get(gpt_dict, "end"); + PROP_ERR(propnum); + ent.ent_lba_end = htole64(prop_uint(propnum)); + propnum = prop_dictionary_get(gpt_dict, "attributes"); + PROP_ERR(propnum); + ent.ent_attr = htole64(prop_uint(propnum)); + propstr = prop_dictionary_get(gpt_dict, "name"); + if (propstr != NULL) { + s = prop_string_cstring_nocopy(propstr); + utf8_to_utf16((const uint8_t *)s, ent.ent_name, + __arraycount(ent.ent_name)); + } + propnum = prop_dictionary_get(gpt_dict, "index"); + PROP_ERR(propnum); + i = prop_number_integer_value(propnum); + if (i > entries) { + gpt_warnx(gpt, "Entity index out of bounds %u > %u\n", + i, entries); + return -1; + } + memcpy((char *)secbuf + gpt->secsz + ((i - 1) * sizeof(ent)), + , sizeof(ent)); + return 0; +} + static int restore(gpt_t gpt) { @@ -84,17 +202,17 @@
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 02:02:43 UTC 2015 Modified Files: src/sbin/gpt: Makefile add.c biosboot.c create.c gpt.c gpt.h gpt_uuid.c header.c main.c migrate.c recover.c resize.c resizedisk.c restore.c set.c show.c unset.c Log Message: WARNS=6 To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sbin/gpt/Makefile src/sbin/gpt/create.c cvs rdiff -u -r1.38 -r1.39 src/sbin/gpt/add.c cvs rdiff -u -r1.21 -r1.22 src/sbin/gpt/biosboot.c cvs rdiff -u -r1.58 -r1.59 src/sbin/gpt/gpt.c cvs rdiff -u -r1.27 -r1.28 src/sbin/gpt/gpt.h cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/gpt_uuid.c cvs rdiff -u -r1.6 -r1.7 src/sbin/gpt/header.c cvs rdiff -u -r1.5 -r1.6 src/sbin/gpt/main.c cvs rdiff -u -r1.26 -r1.27 src/sbin/gpt/migrate.c cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/recover.c src/sbin/gpt/resizedisk.c cvs rdiff -u -r1.20 -r1.21 src/sbin/gpt/resize.c cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/restore.c cvs rdiff -u -r1.10 -r1.11 src/sbin/gpt/set.c src/sbin/gpt/unset.c cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/Makefile diff -u src/sbin/gpt/Makefile:1.17 src/sbin/gpt/Makefile:1.18 --- src/sbin/gpt/Makefile:1.17 Tue Dec 1 04:05:33 2015 +++ src/sbin/gpt/Makefile Wed Dec 2 21:02:43 2015 @@ -1,8 +1,9 @@ -# $NetBSD: Makefile,v 1.17 2015/12/01 09:05:33 christos Exp $ +# $NetBSD: Makefile,v 1.18 2015/12/03 02:02:43 christos Exp $ # $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $ .include +WARNS=6 PROG= gpt SRCS= add.c biosboot.c create.c destroy.c gpt.c header.c label.c map.c \ main.c migrate.c recover.c remove.c resize.c resizedisk.c \ Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.17 src/sbin/gpt/create.c:1.18 --- src/sbin/gpt/create.c:1.17 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/create.c Wed Dec 2 21:02:43 2015 @@ -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.17 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.18 2015/12/03 02:02:43 christos Exp $"); #endif #include @@ -138,7 +138,8 @@ cmd_create(gpt_t gpt, int argc, char *ar primary_only = 1; break; case 'p': - parts = atoi(optarg); + if (gpt_uint_get() == -1) +return -1; break; default: return usage(); Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.38 src/sbin/gpt/add.c:1.39 --- src/sbin/gpt/add.c:1.38 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/add.c Wed Dec 2 21:02:43 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.38 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: add.c,v 1.39 2015/12/03 02:02:43 christos Exp $"); #endif #include @@ -72,8 +72,9 @@ ent_set(struct gpt_ent *ent, const map_t const uint8_t *xname) { gpt_uuid_copy(ent->ent_type, xtype); - ent->ent_lba_start = htole64(map->map_start); - ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL); + ent->ent_lba_start = htole64((uint64_t)map->map_start); + ent->ent_lba_end = htole64((uint64_t)(map->map_start + + map->map_size - 1LL)); if (xname == NULL) return; utf8_to_utf16(xname, ent->ent_name, __arraycount(ent->ent_name)); @@ -193,7 +194,7 @@ cmd_add(gpt_t gpt, int argc, char *argv[ if (optind != argc) return usage(); - if ((sectors = gpt_check_ais(gpt, alignment, ~0, size)) == -1) + if ((sectors = gpt_check_ais(gpt, alignment, ~0U, size)) == -1) return -1; return add(gpt, alignment, block, sectors, size, entry, name, type); Index: src/sbin/gpt/biosboot.c diff -u src/sbin/gpt/biosboot.c:1.21 src/sbin/gpt/biosboot.c:1.22 --- src/sbin/gpt/biosboot.c:1.21 Wed Dec 2 20:07:28 2015 +++ src/sbin/gpt/biosboot.c Wed Dec 2 21:02:43 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.21 2015/12/03 01:07:28 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.21 2015/12/03 01:07:28 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.22 2015/12/03 02:02:43 christos Exp $"); #endif #include @@ -126,7 +126,7 @@ read_boot(gpt_t gpt, const char *bootpat goto fail; } - if (read(bfd, buf, st.st_size) != st.st_size) { + if (read(bfd, buf, (size_t)st.st_size) != (ssize_t)st.st_size) { gpt_warn(gpt, "Error reading from `%s'", bp); goto fail; } @@ -266,7 +266,7 @@ cmd_biosboot(gpt_t gpt, int argc, char * return usage(); break; case 'i': - if (gpt_entry_get() == -1) + if (gpt_uint_get() == -1) return usage(); break; case 'L': Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.58
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 02:16:00 UTC 2015 Modified Files: src/sbin/gpt: gpt.c Log Message: Add a space. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sbin/gpt/gpt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.59 src/sbin/gpt/gpt.c:1.60 --- src/sbin/gpt/gpt.c:1.59 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/gpt.c Wed Dec 2 21:16:00 2015 @@ -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.59 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.60 2015/12/03 02:16:00 christos Exp $"); #endif #include @@ -1199,7 +1199,7 @@ gpt_show_num(const char *prompt, uintmax printf("%s: %ju", prompt, num); #ifdef HN_AUTOSCALE if (human_num[0] != '\0') - printf("(%s)", human_num); + printf(" (%s)", human_num); #endif printf("\n"); }
CVS commit: src/sbin/gpt
Module Name:src Committed By: christos Date: Thu Dec 3 02:09:20 UTC 2015 Modified Files: src/sbin/gpt: resizedisk.c Log Message: Fix stray paste, noted by kre. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/gpt/resizedisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/gpt/resizedisk.c diff -u src/sbin/gpt/resizedisk.c:1.13 src/sbin/gpt/resizedisk.c:1.14 --- src/sbin/gpt/resizedisk.c:1.13 Wed Dec 2 21:02:43 2015 +++ src/sbin/gpt/resizedisk.c Wed Dec 2 21:09:20 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: resizedisk.c,v 1.13 2015/12/03 02:02:43 christos Exp $"); +__RCSID("$NetBSD: resizedisk.c,v 1.14 2015/12/03 02:09:20 christos Exp $"); #endif #include @@ -174,19 +174,18 @@ resizedisk(gpt_t gpt, off_t sector, off_ newloc = sector; else newloc = last; + if ((p = calloc(1, gpt->secsz)) == NULL) { - gpt_warn(gpt, "Error allocating secondary GPT"); - return -1; - } - if (gpt->lbt == NULL) { - gpt_warn(gpt, "Error adding secondary GPT"); + gpt_warn(gpt, "Error allocating secondary GPT header"); return -1; } + gpt->tpg = map_add(gpt, newloc, 1LL, MAP_TYPE_SEC_GPT_HDR, p); - if (gpt->lbt == NULL) { - gpt_warn(gpt, "Error adding secondary GPT"); + if (gpt->tpg == NULL) { + gpt_warn(gpt, "Error adding secondary GPT header"); return -1; } + // XXX: map add with non-allocated memory gpt->lbt = map_add(gpt, newloc - gpt_size, gpt_size, MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data);