|
#if ENABLE_FEATURE_OSF_LABEL |
|
1 |
/* |
/* |
2 |
* Copyright (c) 1987, 1988 Regents of the University of California. |
* Copyright (c) 1987, 1988 Regents of the University of California. |
3 |
* All rights reserved. |
* All rights reserved. |
31 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
32 |
*/ |
*/ |
33 |
|
|
34 |
|
#if ENABLE_FEATURE_OSF_LABEL |
35 |
|
|
36 |
#ifndef BSD_DISKMAGIC |
#ifndef BSD_DISKMAGIC |
37 |
#define BSD_DISKMAGIC ((uint32_t) 0x82564557) |
#define BSD_DISKMAGIC ((uint32_t) 0x82564557) |
45 |
|
|
46 |
#if defined(i386) || defined(__sparc__) || defined(__arm__) \ |
#if defined(i386) || defined(__sparc__) || defined(__arm__) \ |
47 |
|| defined(__m68k__) || defined(__mips__) || defined(__s390__) \ |
|| defined(__m68k__) || defined(__mips__) || defined(__s390__) \ |
48 |
|| defined(__sh__) || defined(__x86_64__) |
|| defined(__s390__) || defined(__s390x__) \ |
49 |
#define BSD_LABELSECTOR 1 |
|| defined(__sh__) || defined(__x86_64__) || defined(__avr32__) |
50 |
#define BSD_LABELOFFSET 0 |
# define BSD_LABELSECTOR 1 |
51 |
|
# define BSD_LABELOFFSET 0 |
52 |
#elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \ |
#elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \ |
53 |
|| defined(__hppa__) |
|| defined(__hppa__) |
54 |
#define BSD_LABELSECTOR 0 |
# define BSD_LABELSECTOR 0 |
55 |
#define BSD_LABELOFFSET 64 |
# define BSD_LABELOFFSET 64 |
|
#elif defined(__s390__) || defined(__s390x__) |
|
|
#define BSD_LABELSECTOR 1 |
|
|
#define BSD_LABELOFFSET 0 |
|
56 |
#else |
#else |
57 |
#error unknown architecture |
# error unknown architecture |
58 |
#endif |
#endif |
59 |
|
|
60 |
#define BSD_BBSIZE 8192 /* size of boot area, with label */ |
#define BSD_BBSIZE 8192 /* size of boot area, with label */ |
65 |
int16_t d_type; /* drive type */ |
int16_t d_type; /* drive type */ |
66 |
int16_t d_subtype; /* controller/d_type specific */ |
int16_t d_subtype; /* controller/d_type specific */ |
67 |
char d_typename[16]; /* type name, e.g. "eagle" */ |
char d_typename[16]; /* type name, e.g. "eagle" */ |
68 |
char d_packname[16]; /* pack identifier */ |
char d_packname[16]; /* pack identifier */ |
69 |
/* disk geometry: */ |
/* disk geometry: */ |
70 |
uint32_t d_secsize; /* # of bytes per sector */ |
uint32_t d_secsize; /* # of bytes per sector */ |
71 |
uint32_t d_nsectors; /* # of data sectors per track */ |
uint32_t d_nsectors; /* # of data sectors per track */ |
72 |
uint32_t d_ntracks; /* # of tracks per cylinder */ |
uint32_t d_ntracks; /* # of tracks per cylinder */ |
87 |
*/ |
*/ |
88 |
uint32_t d_acylinders; /* # of alt. cylinders per unit */ |
uint32_t d_acylinders; /* # of alt. cylinders per unit */ |
89 |
|
|
90 |
/* hardware characteristics: */ |
/* hardware characteristics: */ |
91 |
/* |
/* |
92 |
* d_interleave, d_trackskew and d_cylskew describe perturbations |
* d_interleave, d_trackskew and d_cylskew describe perturbations |
93 |
* in the media format used to compensate for a slow controller. |
* in the media format used to compensate for a slow controller. |
117 |
uint32_t d_spare[NSPARE]; /* reserved for future use */ |
uint32_t d_spare[NSPARE]; /* reserved for future use */ |
118 |
uint32_t d_magic2; /* the magic number (again) */ |
uint32_t d_magic2; /* the magic number (again) */ |
119 |
uint16_t d_checksum; /* xor of data incl. partitions */ |
uint16_t d_checksum; /* xor of data incl. partitions */ |
120 |
/* filesystem and partition information: */ |
/* filesystem and partition information: */ |
121 |
uint16_t d_npartitions; /* number of partitions in following */ |
uint16_t d_npartitions; /* number of partitions in following */ |
122 |
uint32_t d_bbsize; /* size of boot area at sn0, bytes */ |
uint32_t d_bbsize; /* size of boot area at sn0, bytes */ |
123 |
uint32_t d_sbsize; /* max size of fs superblock, bytes */ |
uint32_t d_sbsize; /* max size of fs superblock, bytes */ |
124 |
struct xbsd_partition { /* the partition table */ |
struct xbsd_partition { /* the partition table */ |
125 |
uint32_t p_size; /* number of sectors in partition */ |
uint32_t p_size; /* number of sectors in partition */ |
126 |
uint32_t p_offset; /* starting sector */ |
uint32_t p_offset; /* starting sector */ |
127 |
uint32_t p_fsize; /* filesystem basic fragment size */ |
uint32_t p_fsize; /* filesystem basic fragment size */ |
367 |
partname(disk_device, t+1, 0)); |
partname(disk_device, t+1, 0)); |
368 |
return; |
return; |
369 |
} |
} |
370 |
printf("Reading disklabel of %s at sector %d\n", |
printf("Reading disklabel of %s at sector %u\n", |
371 |
partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR); |
partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR); |
372 |
if (xbsd_readlabel(xbsd_part) == 0) |
if (xbsd_readlabel(xbsd_part) == 0) |
373 |
if (xbsd_create_disklabel() == 0) |
if (xbsd_create_disklabel() == 0) |
510 |
if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1) |
if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1) |
511 |
printf("type: %s\n", xbsd_dktypenames[lp->d_type]); |
printf("type: %s\n", xbsd_dktypenames[lp->d_type]); |
512 |
else |
else |
513 |
printf("type: %d\n", lp->d_type); |
printf("type: %u\n", lp->d_type); |
514 |
printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); |
printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); |
515 |
printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); |
printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); |
516 |
printf("flags: "); |
printf("flags: "); |
518 |
bb_putchar('\n'); |
bb_putchar('\n'); |
519 |
/* On various machines the fields of *lp are short/int/long */ |
/* On various machines the fields of *lp are short/int/long */ |
520 |
/* In order to avoid problems, we cast them all to long. */ |
/* In order to avoid problems, we cast them all to long. */ |
521 |
printf("bytes/sector: %ld\n", (long) lp->d_secsize); |
printf("bytes/sector: %lu\n", (long) lp->d_secsize); |
522 |
printf("sectors/track: %ld\n", (long) lp->d_nsectors); |
printf("sectors/track: %lu\n", (long) lp->d_nsectors); |
523 |
printf("tracks/cylinder: %ld\n", (long) lp->d_ntracks); |
printf("tracks/cylinder: %lu\n", (long) lp->d_ntracks); |
524 |
printf("sectors/cylinder: %ld\n", (long) lp->d_secpercyl); |
printf("sectors/cylinder: %lu\n", (long) lp->d_secpercyl); |
525 |
printf("cylinders: %ld\n", (long) lp->d_ncylinders); |
printf("cylinders: %lu\n", (long) lp->d_ncylinders); |
526 |
printf("rpm: %d\n", lp->d_rpm); |
printf("rpm: %u\n", lp->d_rpm); |
527 |
printf("interleave: %d\n", lp->d_interleave); |
printf("interleave: %u\n", lp->d_interleave); |
528 |
printf("trackskew: %d\n", lp->d_trackskew); |
printf("trackskew: %u\n", lp->d_trackskew); |
529 |
printf("cylinderskew: %d\n", lp->d_cylskew); |
printf("cylinderskew: %u\n", lp->d_cylskew); |
530 |
printf("headswitch: %ld\t\t# milliseconds\n", |
printf("headswitch: %lu\t\t# milliseconds\n", |
531 |
(long) lp->d_headswitch); |
(long) lp->d_headswitch); |
532 |
printf("track-to-track seek: %ld\t# milliseconds\n", |
printf("track-to-track seek: %lu\t# milliseconds\n", |
533 |
(long) lp->d_trkseek); |
(long) lp->d_trkseek); |
534 |
printf("drivedata: "); |
printf("drivedata: "); |
535 |
for (i = NDDATA - 1; i >= 0; i--) |
for (i = NDDATA - 1; i >= 0; i--) |
538 |
if (i < 0) |
if (i < 0) |
539 |
i = 0; |
i = 0; |
540 |
for (j = 0; j <= i; j++) |
for (j = 0; j <= i; j++) |
541 |
printf("%ld ", (long) lp->d_drivedata[j]); |
printf("%lu ", (long) lp->d_drivedata[j]); |
542 |
} |
} |
543 |
printf("\n%d partitions:\n", lp->d_npartitions); |
printf("\n%u partitions:\n", lp->d_npartitions); |
544 |
printf("# start end size fstype [fsize bsize cpg]\n"); |
printf("# start end size fstype [fsize bsize cpg]\n"); |
545 |
pp = lp->d_partitions; |
pp = lp->d_partitions; |
546 |
for (i = 0; i < lp->d_npartitions; i++, pp++) { |
for (i = 0; i < lp->d_npartitions; i++, pp++) { |
547 |
if (pp->p_size) { |
if (pp->p_size) { |
548 |
if (display_in_cyl_units && lp->d_secpercyl) { |
if (display_in_cyl_units && lp->d_secpercyl) { |
549 |
printf(" %c: %8ld%c %8ld%c %8ld%c ", |
printf(" %c: %8lu%c %8lu%c %8lu%c ", |
550 |
'a' + i, |
'a' + i, |
551 |
(long) pp->p_offset / lp->d_secpercyl + 1, |
(unsigned long) pp->p_offset / lp->d_secpercyl + 1, |
552 |
(pp->p_offset % lp->d_secpercyl) ? '*' : ' ', |
(pp->p_offset % lp->d_secpercyl) ? '*' : ' ', |
553 |
(long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl, |
(unsigned long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl, |
554 |
((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ', |
((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ', |
555 |
(long) pp->p_size / lp->d_secpercyl, |
(long) pp->p_size / lp->d_secpercyl, |
556 |
(pp->p_size % lp->d_secpercyl) ? '*' : ' ' |
(pp->p_size % lp->d_secpercyl) ? '*' : ' ' |
557 |
); |
); |
558 |
} else { |
} else { |
559 |
printf(" %c: %8ld %8ld %8ld ", |
printf(" %c: %8lu %8lu %8lu ", |
560 |
'a' + i, |
'a' + i, |
561 |
(long) pp->p_offset, |
(long) pp->p_offset, |
562 |
(long) pp->p_offset + pp->p_size - 1, |
(long) pp->p_offset + pp->p_size - 1, |
571 |
|
|
572 |
switch (pp->p_fstype) { |
switch (pp->p_fstype) { |
573 |
case BSD_FS_UNUSED: |
case BSD_FS_UNUSED: |
574 |
printf(" %5ld %5ld %5.5s ", |
printf(" %5lu %5lu %5.5s ", |
575 |
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, ""); |
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, ""); |
576 |
break; |
break; |
577 |
case BSD_FS_BSDFFS: |
case BSD_FS_BSDFFS: |
578 |
printf(" %5ld %5ld %5d ", |
printf(" %5lu %5lu %5u ", |
579 |
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg); |
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg); |
580 |
break; |
break; |
581 |
default: |
default: |
615 |
|
|
616 |
while (1) { |
while (1) { |
617 |
c = read_nonempty("Do you want to create a disklabel? (y/n) "); |
c = read_nonempty("Do you want to create a disklabel? (y/n) "); |
618 |
if (c == 'y' || c == 'Y') { |
if ((c|0x20) == 'y') { |
619 |
if (xbsd_initlabel( |
if (xbsd_initlabel( |
620 |
#if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \ |
#if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \ |
621 |
defined(__s390__) || defined(__s390x__) |
defined(__s390__) || defined(__s390x__) |
629 |
} |
} |
630 |
return 0; |
return 0; |
631 |
} |
} |
632 |
if (c == 'n') |
if ((c|0x20) == 'n') |
633 |
return 0; |
return 0; |
634 |
} |
} |
635 |
} |
} |
637 |
static int |
static int |
638 |
edit_int(int def, const char *mesg) |
edit_int(int def, const char *mesg) |
639 |
{ |
{ |
640 |
mesg = xasprintf("%s (%d): ", mesg, def); |
mesg = xasprintf("%s (%u): ", mesg, def); |
641 |
do { |
do { |
642 |
if (!read_line(mesg)) |
if (!read_line(mesg)) |
643 |
goto ret; |
goto ret; |
950 |
} |
} |
951 |
|
|
952 |
if (d->d_npartitions > BSD_MAXPARTITIONS) |
if (d->d_npartitions > BSD_MAXPARTITIONS) |
953 |
printf("Warning: too many partitions (%d, maximum is %d)\n", |
printf("Warning: too many partitions (%u, maximum is %u)\n", |
954 |
d->d_npartitions, BSD_MAXPARTITIONS); |
d->d_npartitions, BSD_MAXPARTITIONS); |
955 |
return 1; |
return 1; |
956 |
} |
} |
964 |
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__) |
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__) |
965 |
sector = get_start_sect(p) + BSD_LABELSECTOR; |
sector = get_start_sect(p) + BSD_LABELSECTOR; |
966 |
#else |
#else |
967 |
|
(void)p; /* silence warning */ |
968 |
sector = BSD_LABELSECTOR; |
sector = BSD_LABELSECTOR; |
969 |
#endif |
#endif |
970 |
|
|