2013-01-16 03:52:48 +04:00
|
|
|
/* $NetBSD: interact.c,v 1.36 2013/01/15 23:52:48 christos Exp $ */
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-06-12 23:18:34 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
1997-07-01 02:51:27 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-03-09 02:46:08 +03:00
|
|
|
#ifndef lint
|
2013-01-16 03:52:48 +04:00
|
|
|
__RCSID("$NetBSD: interact.c,v 1.36 2013/01/15 23:52:48 christos Exp $");
|
1997-03-09 02:46:08 +03:00
|
|
|
#endif /* lint */
|
|
|
|
|
1999-11-26 09:03:09 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#define FSTYPENAMES
|
|
|
|
#define DKTYPENAMES
|
|
|
|
|
|
|
|
#include <err.h>
|
1997-03-09 02:46:08 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2013-01-16 03:52:48 +04:00
|
|
|
#include <stdarg.h>
|
1997-03-09 02:46:08 +03:00
|
|
|
#include <stdlib.h>
|
2013-01-16 03:52:48 +04:00
|
|
|
#include <sys/ioctl.h>
|
2005-06-12 23:18:34 +04:00
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#define getmaxpartitions() MAXPARTITIONS
|
|
|
|
#include <nbinclude/sys/disklabel.h>
|
|
|
|
#else
|
1997-03-09 03:14:17 +03:00
|
|
|
#include <util.h>
|
2005-06-12 23:18:34 +04:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
#include "extern.h"
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
static void cmd_help(struct disklabel *, char *, int);
|
2013-01-16 03:52:48 +04:00
|
|
|
static void cmd_adjust(struct disklabel *, char *, int);
|
2000-12-24 08:59:11 +03:00
|
|
|
static void cmd_chain(struct disklabel *, char *, int);
|
|
|
|
static void cmd_print(struct disklabel *, char *, int);
|
|
|
|
static void cmd_printall(struct disklabel *, char *, int);
|
|
|
|
static void cmd_info(struct disklabel *, char *, int);
|
|
|
|
static void cmd_part(struct disklabel *, char *, int);
|
|
|
|
static void cmd_label(struct disklabel *, char *, int);
|
|
|
|
static void cmd_round(struct disklabel *, char *, int);
|
|
|
|
static void cmd_name(struct disklabel *, char *, int);
|
2006-11-26 19:16:31 +03:00
|
|
|
static void cmd_listfstypes(struct disklabel *, char *, int);
|
2000-12-24 08:59:11 +03:00
|
|
|
static int runcmd(struct disklabel *, char *, int);
|
2013-01-16 03:52:48 +04:00
|
|
|
static int getinput(char *, const char *, ...) __printflike(2, 3);
|
2000-12-24 08:59:11 +03:00
|
|
|
static int alphacmp(const void *, const void *);
|
2003-10-20 17:20:20 +04:00
|
|
|
static void defnum(struct disklabel *, char *, uint32_t);
|
2000-12-24 08:59:11 +03:00
|
|
|
static void dumpnames(const char *, const char * const *, size_t);
|
2010-05-28 11:40:53 +04:00
|
|
|
static intmax_t getnum(struct disklabel *, char *, intmax_t);
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
static int rounding = 0; /* sector rounding */
|
1999-05-03 13:45:01 +04:00
|
|
|
static int chaining = 0; /* make partitions contiguous */
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
static struct cmds {
|
|
|
|
const char *name;
|
2000-12-24 08:59:11 +03:00
|
|
|
void (*func)(struct disklabel *, char *, int);
|
1997-03-09 02:46:08 +03:00
|
|
|
const char *help;
|
|
|
|
} cmds[] = {
|
|
|
|
{ "?", cmd_help, "print this menu" },
|
2013-01-16 03:52:48 +04:00
|
|
|
{ "A", cmd_adjust, "adjust the label size to the max disk size" },
|
1999-05-03 13:45:01 +04:00
|
|
|
{ "C", cmd_chain, "make partitions contiguous" },
|
1999-11-26 09:03:09 +03:00
|
|
|
{ "E", cmd_printall, "print disk label and current partition table"},
|
|
|
|
{ "I", cmd_info, "change label information" },
|
2006-11-26 19:16:31 +03:00
|
|
|
{ "L", cmd_listfstypes,"list all known file system types" },
|
1997-03-09 03:14:17 +03:00
|
|
|
{ "N", cmd_name, "name the label" },
|
|
|
|
{ "P", cmd_print, "print current partition table" },
|
|
|
|
{ "Q", NULL, "quit" },
|
|
|
|
{ "R", cmd_round, "rounding (c)ylinders (s)ectors" },
|
|
|
|
{ "W", cmd_label, "write the current partition table" },
|
1997-03-09 02:46:08 +03:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_help(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
|
|
|
struct cmds *cmd;
|
1997-03-09 03:14:17 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
for (cmd = cmds; cmd->name != NULL; cmd++)
|
|
|
|
printf("%s\t%s\n", cmd->name, cmd->help);
|
1997-03-09 03:14:17 +03:00
|
|
|
printf("[a-%c]\tdefine named partition\n",
|
|
|
|
'a' + getmaxpartitions() - 1);
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-16 03:52:48 +04:00
|
|
|
static void
|
|
|
|
cmd_adjust(struct disklabel *lp, char *s, int fd)
|
|
|
|
{
|
|
|
|
struct disklabel dl;
|
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGDEFLABEL, &dl) == -1) {
|
|
|
|
warn("Cannot get default label");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dl.d_secperunit != lp->d_secperunit) {
|
|
|
|
char line[BUFSIZ];
|
|
|
|
int i = getinput(line, "Adjust disklabel sector from %" PRIu32
|
|
|
|
" to %" PRIu32 " [n]? ", lp->d_secperunit, dl.d_secperunit);
|
|
|
|
if (i <= 0)
|
|
|
|
return;
|
|
|
|
if (line[0] != 'Y' && line[0] != 'y')
|
|
|
|
return;
|
|
|
|
lp->d_secperunit = dl.d_secperunit;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Already at %" PRIu32 " sectors\n", dl.d_secperunit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-05-03 13:45:01 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_chain(struct disklabel *lp, char *s, int fd)
|
1999-05-03 13:45:01 +04:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int i;
|
|
|
|
char line[BUFSIZ];
|
1999-05-03 13:45:01 +04:00
|
|
|
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Automatically adjust partitions [%s]? ",
|
|
|
|
chaining ? "yes" : "no");
|
1999-05-03 13:45:01 +04:00
|
|
|
if (i <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (line[0]) {
|
|
|
|
case 'y':
|
|
|
|
chaining = 1;
|
|
|
|
return;
|
|
|
|
case 'n':
|
|
|
|
chaining = 0;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
printf("Invalid answer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1999-11-26 09:03:09 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_printall(struct disklabel *lp, char *s, int fd)
|
1999-11-26 09:03:09 +03:00
|
|
|
{
|
|
|
|
|
2000-12-24 10:08:02 +03:00
|
|
|
showinfo(stdout, lp, specname);
|
|
|
|
showpartitions(stdout, lp, Cflag);
|
1999-11-26 09:03:09 +03:00
|
|
|
}
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_print(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
|
2000-12-24 10:08:02 +03:00
|
|
|
showpartitions(stdout, lp, Cflag);
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1999-11-26 09:03:09 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_info(struct disklabel *lp, char *s, int fd)
|
1999-11-26 09:03:09 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
char line[BUFSIZ];
|
|
|
|
int v, i;
|
1999-11-26 09:03:09 +03:00
|
|
|
u_int32_t u;
|
|
|
|
|
|
|
|
printf("# Current values:\n");
|
2000-12-24 10:08:02 +03:00
|
|
|
showinfo(stdout, lp, specname);
|
1999-11-26 09:03:09 +03:00
|
|
|
|
2000-08-15 02:37:08 +04:00
|
|
|
/* d_type */
|
1999-11-26 09:03:09 +03:00
|
|
|
for (;;) {
|
2000-08-15 02:37:08 +04:00
|
|
|
i = lp->d_type;
|
|
|
|
if (i < 0 || i >= DKMAXTYPES)
|
|
|
|
i = 0;
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Disk type [%s]: ", dktypenames[i]);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2000-08-15 02:37:08 +04:00
|
|
|
if (!strcmp(line, "?")) {
|
|
|
|
dumpnames("Supported disk types", dktypenames,
|
|
|
|
DKMAXTYPES);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (i = 0; i < DKMAXTYPES; i++) {
|
|
|
|
if (!strcasecmp(dktypenames[i], line)) {
|
|
|
|
lp->d_type = i;
|
1999-11-26 09:03:09 +03:00
|
|
|
goto done_typename;
|
|
|
|
}
|
2000-08-15 02:37:08 +04:00
|
|
|
}
|
1999-11-26 09:03:09 +03:00
|
|
|
v = atoi(line);
|
|
|
|
if ((unsigned)v >= DKMAXTYPES) {
|
2000-08-15 02:37:08 +04:00
|
|
|
warnx("Unknown disk type: %s", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_type = v;
|
2000-12-24 08:59:11 +03:00
|
|
|
done_typename:
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-08-15 02:37:08 +04:00
|
|
|
/* d_typename */
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Disk name [%.*s]: ",
|
2000-08-15 02:37:08 +04:00
|
|
|
(int) sizeof(lp->d_typename), lp->d_typename);
|
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 1)
|
|
|
|
(void) strncpy(lp->d_typename, line, sizeof(lp->d_typename));
|
|
|
|
|
1999-11-26 09:03:09 +03:00
|
|
|
/* d_packname */
|
|
|
|
cmd_name(lp, s, fd);
|
|
|
|
|
|
|
|
/* d_npartitions */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Number of partitions [%" PRIu16 "]: ",
|
|
|
|
lp->d_npartitions);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid number of partitions `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_npartitions = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_secsize */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Sector size (bytes) [%" PRIu32 "]: ",
|
|
|
|
lp->d_secsize);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
1999-11-26 09:03:09 +03:00
|
|
|
printf("Invalid sector size `%s'\n", line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_secsize = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_nsectors */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Number of sectors per track [%" PRIu32
|
|
|
|
"]: ", lp->d_nsectors);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid number of sectors `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_nsectors = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_ntracks */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Number of tracks per cylinder [%" PRIu32
|
|
|
|
"]: ", lp->d_ntracks);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
1999-11-26 09:03:09 +03:00
|
|
|
printf("Invalid number of tracks `%s'\n", line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_ntracks = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_secpercyl */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Number of sectors/cylinder [%" PRIu32 "]: ",
|
|
|
|
lp->d_secpercyl);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid number of sector/cylinder `%s'\n",
|
|
|
|
line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_secpercyl = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_ncylinders */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Total number of cylinders [%" PRIu32 "]: ",
|
|
|
|
lp->d_ncylinders);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
1999-11-26 09:03:09 +03:00
|
|
|
printf("Invalid sector size `%s'\n", line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_ncylinders = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_secperunit */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Total number of sectors [%" PRIu32 "]: ",
|
|
|
|
lp->d_secperunit);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid number of sectors `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_secperunit = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_rpm */
|
|
|
|
|
|
|
|
/* d_interleave */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Hardware sectors interleave [%" PRIu16
|
|
|
|
"]: ", lp->d_interleave);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid sector interleave `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_interleave = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_trackskew */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Sector 0 skew, per track [%" PRIu16 "]: ",
|
|
|
|
lp->d_trackskew);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid track sector skew `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_trackskew = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_cylskew */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Sector 0 skew, per cylinder [%" PRIu16
|
|
|
|
"]: ", lp->d_cylskew);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid cylinder sector `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_cylskew = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_headswitch */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Head switch time (usec) [%" PRIu32 "]: ",
|
|
|
|
lp->d_headswitch);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid head switch time `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_headswitch = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* d_trkseek */
|
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Track seek time (usec) [%" PRIu32 "]:",
|
|
|
|
lp->d_trkseek);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1999-11-26 09:03:09 +03:00
|
|
|
break;
|
2011-01-07 00:39:01 +03:00
|
|
|
if (sscanf(line, "%" SCNu32, &u) != 1) {
|
2000-08-15 02:37:08 +04:00
|
|
|
printf("Invalid track seek time `%s'\n", line);
|
1999-11-26 09:03:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lp->d_trkseek = u;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_name(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
char line[BUFSIZ];
|
|
|
|
int i;
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Label name [%.*s]: ",
|
2000-08-15 02:37:08 +04:00
|
|
|
(int) sizeof(lp->d_packname), lp->d_packname);
|
1997-03-09 02:46:08 +03:00
|
|
|
if (i <= 0)
|
|
|
|
return;
|
|
|
|
(void) strncpy(lp->d_packname, line, sizeof(lp->d_packname));
|
|
|
|
}
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_round(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int i;
|
|
|
|
char line[BUFSIZ];
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Rounding [%s]: ", rounding ? "cylinders" :
|
|
|
|
"sectors");
|
1997-03-09 02:46:08 +03:00
|
|
|
if (i <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (line[0]) {
|
|
|
|
case 'c':
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'C':
|
1997-03-09 02:46:08 +03:00
|
|
|
rounding = 1;
|
|
|
|
return;
|
|
|
|
case 's':
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'S':
|
1997-03-09 02:46:08 +03:00
|
|
|
rounding = 0;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
printf("Rounding can be (c)ylinders or (s)ectors\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_part(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int i;
|
2010-05-28 11:40:53 +04:00
|
|
|
intmax_t im;
|
2000-12-24 08:59:11 +03:00
|
|
|
char line[BUFSIZ];
|
|
|
|
char def[BUFSIZ];
|
|
|
|
int part;
|
2001-05-26 23:48:32 +04:00
|
|
|
struct partition *p, ps;
|
2000-12-24 08:59:11 +03:00
|
|
|
|
|
|
|
part = s[0] - 'a';
|
|
|
|
p = &lp->d_partitions[part];
|
1997-03-19 00:26:43 +03:00
|
|
|
if (part >= lp->d_npartitions)
|
1997-03-09 02:46:08 +03:00
|
|
|
lp->d_npartitions = part + 1;
|
|
|
|
|
2001-05-26 23:48:32 +04:00
|
|
|
(void)memcpy(&ps, p, sizeof(ps));
|
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
for (;;) {
|
2000-08-15 02:37:08 +04:00
|
|
|
i = p->p_fstype;
|
|
|
|
if (i < 0 || i >= FSMAXTYPES)
|
|
|
|
i = 0;
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Filesystem type [%s]: ", fstypenames[i]);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
2000-08-15 02:37:08 +04:00
|
|
|
if (!strcmp(line, "?")) {
|
|
|
|
dumpnames("Supported file system types",
|
|
|
|
fstypenames, FSMAXTYPES);
|
1997-03-09 02:46:08 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-08-15 02:37:08 +04:00
|
|
|
for (i = 0; i < FSMAXTYPES; i++)
|
|
|
|
if (!strcasecmp(line, fstypenames[i])) {
|
|
|
|
p->p_fstype = i;
|
|
|
|
goto done_typename;
|
|
|
|
}
|
|
|
|
printf("Invalid file system typename `%s'\n", line);
|
|
|
|
continue;
|
2000-12-24 08:59:11 +03:00
|
|
|
done_typename:
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (;;) {
|
2000-12-24 08:59:11 +03:00
|
|
|
defnum(lp, def, p->p_offset);
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Start offset ('x' to start after partition"
|
|
|
|
" 'x') [%s]: ", def);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
2003-12-29 22:12:29 +03:00
|
|
|
if (line[1] == '\0' &&
|
|
|
|
line[0] >= 'a' && line[0] < 'a' + getmaxpartitions()) {
|
|
|
|
struct partition *cp = lp->d_partitions;
|
|
|
|
|
|
|
|
if ((cp[line[0] - 'a'].p_offset +
|
|
|
|
cp[line[0] - 'a'].p_size) >= lp->d_secperunit) {
|
|
|
|
printf("Bad offset `%s'\n", line);
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
p->p_offset = cp[line[0] - 'a'].p_offset +
|
|
|
|
cp[line[0] - 'a'].p_size;
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-28 11:40:53 +04:00
|
|
|
if ((im = getnum(lp, line, 0)) == -1 || im < 0) {
|
2003-12-29 22:12:29 +03:00
|
|
|
printf("Bad offset `%s'\n", line);
|
|
|
|
continue;
|
2010-05-28 11:40:53 +04:00
|
|
|
} else if (im > 0xffffffffLL ||
|
|
|
|
(uint32_t)im > lp->d_secperunit) {
|
2003-12-29 22:12:29 +03:00
|
|
|
printf("Offset `%s' out of range\n", line);
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-28 11:40:53 +04:00
|
|
|
p->p_offset = (uint32_t)im;
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (;;) {
|
2000-12-24 08:59:11 +03:00
|
|
|
defnum(lp, def, p->p_size);
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Partition size ('$' for all remaining) "
|
|
|
|
"[%s]: ", def);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
else if (i == 0)
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
2010-05-28 11:40:53 +04:00
|
|
|
if ((im = getnum(lp, line, lp->d_secperunit - p->p_offset))
|
1999-12-17 15:30:02 +03:00
|
|
|
== -1) {
|
1997-03-09 02:46:08 +03:00
|
|
|
printf("Bad size `%s'\n", line);
|
|
|
|
continue;
|
2010-05-28 11:40:53 +04:00
|
|
|
} else if (im > 0xffffffffLL ||
|
|
|
|
(im + p->p_offset) > lp->d_secperunit) {
|
2002-06-29 19:24:03 +04:00
|
|
|
printf("Size `%s' out of range\n", line);
|
|
|
|
continue;
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
2010-05-28 11:40:53 +04:00
|
|
|
p->p_size = im;
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
|
|
|
}
|
1999-05-03 13:45:01 +04:00
|
|
|
|
2003-12-29 22:12:29 +03:00
|
|
|
if (memcmp(&ps, p, sizeof(ps)))
|
|
|
|
showpartition(stdout, lp, part, Cflag);
|
1999-05-03 13:45:01 +04:00
|
|
|
if (chaining) {
|
2001-05-26 23:48:32 +04:00
|
|
|
int offs = -1;
|
|
|
|
struct partition *cp = lp->d_partitions;
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++) {
|
|
|
|
if (cp[i].p_fstype != FS_UNUSED) {
|
2009-03-16 15:56:19 +03:00
|
|
|
if (offs != -1 && cp[i].p_offset != (uint32_t)offs) {
|
2001-05-26 23:48:32 +04:00
|
|
|
cp[i].p_offset = offs;
|
2003-12-29 22:12:29 +03:00
|
|
|
showpartition(stdout, lp, i, Cflag);
|
|
|
|
}
|
2001-05-26 23:48:32 +04:00
|
|
|
offs = cp[i].p_offset + cp[i].p_size;
|
1999-05-03 13:45:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
cmd_label(struct disklabel *lp, char *s, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
char line[BUFSIZ];
|
|
|
|
int i;
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2013-01-16 03:52:48 +04:00
|
|
|
i = getinput(line, "Label disk [n]?");
|
1999-09-05 11:27:55 +04:00
|
|
|
if (i <= 0 || (*line != 'y' && *line != 'Y') )
|
1997-03-09 02:46:08 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (checklabel(lp) != 0) {
|
|
|
|
printf("Label not written\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-20 01:22:21 +04:00
|
|
|
if (writelabel(fd, lp) != 0) {
|
1997-09-19 02:20:36 +04:00
|
|
|
printf("Label not written\n");
|
1997-03-09 02:46:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("Label written\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 19:16:31 +03:00
|
|
|
static void
|
|
|
|
cmd_listfstypes(struct disklabel *lp, char *s, int fd)
|
|
|
|
{
|
|
|
|
|
|
|
|
(void)list_fs_types();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
runcmd(struct disklabel *lp, char *line, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
|
|
|
struct cmds *cmd;
|
|
|
|
|
|
|
|
for (cmd = cmds; cmd->name != NULL; cmd++)
|
|
|
|
if (strncmp(line, cmd->name, strlen(cmd->name)) == 0) {
|
|
|
|
if (cmd->func == NULL)
|
|
|
|
return -1;
|
|
|
|
(*cmd->func)(lp, line, fd);
|
1997-07-01 02:51:27 +04:00
|
|
|
return 0;
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
1997-03-09 03:14:17 +03:00
|
|
|
|
|
|
|
if (line[1] == '\0' &&
|
|
|
|
line[0] >= 'a' && line[0] < 'a' + getmaxpartitions()) {
|
|
|
|
cmd_part(lp, line, fd);
|
1997-07-01 02:51:27 +04:00
|
|
|
return 0;
|
1997-03-09 03:14:17 +03:00
|
|
|
}
|
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
printf("Unknown command %s\n", line);
|
1997-07-01 02:51:27 +04:00
|
|
|
return 1;
|
1997-03-09 02:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-01-16 03:52:48 +04:00
|
|
|
getinput(char *line, const char *prompt, ...)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, prompt);
|
|
|
|
vprintf(prompt, ap);
|
|
|
|
va_end(ap);
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
if (fgets(line, BUFSIZ, stdin) == NULL)
|
|
|
|
return -1;
|
2013-01-16 03:52:48 +04:00
|
|
|
if (line[0] == '\n' || line[0] == '\0')
|
|
|
|
return 0;
|
1997-03-09 02:46:08 +03:00
|
|
|
else {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = strrchr(line, '\n')) != NULL)
|
|
|
|
*p = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 02:37:08 +04:00
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
alphacmp(const void *a, const void *b)
|
2000-08-15 02:37:08 +04:00
|
|
|
{
|
|
|
|
|
2005-06-27 05:00:04 +04:00
|
|
|
return (strcasecmp(*(const char * const*)a, *(const char * const*)b));
|
2000-08-15 02:37:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
dumpnames(const char *prompt, const char * const *olist, size_t numentries)
|
2000-08-15 02:37:08 +04:00
|
|
|
{
|
2009-03-16 15:56:19 +03:00
|
|
|
int w;
|
|
|
|
size_t i, entry, lines;
|
|
|
|
int columns, width;
|
2000-08-15 02:37:08 +04:00
|
|
|
const char *p;
|
|
|
|
const char **list;
|
|
|
|
|
2006-03-17 17:50:44 +03:00
|
|
|
if ((list = (const char **)malloc(sizeof(char *) * numentries)) == NULL)
|
|
|
|
err(1, "malloc");
|
2000-08-15 02:37:08 +04:00
|
|
|
width = 0;
|
|
|
|
printf("%s:\n", prompt);
|
|
|
|
for (i = 0; i < numentries; i++) {
|
|
|
|
list[i] = olist[i];
|
|
|
|
w = strlen(list[i]);
|
|
|
|
if (w > width)
|
|
|
|
width = w;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
for (i = 0; i < numentries; i++)
|
|
|
|
printf("%s%s", i == 0 ? "" : ", ", list[i]);
|
|
|
|
puts("");
|
|
|
|
#endif
|
2001-10-19 05:16:37 +04:00
|
|
|
(void)qsort(list, numentries, sizeof(char *), alphacmp);
|
2000-08-15 02:37:08 +04:00
|
|
|
width++; /* want two spaces between items */
|
|
|
|
width = (width + 8) &~ 7;
|
|
|
|
|
|
|
|
#define ttywidth 72
|
|
|
|
columns = ttywidth / width;
|
|
|
|
#undef ttywidth
|
|
|
|
if (columns == 0)
|
|
|
|
columns = 1;
|
|
|
|
lines = (numentries + columns - 1) / columns;
|
2006-03-18 15:48:35 +03:00
|
|
|
/* Output sorted by columns */
|
2000-08-15 02:37:08 +04:00
|
|
|
for (i = 0; i < lines; i++) {
|
2006-03-18 15:48:35 +03:00
|
|
|
putc('\t', stdout);
|
|
|
|
entry = i;
|
|
|
|
for (;;) {
|
|
|
|
p = list[entry];
|
|
|
|
fputs(p, stdout);
|
|
|
|
entry += lines;
|
|
|
|
if (entry >= numentries)
|
2000-08-15 02:37:08 +04:00
|
|
|
break;
|
|
|
|
w = strlen(p);
|
|
|
|
while (w < width) {
|
2006-03-18 15:48:35 +03:00
|
|
|
w = (w + 8) & ~7;
|
2000-08-15 02:37:08 +04:00
|
|
|
putc('\t', stdout);
|
|
|
|
}
|
|
|
|
}
|
2006-03-18 15:48:35 +03:00
|
|
|
putc('\n', stdout);
|
2000-08-15 02:37:08 +04:00
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
static void
|
2003-10-20 17:20:20 +04:00
|
|
|
defnum(struct disklabel *lp, char *buf, uint32_t size)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
|
2011-01-07 00:39:01 +03:00
|
|
|
(void) snprintf(buf, BUFSIZ, "%.40gc, %" PRIu32 "s, %.40gM",
|
1997-03-09 02:46:08 +03:00
|
|
|
size / (float) lp->d_secpercyl,
|
|
|
|
size, size * (lp->d_secsize / (float) (1024 * 1024)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-28 11:40:53 +04:00
|
|
|
static intmax_t
|
|
|
|
getnum(struct disklabel *lp, char *buf, intmax_t defaultval)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
char *ep;
|
|
|
|
double d;
|
2010-05-28 11:40:53 +04:00
|
|
|
intmax_t rv;
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2010-05-28 11:40:53 +04:00
|
|
|
if (defaultval && buf[0] == '$' && buf[1] == 0)
|
|
|
|
return defaultval;
|
1999-12-17 15:30:02 +03:00
|
|
|
|
|
|
|
d = strtod(buf, &ep);
|
1997-03-09 02:46:08 +03:00
|
|
|
if (buf == ep)
|
|
|
|
return -1;
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
#define ROUND(a) ((((a) / lp->d_secpercyl) + \
|
|
|
|
(((a) % lp->d_secpercyl) ? 1 : 0)) * lp->d_secpercyl)
|
1997-03-09 02:46:08 +03:00
|
|
|
|
|
|
|
switch (*ep) {
|
|
|
|
case '\0':
|
|
|
|
case 's':
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'S':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) d;
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'C':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) (d * lp->d_secpercyl);
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
|
|
|
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'k':
|
|
|
|
case 'K':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) (d * 1024 / lp->d_secsize);
|
2005-04-08 01:27:44 +04:00
|
|
|
break;
|
|
|
|
|
2000-08-15 02:37:08 +04:00
|
|
|
case 'm':
|
1997-03-09 02:46:08 +03:00
|
|
|
case 'M':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) (d * 1024 * 1024 / lp->d_secsize);
|
1997-03-09 02:46:08 +03:00
|
|
|
break;
|
|
|
|
|
2005-04-08 01:27:44 +04:00
|
|
|
case 'g':
|
|
|
|
case 'G':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) (d * 1024 * 1024 * 1024 / lp->d_secsize);
|
2005-04-08 01:27:44 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
2010-05-28 11:40:53 +04:00
|
|
|
rv = (intmax_t) (d * 1024 * 1024 * 1024 * 1024 / lp->d_secsize);
|
2005-04-08 01:27:44 +04:00
|
|
|
break;
|
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
default:
|
|
|
|
printf("Unit error %c\n", *ep);
|
2005-04-08 01:27:44 +04:00
|
|
|
printf("Valid units: (S)ectors, (C)ylinders, (K)ilo, (M)ega, "
|
|
|
|
"(G)iga, (T)era");
|
1997-03-09 02:46:08 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rounding)
|
|
|
|
return ROUND(rv);
|
|
|
|
else
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-12-24 08:59:11 +03:00
|
|
|
interact(struct disklabel *lp, int fd)
|
1997-03-09 02:46:08 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
char line[BUFSIZ];
|
1997-03-09 02:46:08 +03:00
|
|
|
|
2009-11-28 13:52:10 +03:00
|
|
|
puts("Enter '?' for help");
|
1997-03-09 02:46:08 +03:00
|
|
|
for (;;) {
|
2013-01-16 03:52:48 +04:00
|
|
|
int i = getinput(line, "partition>");
|
|
|
|
if (i == -1)
|
1997-03-09 02:46:08 +03:00
|
|
|
return;
|
2013-01-16 03:52:48 +04:00
|
|
|
if (i == 0)
|
|
|
|
continue;
|
2000-12-24 08:59:11 +03:00
|
|
|
if (runcmd(lp, line, fd) == -1)
|
1997-03-09 02:46:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|