Merge branch 'sfdisk' of git://github.com/kerolasa/lelux-utiliteetit

* 'sfdisk' of git://github.com/kerolasa/lelux-utiliteetit:
  Merge branch 'master', remote-tracking branch 'upstream/master'
  sfdisk: fix for data type mismatches
  sfdisk: fix implicit overflow
  docs: sfdisk manual update
  sfdisk: previously undocumented options to usage
  sfdisk: help screen format
  sfdisk: declare unused function attributes
This commit is contained in:
Karel Zak 2011-06-29 12:12:48 +02:00
commit fa41c8b530
2 changed files with 164 additions and 88 deletions

View File

@ -165,7 +165,7 @@ Print version number of
.B sfdisk
and exit immediately.
.TP
.BR \-? " or " \-\-help
.BR \-h " or " \-\-help
Print a usage message and exit immediately.
.TP
.BR \-T " or " \-\-list\-types
@ -184,7 +184,7 @@ the partition table.
.BR \-l " or " \-\-list
List the partitions of a device.
.TP
.BR \-d
.BR \-d " or " \-\-dump
Dump the partitions of a device in a format useful as input
to sfdisk. For example,
.br
@ -218,7 +218,7 @@ and change nothing else. (Probably this fifth partition
is called /dev/hdb5, but you are free to call it something else,
like `/my_equipment/disks/2/5' or so).
.TP
.BI \-A " number"
.BI \-A " or " \-\-activate " number"
Make the indicated partition(s) active, and all others inactive.
.TP
.BI \-c "\fR or " \-\-id " number [Id]"
@ -238,22 +238,22 @@ For example:
.fi
first reports that /dev/hdb5 has Id 6, and then changes that into 83.
.TP
.BR \-uS " or " \-uB " or " \-uC " or " \-uM
Accept or report in units of sectors (blocks, cylinders, megabytes,
respectively). The default is cylinders, at least when the geometry
is known.
.BR \-u " or " \-\-unit " SBCM"
Accept as input, or when reporting show, in units of Sectors
(Blocks, Cylinders, Megabytes, respectively). The default is
cylinders, at least when the geometry is known.
.TP
.BR \-x " or " \-\-show\-extended
Also list non-primary extended partitions on output,
and expect descriptors for them on input.
.TP
.BI \-C " cylinders"
.BI \-C " or " \-\-cylinders " cylinders"
Specify the number of cylinders, possibly overriding what the kernel thinks.
.TP
.BI \-H " heads"
.BI \-H " or " \-\-heads " heads"
Specify the number of heads, possibly overriding what the kernel thinks.
.TP
.BI \-S " sectors"
.BI \-S " or " \-\-sectors " sectors"
Specify the number of sectors, possibly overriding what the kernel thinks.
.TP
.BR \-f " or " \-\-force
@ -301,7 +301,7 @@ Sometimes the last cylinder contains a bad sector table.
.B \-n
Go through all the motions, but do not actually write to disk.
.TP
.B \-R
.B \-R " or " \-\-re-read
Only execute the BLKRRPART ioctl (to make the kernel re-read
the partition table). This can be useful for checking in advance
that the final BLKRRPART will be successful, and also when you
@ -316,6 +316,33 @@ is not mounted, or in use as a swap device, and refuses to continue
if it is. This option suppresses the test. (On the other hand, the \-f
option would force sfdisk to continue even when this test fails.)
.TP
.B \-\-in\-order
Caution, see warning section. To be documented.
.TP
.B \-\-not\-in\-order
Caution, see warning section. To be documented.
.TP
.B \-\-inside\-order
Caution, see warning section. Chaining order.
.TP
.B \-\-not\-inside\-order
Caution, see warning section. Chaining order.
.TP
.B \-\-nested
Caution, see warning section. Every partition is contained in the
surrounding partitions and is disjoint from all others.
.TP
.B \-\-chained
Caution, see warning section. Every data partition is contained in
the surrounding partitions and disjoint from all others, but
extended partitions may lie outside (insofar as allowed by
all_logicals_inside_outermost_extended).
.TP
.B \-\-onesector
Caution, see warning section. All data partitions are mutually
disjoint; extended partitions each use one sector only (except
perhaps for the outermost one).
.TP
.BI \-O " file"
Just before writing the new partition, output the sectors
that are going to be overwritten to
@ -479,7 +506,11 @@ and terminate with end-of-file (^D).
.B sfdisk
will assume that your input line represents the first of four,
that the second one is extended, and the 3rd and 4th are empty.)
.SH "CAUTION WARNIGNS"
The options marked with caution in the manual page are dangerous.
For example all functionality is not completely implemented,
which can be a reason for unexpected results.
.SH "DOS 6.x WARNING"
The DOS 6.x FORMAT command looks for some information in the first

View File

@ -1378,7 +1378,7 @@ extended_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
int i, moretodo = 1;
struct partition p;
struct part_desc *partitions = &(z->partitions[0]);
int pno = z->partno;
size_t pno = z->partno;
here = start = ep->start;
@ -1476,7 +1476,7 @@ bsd_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z) {
unsigned long start = ep->start;
struct sector *s;
struct part_desc *partitions = &(z->partitions[0]);
int pno = z->partno;
size_t pno = z->partno;
if (!(s = get_sector(dev,fd,start+1)))
return;
@ -1590,17 +1590,29 @@ msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
}
static int
osf_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
osf_partition(char *dev __attribute__ ((__unused__)),
int fd __attribute__ ((__unused__)),
unsigned long start __attribute__ ((__unused__)),
struct disk_desc *z __attribute__ ((__unused__)))
{
return 0;
}
static int
sun_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
sun_partition(char *dev __attribute__ ((__unused__)),
int fd __attribute__ ((__unused__)),
unsigned long start __attribute__ ((__unused__)),
struct disk_desc *z __attribute__ ((__unused__)))
{
return 0;
}
static int
amiga_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
amiga_partition(char *dev __attribute__ ((__unused__)),
int fd __attribute__ ((__unused__)),
unsigned long start __attribute__ ((__unused__)),
struct disk_desc *z __attribute__ ((__unused__)))
{
return 0;
}
@ -1635,7 +1647,7 @@ write_partitions(char *dev, int fd, struct disk_desc *z) {
if (p->ptype == DOS_TYPE) {
copy_from_part(&(p->p), s->data + p->offset);
s->data[510] = 0x55;
s->data[511] = 0xaa;
s->data[511] = (unsigned char) 0xaa;
}
}
if (save_sector_file) {
@ -1750,7 +1762,7 @@ read_stdin(char **fields, char *line, int fieldssize, int linesize) {
ip++;
if (*ip == 0)
return fno;
for(d = dumpflds; d-dumpflds < ARRAY_SIZE(dumpflds); d++) {
for(d = dumpflds; (size_t) (d - dumpflds) < ARRAY_SIZE(dumpflds); d++) {
if (!strncmp(ip, d->fldname, strlen(d->fldname))) {
ip += strlen(d->fldname);
while(isspace(*ip))
@ -1945,7 +1957,7 @@ compute_start_sect(struct part_desc *p, struct part_desc *ep) {
p->size += delta;
if (is_extended(p->p.sys_type) && boxes == ONESECTOR)
p->size = inc;
else if (old_size <= -delta) {
else if ((ssize_t) old_size <= (ssize_t) -delta) {
my_warn(_("no room for partition descriptor\n"));
return 0;
}
@ -2239,7 +2251,8 @@ read_partition(char *dev, int interactive, int pno, struct part_desc *ep,
static void
read_partition_chain(char *dev, int interactive, struct part_desc *ep,
struct disk_desc *z) {
int i, base;
int i;
size_t base;
eob = 0;
while (1) {
@ -2270,7 +2283,7 @@ read_partition_chain(char *dev, int interactive, struct part_desc *ep,
static void
read_input(char *dev, int interactive, struct disk_desc *z) {
int i;
size_t i;
struct part_desc *partitions = &(z->partitions[0]), *ep;
for (i=0; i < ARRAY_SIZE(z->partitions); i++)
@ -2296,47 +2309,64 @@ read_input(char *dev, int interactive, struct disk_desc *z) {
/*
* G. The command line
*/
static void usage(FILE * out)
{
static void version(void) {
printf("sfdisk (%s)\n", PACKAGE_STRING);
fprintf(out, _("\nUsage:\n"
" %s [options] device [...]\n"),
program_invocation_short_name);
fprintf(out, _("Device is something like /dev/hda or /dev/sda\n"));
fprintf(out, _("\nOptions:\n"
" -s, --show-size list size of a partition\n"
" -c, --id change or print partition Id\n"
" --change-id change Id\n"
" --print-id print Id\n"
" -l, --list list partitions of each device\n"
" -d, --dump idem, but in a format suitable for later input\n"
" -i, --increment number cylinders etc. from 1 instead of from 0\n"
" -u, --unit=[SBCM] units in sectors, blocks, cylinders or MB\n"
" -1, --one-only reserved option that does nothing currently\n"
" -T, --list-types list the known partition types\n"
" -D, --DOS for DOS-compatibility: waste a little space\n"
" -E, --DOS-extended DOS extended partition compatibility\n"
" -R, --re-read make kernel reread partition table\n"
" -N=NUM change only the partition with number NUM\n"
" -n do not actually write to disk\n"
" -O FILE save the sectors that will be overwritten to file\n"
" -I FILE restore sectors from file\n"
" -V, --verify check that listed partition is reasonable\n"
" -v, --version print version\n"
" -h, --help print this message\n"));
fprintf(out, _("\nDangerous options:\n"
" -f, --force disable all consistency checking\n"
" -g, --show-geometry print the kernel's idea of the geometry\n"
" -A, --activate[=device] activate bootable flag\n"
" -G, --show-pt-geometry print geometry guessed from the partition table\n"
" -U, --unhide[=device] set partition unhidden\n"
" --no-reread skip partition re-read at boot\n"
" -x, --show-extended also list extended partitions on output\n"
" or expect descriptors for them on input\n"
" --leave-last do not allocate the last cylinder\n"
" --IBM same as --leave-last\n"
" --in-order partitions are in order\n"
" --not-in-order partitions are not in order\n"
" --inside-order all logicals inside outermost extended\n"
" --not-inside-order not all logicals inside outermost extended\n"
" --nested every partition is disjoint from all others\n"
" --chained like nested, but extended partitions may lie outside\n"
" --onesector partitions are mutually disjoint\n"
" -L, --Linux do not complain about things irrelevant for Linux\n"
" -q, --quiet suppress warning messages\n"
"\n Override the detected geometry using:\n"
" -C, --cylinders=NUM set the number of cylinders to use\n"
" -H, --heads=NUM set the number of heads to use\n"
" -S, --sectors=NUM set the number of sectors to use\n\n"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
static void
usage(void) {
version();
printf(_("Usage: %s [options] device ...\n"), PROGNAME);
puts (_("device: something like /dev/hda or /dev/sda"));
puts (_("useful options:"));
puts (_(" -s [or --show-size]: list size of a partition"));
puts (_(" -c [or --id]: print or change partition Id"));
puts (_(" -l [or --list]: list partitions of each device"));
puts (_(" -d [or --dump]: idem, but in a format suitable for later input"));
puts (_(" -i [or --increment]: number cylinders etc. from 1 instead of from 0"));
puts (_(" -uS, -uB, -uC, -uM: accept/report in units of sectors/blocks/cylinders/MB"));
puts (_(" -T [or --list-types]:list the known partition types"));
puts (_(" -D [or --DOS]: for DOS-compatibility: waste a little space"));
puts (_(" -R [or --re-read]: make kernel reread partition table"));
puts (_(" -N# : change only the partition with number #"));
puts (_(" -n : do not actually write to disk"));
puts (_(" -O file : save the sectors that will be overwritten to file"));
puts (_(" -I file : restore these sectors again"));
puts (_(" -v [or --version]: print version"));
puts (_(" -? [or --help]: print this message"));
puts (_("dangerous options:"));
puts (_(" -g [or --show-geometry]: print the kernel's idea of the geometry"));
puts (_(" -G [or --show-pt-geometry]: print geometry guessed from the partition table"));
puts (_(" -x [or --show-extended]: also list extended partitions on output\n"
" or expect descriptors for them on input"));
puts (_(" -L [or --Linux]: do not complain about things irrelevant for Linux"));
puts (_(" -q [or --quiet]: suppress warning messages"));
puts (_(" You can override the detected geometry using:"));
puts (_(" -C# [or --cylinders #]:set the number of cylinders to use"));
puts (_(" -H# [or --heads #]: set the number of heads to use"));
puts (_(" -S# [or --sectors #]: set the number of sectors to use"));
puts (_("You can disable all consistency checking with:"));
puts (_(" -f [or --force]: do what I say, even if it is stupid"));
exit(1);
}
static void
activate_usage(char *progn) {
@ -2348,15 +2378,27 @@ activate_usage(char *progn) {
}
static void
unhide_usage(char *progn) {
unhide_usage(char *progn __attribute__ ((__unused__))) {
exit(1);
}
static char short_opts[] = "cdfgilnqsu:vx?1A::C:DGH:I:LN:O:RS:TU::V";
static const char short_opts[] = "cdfghilnqsu:vx1A::C:DGH:I:LN:O:RS:TU::V";
#define PRINT_ID 0400
#define CHANGE_ID 01000
enum {
OPT_NO_REREAD = CHAR_MAX + 1,
OPT_LEAVE_LAST,
OPT_IN_ORDER,
OPT_NOT_IN_ORDER,
OPT_INSIDE_OUTER,
OPT_NOT_INSIDE_OUTER,
OPT_NESTED,
OPT_CHAINED,
OPT_ONESECTOR
};
static const struct option long_opts[] = {
{ "change-id", no_argument, NULL, 'c' + CHANGE_ID },
{ "print-id", no_argument, NULL, 'c' + PRINT_ID },
@ -2364,6 +2406,7 @@ static const struct option long_opts[] = {
{ "dump", no_argument, NULL, 'd' },
{ "force", no_argument, NULL, 'f' },
{ "show-geometry", no_argument, NULL, 'g' },
{ "help", no_argument, NULL, 'h' },
{ "increment", no_argument, NULL, 'i' },
{ "list", no_argument, NULL, 'l' },
{ "quiet", no_argument, NULL, 'q' },
@ -2371,7 +2414,6 @@ static const struct option long_opts[] = {
{ "unit", required_argument, NULL, 'u' },
{ "version", no_argument, NULL, 'v' },
{ "show-extended", no_argument, NULL, 'x' },
{ "help", no_argument, NULL, '?' },
{ "one-only", no_argument, NULL, '1' },
{ "cylinders", required_argument, NULL, 'C' },
{ "heads", required_argument, NULL, 'H' },
@ -2384,17 +2426,17 @@ static const struct option long_opts[] = {
{ "re-read", no_argument, NULL, 'R' },
{ "list-types", no_argument, NULL, 'T' },
{ "unhide", optional_argument, NULL, 'U' },
{ "no-reread", no_argument, NULL, 160 },
{ "IBM", no_argument, NULL, 161 },
{ "leave-last", no_argument, NULL, 161 },
/* undocumented flags - not all completely implemented */
{ "in-order", no_argument, NULL, 128 },
{ "not-in-order", no_argument, NULL, 129 },
{ "inside-outer", no_argument, NULL, 130 },
{ "not-inside-outer", no_argument, NULL, 131 },
{ "nested", no_argument, NULL, 132 },
{ "chained", no_argument, NULL, 133 },
{ "onesector", no_argument, NULL, 134 },
{ "no-reread", no_argument, NULL, OPT_NO_REREAD },
{ "IBM", no_argument, NULL, OPT_LEAVE_LAST },
{ "leave-last", no_argument, NULL, OPT_LEAVE_LAST },
/* dangerous flags - not all completely implemented */
{ "in-order", no_argument, NULL, OPT_IN_ORDER },
{ "not-in-order", no_argument, NULL, OPT_NOT_IN_ORDER },
{ "inside-outer", no_argument, NULL, OPT_INSIDE_OUTER },
{ "not-inside-outer", no_argument, NULL, OPT_NOT_INSIDE_OUTER },
{ "nested", no_argument, NULL, OPT_NESTED },
{ "chained", no_argument, NULL, OPT_CHAINED },
{ "onesector", no_argument, NULL, OPT_ONESECTOR },
{ NULL, 0, NULL, 0 }
};
@ -2544,8 +2586,12 @@ main(int argc, char **argv) {
case 'u':
set_format(*optarg); break;
case 'v':
version();
exit(0);
printf(_("%s from %s\n"), program_invocation_short_name,
PACKAGE_STRING);
return EXIT_SUCCESS;
case 'h':
usage(stdout);
return EXIT_SUCCESS;
case 'x':
show_extended = 1; break;
case 'A':
@ -2579,30 +2625,29 @@ main(int argc, char **argv) {
unhide = 1; break;
case 'V':
verify = 1; break;
case '?':
default:
usage(); break;
usage(stderr); break;
/* undocumented flags */
case 128:
/* dangerous flags */
case OPT_IN_ORDER:
partitions_in_order = 1; break;
case 129:
case OPT_NOT_IN_ORDER:
partitions_in_order = 0; break;
case 130:
case OPT_INSIDE_OUTER:
all_logicals_inside_outermost_extended = 1; break;
case 131:
case OPT_NOT_INSIDE_OUTER:
all_logicals_inside_outermost_extended = 0; break;
case 132:
case OPT_NESTED:
boxes = NESTED; break;
case 133:
case OPT_CHAINED:
boxes = CHAINED; break;
case 134:
case OPT_ONESECTOR:
boxes = ONESECTOR; break;
/* more flags */
case 160:
case OPT_NO_REREAD:
no_reread = 1; break;
case 161:
case OPT_LEAVE_LAST:
leave_last = 1; break;
}
}
@ -2647,7 +2692,7 @@ main(int argc, char **argv) {
else if (unhide)
unhide_usage(fdisk ? "sfdisk -U" : progn);
else
usage();
usage(stderr);
}
if (opt_list || opt_out_geom || opt_out_pt_geom || opt_size || verify) {