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 * Copyright (c) 1994, 1995 Gordon W. Ross
29 * Copyright (c) 1994 Theo de Raadt
30 * All rights reserved.
31 * Copyright (c) 1987, 1993
32 * The Regents of the University of California. All rights reserved.
34 * This code is derived from software contributed to Berkeley by
35 * Symmetric Computer Systems.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * This product includes software developed by Theo de Raadt.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * from: $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk $
69 #include <sys/cdefs.h>
70 __FBSDID("$FreeBSD$");
72 #include <sys/types.h>
73 #include <sys/param.h>
75 #include <sys/ioctl.h>
76 #include <sys/sun_disklabel.h>
90 #define _PATH_TMPFILE "/tmp/EdDk.XXXXXXXXXX"
91 #define _PATH_BOOT "/boot/boot1"
102 static off_t mediasize;
103 static uint32_t sectorsize;
110 static int check_label(struct sun_disklabel *sl);
111 static void read_label(struct sun_disklabel *sl, const char *disk);
112 static void write_label(struct sun_disklabel *sl, const char *disk,
113 const char *bootpath);
114 static void edit_label(struct sun_disklabel *sl, const char *disk,
115 const char *bootpath);
116 static int parse_label(struct sun_disklabel *sl, const char *file);
117 static void print_label(struct sun_disklabel *sl, const char *disk, FILE *out);
119 static int parse_size(struct sun_disklabel *sl, int part, char *size);
120 static int parse_offset(struct sun_disklabel *sl, int part, char *offset);
122 static const char *flagname(unsigned int tag);
123 static const char *tagname(unsigned int tag);
124 static unsigned int parse_flag(struct sun_disklabel *sl, int part,
126 static unsigned int parse_tag(struct sun_disklabel *sl, int part,
128 static const char *make_h_number(uintmax_t u);
130 static void usage(void);
132 extern char *__progname;
134 static struct tags knowntags[] = {
135 { "unassigned", VTOC_UNASSIGNED },
136 { "boot", VTOC_BOOT },
137 { "root", VTOC_ROOT },
138 { "swap", VTOC_SWAP },
140 { "backup", VTOC_BACKUP },
141 { "stand", VTOC_STAND },
143 { "home", VTOC_HOME },
144 { "altsctr", VTOC_ALTSCTR },
145 { "cache", VTOC_CACHE },
146 { "VxVM_pub", VTOC_VXVM_PUB },
147 { "VxVM_priv", VTOC_VXVM_PRIV },
150 static struct tags knownflags[] = {
152 { "wu", VTOC_UNMNT },
153 { "rm", VTOC_RONLY },
154 { "ru", VTOC_UNMNT | VTOC_RONLY },
158 * Disk label editor for sun disklabels.
161 main(int ac, char **av)
163 struct sun_disklabel sl;
164 const char *bootpath;
169 bootpath = _PATH_BOOT;
170 while ((ch = getopt(ac, av, "b:BcehnrRw")) != -1)
192 fprintf(stderr, "Obsolete -r flag ignored\n");
206 if (nflag && !(Bflag || eflag || Rflag || wflag))
208 if (eflag && (Rflag || wflag))
216 bzero(&sl, sizeof(sl));
219 if (ac != 2 || strcmp(av[1], "auto") != 0)
221 read_label(&sl, disk);
222 bzero(sl.sl_part, sizeof(sl.sl_part));
223 sl.sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
224 sl.sl_part[SUN_RAWPART].sdkp_nsectors = sl.sl_ncylinders *
225 sl.sl_ntracks * sl.sl_nsectors;
226 write_label(&sl, disk, bootpath);
230 read_label(&sl, disk);
231 if (sl.sl_magic != SUN_DKMAGIC)
232 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
233 edit_label(&sl, disk, bootpath);
238 read_label(&sl, disk);
239 if (parse_label(&sl, proto) != 0)
240 errx(1, "%s: invalid label", proto);
241 write_label(&sl, disk, bootpath);
243 read_label(&sl, disk);
244 if (sl.sl_magic != SUN_DKMAGIC)
245 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
246 write_label(&sl, disk, bootpath);
248 read_label(&sl, disk);
249 if (sl.sl_magic != SUN_DKMAGIC)
250 errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
251 print_label(&sl, disk, stdout);
257 check_label(struct sun_disklabel *sl)
269 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
271 nsectors = sl->sl_ncylinders * sl->sl_ntracks * sl->sl_nsectors;
272 if (sl->sl_part[SUN_RAWPART].sdkp_cyloffset != 0 ||
273 sl->sl_part[SUN_RAWPART].sdkp_nsectors != nsectors) {
274 warnx("partition c is incorrect, must start at 0 and cover "
278 if (havevtoc && sl->sl_vtoc_map[2].svtoc_tag != VTOC_BACKUP) {
279 warnx("partition c must have tag \"backup\"");
282 for (i = 0; i < SUN_NPART; i++) {
283 if (i == 2 || sl->sl_part[i].sdkp_nsectors == 0)
285 start = (uint64_t)sl->sl_part[i].sdkp_cyloffset *
286 sl->sl_ntracks * sl->sl_nsectors;
287 end = start + sl->sl_part[i].sdkp_nsectors;
288 if (end > nsectors) {
289 warnx("partition %c extends past end of disk",
294 if (sl->sl_vtoc_map[i].svtoc_tag == VTOC_BACKUP) {
295 warnx("only partition c is allowed to have "
300 for (j = 0; j < SUN_NPART; j++) {
302 * Overlaps for unmountable partitions are
303 * non-fatal but will be warned anyway.
305 warnonly = havevtoc &&
306 ((sl->sl_vtoc_map[i].svtoc_flag & VTOC_UNMNT) != 0 ||
307 (sl->sl_vtoc_map[j].svtoc_flag & VTOC_UNMNT) != 0);
309 if (j == 2 || j == i ||
310 sl->sl_part[j].sdkp_nsectors == 0)
312 ostart = (uint64_t)sl->sl_part[j].sdkp_cyloffset *
313 sl->sl_ntracks * sl->sl_nsectors;
314 oend = ostart + sl->sl_part[j].sdkp_nsectors;
315 if ((start <= ostart && end >= oend) ||
316 (start > ostart && start < oend) ||
317 (end > ostart && end < oend)) {
318 warnx("partition %c overlaps partition %c",
329 read_label(struct sun_disklabel *sl, const char *disk)
331 char path[MAXPATHLEN];
337 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk);
338 if ((fd = open(path, O_RDONLY)) < 0)
339 err(1, "open %s", path);
340 if (read(fd, buf, sizeof(buf)) != sizeof(buf))
342 error = sunlabel_dec(buf, sl);
343 if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
345 err(1, "%s: ioctl(DIOCGMEDIASIZE) failed", disk);
346 if (ioctl(fd, DIOCGSECTORSIZE, §orsize) != 0) {
348 err(1, "%s: DIOCGSECTORSIZE failed", disk);
353 bzero(sl, sizeof(*sl));
354 if (ioctl(fd, DIOCGFWSECTORS, &fwsectors) != 0)
356 if (ioctl(fd, DIOCGFWHEADS, &fwheads) != 0) {
357 if (mediasize <= 63 * 1024 * sectorsize)
359 else if (mediasize <= 63 * 16 * 1024 * sectorsize)
365 sl->sl_pcylinders = mediasize / (fwsectors * fwheads *
367 sl->sl_sparespercyl = 0;
368 sl->sl_interleave = 1;
369 sl->sl_ncylinders = sl->sl_pcylinders - 2;
370 sl->sl_acylinders = 2;
371 sl->sl_nsectors = fwsectors;
372 sl->sl_ntracks = fwheads;
373 sl->sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
374 sl->sl_part[SUN_RAWPART].sdkp_nsectors = sl->sl_ncylinders *
375 sl->sl_ntracks * sl->sl_nsectors;
376 if (mediasize > (off_t)4999L * 1024L * 1024L) {
378 "FreeBSD%jdG cyl %u alt %u hd %u sec %u",
379 (intmax_t)(mediasize + 512 * 1024 * 1024) /
380 (1024 * 1024 * 1024),
381 sl->sl_ncylinders, sl->sl_acylinders,
382 sl->sl_ntracks, sl->sl_nsectors);
385 "FreeBSD%jdM cyl %u alt %u hd %u sec %u",
386 (intmax_t)(mediasize + 512 * 1024) / (1024 * 1024),
387 sl->sl_ncylinders, sl->sl_acylinders,
388 sl->sl_ntracks, sl->sl_nsectors);
395 write_label(struct sun_disklabel *sl, const char *disk, const char *bootpath)
397 char path[MAXPATHLEN];
398 char boot[SUN_BOOTSIZE];
405 struct gctl_req *grq;
407 sl->sl_magic = SUN_DKMAGIC;
409 if (check_label(sl) != 0)
410 errx(1, "invalid label");
412 bzero(buf, sizeof(buf));
413 sunlabel_enc(buf, sl);
416 print_label(sl, disk, stdout);
420 if ((bfd = open(bootpath, O_RDONLY)) < 0)
421 err(1, "open %s", bootpath);
422 i = read(bfd, boot, sizeof(boot));
425 else if (i != sizeof (boot))
426 errx(1, "read wrong size boot code (%d)", i);
429 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk);
430 fd = open(path, O_RDWR);
432 grq = gctl_get_handle();
433 gctl_ro_param(grq, "verb", -1, "write label");
434 gctl_ro_param(grq, "class", -1, "SUN");
435 gctl_ro_param(grq, "geom", -1, disk);
436 gctl_ro_param(grq, "label", sizeof buf, buf);
437 errstr = gctl_issue(grq);
439 errx(1, "%s", errstr);
442 grq = gctl_get_handle();
443 gctl_ro_param(grq, "verb", -1, "write bootcode");
444 gctl_ro_param(grq, "class", -1, "SUN");
445 gctl_ro_param(grq, "geom", -1, disk);
446 gctl_ro_param(grq, "bootcode", sizeof boot, boot);
447 errstr = gctl_issue(grq);
449 errx(1, "%s", errstr);
453 if (lseek(fd, 0, SEEK_SET) < 0)
455 if (write(fd, buf, sizeof(buf)) != sizeof(buf))
458 for (i = 0; i < SUN_NPART; i++) {
459 if (sl->sl_part[i].sdkp_nsectors == 0)
461 off = sl->sl_part[i].sdkp_cyloffset *
462 sl->sl_ntracks * sl->sl_nsectors * 512;
464 * Ignore first SUN_SIZE bytes of boot code to
465 * avoid overwriting the label.
467 if (lseek(fd, off + SUN_SIZE, SEEK_SET) < 0)
469 if (write(fd, boot + SUN_SIZE,
470 sizeof(boot) - SUN_SIZE) !=
471 sizeof(boot) - SUN_SIZE)
481 edit_label(struct sun_disklabel *sl, const char *disk, const char *bootpath)
483 char tmpfil[] = _PATH_TMPFILE;
492 if ((fd = mkstemp(tmpfil)) < 0)
494 if ((fp = fdopen(fd, "w")) == NULL)
496 print_label(sl, disk, fp);
499 if ((pid = fork()) < 0)
502 if ((editor = getenv("EDITOR")) == NULL)
504 execlp(editor, editor, tmpfil, (char *)NULL);
505 err(1, "execlp %s", editor);
508 while ((r = wait(&status)) > 0 && r != pid)
510 if (WIFEXITED(status)) {
511 if (parse_label(sl, tmpfil) == 0) {
514 write_label(sl, disk, bootpath);
517 printf("re-edit the label? [y]: ");
520 if (c != EOF && c != '\n')
521 while (getchar() != '\n')
536 parse_label(struct sun_disklabel *sl, const char *file)
544 char volname[SUN_VOLNAME_LEN + 1];
545 struct sun_disklabel sl1;
553 unsigned alt, cyl, hd, nr, sec;
556 if ((fp = fopen(file, "r")) == NULL)
559 bzero(&sl1.sl_part, sizeof(sl1.sl_part));
560 while (fgets(buf, sizeof(buf), fp) != NULL) {
562 * In order to recognize a partition entry, we search
563 * for lines starting with a single letter followed by
564 * a colon as their first non-white characters. We
565 * silently ignore any other lines, so any comment etc.
566 * lines in the label template will be ignored.
568 * XXX We should probably also recognize the geometry
569 * fields on top, and allow changing the geometry
570 * emulated by this disk.
572 for (bp = buf; isspace(*bp); bp++)
574 if (strncmp(bp, "text:", strlen("text:")) == 0) {
575 bp += strlen("text:");
577 " %s cyl %u alt %u hd %u sec %u",
578 text, &cyl, &alt, &hd, &sec);
580 warnx("%s, line %d: text label does not "
581 "contain required fields",
587 warnx("%s, line %d: # alt must be equal 2",
592 if (cyl == 0 || cyl > USHRT_MAX) {
596 warnx("%s, line %d: # %s %d unreasonable",
597 file, line + 1, what, nr);
601 if (hd == 0 || hd > USHRT_MAX) {
606 if (sec == 0 || sec > USHRT_MAX) {
612 warnx("unit size unknown, no sector count "
613 "check could be done");
614 else if ((uintmax_t)(cyl + alt) * sec * hd >
615 (uintmax_t)mediasize / sectorsize) {
616 warnx("%s, line %d: sector count %ju exceeds "
619 (uintmax_t)(cyl + alt) * sec * hd,
620 (uintmax_t)mediasize / sectorsize);
624 sl1.sl_pcylinders = cyl + alt;
625 sl1.sl_ncylinders = cyl;
626 sl1.sl_acylinders = alt;
627 sl1.sl_nsectors = sec;
629 memset(sl1.sl_text, 0, sizeof(sl1.sl_text));
630 snprintf(sl1.sl_text, sizeof(sl1.sl_text),
631 "%s cyl %u alt %u hd %u sec %u",
632 text, cyl, alt, hd, sec);
635 if (strncmp(bp, "volume name:", strlen("volume name:")) == 0) {
636 wantvtoc = 1; /* Volume name requires VTOC. */
637 bp += strlen("volume name:");
638 #if SUN_VOLNAME_LEN != 8
639 # error "scanf field width does not match SUN_VOLNAME_LEN"
642 * We set the field length to one more than
643 * SUN_VOLNAME_LEN to allow detecting an
646 memset(volname, 0, sizeof volname);
647 rv = sscanf(bp, " %9[^\n]", volname);
649 /* Clear the volume name. */
650 memset(sl1.sl_vtoc_volname, 0,
653 memcpy(sl1.sl_vtoc_volname, volname,
655 if (volname[SUN_VOLNAME_LEN] != '\0')
657 "%s, line %d: volume name longer than %d characters, truncating",
658 file, line + 1, SUN_VOLNAME_LEN);
662 if (strlen(bp) < 2 || bp[1] != ':') {
666 rv = sscanf(bp, "%c: %30s %30s %30s %30s",
667 &part, size, offset, tag, flag);
670 warnx("%s: syntax error on line %d",
675 if (parse_size(&sl1, part - 'a', size) ||
676 parse_offset(&sl1, part - 'a', offset))
680 if (rv == 5 && parse_flag(&sl1, part - 'a', flag))
682 if (parse_tag(&sl1, part - 'a', tag))
689 sl1.sl_vtoc_sane = SUN_VTOC_SANE;
690 sl1.sl_vtoc_vers = SUN_VTOC_VERSION;
691 sl1.sl_vtoc_nparts = SUN_NPART;
693 sl1.sl_vtoc_sane = 0;
694 sl1.sl_vtoc_vers = 0;
695 sl1.sl_vtoc_nparts = 0;
696 bzero(&sl1.sl_vtoc_map, sizeof(sl1.sl_vtoc_map));
699 return (check_label(sl));
703 parse_size(struct sun_disklabel *sl, int part, char *size)
712 n = strtoumax(size, &p, 10);
714 if (strcmp(size, "*") == 0) {
715 total = sl->sl_ncylinders * sl->sl_ntracks *
717 for (i = 0; i < part; i++) {
720 nsectors += sl->sl_part[i].sdkp_nsectors;
722 n = total - nsectors;
723 } else if (p[1] == '\0' && (p[0] == 'C' || p[0] == 'c')) {
724 n = n * sl->sl_ntracks * sl->sl_nsectors;
725 } else if (p[1] == '\0' && (p[0] == 'K' || p[0] == 'k')) {
726 n = roundup((n * 1024) / 512,
727 sl->sl_ntracks * sl->sl_nsectors);
728 } else if (p[1] == '\0' && (p[0] == 'M' || p[0] == 'm')) {
729 n = roundup((n * 1024 * 1024) / 512,
730 sl->sl_ntracks * sl->sl_nsectors);
731 } else if (p[1] == '\0' && (p[0] == 'S' || p[0] == 's')) {
732 /* size in sectors, no action neded */
733 } else if (p[1] == '\0' && (p[0] == 'G' || p[0] == 'g')) {
734 n = roundup((n * 1024 * 1024 * 1024) / 512,
735 sl->sl_ntracks * sl->sl_nsectors);
739 n = n * sl->sl_ntracks * sl->sl_nsectors;
741 sl->sl_part[part].sdkp_nsectors = n;
746 parse_offset(struct sun_disklabel *sl, int part, char *offset)
754 n = strtoumax(offset, &p, 10);
756 if (strcmp(offset, "*") == 0) {
757 for (i = 0; i < part; i++) {
760 nsectors += sl->sl_part[i].sdkp_nsectors;
762 n = nsectors / (sl->sl_nsectors * sl->sl_ntracks);
766 sl->sl_part[part].sdkp_cyloffset = n;
771 print_label(struct sun_disklabel *sl, const char *disk, FILE *out)
776 /* Long enough to hex-encode each character. */
777 char volname[4 * SUN_VOLNAME_LEN + 1];
779 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
780 secpercyl = sl->sl_nsectors * sl->sl_ntracks;
786 "sectors/cylinder: %ju\n",
793 "# max sectors/unit (including alt cylinders): %ju\n",
794 (uintmax_t)mediasize / sectorsize);
796 "sectors/unit: %ju\n",
797 secpercyl * sl->sl_ncylinders);
798 if (havevtoc && sl->sl_vtoc_volname[0] != '\0') {
799 for (i = j = 0; i < SUN_VOLNAME_LEN; i++) {
800 if (sl->sl_vtoc_volname[i] == '\0')
802 if (isprint(sl->sl_vtoc_volname[i]))
803 volname[j++] = sl->sl_vtoc_volname[i];
805 j += sprintf(volname + j, "\\x%02X",
806 sl->sl_vtoc_volname[i]);
809 fprintf(out, "volume name: %s\n", volname);
817 fprintf(out, "# Size is in %s.", cflag? "cylinders": "sectors");
820 " Use %%d%c, %%dK, %%dM or %%dG to specify in %s,\n"
821 "# kilobytes, megabytes or gigabytes respectively, or '*' to specify rest of\n"
824 cflag? "sectors": "cylinders");
827 fprintf(out, "# Offset is in cylinders.");
830 " Use '*' to calculate offsets automatically.\n"
837 "# size offset tag flag\n"
838 "# ---------- ---------- ---------- ----\n"
843 "# ---------- ----------\n"
846 for (i = 0; i < SUN_NPART; i++) {
847 if (sl->sl_part[i].sdkp_nsectors == 0)
850 fprintf(out, " %c: %10s",
852 make_h_number((uintmax_t)
853 sl->sl_part[i].sdkp_nsectors * 512));
854 fprintf(out, " %10s",
855 make_h_number((uintmax_t)
856 sl->sl_part[i].sdkp_cyloffset * 512
859 fprintf(out, " %c: %10ju %10u",
861 sl->sl_part[i].sdkp_nsectors / (cflag? secpercyl: 1),
862 sl->sl_part[i].sdkp_cyloffset);
865 fprintf(out, " %11s %5s",
866 tagname(sl->sl_vtoc_map[i].svtoc_tag),
867 flagname(sl->sl_vtoc_map[i].svtoc_flag));
876 fprintf(stderr, "usage:"
877 "\t%s [-r] [-c | -h] disk\n"
878 "\t\t(to read label)\n"
879 "\t%s -B [-b boot1] [-n] disk\n"
880 "\t\t(to install boot program only)\n"
881 "\t%s -R [-B [-b boot1]] [-r] [-n] [-c] disk protofile\n"
882 "\t\t(to restore label)\n"
883 "\t%s -e [-B [-b boot1]] [-r] [-n] [-c] disk\n"
884 "\t\t(to edit label)\n"
885 "\t%s -w [-B [-b boot1]] [-r] [-n] disk type\n"
886 "\t\t(to write default label)\n",
896 * Return VTOC tag and flag names for tag or flag ID, resp.
899 tagname(unsigned int tag)
905 for (i = 0, tp = knowntags;
906 i < sizeof(knowntags) / sizeof(struct tags);
911 sprintf(buf, "%u", tag);
917 flagname(unsigned int flag)
923 for (i = 0, tp = knownflags;
924 i < sizeof(knownflags) / sizeof(struct tags);
929 sprintf(buf, "%u", flag);
935 parse_tag(struct sun_disklabel *sl, int part, const char *tag)
942 for (i = 0, tp = knowntags;
943 i < sizeof(knowntags) / sizeof(struct tags);
945 if (strcmp(tp->name, tag) == 0) {
946 sl->sl_vtoc_map[part].svtoc_tag = (uint16_t)tp->id;
950 l = strtoul(tag, &endp, 0);
951 if (*tag != '\0' && *endp == '\0') {
952 sl->sl_vtoc_map[part].svtoc_tag = (uint16_t)l;
960 parse_flag(struct sun_disklabel *sl, int part, const char *flag)
967 for (i = 0, tp = knownflags;
968 i < sizeof(knownflags) / sizeof(struct tags);
970 if (strcmp(tp->name, flag) == 0) {
971 sl->sl_vtoc_map[part].svtoc_flag = (uint16_t)tp->id;
975 l = strtoul(flag, &endp, 0);
976 if (*flag != '\0' && *endp == '\0') {
977 sl->sl_vtoc_map[part].svtoc_flag = (uint16_t)l;
985 * Convert argument into `human readable' byte number form.
988 make_h_number(uintmax_t u)
995 } else if (u > 2000000000UL) {
997 sprintf(buf, "%.1fG", d);
998 } else if (u > 2000000UL) {
1000 sprintf(buf, "%.1fM", d);
1002 d = (double)u / 1e3;
1003 sprintf(buf, "%.1fK", d);