2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2004,2005 Joerg Wunsch.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SPDX-License-Identifier: BSD-4-Clause
30 * Copyright (c) 1994, 1995 Gordon W. Ross
31 * Copyright (c) 1994 Theo de Raadt
32 * All rights reserved.
33 * Copyright (c) 1987, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Symmetric Computer Systems.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * This product includes software developed by Theo de Raadt.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * from: $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk $
71 #include <sys/cdefs.h>
72 __FBSDID("$FreeBSD$");
74 #include <sys/types.h>
75 #include <sys/param.h>
77 #include <sys/ioctl.h>
78 #include <sys/sun_disklabel.h>
92 #define _PATH_TMPFILE "/tmp/EdDk.XXXXXXXXXX"
93 #define _PATH_BOOT "/boot/boot1"
104 static off_t mediasize;
105 static uint32_t sectorsize;
112 static int check_label(struct sun_disklabel *sl);
113 static void read_label(struct sun_disklabel *sl, const char *disk);
114 static void write_label(struct sun_disklabel *sl, const char *disk,
115 const char *bootpath);
116 static void edit_label(struct sun_disklabel *sl, const char *disk,
117 const char *bootpath);
118 static int parse_label(struct sun_disklabel *sl, const char *file);
119 static void print_label(struct sun_disklabel *sl, const char *disk, FILE *out);
121 static int parse_size(struct sun_disklabel *sl, int part, char *size);
122 static int parse_offset(struct sun_disklabel *sl, int part, char *offset);
124 static const char *flagname(unsigned int tag);
125 static const char *tagname(unsigned int tag);
126 static unsigned int parse_flag(struct sun_disklabel *sl, int part,
128 static unsigned int parse_tag(struct sun_disklabel *sl, int part,
130 static const char *make_h_number(uintmax_t u);
132 static void usage(void);
134 extern char *__progname;
136 static struct tags knowntags[] = {
137 { "unassigned", VTOC_UNASSIGNED },
138 { "boot", VTOC_BOOT },
139 { "root", VTOC_ROOT },
140 { "swap", VTOC_SWAP },
142 { "backup", VTOC_BACKUP },
143 { "stand", VTOC_STAND },
145 { "home", VTOC_HOME },
146 { "altsctr", VTOC_ALTSCTR },
147 { "cache", VTOC_CACHE },
148 { "VxVM_pub", VTOC_VXVM_PUB },
149 { "VxVM_priv", VTOC_VXVM_PRIV },
152 static struct tags knownflags[] = {
154 { "wu", VTOC_UNMNT },
155 { "rm", VTOC_RONLY },
156 { "ru", VTOC_UNMNT | VTOC_RONLY },
160 * Disk label editor for sun disklabels.
163 main(int ac, char **av)
165 struct sun_disklabel sl;
166 const char *bootpath;
171 bootpath = _PATH_BOOT;
172 while ((ch = getopt(ac, av, "b:BcehnrRw")) != -1)
194 fprintf(stderr, "Obsolete -r flag ignored\n");
208 if (nflag && !(Bflag || eflag || Rflag || wflag))
210 if (eflag && (Rflag || wflag))
218 bzero(&sl, sizeof(sl));
221 if (ac != 2 || strcmp(av[1], "auto") != 0)
223 read_label(&sl, disk);
224 bzero(sl.sl_part, sizeof(sl.sl_part));
225 sl.sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
226 sl.sl_part[SUN_RAWPART].sdkp_nsectors = sl.sl_ncylinders *
227 sl.sl_ntracks * sl.sl_nsectors;
228 write_label(&sl, disk, bootpath);
232 read_label(&sl, disk);
233 if (sl.sl_magic != SUN_DKMAGIC)
234 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
235 edit_label(&sl, disk, bootpath);
240 read_label(&sl, disk);
241 if (parse_label(&sl, proto) != 0)
242 errx(1, "%s: invalid label", proto);
243 write_label(&sl, disk, bootpath);
245 read_label(&sl, disk);
246 if (sl.sl_magic != SUN_DKMAGIC)
247 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
248 write_label(&sl, disk, bootpath);
250 read_label(&sl, disk);
251 if (sl.sl_magic != SUN_DKMAGIC)
252 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
253 print_label(&sl, disk, stdout);
259 check_label(struct sun_disklabel *sl)
271 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
273 nsectors = sl->sl_ncylinders * sl->sl_ntracks * sl->sl_nsectors;
274 if (sl->sl_part[SUN_RAWPART].sdkp_cyloffset != 0 ||
275 sl->sl_part[SUN_RAWPART].sdkp_nsectors != nsectors) {
276 warnx("partition c is incorrect, must start at 0 and cover "
280 if (havevtoc && sl->sl_vtoc_map[2].svtoc_tag != VTOC_BACKUP) {
281 warnx("partition c must have tag \"backup\"");
284 for (i = 0; i < SUN_NPART; i++) {
285 if (i == 2 || sl->sl_part[i].sdkp_nsectors == 0)
287 start = (uint64_t)sl->sl_part[i].sdkp_cyloffset *
288 sl->sl_ntracks * sl->sl_nsectors;
289 end = start + sl->sl_part[i].sdkp_nsectors;
290 if (end > nsectors) {
291 warnx("partition %c extends past end of disk",
296 if (sl->sl_vtoc_map[i].svtoc_tag == VTOC_BACKUP) {
297 warnx("only partition c is allowed to have "
302 for (j = 0; j < SUN_NPART; j++) {
304 * Overlaps for unmountable partitions are
305 * non-fatal but will be warned anyway.
307 warnonly = havevtoc &&
308 ((sl->sl_vtoc_map[i].svtoc_flag & VTOC_UNMNT) != 0 ||
309 (sl->sl_vtoc_map[j].svtoc_flag & VTOC_UNMNT) != 0);
311 if (j == 2 || j == i ||
312 sl->sl_part[j].sdkp_nsectors == 0)
314 ostart = (uint64_t)sl->sl_part[j].sdkp_cyloffset *
315 sl->sl_ntracks * sl->sl_nsectors;
316 oend = ostart + sl->sl_part[j].sdkp_nsectors;
317 if ((start <= ostart && end >= oend) ||
318 (start > ostart && start < oend) ||
319 (end > ostart && end < oend)) {
320 warnx("partition %c overlaps partition %c",
331 read_label(struct sun_disklabel *sl, const char *disk)
333 char path[MAXPATHLEN];
339 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk);
340 if ((fd = open(path, O_RDONLY)) < 0)
341 err(1, "open %s", path);
342 if (read(fd, buf, sizeof(buf)) != sizeof(buf))
344 error = sunlabel_dec(buf, sl);
345 if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
347 err(1, "%s: ioctl(DIOCGMEDIASIZE) failed", disk);
348 if (ioctl(fd, DIOCGSECTORSIZE, §orsize) != 0) {
350 err(1, "%s: DIOCGSECTORSIZE failed", disk);
355 bzero(sl, sizeof(*sl));
356 if (ioctl(fd, DIOCGFWSECTORS, &fwsectors) != 0)
358 if (ioctl(fd, DIOCGFWHEADS, &fwheads) != 0) {
359 if (mediasize <= 63 * 1024 * sectorsize)
361 else if (mediasize <= 63 * 16 * 1024 * sectorsize)
367 sl->sl_pcylinders = mediasize / (fwsectors * fwheads *
369 sl->sl_sparespercyl = 0;
370 sl->sl_interleave = 1;
371 sl->sl_ncylinders = sl->sl_pcylinders - 2;
372 sl->sl_acylinders = 2;
373 sl->sl_nsectors = fwsectors;
374 sl->sl_ntracks = fwheads;
375 sl->sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
376 sl->sl_part[SUN_RAWPART].sdkp_nsectors = sl->sl_ncylinders *
377 sl->sl_ntracks * sl->sl_nsectors;
378 if (mediasize > (off_t)4999L * 1024L * 1024L) {
380 "FreeBSD%jdG cyl %u alt %u hd %u sec %u",
381 (intmax_t)(mediasize + 512 * 1024 * 1024) /
382 (1024 * 1024 * 1024),
383 sl->sl_ncylinders, sl->sl_acylinders,
384 sl->sl_ntracks, sl->sl_nsectors);
387 "FreeBSD%jdM cyl %u alt %u hd %u sec %u",
388 (intmax_t)(mediasize + 512 * 1024) / (1024 * 1024),
389 sl->sl_ncylinders, sl->sl_acylinders,
390 sl->sl_ntracks, sl->sl_nsectors);
397 write_label(struct sun_disklabel *sl, const char *disk, const char *bootpath)
399 char path[MAXPATHLEN];
400 char boot[SUN_BOOTSIZE];
407 struct gctl_req *grq;
409 sl->sl_magic = SUN_DKMAGIC;
411 if (check_label(sl) != 0)
412 errx(1, "invalid label");
414 bzero(buf, sizeof(buf));
415 sunlabel_enc(buf, sl);
418 print_label(sl, disk, stdout);
422 if ((bfd = open(bootpath, O_RDONLY)) < 0)
423 err(1, "open %s", bootpath);
424 i = read(bfd, boot, sizeof(boot));
427 else if (i != sizeof (boot))
428 errx(1, "read wrong size boot code (%d)", i);
431 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk);
432 fd = open(path, O_RDWR);
434 grq = gctl_get_handle();
435 gctl_ro_param(grq, "verb", -1, "write label");
436 gctl_ro_param(grq, "class", -1, "SUN");
437 gctl_ro_param(grq, "geom", -1, disk);
438 gctl_ro_param(grq, "label", sizeof buf, buf);
439 errstr = gctl_issue(grq);
441 errx(1, "%s", errstr);
444 grq = gctl_get_handle();
445 gctl_ro_param(grq, "verb", -1, "write bootcode");
446 gctl_ro_param(grq, "class", -1, "SUN");
447 gctl_ro_param(grq, "geom", -1, disk);
448 gctl_ro_param(grq, "bootcode", sizeof boot, boot);
449 errstr = gctl_issue(grq);
451 errx(1, "%s", errstr);
455 if (lseek(fd, 0, SEEK_SET) < 0)
457 if (write(fd, buf, sizeof(buf)) != sizeof(buf))
460 for (i = 0; i < SUN_NPART; i++) {
461 if (sl->sl_part[i].sdkp_nsectors == 0)
463 off = sl->sl_part[i].sdkp_cyloffset *
464 sl->sl_ntracks * sl->sl_nsectors * 512;
466 * Ignore first SUN_SIZE bytes of boot code to
467 * avoid overwriting the label.
469 if (lseek(fd, off + SUN_SIZE, SEEK_SET) < 0)
471 if (write(fd, boot + SUN_SIZE,
472 sizeof(boot) - SUN_SIZE) !=
473 sizeof(boot) - SUN_SIZE)
483 edit_label(struct sun_disklabel *sl, const char *disk, const char *bootpath)
485 char tmpfil[] = _PATH_TMPFILE;
494 if ((fd = mkstemp(tmpfil)) < 0)
496 if ((fp = fdopen(fd, "w")) == NULL)
498 print_label(sl, disk, fp);
501 if ((pid = fork()) < 0)
504 if ((editor = getenv("EDITOR")) == NULL)
506 execlp(editor, editor, tmpfil, (char *)NULL);
507 err(1, "execlp %s", editor);
510 while ((r = wait(&status)) > 0 && r != pid)
512 if (WIFEXITED(status)) {
513 if (parse_label(sl, tmpfil) == 0) {
516 write_label(sl, disk, bootpath);
519 printf("re-edit the label? [y]: ");
522 if (c != EOF && c != '\n')
523 while (getchar() != '\n')
538 parse_label(struct sun_disklabel *sl, const char *file)
546 char volname[SUN_VOLNAME_LEN + 1];
547 struct sun_disklabel sl1;
555 unsigned alt, cyl, hd, nr, sec;
558 if ((fp = fopen(file, "r")) == NULL)
561 bzero(&sl1.sl_part, sizeof(sl1.sl_part));
562 while (fgets(buf, sizeof(buf), fp) != NULL) {
564 * In order to recognize a partition entry, we search
565 * for lines starting with a single letter followed by
566 * a colon as their first non-white characters. We
567 * silently ignore any other lines, so any comment etc.
568 * lines in the label template will be ignored.
570 * XXX We should probably also recognize the geometry
571 * fields on top, and allow changing the geometry
572 * emulated by this disk.
574 for (bp = buf; isspace(*bp); bp++)
576 if (strncmp(bp, "text:", strlen("text:")) == 0) {
577 bp += strlen("text:");
579 " %s cyl %u alt %u hd %u sec %u",
580 text, &cyl, &alt, &hd, &sec);
582 warnx("%s, line %d: text label does not "
583 "contain required fields",
589 warnx("%s, line %d: # alt must be equal 2",
594 if (cyl == 0 || cyl > USHRT_MAX) {
598 warnx("%s, line %d: # %s %d unreasonable",
599 file, line + 1, what, nr);
603 if (hd == 0 || hd > USHRT_MAX) {
608 if (sec == 0 || sec > USHRT_MAX) {
614 warnx("unit size unknown, no sector count "
615 "check could be done");
616 else if ((uintmax_t)(cyl + alt) * sec * hd >
617 (uintmax_t)mediasize / sectorsize) {
618 warnx("%s, line %d: sector count %ju exceeds "
621 (uintmax_t)(cyl + alt) * sec * hd,
622 (uintmax_t)mediasize / sectorsize);
626 sl1.sl_pcylinders = cyl + alt;
627 sl1.sl_ncylinders = cyl;
628 sl1.sl_acylinders = alt;
629 sl1.sl_nsectors = sec;
631 memset(sl1.sl_text, 0, sizeof(sl1.sl_text));
632 snprintf(sl1.sl_text, sizeof(sl1.sl_text),
633 "%s cyl %u alt %u hd %u sec %u",
634 text, cyl, alt, hd, sec);
637 if (strncmp(bp, "volume name:", strlen("volume name:")) == 0) {
638 wantvtoc = 1; /* Volume name requires VTOC. */
639 bp += strlen("volume name:");
640 #if SUN_VOLNAME_LEN != 8
641 # error "scanf field width does not match SUN_VOLNAME_LEN"
644 * We set the field length to one more than
645 * SUN_VOLNAME_LEN to allow detecting an
648 memset(volname, 0, sizeof volname);
649 rv = sscanf(bp, " %9[^\n]", volname);
651 /* Clear the volume name. */
652 memset(sl1.sl_vtoc_volname, 0,
655 memcpy(sl1.sl_vtoc_volname, volname,
657 if (volname[SUN_VOLNAME_LEN] != '\0')
659 "%s, line %d: volume name longer than %d characters, truncating",
660 file, line + 1, SUN_VOLNAME_LEN);
664 if (strlen(bp) < 2 || bp[1] != ':') {
668 rv = sscanf(bp, "%c: %30s %30s %30s %30s",
669 &part, size, offset, tag, flag);
672 warnx("%s: syntax error on line %d",
677 if (parse_size(&sl1, part - 'a', size) ||
678 parse_offset(&sl1, part - 'a', offset))
682 if (rv == 5 && parse_flag(&sl1, part - 'a', flag))
684 if (parse_tag(&sl1, part - 'a', tag))
691 sl1.sl_vtoc_sane = SUN_VTOC_SANE;
692 sl1.sl_vtoc_vers = SUN_VTOC_VERSION;
693 sl1.sl_vtoc_nparts = SUN_NPART;
695 sl1.sl_vtoc_sane = 0;
696 sl1.sl_vtoc_vers = 0;
697 sl1.sl_vtoc_nparts = 0;
698 bzero(&sl1.sl_vtoc_map, sizeof(sl1.sl_vtoc_map));
701 return (check_label(sl));
705 parse_size(struct sun_disklabel *sl, int part, char *size)
714 n = strtoumax(size, &p, 10);
716 if (strcmp(size, "*") == 0) {
717 total = sl->sl_ncylinders * sl->sl_ntracks *
719 for (i = 0; i < part; i++) {
722 nsectors += sl->sl_part[i].sdkp_nsectors;
724 n = total - nsectors;
725 } else if (p[1] == '\0' && (p[0] == 'C' || p[0] == 'c')) {
726 n = n * sl->sl_ntracks * sl->sl_nsectors;
727 } else if (p[1] == '\0' && (p[0] == 'K' || p[0] == 'k')) {
728 n = roundup((n * 1024) / 512,
729 sl->sl_ntracks * sl->sl_nsectors);
730 } else if (p[1] == '\0' && (p[0] == 'M' || p[0] == 'm')) {
731 n = roundup((n * 1024 * 1024) / 512,
732 sl->sl_ntracks * sl->sl_nsectors);
733 } else if (p[1] == '\0' && (p[0] == 'S' || p[0] == 's')) {
734 /* size in sectors, no action neded */
735 } else if (p[1] == '\0' && (p[0] == 'G' || p[0] == 'g')) {
736 n = roundup((n * 1024 * 1024 * 1024) / 512,
737 sl->sl_ntracks * sl->sl_nsectors);
741 n = n * sl->sl_ntracks * sl->sl_nsectors;
743 sl->sl_part[part].sdkp_nsectors = n;
748 parse_offset(struct sun_disklabel *sl, int part, char *offset)
756 n = strtoumax(offset, &p, 10);
758 if (strcmp(offset, "*") == 0) {
759 for (i = 0; i < part; i++) {
762 nsectors += sl->sl_part[i].sdkp_nsectors;
764 n = nsectors / (sl->sl_nsectors * sl->sl_ntracks);
768 sl->sl_part[part].sdkp_cyloffset = n;
773 print_label(struct sun_disklabel *sl, const char *disk, FILE *out)
778 /* Long enough to hex-encode each character. */
779 char volname[4 * SUN_VOLNAME_LEN + 1];
781 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
782 secpercyl = sl->sl_nsectors * sl->sl_ntracks;
788 "sectors/cylinder: %ju\n",
795 "# max sectors/unit (including alt cylinders): %ju\n",
796 (uintmax_t)mediasize / sectorsize);
798 "sectors/unit: %ju\n",
799 secpercyl * sl->sl_ncylinders);
800 if (havevtoc && sl->sl_vtoc_volname[0] != '\0') {
801 for (i = j = 0; i < SUN_VOLNAME_LEN; i++) {
802 if (sl->sl_vtoc_volname[i] == '\0')
804 if (isprint(sl->sl_vtoc_volname[i]))
805 volname[j++] = sl->sl_vtoc_volname[i];
807 j += sprintf(volname + j, "\\x%02X",
808 sl->sl_vtoc_volname[i]);
811 fprintf(out, "volume name: %s\n", volname);
819 fprintf(out, "# Size is in %s.", cflag? "cylinders": "sectors");
822 " Use %%d%c, %%dK, %%dM or %%dG to specify in %s,\n"
823 "# kilobytes, megabytes or gigabytes respectively, or '*' to specify rest of\n"
826 cflag? "sectors": "cylinders");
829 fprintf(out, "# Offset is in cylinders.");
832 " Use '*' to calculate offsets automatically.\n"
839 "# size offset tag flag\n"
840 "# ---------- ---------- ---------- ----\n"
845 "# ---------- ----------\n"
848 for (i = 0; i < SUN_NPART; i++) {
849 if (sl->sl_part[i].sdkp_nsectors == 0)
852 fprintf(out, " %c: %10s",
854 make_h_number((uintmax_t)
855 sl->sl_part[i].sdkp_nsectors * 512));
856 fprintf(out, " %10s",
857 make_h_number((uintmax_t)
858 sl->sl_part[i].sdkp_cyloffset * 512
861 fprintf(out, " %c: %10ju %10u",
863 sl->sl_part[i].sdkp_nsectors / (cflag? secpercyl: 1),
864 sl->sl_part[i].sdkp_cyloffset);
867 fprintf(out, " %11s %5s",
868 tagname(sl->sl_vtoc_map[i].svtoc_tag),
869 flagname(sl->sl_vtoc_map[i].svtoc_flag));
878 fprintf(stderr, "usage:"
879 "\t%s [-r] [-c | -h] disk\n"
880 "\t\t(to read label)\n"
881 "\t%s -B [-b boot1] [-n] disk\n"
882 "\t\t(to install boot program only)\n"
883 "\t%s -R [-B [-b boot1]] [-r] [-n] [-c] disk protofile\n"
884 "\t\t(to restore label)\n"
885 "\t%s -e [-B [-b boot1]] [-r] [-n] [-c] disk\n"
886 "\t\t(to edit label)\n"
887 "\t%s -w [-B [-b boot1]] [-r] [-n] disk type\n"
888 "\t\t(to write default label)\n",
898 * Return VTOC tag and flag names for tag or flag ID, resp.
901 tagname(unsigned int tag)
907 for (i = 0, tp = knowntags; i < nitems(knowntags); i++, tp++)
911 sprintf(buf, "%u", tag);
917 flagname(unsigned int flag)
923 for (i = 0, tp = knownflags; i < nitems(knownflags); i++, tp++)
927 sprintf(buf, "%u", flag);
933 parse_tag(struct sun_disklabel *sl, int part, const char *tag)
940 for (i = 0, tp = knowntags; i < nitems(knowntags); i++, tp++)
941 if (strcmp(tp->name, tag) == 0) {
942 sl->sl_vtoc_map[part].svtoc_tag = (uint16_t)tp->id;
946 l = strtoul(tag, &endp, 0);
947 if (*tag != '\0' && *endp == '\0') {
948 sl->sl_vtoc_map[part].svtoc_tag = (uint16_t)l;
956 parse_flag(struct sun_disklabel *sl, int part, const char *flag)
963 for (i = 0, tp = knownflags; i < nitems(knownflags); i++, tp++)
964 if (strcmp(tp->name, flag) == 0) {
965 sl->sl_vtoc_map[part].svtoc_flag = (uint16_t)tp->id;
969 l = strtoul(flag, &endp, 0);
970 if (*flag != '\0' && *endp == '\0') {
971 sl->sl_vtoc_map[part].svtoc_flag = (uint16_t)l;
979 * Convert argument into `human readable' byte number form.
982 make_h_number(uintmax_t u)
989 } else if (u > 2000000000UL) {
991 sprintf(buf, "%.1fG", d);
992 } else if (u > 2000000UL) {
994 sprintf(buf, "%.1fM", d);
997 sprintf(buf, "%.1fK", d);