summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorJoshua M. Clulow <josh@sysmgr.org>2020-09-11 15:17:04 -0700
committerJoshua M. Clulow <josh@sysmgr.org>2020-09-11 15:17:04 -0700
commit51706d6c808d070acc209c5894e98814aa259ba6 (patch)
tree83765501c430466707b5e230f1609986bf483762 /usr/src
parent93dc830ecbbcd243760848e27a0f901125432b04 (diff)
downloadillumos-joyent-51706d6c808d070acc209c5894e98814aa259ba6.tar.gz
12510 prtvtoc columns are not wide enough for modern disks
Reviewed by: Robert Mustacchi <rm@fingolfin.org> Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/prtvtoc/Makefile6
-rw-r--r--usr/src/cmd/prtvtoc/prtvtoc.c515
-rw-r--r--usr/src/man/man1m/prtvtoc.1m67
3 files changed, 333 insertions, 255 deletions
diff --git a/usr/src/cmd/prtvtoc/Makefile b/usr/src/cmd/prtvtoc/Makefile
index 1a64695fa6..adf9f5396a 100644
--- a/usr/src/cmd/prtvtoc/Makefile
+++ b/usr/src/cmd/prtvtoc/Makefile
@@ -31,11 +31,7 @@ RELUSRSBIN= ../usr/sbin
ROOTSYMLINK= $(ROOTETC)/$(PROG)
LDLIBS += -ladm -lefi
-CERRWARN += -_gcc=-Wno-parentheses
-CERRWARN += $(CNOWARN_UNINIT)
-
-# not linted
-SMATCH=off
+CSTD = $(CSTD_GNU99)
.KEEP_STATE:
diff --git a/usr/src/cmd/prtvtoc/prtvtoc.c b/usr/src/cmd/prtvtoc/prtvtoc.c
index 531fd244e8..16a1a5a4c3 100644
--- a/usr/src/cmd/prtvtoc/prtvtoc.c
+++ b/usr/src/cmd/prtvtoc/prtvtoc.c
@@ -18,12 +18,12 @@
*
* CDDL HEADER END
*/
-/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
-/* Copyright (c) 1984 AT&T */
-/* All Rights Reserved */
+/* Copyright (c) 1984 AT&T */
+/* All Rights Reserved */
/*
@@ -42,6 +42,7 @@
#include <string.h>
#include <stdio.h>
#include <limits.h>
+#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -56,10 +57,10 @@
* Assumes V_NUMPAR must be a power of 2.
*
* for V_NUMPAR = 8, we have
- * parttn(x)=(x & 0x07) noparttn(x)=(x & 0x3fff8)
+ * parttn(x)=(x & 0x07) noparttn(x)=(x & 0x3fff8)
*
* for V_NUMPAR = 16, we have
- * parttn(x)=(x & 0x0f) noparttn(x)=(x & 0x3fff0)
+ * parttn(x)=(x & 0x0f) noparttn(x)=(x & 0x3fff0)
*/
#define parttn(x) (x % V_NUMPAR)
#define noparttn(x) (x & (MAXMIN & ~(V_NUMPAR-1)))
@@ -86,8 +87,11 @@ static int readgeom(int, char *, struct dk_geom *);
static int readvtoc(int, char *, struct extvtoc *);
static int readefi(int, char *, struct dk_gpt **);
static void usage(void);
-static int warn(char *, char *);
-static char *safe_strdup(char *);
+static char *safe_strdup(const char *, const char *);
+static void *safe_calloc(const char *, size_t, size_t);
+
+#define SAFE_STRDUP(a) safe_strdup(__func__, (a))
+#define SAFE_CALLOC(a, b) safe_calloc(__func__, (a), (b))
/*
* External variables.
@@ -101,19 +105,15 @@ static short hflag; /* Omit headers */
static short sflag; /* Omit all but the column header */
static char *fstab = VFSTAB; /* Fstab pathname */
static char *mnttab = MNTTAB; /* mnttab pathname */
-static char *progname; /* Last qualifier of arg0 */
int
-main(int ac, char **av)
+main(int argc, char *argv[])
{
- int idx;
+ int status = EXIT_SUCCESS;
+ int c;
- if (progname = strrchr(av[0], '/'))
- ++progname;
- else
- progname = av[0];
- while ((idx = getopt(ac, av, "fhst:m:")) != -1)
- switch (idx) {
+ while ((c = getopt(argc, argv, "fhst:m:")) != -1) {
+ switch (c) {
case 'f':
++fflag;
break;
@@ -132,12 +132,18 @@ main(int ac, char **av)
default:
usage();
}
- if (optind >= ac)
+ }
+
+ if (optind >= argc)
usage();
- idx = 0;
- while (optind < ac)
- idx |= prtvtoc(av[optind++]);
- return (idx == 0 ? 0 : 1);
+
+ for (int i = optind; i < argc; i++) {
+ if (prtvtoc(argv[i]) != 0) {
+ status = EXIT_FAILURE;
+ }
+ }
+
+ return (status);
}
static freemap_t *freemap;
@@ -147,36 +153,38 @@ static freemap_t *freemap;
static freemap_t *
findfree(struct dk_geom *geom, struct extvtoc *vtoc)
{
- struct extpartition *part;
- struct extpartition **list;
- freemap_t *freeidx;
- diskaddr_t fullsize;
- ulong_t cylsize;
- struct extpartition *sorted[V_NUMPAR + 1];
-
- freemap = calloc(sizeof (freemap_t), V_NUMPAR + 1);
- cylsize = (geom->dkg_nsect) * (geom->dkg_nhead);
- fullsize = (diskaddr_t)(geom->dkg_ncyl) * cylsize;
+ struct extpartition *part;
+ struct extpartition **list;
+ freemap_t *freeidx;
+ diskaddr_t fullsize;
+ ulong_t cylsize;
+ struct extpartition *sorted[V_NUMPAR + 1];
+
if (vtoc->v_nparts > V_NUMPAR) {
- (void) warn("putfree()", "Too many partitions on disk!");
- exit(1);
+ errx(EXIT_FAILURE, "putfree(): Too many partitions on disk!");
}
+
+ freemap = SAFE_CALLOC(sizeof (freemap_t), V_NUMPAR + 1);
+ cylsize = (geom->dkg_nsect) * (geom->dkg_nhead);
+ fullsize = (diskaddr_t)(geom->dkg_ncyl) * cylsize;
list = sorted;
- for (part = vtoc->v_part; part < vtoc->v_part + vtoc->v_nparts; ++part)
+ for (part = vtoc->v_part; part < vtoc->v_part + vtoc->v_nparts;
+ ++part) {
if (part->p_size && part->p_tag != V_BACKUP)
*list++ = part;
+ }
*list = 0;
- qsort((char *)sorted, (uint_t)(list - sorted),
- sizeof (*sorted), partcmp);
+ qsort(sorted, list - sorted, sizeof (*sorted), partcmp);
freeidx = freemap;
freeidx->fr_start = 0;
- for (list = sorted; (part = *list) != NULL; ++list)
- if (part->p_start <= freeidx->fr_start)
+ for (list = sorted; (part = *list) != NULL; ++list) {
+ if (part->p_start <= freeidx->fr_start) {
freeidx->fr_start += part->p_size;
- else {
+ } else {
freeidx->fr_size = part->p_start - freeidx->fr_start;
(++freeidx)->fr_start = part->p_start + part->p_size;
}
+ }
if (freeidx->fr_start < fullsize) {
freeidx->fr_size = fullsize - freeidx->fr_start;
++freeidx;
@@ -191,33 +199,33 @@ findfree(struct dk_geom *geom, struct extvtoc *vtoc)
static freemap_t *
findfree64(struct dk_gpt *efi)
{
- struct dk_part *part;
- struct dk_part **list;
- freemap_t *freeidx;
- diskaddr_t fullsize;
- struct dk_part **sorted;
-
- freemap = calloc(sizeof (freemap_t), efi->efi_nparts + 1);
- sorted = calloc(sizeof (struct dk_part), efi->efi_nparts + 1);
+ struct dk_part *part;
+ struct dk_part **list;
+ freemap_t *freeidx;
+ diskaddr_t fullsize;
+ struct dk_part **sorted;
+
+ freemap = SAFE_CALLOC(sizeof (freemap_t), efi->efi_nparts + 1);
+ sorted = SAFE_CALLOC(sizeof (struct dk_part), efi->efi_nparts + 1);
fullsize = efi->efi_last_u_lba;
list = sorted;
- for (part = efi->efi_parts;
- part < efi->efi_parts + efi->efi_nparts;
- ++part)
+ for (part = efi->efi_parts; part < efi->efi_parts + efi->efi_nparts;
+ ++part) {
if (part->p_size && part->p_tag != V_BACKUP)
*list++ = part;
+ }
*list = 0;
- qsort((char *)sorted, (uint_t)(list - sorted),
- sizeof (*sorted), partcmp64);
+ qsort(sorted, list - sorted, sizeof (*sorted), partcmp64);
freeidx = freemap;
freeidx->fr_start = efi->efi_first_u_lba;
- for (list = sorted; (part = *list) != NULL; ++list)
- if (part->p_start == freeidx->fr_start)
+ for (list = sorted; (part = *list) != NULL; ++list) {
+ if (part->p_start == freeidx->fr_start) {
freeidx->fr_start += part->p_size;
- else {
+ } else {
freeidx->fr_size = part->p_start - freeidx->fr_start;
(++freeidx)->fr_start = part->p_start + part->p_size;
}
+ }
if (freeidx->fr_start < fullsize) {
freeidx->fr_size = fullsize - freeidx->fr_start;
++freeidx;
@@ -236,7 +244,6 @@ findfree64(struct dk_gpt *efi)
static char **
getmntpt(major_t slot, minor_t nopartminor)
{
- int idx;
FILE *file;
char devbuf[PATH_MAX], *item;
static char *list[V_NUMPAR];
@@ -244,22 +251,22 @@ getmntpt(major_t slot, minor_t nopartminor)
struct mnttab mtab;
struct vfstab vtab;
- for (idx = 0; idx < V_NUMPAR; ++idx)
+ for (unsigned idx = 0; idx < V_NUMPAR; ++idx)
list[idx] = NULL;
/* read mnttab for partition mountpoints */
if ((file = fopen(mnttab, "r")) == NULL) {
- (void) warn(mnttab, strerror(errno));
+ warn("failed to open %s", mnttab);
} else {
while (getmntent(file, &mtab) == 0) {
item = mtab.mnt_special;
- if ((item == NULL) || (mtab.mnt_mountp == NULL))
+ if (item == NULL || mtab.mnt_mountp == NULL)
continue;
/*
* Is it from /dev?
*/
- if (strncmp(item, "/dev/", strlen("/dev/") != 0))
+ if (strncmp(item, "/dev/", strlen("/dev/")) != 0)
continue;
/*
@@ -268,25 +275,27 @@ getmntpt(major_t slot, minor_t nopartminor)
(void) snprintf(devbuf, sizeof (devbuf), "/dev/r%s",
item + strlen("/dev/"));
- if ((stat(devbuf, &sb) != 0) ||
- ((sb.st_mode & S_IFMT) != S_IFCHR))
+ if (stat(devbuf, &sb) != 0 ||
+ (sb.st_mode & S_IFMT) != S_IFCHR) {
continue;
+ }
/*
* device must match input slot and nopartminor
*/
- if ((major(sb.st_rdev) != slot) ||
- (noparttn(minor(sb.st_rdev)) != nopartminor))
+ if (major(sb.st_rdev) != slot ||
+ noparttn(minor(sb.st_rdev)) != nopartminor) {
continue;
+ }
list[parttn(minor(sb.st_rdev))] =
- safe_strdup(mtab.mnt_mountp);
+ SAFE_STRDUP(mtab.mnt_mountp);
}
(void) fclose(file);
}
if ((file = fopen(fstab, "r")) == NULL) {
- (void) warn(fstab, strerror(errno));
+ warn("failed to open %s", fstab);
return (list);
}
@@ -296,7 +305,7 @@ getmntpt(major_t slot, minor_t nopartminor)
*/
while (getvfsent(file, &vtab) == 0) {
item = vtab.vfs_special;
- if ((item == NULL) || (vtab.vfs_mountp == NULL))
+ if (item == NULL || vtab.vfs_mountp == NULL)
continue;
if (strncmp(item, "/dev/", strlen("/dev/")) != 0)
@@ -308,16 +317,18 @@ getmntpt(major_t slot, minor_t nopartminor)
(void) snprintf(devbuf, sizeof (devbuf), "/dev/r%s",
item + strlen("/dev/"));
- if ((stat(devbuf, &sb) != 0) ||
- ((sb.st_mode & S_IFMT) != S_IFCHR))
+ if (stat(devbuf, &sb) != 0 ||
+ (sb.st_mode & S_IFMT) != S_IFCHR) {
continue;
+ }
/*
* device must match input slot and nopartminor
*/
- if ((major(sb.st_rdev) != slot) ||
- (noparttn(minor(sb.st_rdev)) != nopartminor))
+ if (major(sb.st_rdev) != slot ||
+ noparttn(minor(sb.st_rdev)) != nopartminor) {
continue;
+ }
/*
* use mnttab entry if both tables have entries
@@ -325,7 +336,7 @@ getmntpt(major_t slot, minor_t nopartminor)
if (list[parttn(minor(sb.st_rdev))] != NULL)
continue;
- list[parttn(minor(sb.st_rdev))] = safe_strdup(vtab.vfs_mountp);
+ list[parttn(minor(sb.st_rdev))] = SAFE_STRDUP(vtab.vfs_mountp);
}
(void) fclose(file);
@@ -338,22 +349,31 @@ getmntpt(major_t slot, minor_t nopartminor)
static int
partcmp(const void *one, const void *two)
{
- return ((*(struct partition **)one)->p_start -
- (*(struct partition **)two)->p_start);
+ struct partition *p1 = *(struct partition **)one;
+ struct partition *p2 = *(struct partition **)two;
+
+ if (p1->p_start > p2->p_start) {
+ return (1);
+ } else if (p1->p_start < p2->p_start) {
+ return (-1);
+ } else {
+ return (0);
+ }
}
static int
partcmp64(const void *one, const void *two)
{
- if ((*(struct dk_part **)one)->p_start >
- (*(struct dk_part **)two)->p_start)
- return (1);
- else if ((*(struct dk_part **)one)->p_start <
- (*(struct dk_part **)two)->p_start)
- return (-1);
- else
- return (0);
+ dk_part_t *p1 = *(dk_part_t **)one;
+ dk_part_t *p2 = *(dk_part_t **)two;
+ if (p1->p_start > p2->p_start) {
+ return (1);
+ } else if (p1->p_start < p2->p_start) {
+ return (-1);
+ } else {
+ return (0);
+ }
}
/*
@@ -362,37 +382,46 @@ partcmp64(const void *one, const void *two)
static int
prtvtoc(char *devname)
{
- int fd;
- int idx;
- freemap_t *freemap;
- struct stat sb;
- struct extvtoc vtoc;
- int geo;
- struct dk_geom geom;
- char *name;
- int newvtoc = 0;
- struct dk_gpt *efi;
+ int fd;
+ int idx;
+ freemap_t *freemap;
+ struct stat sb;
+ struct extvtoc vtoc;
+ int geo;
+ struct dk_geom geom;
+ char *name;
+ int newvtoc = 0;
+ struct dk_gpt *efi;
name = getfullrawname(devname);
- if (name == NULL)
- return (warn(devname,
- "internal administrative call (getfullrawname) failed"));
+ if (name == NULL) {
+ warnx("%s: internal administrative call (getfullrawname) "
+ "failed", devname);
+ return (-1);
+ }
if (strcmp(name, "") == 0)
name = devname;
- if ((fd = open(name, O_NONBLOCK|O_RDONLY)) < 0)
- return (warn(name, strerror(errno)));
- if (fstat(fd, &sb) < 0)
- return (warn(name, strerror(errno)));
- if ((sb.st_mode & S_IFMT) != S_IFCHR)
- return (warn(name, "Not a raw device"));
+ if ((fd = open(name, O_NONBLOCK|O_RDONLY)) < 0) {
+ warn("%s: failed to open device", name);
+ return (-1);
+ }
+ if (fstat(fd, &sb) < 0) {
+ warn("%s: failed to stat device", name);
+ return (-1);
+ }
+ if ((sb.st_mode & S_IFMT) != S_IFCHR) {
+ warnx("%s: Not a raw device", name);
+ return (-1);
+ }
geo = (readgeom(fd, name, &geom) == 0);
if (geo) {
if ((idx = readvtoc(fd, name, &vtoc)) == VT_ENOTSUP) {
idx = (readefi(fd, name, &efi) == 0);
newvtoc = 1;
- } else
+ } else {
idx = (idx == 0);
+ }
}
(void) close(fd);
if ((!geo) || (!idx))
@@ -407,14 +436,15 @@ prtvtoc(char *devname)
else
putfree64(efi, freemap);
} else {
- if (!newvtoc)
+ if (!newvtoc) {
puttable(&geom, &vtoc, freemap, devname,
getmntpt(major(sb.st_rdev),
noparttn(minor(sb.st_rdev))));
- else
+ } else {
puttable64(efi, freemap, devname,
getmntpt(major(sb.st_rdev),
noparttn(minor(sb.st_rdev))));
+ }
}
if (newvtoc)
efi_free(efi);
@@ -468,6 +498,51 @@ putfree64(struct dk_gpt *efi, freemap_t *freemap)
(void) printf("\n");
}
+static void
+print_table_header()
+{
+ (void) printf("* First Sector"
+ " Last\n");
+ (void) printf("* Partition Tag Flags Sector Count"
+ " Sector Mount Directory\n");
+}
+
+static void
+print_table_row(uint_t partition, uint_t tag, uint_t flag,
+ u_longlong_t first_sector, u_longlong_t sector_count,
+ u_longlong_t last_sector, const char *mount_dir)
+{
+ (void) printf(" %6u %4u %02x %11llu %11llu %11llu",
+ partition, tag, flag, first_sector, sector_count, last_sector);
+ if (mount_dir != NULL) {
+ (void) printf(" %s", mount_dir);
+ }
+ (void) printf("\n");
+}
+
+static void
+print_freemap(freemap_t *freemap)
+{
+ if (freemap->fr_size == 0) {
+ /*
+ * The freemap is completely empty, so do not print the header.
+ */
+ return;
+ }
+
+ (void) printf("* Unallocated space:\n"
+ "* First Sector Last\n"
+ "* Sector Count Sector\n");
+
+ do {
+ (void) printf("* %11llu %11llu %11llu\n",
+ freemap->fr_start, freemap->fr_size,
+ freemap->fr_size + freemap->fr_start - 1);
+ } while ((++freemap)->fr_size != 0);
+
+ (void) printf("*\n");
+}
+
/*
* puttable(): Print a human-readable VTOC.
*/
@@ -475,54 +550,47 @@ static void
puttable(struct dk_geom *geom, struct extvtoc *vtoc, freemap_t *freemap,
char *name, char **mtab)
{
- ushort_t idx;
- ulong_t cylsize;
+ ushort_t idx;
+ ulong_t cylsize;
cylsize = (geom->dkg_nsect) * (geom->dkg_nhead);
if (!hflag && !sflag) {
(void) printf("* %s", name);
- if (*vtoc->v_volume)
+ if (vtoc->v_volume[0] != '\0')
(void) printf(" (volume \"%.8s\")", vtoc->v_volume);
(void) printf(" partition map\n");
(void) printf("*\n* Dimensions:\n");
- (void) printf("* %7u bytes/sector\n", vtoc->v_sectorsz);
- (void) printf("* %7u sectors/track\n", geom->dkg_nsect);
- (void) printf("* %7u tracks/cylinder\n", geom->dkg_nhead);
- (void) printf("* %7lu sectors/cylinder\n", cylsize);
- (void) printf("* %7u cylinders\n", geom->dkg_pcyl);
- (void) printf("* %7u accessible cylinders\n", geom->dkg_ncyl);
+ (void) printf("* %11u bytes/sector\n", vtoc->v_sectorsz);
+ (void) printf("* %11u sectors/track\n", geom->dkg_nsect);
+ (void) printf("* %11u tracks/cylinder\n", geom->dkg_nhead);
+ (void) printf("* %11lu sectors/cylinder\n", cylsize);
+ (void) printf("* %11u cylinders\n", geom->dkg_pcyl);
+ (void) printf("* %11u accessible cylinders\n", geom->dkg_ncyl);
(void) printf("*\n* Flags:\n");
(void) printf("* 1: unmountable\n");
(void) printf("* 10: read-only\n*\n");
- if (freemap->fr_size) {
- (void) printf("* Unallocated space:\n");
- (void) printf("*\tFirst Sector Last\n");
- (void) printf("*\tSector Count Sector \n");
- do {
- (void) printf("* %9llu %9llu %9llu\n",
- freemap->fr_start, freemap->fr_size,
- freemap->fr_size + freemap->fr_start - 1);
- } while ((++freemap)->fr_size);
- (void) printf("*\n");
- }
+ print_freemap(freemap);
}
- if (!hflag) {
- (void) printf(\
-"* First Sector Last\n"
-"* Partition Tag Flags Sector Count Sector Mount Directory\n");
+
+ if (!hflag) {
+ print_table_header();
}
+
for (idx = 0; idx < vtoc->v_nparts; ++idx) {
- if (vtoc->v_part[idx].p_size == 0)
+ const char *mount_dir = NULL;
+ struct extpartition *p = &vtoc->v_part[idx];
+
+ if (p->p_size == 0)
continue;
- (void) printf(" %2u %5u %02x %9llu %9llu %9llu",
- idx, vtoc->v_part[idx].p_tag, vtoc->v_part[idx].p_flag,
- vtoc->v_part[idx].p_start, vtoc->v_part[idx].p_size,
- vtoc->v_part[idx].p_start + vtoc->v_part[idx].p_size - 1);
- if (mtab && mtab[idx])
- (void) printf(" %s", mtab[idx]);
- (void) printf("\n");
+
+ if (mtab != NULL) {
+ mount_dir = mtab[idx];
+ }
+
+ print_table_row(idx, p->p_tag, p->p_flag, p->p_start,
+ p->p_size, p->p_start + p->p_size - 1, mount_dir);
}
}
@@ -530,55 +598,47 @@ puttable(struct dk_geom *geom, struct extvtoc *vtoc, freemap_t *freemap,
* puttable(): Print a human-readable VTOC.
*/
static void
-puttable64(struct dk_gpt *efi, freemap_t *freemap, char *name,
- char **mtab)
+puttable64(struct dk_gpt *efi, freemap_t *freemap, char *name, char **mtab)
{
- ushort_t idx;
-
if (!hflag && !sflag) {
(void) printf("* %s", name);
- for (idx = 0; idx < efi->efi_nparts; idx++)
- if (efi->efi_parts[idx].p_tag == V_RESERVED &&
- *efi->efi_parts[idx].p_name)
- (void) printf(" (volume \"%.8s\")",
+ for (uint_t idx = 0; idx < efi->efi_nparts; idx++) {
+ if (efi->efi_parts[idx].p_tag == V_RESERVED &&
+ efi->efi_parts[idx].p_name[0] != '\0') {
+ (void) printf(" (volume \"%.8s\")",
efi->efi_parts[idx].p_name);
+ }
+ }
(void) printf(" partition map\n");
(void) printf("*\n* Dimensions:\n");
- (void) printf("* %7u bytes/sector\n", efi->efi_lbasize);
- (void) printf("* %llu sectors\n", efi->efi_last_lba + 1);
- (void) printf("* %llu accessible sectors\n",
+ (void) printf("* %11u bytes/sector\n", efi->efi_lbasize);
+ (void) printf("* %11llu sectors\n", efi->efi_last_lba + 1);
+ (void) printf("* %11llu accessible sectors\n",
efi->efi_last_u_lba - efi->efi_first_u_lba + 1);
(void) printf("*\n* Flags:\n");
(void) printf("* 1: unmountable\n");
(void) printf("* 10: read-only\n*\n");
- if (freemap->fr_size) {
- (void) printf("* Unallocated space:\n");
- (void) printf("*\tFirst Sector Last\n");
- (void) printf("*\tSector Count Sector \n");
- do {
- (void) printf("* %9llu %9llu %9llu\n",
- freemap->fr_start, freemap->fr_size,
- freemap->fr_size + freemap->fr_start - 1);
- } while ((++freemap)->fr_size);
- (void) printf("*\n");
- }
+ print_freemap(freemap);
}
- if (!hflag) {
- (void) printf(\
-"* First Sector Last\n"
-"* Partition Tag Flags Sector Count Sector Mount Directory\n");
+
+ if (!hflag) {
+ print_table_header();
}
- for (idx = 0; idx < efi->efi_nparts; ++idx) {
- if (efi->efi_parts[idx].p_size == 0)
- continue;
- (void) printf(" %2u %5u %02x %9llu %9llu %9llu",
- idx, efi->efi_parts[idx].p_tag, efi->efi_parts[idx].p_flag,
- efi->efi_parts[idx].p_start, efi->efi_parts[idx].p_size,
- efi->efi_parts[idx].p_start + efi->efi_parts[idx].p_size - 1);
- if ((idx < 7) && mtab && mtab[idx])
- (void) printf(" %s", mtab[idx]);
- (void) printf("\n");
+
+ for (uint_t idx = 0; idx < efi->efi_nparts; ++idx) {
+ const char *mount_dir = NULL;
+ dk_part_t *p = &efi->efi_parts[idx];
+
+ if (p->p_size == 0)
+ continue;
+
+ if (idx < 7 && mtab != NULL) {
+ mount_dir = mtab[idx];
+ }
+
+ print_table_row(idx, p->p_tag, p->p_flag, p->p_start,
+ p->p_size, p->p_start + p->p_size - 1, mount_dir);
}
}
@@ -588,16 +648,16 @@ puttable64(struct dk_gpt *efi, freemap_t *freemap, char *name,
static int
readgeom(int fd, char *name, struct dk_geom *geom)
{
- char err_string[128];
-
- if ((ioctl(fd, DKIOCGGEOM, geom) < 0) && (errno != ENOTSUP)) {
- (void) sprintf(err_string,
- "Unable to read Disk geometry errno = 0x%x",
- errno);
- return (warn(name, err_string));
- } else if (errno == ENOTSUP) {
+ if (ioctl(fd, DKIOCGGEOM, geom) < 0) {
+ if (errno != ENOTSUP) {
+ warnx("%s: Unable to read Disk geometry errno = 0x%x",
+ name, errno);
+ return (-1);
+ }
+
(void) memset(geom, 0, sizeof (struct dk_geom));
}
+
return (0);
}
@@ -607,19 +667,23 @@ readgeom(int fd, char *name, struct dk_geom *geom)
static int
readvtoc(int fd, char *name, struct extvtoc *vtoc)
{
- int retval;
+ int retval;
if ((retval = read_extvtoc(fd, vtoc)) >= 0)
return (0);
switch (retval) {
- case (VT_EIO):
- return (warn(name, "Unable to read VTOC"));
- case (VT_EINVAL):
- return (warn(name, "Invalid VTOC"));
- case (VT_ERROR):
- return (warn(name, "Unknown problem reading VTOC"));
+ case VT_EIO:
+ warnx("%s: Unable to read VTOC", name);
+ return (-1);
+ case VT_EINVAL:
+ warnx("%s: Invalid VTOC", name);
+ return (-1);
+ case VT_ERROR:
+ warnx("%s: Unknown problem reading VTOC", name);
+ return (-1);
}
+
return (retval);
}
@@ -635,25 +699,64 @@ readefi(int fd, char *name, struct dk_gpt **efi)
return (0);
switch (retval) {
- case (VT_EIO):
- return (warn(name, "Unable to read VTOC"));
- case (VT_EINVAL):
- return (warn(name, "Invalid VTOC"));
- case (VT_ERROR):
- return (warn(name, "Unknown problem reading VTOC"));
+ case VT_EIO:
+ warnx("%s: Unable to read VTOC", name);
+ return (-1);
+ case VT_EINVAL:
+ warnx("%s: Invalid VTOC", name);
+ return (-1);
+ case VT_ERROR:
+ warnx("%s: Unknown problem reading VTOC", name);
+ return (-1);
}
+
return (retval);
}
+static void
+memory_err(size_t l, int e, const char *fname)
+{
+ const char *reason;
+
+ switch (e) {
+ case EAGAIN:
+ reason = "not enough memory was available, please try again";
+ break;
+ case ENOMEM:
+ reason = "allocation size was too large";
+ break;
+ default:
+ reason = strerror(e);
+ break;
+ }
+
+ errx(EXIT_FAILURE, "%s: failed to allocate %llu bytes of memory: %s",
+ fname, (u_longlong_t)l, reason);
+}
+
+static void *
+safe_calloc(const char *fname, size_t nelem, size_t elsize)
+{
+ void *r;
+
+ if ((r = calloc(nelem, elsize)) == NULL) {
+ memory_err(nelem * elsize, errno, fname);
+ }
+
+ return (r);
+}
+
static char *
-safe_strdup(char *str)
+safe_strdup(const char *fname, const char *str)
{
- char *ret;
- if ((ret = strdup(str)) == NULL) {
- (void) warn("memory allocation", strerror(errno));
- exit(1);
+ size_t l = strlen(str);
+ char *r;
+
+ if ((r = strndup(str, l)) == NULL) {
+ memory_err(l + 1, errno, fname);
}
- return (ret);
+
+ return (r);
}
/*
@@ -663,16 +766,6 @@ static void
usage()
{
(void) fprintf(stderr, "Usage:\t%s [ -fhs ] [ -t fstab ] [ -m mnttab ] "
- "rawdisk ...\n", progname);
+ "rawdisk ...\n", getprogname());
exit(1);
}
-
-/*
- * warn(): Print an error message. Always returns -1.
- */
-static int
-warn(char *what, char *why)
-{
- (void) fprintf(stderr, "%s: %s: %s\n", progname, what, why);
- return (-1);
-}
diff --git a/usr/src/man/man1m/prtvtoc.1m b/usr/src/man/man1m/prtvtoc.1m
index 4f883420c1..8b353d750b 100644
--- a/usr/src/man/man1m/prtvtoc.1m
+++ b/usr/src/man/man1m/prtvtoc.1m
@@ -3,28 +3,23 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH PRTVTOC 1M "Jul 25, 2002"
+.TH PRTVTOC 1M "Apr 14, 2020"
.SH NAME
prtvtoc \- report information about a disk geometry and partitioning
.SH SYNOPSIS
-.LP
.nf
\fBprtvtoc\fR [\fB-fhs\fR] [\fB-t\fR \fIvfstab\fR] [\fB-m\fR \fImnttab\fR] \fIdevice\fR
.fi
.SH DESCRIPTION
-.sp
-.LP
The \fBprtvtoc\fR command allows the contents of the label to be viewed. The
command can be used only by the super-user.
.sp
.LP
The \fIdevice\fR name can be the file name of a raw device in the form of
-\fB/dev/rdsk/c?t?d?s2\fR or can be the file name of a block device in the form
-of \fB/dev/dsk/c?t?d?s2\fR.
+\fB/dev/rdsk/c*t*d*s2\fR or can be the file name of a block device in the form
+of \fB/dev/dsk/c*t*d*s2\fR.
.SH OPTIONS
-.sp
-.LP
The following options are supported:
.sp
.ne 2
@@ -75,7 +70,6 @@ Use \fIvfstab\fR as the list of filesystem defaults, in place of
.RE
.SH EXAMPLES
-.LP
\fBExample 1 \fRUsing the \fBprtvtoc\fR Command
.sp
.LP
@@ -88,26 +82,25 @@ disk:
example# prtvtoc /dev/rdsk/c0t3d0s2
* /dev/rdsk/c0t3d0s2 partition map
*
-* Dimension:
-* 512 bytes/sector
-* 80 sectors/track
-* 9 tracks/cylinder
-* 720 sectors/cylinder
-* 2500 cylinders
-* 1151 accessible cylinders
+* Dimensions:
+* 512 bytes/sector
+* 80 sectors/track
+* 9 tracks/cylinder
+* 720 sectors/cylinder
+* 2500 cylinders
+* 1151 accessible cylinders
*
* Flags:
* 1: unmountable
* 10: read-only
-* * First Sector Last
-* Partition Tag Flags Sector Count Sector Mount Directory
- 0 2 00 0 76320 76319 /
- 1 3 01 76320 132480 208799
- 2 5 00 0 828720 828719
- 5 6 00 208800 131760 340559 /opt
- 6 4 00 340560 447120 787679 /usr
- 7 8 00 787680 41040 828719 /export/home
-example#
+* First Sector Last
+* Partition Tag Flags Sector Count Sector Mount Directory
+ 0 2 00 0 76320 76319 /
+ 1 3 01 76320 132480 208799
+ 2 5 00 0 828720 828719
+ 5 6 00 208800 131760 340559 /opt
+ 6 4 00 340560 447120 787679 /usr
+ 7 8 00 787680 41040 828719 /export/home
.fi
.in -2
.sp
@@ -133,7 +126,7 @@ BACKUP 0x05
STAND 0x06
VAR 0x07
HOME 0x08
-ALTSCTR 0x09
+ALTSCTR 0x09
CACHE 0x0a
RESERVED 0x0b
.TE
@@ -185,30 +178,26 @@ example# prtvtoc /dev/rdsk/c1t1d0s2
* /dev/rdsk/c1t1d0s2 partition map
*
* Dimensions:
-* 512 bytes/sector
-* 3187630080 sectors
-* 3187630013 accessible sectors
+* 512 bytes/sector
+* 3187630080 sectors
+* 3187630013 accessible sectors
*
* Flags:
* 1: unmountable
* 10: read-only
*
-* First Sector Last
-* Partition Tag Flags Sector Count Sector Mount Directory
-0 2 00 34 262144 262177
-1 3 01 262178 262144 524321
-6 4 00 524322 3187089340 3187613661
-8 11 00 3187613662 16384 318763004
+* First Sector Last
+* Partition Tag Flags Sector Count Sector Mount Directory
+ 0 2 00 34 262144 262177
+ 1 3 01 262178 262144 524321
+ 6 4 00 524322 3187089340 3187613661
+ 8 11 00 3187613662 16384 318763004
.fi
.in -2
.sp
.SH SEE ALSO
-.sp
-.LP
\fBdevinfo\fR(1M), \fBfmthard\fR(1M), \fBformat\fR(1M), \fBmount\fR(1M),
\fBattributes\fR(5)
.SH WARNINGS
-.sp
-.LP
The \fBmount\fR command does not check the "not mountable" bit.