Deleted Added
full compact
sunlabel.c (141956) sunlabel.c (144328)
1/*-
2 * Copyright (c) 2003 Jake Burkholder.
1/*-
2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2004 Joerg Wunsch.
3 * Copyright (c) 2004,2005 Joerg Wunsch.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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

--- 50 unchanged lines hidden (view full) ---

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
64 * SUCH DAMAGE.
65 *
66 * from: $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk $
67 */
68
69#include <sys/cdefs.h>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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

--- 50 unchanged lines hidden (view full) ---

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
64 * SUCH DAMAGE.
65 *
66 * from: $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk $
67 */
68
69#include <sys/cdefs.h>
70__FBSDID("$FreeBSD: head/sbin/sunlabel/sunlabel.c 141956 2005-02-15 22:31:05Z obrien $");
70__FBSDID("$FreeBSD: head/sbin/sunlabel/sunlabel.c 144328 2005-03-30 09:33:10Z joerg $");
71
72#include <sys/types.h>
73#include <sys/param.h>
74#include <sys/disk.h>
75#include <sys/ioctl.h>
76#include <sys/sun_disklabel.h>
77#include <sys/wait.h>
78

--- 457 unchanged lines hidden (view full) ---

536parse_label(struct sun_disklabel *sl, const char *file)
537{
538 char offset[32];
539 char size[32];
540 char flag[32];
541 char tag[32];
542 char buf[128];
543 char text[128];
71
72#include <sys/types.h>
73#include <sys/param.h>
74#include <sys/disk.h>
75#include <sys/ioctl.h>
76#include <sys/sun_disklabel.h>
77#include <sys/wait.h>
78

--- 457 unchanged lines hidden (view full) ---

536parse_label(struct sun_disklabel *sl, const char *file)
537{
538 char offset[32];
539 char size[32];
540 char flag[32];
541 char tag[32];
542 char buf[128];
543 char text[128];
544 char volname[SUN_VOLNAME_LEN + 1];
544 struct sun_disklabel sl1;
545 char *bp;
546 const char *what;
547 uint8_t part;
548 FILE *fp;
549 int line;
550 int rv;
551 int wantvtoc;

--- 74 unchanged lines hidden (view full) ---

626 sl1.sl_nsectors = sec;
627 sl1.sl_ntracks = hd;
628 memset(sl1.sl_text, 0, sizeof(sl1.sl_text));
629 snprintf(sl1.sl_text, sizeof(sl1.sl_text),
630 "%s cyl %u alt %u hd %u sec %u",
631 text, cyl, alt, hd, sec);
632 continue;
633 }
545 struct sun_disklabel sl1;
546 char *bp;
547 const char *what;
548 uint8_t part;
549 FILE *fp;
550 int line;
551 int rv;
552 int wantvtoc;

--- 74 unchanged lines hidden (view full) ---

627 sl1.sl_nsectors = sec;
628 sl1.sl_ntracks = hd;
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);
633 continue;
634 }
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"
640#endif
641 /*
642 * We set the field length to one more than
643 * SUN_VOLNAME_LEN to allow detecting an
644 * overflow.
645 */
646 memset(volname, 0, sizeof volname);
647 rv = sscanf(bp, " %9[^\n]", volname);
648 if (rv != 1) {
649 /* Clear the volume name. */
650 memset(sl1.sl_vtoc_volname, 0,
651 SUN_VOLNAME_LEN);
652 } else {
653 memcpy(sl1.sl_vtoc_volname, volname,
654 SUN_VOLNAME_LEN);
655 if (volname[SUN_VOLNAME_LEN] != '\0')
656 warnx(
657"%s, line %d: volume name longer than %d characters, truncating",
658 file, line + 1, SUN_VOLNAME_LEN);
659 }
660 continue;
661 }
634 if (strlen(bp) < 2 || bp[1] != ':') {
635 line++;
636 continue;
637 }
638 rv = sscanf(bp, "%c: %30s %30s %30s %30s",
639 &part, size, offset, tag, flag);
640 if (rv < 3) {
641 syntaxerr:

--- 95 unchanged lines hidden (view full) ---

737 }
738 sl->sl_part[part].sdkp_cyloffset = n;
739 return (0);
740}
741
742static void
743print_label(struct sun_disklabel *sl, const char *disk, FILE *out)
744{
662 if (strlen(bp) < 2 || bp[1] != ':') {
663 line++;
664 continue;
665 }
666 rv = sscanf(bp, "%c: %30s %30s %30s %30s",
667 &part, size, offset, tag, flag);
668 if (rv < 3) {
669 syntaxerr:

--- 95 unchanged lines hidden (view full) ---

765 }
766 sl->sl_part[part].sdkp_cyloffset = n;
767 return (0);
768}
769
770static void
771print_label(struct sun_disklabel *sl, const char *disk, FILE *out)
772{
745 int i;
773 int i, j;
746 int havevtoc;
747 uintmax_t secpercyl;
774 int havevtoc;
775 uintmax_t secpercyl;
776 /* Long enough to hex-encode each character. */
777 char volname[4 * SUN_VOLNAME_LEN + 1];
748
749 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
750 secpercyl = sl->sl_nsectors * sl->sl_ntracks;
751
752 fprintf(out,
753"# /dev/%s:\n"
754"text: %s\n"
755"bytes/sector: %d\n"
756"sectors/cylinder: %ju\n",
757 disk,
758 sl->sl_text,
759 sectorsize,
760 secpercyl);
761 if (eflag)
762 fprintf(out,
763 "# max sectors/unit (including alt cylinders): %ju\n",
764 (uintmax_t)mediasize / sectorsize);
765 fprintf(out,
778
779 havevtoc = sl->sl_vtoc_sane == SUN_VTOC_SANE;
780 secpercyl = sl->sl_nsectors * sl->sl_ntracks;
781
782 fprintf(out,
783"# /dev/%s:\n"
784"text: %s\n"
785"bytes/sector: %d\n"
786"sectors/cylinder: %ju\n",
787 disk,
788 sl->sl_text,
789 sectorsize,
790 secpercyl);
791 if (eflag)
792 fprintf(out,
793 "# max sectors/unit (including alt cylinders): %ju\n",
794 (uintmax_t)mediasize / sectorsize);
795 fprintf(out,
766"sectors/unit: %ju\n"
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')
801 break;
802 if (isprint(sl->sl_vtoc_volname[i]))
803 volname[j++] = sl->sl_vtoc_volname[i];
804 else
805 j += sprintf(volname + j, "\\x%02X",
806 sl->sl_vtoc_volname[i]);
807 }
808 volname[j] = '\0';
809 fprintf(out, "volume name: %s\n", volname);
810 }
811 fprintf(out,
767"\n"
768"%d partitions:\n"
769"#\n",
812"\n"
813"%d partitions:\n"
814"#\n",
770 secpercyl * sl->sl_ncylinders,
771 SUN_NPART);
772 if (!hflag) {
773 fprintf(out, "# Size is in %s.", cflag? "cylinders": "sectors");
774 if (eflag)
775 fprintf(out,
776" Use %%d%c, %%dK, %%dM or %%dG to specify in %s,\n"
777"# kilobytes, megabytes or gigabytes respectively, or '*' to specify rest of\n"
778"# disk.\n",

--- 185 unchanged lines hidden ---
815 SUN_NPART);
816 if (!hflag) {
817 fprintf(out, "# Size is in %s.", cflag? "cylinders": "sectors");
818 if (eflag)
819 fprintf(out,
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"
822"# disk.\n",

--- 185 unchanged lines hidden ---