Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sbin/gpt Catch up to current for the following, requested...
details: https://anonhg.NetBSD.org/src/rev/f76e50d0686f
branches: netbsd-7
changeset: 800522:f76e50d0686f
user: martin <martin%NetBSD.org@localhost>
date: Mon Aug 13 16:12:12 2018 +0000
description:
Catch up to current for the following, requested by sborrill in ticket #1629:
sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14
Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- 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.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
diffstat:
sbin/gpt/Makefile | 22 +-
sbin/gpt/add.c | 288 +++-------
sbin/gpt/backup.c | 438 +++++++++-------
sbin/gpt/biosboot.c | 356 ++++++-------
sbin/gpt/create.c | 227 ++------
sbin/gpt/destroy.c | 93 +-
sbin/gpt/drvctl.c | 134 -----
sbin/gpt/gpt.8 | 320 ++++++++---
sbin/gpt/gpt.c | 1258 +++++++++++++++++++++++++++++++++++------------
sbin/gpt/gpt.h | 103 ++-
sbin/gpt/gpt_private.h | 46 +
sbin/gpt/gpt_uuid.c | 86 ++-
sbin/gpt/gpt_uuid.h | 6 +-
sbin/gpt/header.c | 108 ++++
sbin/gpt/label.c | 257 ++-------
sbin/gpt/main.c | 257 +++++++++
sbin/gpt/map.c | 262 ++++++---
sbin/gpt/map.h | 25 +-
sbin/gpt/migrate.c | 489 +++++++-----------
sbin/gpt/recover.c | 286 ++++++----
sbin/gpt/remove.c | 201 +------
sbin/gpt/resize.c | 253 ++-------
sbin/gpt/resizedisk.c | 278 +++++-----
sbin/gpt/restore.c | 466 +++++++++--------
sbin/gpt/set.c | 156 +----
sbin/gpt/show.c | 386 ++++++++-----
sbin/gpt/type.c | 215 +------
sbin/gpt/unset.c | 156 +----
28 files changed, 3772 insertions(+), 3400 deletions(-)
diffs (truncated from 9161 to 300 lines):
diff -r 51cb9853fb42 -r f76e50d0686f sbin/gpt/Makefile
--- a/sbin/gpt/Makefile Sat Aug 11 13:36:49 2018 +0000
+++ b/sbin/gpt/Makefile Mon Aug 13 16:12:12 2018 +0000
@@ -1,26 +1,22 @@
-# $NetBSD: Makefile,v 1.8.2.1 2015/06/02 19:49:38 snj Exp $
+# $NetBSD: Makefile,v 1.8.2.2 2018/08/13 16:12:12 martin Exp $
# $FreeBSD: src/sbin/gpt/Makefile,v 1.7 2005/09/01 02:49:20 marcel Exp $
+.include <bsd.own.mk>
+
+WARNS=6
PROG= gpt
-SRCS= add.c biosboot.c create.c destroy.c gpt.c label.c map.c \
- migrate.c recover.c remove.c resize.c resizedisk.c \
+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 \
set.c show.c type.c unset.c gpt_uuid.c
MAN= gpt.8
+#LINKS= ${BINDIR}/gpt ${BINDIR}/gptlabel
+#MLINKS= gpt.8 gptlabel.8
+
.if (${HOSTPROG:U} == "")
SRCS+= backup.c restore.c
LDADD+= -lprop -lutil
DPADD+= ${LIBPROP} ${LIBUTIL}
-
-.if ${USE_DRVCTL:Uno} == "yes"
-CPPFLAGS+=-DUSE_DRVCTL
-SRCS+=drvctl.c
-.else
-.PATH: ${.CURDIR}/../fsck
-CPPFLAGS+=-I${.CURDIR}/../fsck
-SRCS+=partutil.c
-.endif
.endif
-
.include <bsd.prog.mk>
diff -r 51cb9853fb42 -r f76e50d0686f sbin/gpt/add.c
--- a/sbin/gpt/add.c Sat Aug 11 13:36:49 2018 +0000
+++ b/sbin/gpt/add.c Mon Aug 13 16:12:12 2018 +0000
@@ -33,10 +33,12 @@
__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.24.4.1 2015/06/02 19:49:38 snj Exp $");
+__RCSID("$NetBSD: add.c,v 1.24.4.2 2018/08/13 16:12:12 martin Exp $");
#endif
#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
#include <err.h>
#include <stddef.h>
@@ -47,258 +49,160 @@
#include "map.h"
#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 *[]);
-const char addmsg1[] = "add [-a alignment] [-b blocknr] [-i index] [-l label]";
-const char addmsg2[] = " [-s size] [-t type] device ...";
+static const char *addhelp[] = {
+ "[-a alignment] [-b blocknr] [-i index] [-l label]",
+ "[-s size] [-t type]",
+};
-__dead static void
-usage_add(void)
-{
+struct gpt_cmd c_add = {
+ "add",
+ cmd_add,
+ addhelp, __arraycount(addhelp),
+ GPT_SYNC,
+};
+
+#define usage() gpt_usage(NULL, &c_add)
- fprintf(stderr,
- "usage: %s %s\n"
- " %*s %s\n", getprogname(), addmsg1,
- (int)strlen(getprogname()), "", addmsg2);
- exit(1);
+static void
+ent_set(struct gpt_ent *ent, const map_t map, const gpt_uuid_t xtype,
+ const uint8_t *xname)
+{
+ gpt_uuid_copy(ent->ent_type, xtype);
+ 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));
}
-static void
-add(int fd)
+static int
+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 *gpt, *tpg;
- map_t *tbl, *lbt;
- map_t *map;
+ map_t map;
struct gpt_hdr *hdr;
struct gpt_ent *ent;
unsigned int i;
off_t alignsecs;
+ char buf[128];
-
- gpt = map_find(MAP_TYPE_PRI_GPT_HDR);
- ent = NULL;
- if (gpt == NULL) {
- warnx("%s: error: no primary GPT header; run create or recover",
- device_name);
- return;
- }
+ if ((hdr = gpt_hdr(gpt)) == NULL)
+ return -1;
- tpg = map_find(MAP_TYPE_SEC_GPT_HDR);
- if (tpg == NULL) {
- warnx("%s: error: no secondary GPT header; run recover",
- device_name);
- return;
- }
+ ent = NULL;
- tbl = map_find(MAP_TYPE_PRI_GPT_TBL);
- lbt = map_find(MAP_TYPE_SEC_GPT_TBL);
- if (tbl == NULL || lbt == NULL) {
- warnx("%s: error: run recover -- trust me", device_name);
- return;
- }
-
- hdr = gpt->map_data;
if (entry > le32toh(hdr->hdr_entries)) {
- warnx("%s: error: index %u out of range (%u max)", device_name,
+ gpt_warnx(gpt, "index %u out of range (%u max)",
entry, le32toh(hdr->hdr_entries));
- return;
+ return -1;
}
if (entry > 0) {
i = entry - 1;
- ent = (void*)((char*)tbl->map_data + i *
- le32toh(hdr->hdr_entsz));
+ ent = gpt_ent_primary(gpt, i);
if (!gpt_uuid_is_nil(ent->ent_type)) {
- warnx("%s: error: entry at index %u is not free",
- device_name, entry);
- return;
+ gpt_warnx(gpt, "Entry at index %u is not free", entry);
+ return -1;
}
} else {
/* Find empty slot in GPT table. */
for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
- ent = (void*)((char*)tbl->map_data + i *
- le32toh(hdr->hdr_entsz));
+ ent = gpt_ent_primary(gpt, i);
if (gpt_uuid_is_nil(ent->ent_type))
break;
}
if (i == le32toh(hdr->hdr_entries)) {
- warnx("%s: error: no available table entries",
- device_name);
- return;
+ gpt_warnx(gpt, "No available table entries");
+ return -1;
}
}
if (alignment > 0) {
- alignsecs = alignment / secsz;
- map = map_alloc(block, sectors, alignsecs);
+ alignsecs = alignment / gpt->secsz;
+ map = map_alloc(gpt, block, sectors, alignsecs);
if (map == NULL) {
- warnx("%s: error: not enough space available on "
- "device for an aligned partition", device_name);
- return;
+ gpt_warnx(gpt, "Not enough space available on "
+ "device for an aligned partition");
+ return -1;
}
} else {
- map = map_alloc(block, sectors, 0);
+ map = map_alloc(gpt, block, sectors, 0);
if (map == NULL) {
- warnx("%s: error: not enough space available on "
- "device", device_name);
- return;
+ gpt_warnx(gpt, "Not enough space available on device");
+ return -1;
}
}
- gpt_uuid_copy(ent->ent_type, type);
- ent->ent_lba_start = htole64(map->map_start);
- ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
- if (name != NULL)
- utf8_to_utf16(name, ent->ent_name, 36);
-
- hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
- le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
- hdr->hdr_crc_self = 0;
- hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));
-
- gpt_write(fd, gpt);
- gpt_write(fd, tbl);
-
- hdr = tpg->map_data;
- ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz));
+ ent_set(ent, map, type, name);
+ if (gpt_write_primary(gpt) == -1)
+ return -1;
- gpt_uuid_copy(ent->ent_type, type);
- ent->ent_lba_start = htole64(map->map_start);
- ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);
- if (name != NULL)
- utf8_to_utf16(name, ent->ent_name, 36);
+ ent = gpt_ent_backup(gpt, i);
+ ent_set(ent, map, type, name);
+ if (gpt_write_backup(gpt) == -1)
+ return -1;
- hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
- le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
- hdr->hdr_crc_self = 0;
- hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));
-
- gpt_write(fd, lbt);
- gpt_write(fd, tpg);
-
- printf("Partition %d added, use:\n", i + 1);
- printf("\tdkctl %s addwedge <wedgename> %" PRIu64 " %" PRIu64
- " <type>\n", device_arg, map->map_start, map->map_size);
- printf("to create a wedge for it\n");
+ gpt_uuid_snprintf(buf, sizeof(buf), "%d", type);
+ gpt_msg(gpt, "Partition %d added: %s %" PRIu64 " %" PRIu64, i + 1,
+ buf, map->map_start, map->map_size);
+ return 0;
}
-int
-cmd_add(int argc, char *argv[])
+static int
+cmd_add(gpt_t gpt, int argc, char *argv[])
{
- char *p;
- int ch, fd;
- int64_t human_num;
+ int ch;
+ off_t alignment = 0, block = 0, sectors = 0, size = 0;
+ unsigned int entry = 0;
+ uint8_t *name = NULL;
+ gpt_uuid_t type;
- while ((ch = getopt(argc, argv, "a:b:i:l:s:t:")) != -1) {
+ gpt_uuid_copy(type, gpt_uuid_nil);
+
+ while ((ch = getopt(argc, argv, GPT_AIS "b:l:t:")) != -1) {
switch(ch) {
- case 'a':
- if (alignment > 0)
- usage_add();
- if (dehumanize_number(optarg, &human_num) < 0)
- usage_add();
- alignment = human_num;
- if (alignment < 1)
- usage_add();
- break;
case 'b':
- if (block > 0)
- usage_add();
- if (dehumanize_number(optarg, &human_num) < 0)
- usage_add();
- block = human_num;
- if (block < 1)
- usage_add();
- break;
- case 'i':
- if (entry > 0)
- usage_add();
- entry = strtoul(optarg, &p, 10);
Home |
Main Index |
Thread Index |
Old Index