#define BSD_FS_MSDOS 8 /* MS-DOS file system */
#endif
-static const struct systypes xbsd_fstypes[] = {
- { "\x00" "unused" }, /* BSD_FS_UNUSED */
- { "\x01" "swap" }, /* BSD_FS_SWAP */
- { "\x02" "Version 6" }, /* BSD_FS_V6 */
- { "\x03" "Version 7" }, /* BSD_FS_V7 */
- { "\x04" "System V" }, /* BSD_FS_SYSV */
- { "\x05" "4.1BSD" }, /* BSD_FS_V71K */
- { "\x06" "Eighth Edition" }, /* BSD_FS_V8 */
- { "\x07" "4.2BSD" }, /* BSD_FS_BSDFFS */
+static const char *const xbsd_fstypes[] = {
+ "\x00" "unused", /* BSD_FS_UNUSED */
+ "\x01" "swap", /* BSD_FS_SWAP */
+ "\x02" "Version 6", /* BSD_FS_V6 */
+ "\x03" "Version 7", /* BSD_FS_V7 */
+ "\x04" "System V", /* BSD_FS_SYSV */
+ "\x05" "4.1BSD", /* BSD_FS_V71K */
+ "\x06" "Eighth Edition", /* BSD_FS_V8 */
+ "\x07" "4.2BSD", /* BSD_FS_BSDFFS */
#ifdef __alpha__
- { "\x08" "ext2" }, /* BSD_FS_EXT2 */
+ "\x08" "ext2", /* BSD_FS_EXT2 */
#else
- { "\x08" "MS-DOS" }, /* BSD_FS_MSDOS */
+ "\x08" "MS-DOS", /* BSD_FS_MSDOS */
#endif
- { "\x09" "4.4LFS" }, /* BSD_FS_BSDLFS */
- { "\x0a" "unknown" }, /* BSD_FS_OTHER */
- { "\x0b" "HPFS" }, /* BSD_FS_HPFS */
- { "\x0c" "ISO-9660" }, /* BSD_FS_ISO9660 */
- { "\x0d" "boot" }, /* BSD_FS_BOOT */
- { "\x0e" "ADOS" }, /* BSD_FS_ADOS */
- { "\x0f" "HFS" }, /* BSD_FS_HFS */
- { "\x10" "AdvFS" }, /* BSD_FS_ADVFS */
- { NULL }
+ "\x09" "4.4LFS", /* BSD_FS_BSDLFS */
+ "\x0a" "unknown", /* BSD_FS_OTHER */
+ "\x0b" "HPFS", /* BSD_FS_HPFS */
+ "\x0c" "ISO-9660", /* BSD_FS_ISO9660 */
+ "\x0d" "boot", /* BSD_FS_BOOT */
+ "\x0e" "ADOS", /* BSD_FS_ADOS */
+ "\x0f" "HFS", /* BSD_FS_HFS */
+ "\x10" "AdvFS", /* BSD_FS_ADVFS */
+ NULL
};
#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
static int xbsd_check_new_partition(int *i);
static void xbsd_list_types(void);
static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp);
-static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d);
-static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d);
-static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d);
+static int xbsd_initlabel(struct partition *p);
+static int xbsd_readlabel(struct partition *p);
+static int xbsd_writelabel(struct partition *p);
#if defined(__alpha__)
static void alpha_bootblock_checksum(char *boot);
static int xbsd_part_index;
#endif
+
+/* Group big globals data and allocate it in one go */
+struct bsd_globals {
/* We access this through a uint64_t * when checksumming */
/* hopefully xmalloc gives us required alignment */
-static char *disklabelbuffer; /*[BSD_BBSIZE]*/
+ char disklabelbuffer[BSD_BBSIZE];
+ struct xbsd_disklabel xbsd_dlabel;
+};
+
+static struct bsd_globals *bsd_globals_ptr;
+
+#define disklabelbuffer (bsd_globals_ptr->disklabelbuffer)
+#define xbsd_dlabel (bsd_globals_ptr->xbsd_dlabel)
-static struct xbsd_disklabel xbsd_dlabel;
+
+/* Code */
#define bsd_cround(n) \
(display_in_cyl_units ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n))
static int
check_osf_label(void)
{
- if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)
+ if (xbsd_readlabel(NULL) == 0)
return 0;
return 1;
}
static int
bsd_trydev(const char * dev)
{
- if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)
+ if (xbsd_readlabel(NULL) == 0)
return -1;
- printf(_("\nBSD label for device: %s\n"), dev);
+ printf("\nBSD label for device: %s\n", dev);
xbsd_print_disklabel(0);
return 0;
}
static void
bsd_menu(void)
{
- puts(_("Command action"));
- puts(_("\td\tdelete a BSD partition"));
- puts(_("\te\tedit drive data"));
- puts(_("\ti\tinstall bootstrap"));
- puts(_("\tl\tlist known filesystem types"));
- puts(_("\tm\tprint this menu"));
- puts(_("\tn\tadd a new BSD partition"));
- puts(_("\tp\tprint BSD partition table"));
- puts(_("\tq\tquit without saving changes"));
- puts(_("\tr\treturn to main menu"));
- puts(_("\ts\tshow complete disklabel"));
- puts(_("\tt\tchange a partition's filesystem id"));
- puts(_("\tu\tchange units (cylinders/sectors)"));
- puts(_("\tw\twrite disklabel to disk"));
+ puts("Command Action");
+ puts("d\tdelete a BSD partition");
+ puts("e\tedit drive data");
+ puts("i\tinstall bootstrap");
+ puts("l\tlist known filesystem types");
+ puts("n\tadd a new BSD partition");
+ puts("p\tprint BSD partition table");
+ puts("q\tquit without saving changes");
+ puts("r\treturn to main menu");
+ puts("s\tshow complete disklabel");
+ puts("t\tchange a partition's filesystem id");
+ puts("u\tchange units (cylinders/sectors)");
+ puts("w\twrite disklabel to disk");
#if !defined(__alpha__)
- puts(_("\tx\tlink BSD partition to non-BSD partition"));
+ puts("x\tlink BSD partition to non-BSD partition");
#endif
}
xbsd_part_index = t;
ss = get_start_sect(xbsd_part);
if (ss == 0) {
- fprintf(stderr, _("Partition %s has invalid starting sector 0.\n"),
+ printf("Partition %s has invalid starting sector 0\n",
partname(disk_device, t+1, 0));
return;
}
- printf(_("Reading disklabel of %s at sector %d.\n"),
+ printf("Reading disklabel of %s at sector %d\n",
partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);
- if (xbsd_readlabel(xbsd_part, &xbsd_dlabel) == 0)
+ if (xbsd_readlabel(xbsd_part) == 0)
if (xbsd_create_disklabel() == 0)
return;
break;
}
if (t == 4) {
- printf(_("There is no *BSD partition on %s.\n"), disk_device);
+ printf("There is no *BSD partition on %s\n", disk_device);
return;
}
#elif defined(__alpha__)
- if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)
+ if (xbsd_readlabel(NULL) == 0)
if (xbsd_create_disklabel() == 0)
exit(EXIT_SUCCESS);
while (1) {
putchar('\n');
- switch (tolower(read_nonempty(_("BSD disklabel command (m for help): ")))) {
+ switch (tolower(read_nonempty("BSD disklabel command (m for help): "))) {
case 'd':
xbsd_delete_part();
break;
end = xbsd_dlabel.d_secperunit - 1;
#endif
- snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
+ snprintf(mesg, sizeof(mesg), "First %s", str_units(SINGULAR));
begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end),
0, mesg);
if (display_in_cyl_units)
begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
- snprintf(mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"),
+ snprintf(mesg, sizeof(mesg), "Last %s or +size or +sizeM or +sizeK",
str_units(SINGULAR));
end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end),
bsd_cround(begin), mesg);
printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
#endif
if ((unsigned) lp->d_type < BSD_DKMAXTYPES)
- printf(_("type: %s\n"), xbsd_dktypenames[lp->d_type]);
+ printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
else
- printf(_("type: %d\n"), lp->d_type);
- printf(_("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename);
- printf(_("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname);
- printf(_("flags:"));
+ printf("type: %d\n", lp->d_type);
+ printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
+ printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
+ printf("flags:");
if (lp->d_flags & BSD_D_REMOVABLE)
- printf(_(" removable"));
+ printf(" removable");
if (lp->d_flags & BSD_D_ECC)
- printf(_(" ecc"));
+ printf(" ecc");
if (lp->d_flags & BSD_D_BADSECT)
- printf(_(" badsect"));
+ printf(" badsect");
puts("");
/* On various machines the fields of *lp are short/int/long */
/* In order to avoid problems, we cast them all to long. */
- printf(_("bytes/sector: %ld\n"), (long) lp->d_secsize);
- printf(_("sectors/track: %ld\n"), (long) lp->d_nsectors);
- printf(_("tracks/cylinder: %ld\n"), (long) lp->d_ntracks);
- printf(_("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl);
- printf(_("cylinders: %ld\n"), (long) lp->d_ncylinders);
- printf(_("rpm: %d\n"), lp->d_rpm);
- printf(_("interleave: %d\n"), lp->d_interleave);
- printf(_("trackskew: %d\n"), lp->d_trackskew);
- printf(_("cylinderskew: %d\n"), lp->d_cylskew);
- printf(_("headswitch: %ld\t\t# milliseconds\n"),
+ printf("bytes/sector: %ld\n", (long) lp->d_secsize);
+ printf("sectors/track: %ld\n", (long) lp->d_nsectors);
+ printf("tracks/cylinder: %ld\n", (long) lp->d_ntracks);
+ printf("sectors/cylinder: %ld\n", (long) lp->d_secpercyl);
+ printf("cylinders: %ld\n", (long) lp->d_ncylinders);
+ printf("rpm: %d\n", lp->d_rpm);
+ printf("interleave: %d\n", lp->d_interleave);
+ printf("trackskew: %d\n", lp->d_trackskew);
+ printf("cylinderskew: %d\n", lp->d_cylskew);
+ printf("headswitch: %ld\t\t# milliseconds\n",
(long) lp->d_headswitch);
- printf(_("track-to-track seek: %ld\t# milliseconds\n"),
+ printf("track-to-track seek: %ld\t# milliseconds\n",
(long) lp->d_trkseek);
- printf(_("drivedata: "));
+ printf("drivedata: ");
for (i = NDDATA - 1; i >= 0; i--)
if (lp->d_drivedata[i])
break;
for (j = 0; j <= i; j++)
printf("%ld ", (long) lp->d_drivedata[j]);
}
- printf(_("\n%d partitions:\n"), lp->d_npartitions);
- printf(_("# start end size fstype [fsize bsize cpg]\n"));
+ printf("\n%d partitions:\n", lp->d_npartitions);
+ printf("# start end size fstype [fsize bsize cpg]\n");
pp = lp->d_partitions;
for (i = 0; i < lp->d_npartitions; i++, pp++) {
if (pp->p_size) {
}
if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES)
- printf("%8.8s", xbsd_fstypes[pp->p_fstype].name);
+ printf("%8.8s", xbsd_fstypes[pp->p_fstype]);
else
printf("%8x", pp->p_fstype);
xbsd_write_disklabel(void)
{
#if defined(__alpha__)
- printf(_("Writing disklabel to %s.\n"), disk_device);
- xbsd_writelabel(NULL, &xbsd_dlabel);
+ printf("Writing disklabel to %s\n", disk_device);
+ xbsd_writelabel(NULL);
#else
- printf(_("Writing disklabel to %s.\n"),
+ printf("Writing disklabel to %s\n",
partname(disk_device, xbsd_part_index + 1, 0));
- xbsd_writelabel(xbsd_part, &xbsd_dlabel);
+ xbsd_writelabel(xbsd_part);
#endif
reread_partition_table(0); /* no exit yet */
}
char c;
#if defined(__alpha__)
- fprintf(stderr, _("%s contains no disklabel.\n"), disk_device);
+ printf("%s contains no disklabel\n", disk_device);
#else
- fprintf(stderr, _("%s contains no disklabel.\n"),
+ printf("%s contains no disklabel\n",
partname(disk_device, xbsd_part_index + 1, 0));
#endif
while (1) {
- c = read_nonempty(_("Do you want to create a disklabel? (y/n) "));
+ c = read_nonempty("Do you want to create a disklabel? (y/n) ");
if (c == 'y' || c == 'Y') {
if (xbsd_initlabel(
#if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \
defined(__s390__) || defined(__s390x__)
- NULL, &xbsd_dlabel
+ NULL
#else
- xbsd_part, &xbsd_dlabel/* not used, xbsd_part_index*/
+ xbsd_part
#endif
) == 1) {
xbsd_print_disklabel(1);
}
static int
-edit_int(int def, char *mesg)
+edit_int(int def, const char *mesg)
{
+ mesg = xasprintf("%s (%d): ", mesg, def);
do {
- fputs(mesg, stdout);
- printf(" (%d): ", def);
- if (!read_line())
- return def;
+ if (!read_line(mesg))
+ goto ret;
} while (!isdigit(*line_ptr));
- return atoi(line_ptr);
+ def = atoi(line_ptr);
+ ret:
+ free((char*)mesg);
+ return def;
}
static void
d = &xbsd_dlabel;
#if defined(__alpha__) || defined(__ia64__)
- d->d_secsize = edit_int(d->d_secsize ,_("bytes/sector"));
- d->d_nsectors = edit_int(d->d_nsectors ,_("sectors/track"));
- d->d_ntracks = edit_int(d->d_ntracks ,_("tracks/cylinder"));
- d->d_ncylinders = edit_int(d->d_ncylinders ,_("cylinders"));
+ d->d_secsize = edit_int(d->d_secsize , "bytes/sector");
+ d->d_nsectors = edit_int(d->d_nsectors , "sectors/track");
+ d->d_ntracks = edit_int(d->d_ntracks , "tracks/cylinder");
+ d->d_ncylinders = edit_int(d->d_ncylinders , "cylinders");
#endif
/* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */
while (1) {
d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks,
- _("sectors/cylinder"));
+ "sectors/cylinder");
if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)
break;
- printf(_("Must be <= sectors/track * tracks/cylinder (default).\n"));
+ printf("Must be <= sectors/track * tracks/cylinder (default)\n");
}
- d->d_rpm = edit_int(d->d_rpm ,_("rpm"));
- d->d_interleave = edit_int(d->d_interleave,_("interleave"));
- d->d_trackskew = edit_int(d->d_trackskew ,_("trackskew"));
- d->d_cylskew = edit_int(d->d_cylskew ,_("cylinderskew"));
- d->d_headswitch = edit_int(d->d_headswitch,_("headswitch"));
- d->d_trkseek = edit_int(d->d_trkseek ,_("track-to-track seek"));
+ d->d_rpm = edit_int(d->d_rpm , "rpm");
+ d->d_interleave = edit_int(d->d_interleave, "interleave");
+ d->d_trackskew = edit_int(d->d_trackskew , "trackskew");
+ d->d_cylskew = edit_int(d->d_cylskew , "cylinderskew");
+ d->d_headswitch = edit_int(d->d_headswitch, "headswitch");
+ d->d_trkseek = edit_int(d->d_trkseek , "track-to-track seek");
d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
}
static void
sync_disks(void)
{
- printf(_("\nSyncing disks.\n"));
+ printf("Syncing disks\n");
sync();
- sleep(4); /* What? */
+ /* sleep(4); What? */
}
static void
xbsd_write_bootstrap(void)
{
- char *bootdir = BSD_LINUX_BOOTDIR;
char path[MAXPATHLEN];
- char *dkbasename;
+ const char *bootdir = BSD_LINUX_BOOTDIR;
+ const char *dkbasename;
struct xbsd_disklabel dl;
char *d, *p, *e;
int sector;
else
dkbasename = "wd";
- printf(_("Bootstrap: %sboot -> boot%s (%s): "),
+ snprintf(path, sizeof(path), "Bootstrap: %sboot -> boot%s (%s): ",
dkbasename, dkbasename, dkbasename);
- if (read_line()) {
- line_ptr[strlen(line_ptr)-1] = '\0';
+ if (read_line(path)) {
dkbasename = line_ptr;
}
snprintf(path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
e = d + sizeof(struct xbsd_disklabel);
for (p = d; p < e; p++)
if (*p) {
- fprintf(stderr, _("Bootstrap overlaps with disk label!\n"));
+ printf("Bootstrap overlaps with disk label!\n");
exit(EXIT_FAILURE);
}
fdisk_fatal(unable_to_write);
#if defined(__alpha__)
- printf(_("Bootstrap installed on %s.\n"), disk_device);
+ printf("Bootstrap installed on %s\n", disk_device);
#else
- printf(_("Bootstrap installed on %s.\n"),
+ printf("Bootstrap installed on %s\n",
partname(disk_device, xbsd_part_index+1, 0));
#endif
static int
xbsd_get_part_index(int max)
{
- char prompt[256];
+ char prompt[sizeof("Partition (a-%c): ") + 16];
char l;
- snprintf(prompt, sizeof(prompt), _("Partition (a-%c): "), 'a' + max - 1);
+ snprintf(prompt, sizeof(prompt), "Partition (a-%c): ", 'a' + max - 1);
do
l = tolower(read_nonempty(prompt));
while (l < 'a' || l > 'a' + max - 1);
break;
if (t == BSD_MAXPARTITIONS) {
- fprintf(stderr, _("The maximum number of partitions "
- "has been created\n"));
+ printf("The maximum number of partitions has been created\n");
return 0;
}
}
xbsd_dlabel.d_npartitions = (*i) + 1;
if (xbsd_dlabel.d_partitions[*i].p_size != 0) {
- fprintf(stderr, _("This partition already exists.\n"));
+ printf("This partition already exists\n");
return 0;
}
}
static int
-xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d)
+xbsd_initlabel(struct partition *p)
{
+ struct xbsd_disklabel *d = &xbsd_dlabel;
struct xbsd_partition *pp;
get_geometry();
pp->p_offset = 0;
pp->p_size = d->d_secperunit;
pp->p_fstype = BSD_FS_UNUSED;
-#elif defined(__alpha__)
+#else
d->d_npartitions = 3;
pp = &d->d_partitions[2]; /* Partition C should be
the whole disk */
* If it has the right magic, return 1.
*/
static int
-xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d)
+xbsd_readlabel(struct partition *p)
{
+ struct xbsd_disklabel *d;
int t, sector;
- if (!disklabelbuffer)
- disklabelbuffer = xmalloc(BSD_BBSIZE);
+ if (!bsd_globals_ptr)
+ bsd_globals_ptr = xzalloc(sizeof(*bsd_globals_ptr));
+
+ d = &xbsd_dlabel;
/* p is used only to get the starting sector */
#if !defined(__alpha__)
sector = (p ? get_start_sect(p) : 0);
-#elif defined(__alpha__)
+#else
sector = 0;
#endif
}
if (d->d_npartitions > BSD_MAXPARTITIONS)
- fprintf(stderr, _("Warning: too many partitions "
- "(%d, maximum is %d).\n"),
+ printf("Warning: too many partitions (%d, maximum is %d)\n",
d->d_npartitions, BSD_MAXPARTITIONS);
return 1;
}
static int
-xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d)
+xbsd_writelabel(struct partition *p)
{
+ struct xbsd_disklabel *d = &xbsd_dlabel;
unsigned int sector;
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)
#endif
#if defined(__alpha__)
-
static void
alpha_bootblock_checksum(char *boot)
{
}
#endif /* __alpha__ */
+/* Undefine 'global' tricks */
+#undef disklabelbuffer
+#undef xbsd_dlabel
+
#endif /* OSF_LABEL */