Correct use of .Nm, use .Bx Free for FreeBSD. Add rcsid, remove unused
#includes. Spelling. Use err(3) and add usage().
This commit is contained in:
parent
f71f5262b1
commit
d98b16689b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37415
@ -5,7 +5,7 @@
|
||||
.Nm fdisk
|
||||
.Nd DOS partition maintenance program
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Nm fdisk
|
||||
.Op Fl i
|
||||
.Op Fl u
|
||||
.Op Fl a
|
||||
@ -42,8 +42,9 @@ The DOS
|
||||
program can be used to divide space on the disk into partitions and set one
|
||||
.Em active .
|
||||
.Sh DESCRIPTION
|
||||
.Pp
|
||||
The FreeBSD program
|
||||
The
|
||||
.Bx Free
|
||||
program
|
||||
.Nm
|
||||
serves a similar purpose to the DOS program. The first form is used to
|
||||
display partition information or to interactively edit the partition
|
||||
@ -57,7 +58,7 @@ Is used for updating (editing) sector 0 of the disk. Ignored if
|
||||
.Fl f
|
||||
is given.
|
||||
.It Fl i
|
||||
Initializes sector 0 of the disk. This implies
|
||||
Initialize sector 0 of the disk. This implies
|
||||
.Fl u ,
|
||||
unless
|
||||
.Fl f
|
||||
@ -85,10 +86,10 @@ is read. The
|
||||
can be "-", in which case
|
||||
.Ar stdin
|
||||
is read. See
|
||||
.Em CONFIGURATION FILE ,
|
||||
.Sx CONFIGURATION FILE ,
|
||||
below, for file syntax.
|
||||
.Pp
|
||||
.Em WARNING:
|
||||
.Em WARNING Ns :
|
||||
when
|
||||
.Fl f
|
||||
is used, you are not asked if you really want to write the partition
|
||||
@ -157,7 +158,9 @@ The second partition overlaps the end of the first.
|
||||
(Used for debugging purposes)
|
||||
.Bl -tag -width "cyl, sector and head"
|
||||
.It Em "sysid"
|
||||
is used to label the partition. FreeBSD reserves the
|
||||
is used to label the partition.
|
||||
.Bx Free
|
||||
reserves the
|
||||
magic number 165 decimal (A5 in hex).
|
||||
.It Em "start and size"
|
||||
fields provide the start address
|
||||
@ -184,7 +187,7 @@ option is not used, the
|
||||
.Nm
|
||||
program will enter a conversational mode.
|
||||
This mode is designed not to change any data unless you explicitly tell it to.
|
||||
.Nm
|
||||
.Nm Fdisk
|
||||
selects defaults for its questions to guarantee the above behavior.
|
||||
.Pp
|
||||
It displays each partition
|
||||
@ -195,7 +198,7 @@ and asking for a new one.
|
||||
When you are done with a partition,
|
||||
.Nm
|
||||
will display it and ask if it is correct.
|
||||
.Nm
|
||||
.Nm Fdisk
|
||||
will then proceed to the next entry.
|
||||
.Pp
|
||||
Getting the
|
||||
@ -228,10 +231,10 @@ flag just edits the fields as they appear on the disk.
|
||||
While the
|
||||
.Fl i
|
||||
flag is used to "initialize" sector 0;
|
||||
it will setup the last BIOS partition to use the whole disk for FreeBSD;
|
||||
it will setup the last BIOS partition to use the whole disk for
|
||||
.Bx Free ;
|
||||
and make it active.
|
||||
.Sh NOTES
|
||||
.Pp
|
||||
The automatic calculation of starting cylinder etc. uses
|
||||
a set of figures that represent what the BIOS thinks is the
|
||||
geometry of the drive.
|
||||
@ -241,7 +244,9 @@ This allows the user to create a bootblock that can work with drives
|
||||
that use geometry translation under the BIOS.
|
||||
.Pp
|
||||
If you hand craft your disk layout,
|
||||
please make sure that the FreeBSD partition starts on a cylinder boundary.
|
||||
please make sure that the
|
||||
.Bx Free
|
||||
partition starts on a cylinder boundary.
|
||||
A number of decisions made later may assume this.
|
||||
(This might not be necessary later.)
|
||||
.Pp
|
||||
@ -253,7 +258,6 @@ works. This is completely safe as long as you answer the last question
|
||||
in the negative. There are subtleties that the program detects that are
|
||||
not fully explained in this manual page.
|
||||
.Sh CONFIGURATION FILE
|
||||
.Pp
|
||||
When the
|
||||
.Fl f
|
||||
option is given, a disk's partition table can be written using values
|
||||
@ -309,7 +313,8 @@ It is an error if the following is not true:
|
||||
.Pp
|
||||
The number of cylinders should be less than or equal to 1024, but this
|
||||
is not enforced, although a warning will be output. Note that bootable
|
||||
FreeBSD partitions (the "/" filesystem) must lie completely within the
|
||||
.Bx Free
|
||||
partitions (the "/" filesystem) must lie completely within the
|
||||
first 1024 cylinders; if this is not true, booting may fail.
|
||||
Non-bootable partitions do not have this restriction.
|
||||
.Pp
|
||||
@ -352,7 +357,9 @@ if one is present.
|
||||
.Pp
|
||||
The
|
||||
.Ar type
|
||||
is 165 for FreeBSD partitions. Specifying a partition type of zero is
|
||||
is 165 for
|
||||
.Bx Free
|
||||
partitions. Specifying a partition type of zero is
|
||||
the same as clearing the partition and marking it as unused; however,
|
||||
dummy values (such as "0") must still be specified for
|
||||
.Ar start
|
||||
@ -369,7 +376,9 @@ Example: to clear partition 4 and mark it as unused:
|
||||
p 4 0 0 0
|
||||
.fi
|
||||
.Pp
|
||||
Example: to set partition 1 to a FreeBSD partition, starting at sector 1
|
||||
Example: to set partition 1 to a
|
||||
.Bx Free
|
||||
partition, starting at sector 1
|
||||
for 2503871 sectors (note: these numbers will be rounded upwards and
|
||||
downwards to correspond to head and cylinder boundaries):
|
||||
.Pp
|
||||
@ -404,6 +413,8 @@ is used where it should actually be
|
||||
.Sq slice ,
|
||||
in order to conform with the terms used elsewhere.
|
||||
.Pp
|
||||
You cannot use this command to completely dedicate a disk to FreeBSD. The
|
||||
You cannot use this command to completely dedicate a disk to
|
||||
.Bx Free .
|
||||
The
|
||||
.Xr disklabel 8
|
||||
command must be used for this.
|
||||
|
@ -24,14 +24,20 @@
|
||||
* the rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/disklabel.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int iotest;
|
||||
@ -64,15 +70,13 @@ const char *disks[] =
|
||||
"/dev/rwd0", "/dev/rsd0", "/dev/rod0", 0
|
||||
};
|
||||
|
||||
char *name;
|
||||
|
||||
struct disklabel disklabel; /* disk parameters */
|
||||
|
||||
int cyls, sectors, heads, cylsecs, disksecs;
|
||||
|
||||
struct mboot
|
||||
{
|
||||
unsigned char padding[2]; /* force the longs to be long alligned */
|
||||
unsigned char padding[2]; /* force the longs to be long aligned */
|
||||
unsigned char bootinst[DOSPARTOFF];
|
||||
struct dos_partition parts[4];
|
||||
unsigned short int signature;
|
||||
@ -228,6 +232,7 @@ static int decimal(char *str, int *num, int deflt);
|
||||
static char *get_type(int type);
|
||||
static int read_config(char *config_file);
|
||||
static void reset_boot(void);
|
||||
static void usage(void);
|
||||
#if 0
|
||||
static int hex(char *str, int *num, int deflt);
|
||||
static int string(char *str, char **ans);
|
||||
@ -239,11 +244,6 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
name = *argv;
|
||||
{register char *cp = name;
|
||||
while (*cp) if (*cp++ == '/') name = cp;
|
||||
}
|
||||
|
||||
for ( argv++ ; --argc ; argv++ ) { register char *token = *argv;
|
||||
if (*token++ != '-' || !*token)
|
||||
break;
|
||||
@ -274,9 +274,7 @@ main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
goto usage;
|
||||
}
|
||||
usage();
|
||||
--argc;
|
||||
f_flag = *++argv;
|
||||
}
|
||||
@ -297,7 +295,7 @@ main(int argc, char *argv[])
|
||||
v_flag = 1;
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,11 +314,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (open_disk(u_flag) < 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot open disk %s (%s)\n",
|
||||
disk, sys_errlist[errno]);
|
||||
exit(1);
|
||||
}
|
||||
err(1, "cannot open disk %s", disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -333,11 +327,7 @@ main(int argc, char *argv[])
|
||||
if(rv != -2) break;
|
||||
}
|
||||
if(rv < 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot open any disk (%s)\n",
|
||||
sys_errlist[errno]);
|
||||
exit(1);
|
||||
}
|
||||
err(1, "cannot open any disk");
|
||||
}
|
||||
|
||||
printf("******* Working on device %s *******\n",disk);
|
||||
@ -408,10 +398,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usage:
|
||||
printf("fdisk {-a|-i|-u} [-f <config file> [-t] [-v]] [-{1,2,3,4}] [disk]\n");
|
||||
return(1);
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: fdisk {-a|-i|-u} [-f <config file> [-t] [-v]] [-{1,2,3,4}] [disk]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -648,22 +642,19 @@ open_disk(int u_flag)
|
||||
struct stat st;
|
||||
|
||||
if (stat(disk, &st) == -1) {
|
||||
fprintf(stderr, "%s: Can't get file status of %s\n",
|
||||
name, disk);
|
||||
warnx("can't get file status of %s", disk);
|
||||
return -1;
|
||||
}
|
||||
if ( !(st.st_mode & S_IFCHR) )
|
||||
fprintf(stderr,"%s: Device %s is not character special\n",
|
||||
name, disk);
|
||||
warnx("device %s is not character special", disk);
|
||||
if ((fd = open(disk, a_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) {
|
||||
if(errno == ENXIO)
|
||||
return -2;
|
||||
fprintf(stderr,"%s: Can't open device %s\n", name, disk);
|
||||
warnx("can't open device %s", disk);
|
||||
return -1;
|
||||
}
|
||||
if (get_params(0) == -1) {
|
||||
fprintf(stderr, "%s: Can't get disk parameters on %s\n",
|
||||
name, disk);
|
||||
warnx("can't get disk parameters on %s", disk);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
@ -702,9 +693,7 @@ get_params()
|
||||
{
|
||||
|
||||
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
|
||||
fprintf(stderr,
|
||||
"%s: Can't get disk parameters on %s; supplying dummy ones\n",
|
||||
name, disk);
|
||||
warnx("can't get disk parameters on %s; supplying dummy ones", disk);
|
||||
dos_cyls = cyls = 1;
|
||||
dos_heads = heads = 1;
|
||||
dos_sectors = sectors = 1;
|
||||
@ -727,12 +716,11 @@ static int
|
||||
read_s0()
|
||||
{
|
||||
if (read_disk(0, (char *) mboot.bootinst) == -1) {
|
||||
fprintf(stderr, "%s: Can't read fdisk partition table\n", name);
|
||||
warnx("can't read fdisk partition table");
|
||||
return -1;
|
||||
}
|
||||
if (mboot.signature != BOOT_MAGIC) {
|
||||
fprintf(stderr, "%s: Invalid fdisk partition table found\n",
|
||||
name);
|
||||
warnx("invalid fdisk partition table found");
|
||||
/* So should we initialize things */
|
||||
return -1;
|
||||
}
|
||||
@ -756,11 +744,10 @@ write_s0()
|
||||
flag = 1;
|
||||
#ifdef NOT_NOW
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
perror("ioctl DIOCWLABEL");
|
||||
warn("ioctl DIOCWLABEL");
|
||||
#endif
|
||||
if (write_disk(0, (char *) mboot.bootinst) == -1) {
|
||||
fprintf(stderr, "%s: Can't write fdisk partition table\n",
|
||||
name);
|
||||
warnx("can't write fdisk partition table");
|
||||
return -1;
|
||||
flag = 0;
|
||||
#ifdef NOT_NOW
|
||||
@ -979,18 +966,17 @@ process_geometry(command)
|
||||
geom_processed = 1;
|
||||
if (part_processed)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: the geometry specification line must occur before\n\
|
||||
all partition specifications.\n",
|
||||
name, current_line_number);
|
||||
warnx(
|
||||
"ERROR line %d: the geometry specification line must occur before\n\
|
||||
all partition specifications",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
if (command->n_args != 3)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of geometry args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of geometry args",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
@ -1011,9 +997,9 @@ process_geometry(command)
|
||||
dos_sectors = command->args[i].arg_val;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: unknown geometry arg type: '%c' (0x%02x)\n",
|
||||
name, current_line_number, command->args[i].argtype,
|
||||
warnx(
|
||||
"ERROR line %d: unknown geometry arg type: '%c' (0x%02x)",
|
||||
current_line_number, command->args[i].argtype,
|
||||
command->args[i].argtype);
|
||||
status = 0;
|
||||
break;
|
||||
@ -1031,46 +1017,42 @@ process_geometry(command)
|
||||
*/
|
||||
if (dos_cyls < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of cylinders not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of cylinders not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
if (dos_cyls == 0 || dos_cyls > 1024)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: WARNING line %d: number of cylinders (%d) may be out-of-range\n\
|
||||
warnx(
|
||||
"WARNING line %d: number of cylinders (%d) may be out-of-range\n\
|
||||
(must be within 1-1024 for normal BIOS operation, unless the entire disk\n\
|
||||
is dedicated to FreeBSD).\n",
|
||||
name, current_line_number, dos_cyls);
|
||||
is dedicated to FreeBSD)",
|
||||
current_line_number, dos_cyls);
|
||||
}
|
||||
|
||||
if (dos_heads < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of heads not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of heads not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
else if (dos_heads < 1 || dos_heads > 256)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of heads must be within (1-256)\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of heads must be within (1-256)",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
|
||||
if (dos_sectors < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: number of sectors not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of sectors not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
else if (dos_sectors < 1 || dos_sectors > 63)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of sectors must be within (1-63)\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of sectors must be within (1-63)",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
|
||||
@ -1093,16 +1075,15 @@ process_partition(command)
|
||||
part_processed = 1;
|
||||
if (command->n_args != 4)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of partition args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of partition args",
|
||||
current_line_number);
|
||||
break;
|
||||
}
|
||||
partition = command->args[0].arg_val;
|
||||
if (partition < 1 || partition > 4)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: invalid partition number %d\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: invalid partition number %d",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
partp = ((struct dos_partition *) &mboot.parts) + partition - 1;
|
||||
@ -1137,16 +1118,16 @@ process_partition(command)
|
||||
/*
|
||||
* Can't go past end of partition
|
||||
*/
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: unable to adjust start of partition %d to fall on\n\
|
||||
a cylinder boundary.\n",
|
||||
name, current_line_number, partition);
|
||||
warnx(
|
||||
"ERROR line %d: unable to adjust start of partition %d to fall on\n\
|
||||
a cylinder boundary",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%s: WARNING: adjusting start offset of partition '%d' from %lu\n\
|
||||
to %lu, to round to an head boundary.\n",
|
||||
name, partition, (u_long)partp->dp_start, adj_size);
|
||||
warnx(
|
||||
"WARNING: adjusting start offset of partition '%d' from %lu\n\
|
||||
to %lu, to round to an head boundary",
|
||||
partition, (u_long)partp->dp_start, adj_size);
|
||||
partp->dp_start = adj_size;
|
||||
}
|
||||
|
||||
@ -1159,10 +1140,10 @@ process_partition(command)
|
||||
adj_size = chunks - partp->dp_start;
|
||||
if (adj_size != partp->dp_size)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: WARNING: adjusting size of partition '%d' from %lu to %lu,\n\
|
||||
to round to a cylinder boundary.\n",
|
||||
name, partition, (u_long)partp->dp_size, adj_size);
|
||||
warnx(
|
||||
"WARNING: adjusting size of partition '%d' from %lu to %lu,\n\
|
||||
to round to a cylinder boundary",
|
||||
partition, (u_long)partp->dp_size, adj_size);
|
||||
if (chunks > 0)
|
||||
{
|
||||
partp->dp_size = adj_size;
|
||||
@ -1174,9 +1155,8 @@ process_partition(command)
|
||||
}
|
||||
if (partp->dp_size < 1)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: size for partition '%d' is zero.\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: size for partition '%d' is zero",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1203,17 +1183,16 @@ process_active(command)
|
||||
active_processed = 1;
|
||||
if (command->n_args != 1)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of active args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of active args",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
partition = command->args[0].arg_val;
|
||||
if (partition < 1 || partition > 4)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: invalid partition number %d\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: invalid partition number %d",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
|
@ -5,7 +5,7 @@
|
||||
.Nm fdisk
|
||||
.Nd DOS partition maintenance program
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Nm fdisk
|
||||
.Op Fl i
|
||||
.Op Fl u
|
||||
.Op Fl a
|
||||
@ -42,8 +42,9 @@ The DOS
|
||||
program can be used to divide space on the disk into partitions and set one
|
||||
.Em active .
|
||||
.Sh DESCRIPTION
|
||||
.Pp
|
||||
The FreeBSD program
|
||||
The
|
||||
.Bx Free
|
||||
program
|
||||
.Nm
|
||||
serves a similar purpose to the DOS program. The first form is used to
|
||||
display partition information or to interactively edit the partition
|
||||
@ -57,7 +58,7 @@ Is used for updating (editing) sector 0 of the disk. Ignored if
|
||||
.Fl f
|
||||
is given.
|
||||
.It Fl i
|
||||
Initializes sector 0 of the disk. This implies
|
||||
Initialize sector 0 of the disk. This implies
|
||||
.Fl u ,
|
||||
unless
|
||||
.Fl f
|
||||
@ -85,10 +86,10 @@ is read. The
|
||||
can be "-", in which case
|
||||
.Ar stdin
|
||||
is read. See
|
||||
.Em CONFIGURATION FILE ,
|
||||
.Sx CONFIGURATION FILE ,
|
||||
below, for file syntax.
|
||||
.Pp
|
||||
.Em WARNING:
|
||||
.Em WARNING Ns :
|
||||
when
|
||||
.Fl f
|
||||
is used, you are not asked if you really want to write the partition
|
||||
@ -157,7 +158,9 @@ The second partition overlaps the end of the first.
|
||||
(Used for debugging purposes)
|
||||
.Bl -tag -width "cyl, sector and head"
|
||||
.It Em "sysid"
|
||||
is used to label the partition. FreeBSD reserves the
|
||||
is used to label the partition.
|
||||
.Bx Free
|
||||
reserves the
|
||||
magic number 165 decimal (A5 in hex).
|
||||
.It Em "start and size"
|
||||
fields provide the start address
|
||||
@ -184,7 +187,7 @@ option is not used, the
|
||||
.Nm
|
||||
program will enter a conversational mode.
|
||||
This mode is designed not to change any data unless you explicitly tell it to.
|
||||
.Nm
|
||||
.Nm Fdisk
|
||||
selects defaults for its questions to guarantee the above behavior.
|
||||
.Pp
|
||||
It displays each partition
|
||||
@ -195,7 +198,7 @@ and asking for a new one.
|
||||
When you are done with a partition,
|
||||
.Nm
|
||||
will display it and ask if it is correct.
|
||||
.Nm
|
||||
.Nm Fdisk
|
||||
will then proceed to the next entry.
|
||||
.Pp
|
||||
Getting the
|
||||
@ -228,10 +231,10 @@ flag just edits the fields as they appear on the disk.
|
||||
While the
|
||||
.Fl i
|
||||
flag is used to "initialize" sector 0;
|
||||
it will setup the last BIOS partition to use the whole disk for FreeBSD;
|
||||
it will setup the last BIOS partition to use the whole disk for
|
||||
.Bx Free ;
|
||||
and make it active.
|
||||
.Sh NOTES
|
||||
.Pp
|
||||
The automatic calculation of starting cylinder etc. uses
|
||||
a set of figures that represent what the BIOS thinks is the
|
||||
geometry of the drive.
|
||||
@ -241,7 +244,9 @@ This allows the user to create a bootblock that can work with drives
|
||||
that use geometry translation under the BIOS.
|
||||
.Pp
|
||||
If you hand craft your disk layout,
|
||||
please make sure that the FreeBSD partition starts on a cylinder boundary.
|
||||
please make sure that the
|
||||
.Bx Free
|
||||
partition starts on a cylinder boundary.
|
||||
A number of decisions made later may assume this.
|
||||
(This might not be necessary later.)
|
||||
.Pp
|
||||
@ -253,7 +258,6 @@ works. This is completely safe as long as you answer the last question
|
||||
in the negative. There are subtleties that the program detects that are
|
||||
not fully explained in this manual page.
|
||||
.Sh CONFIGURATION FILE
|
||||
.Pp
|
||||
When the
|
||||
.Fl f
|
||||
option is given, a disk's partition table can be written using values
|
||||
@ -309,7 +313,8 @@ It is an error if the following is not true:
|
||||
.Pp
|
||||
The number of cylinders should be less than or equal to 1024, but this
|
||||
is not enforced, although a warning will be output. Note that bootable
|
||||
FreeBSD partitions (the "/" filesystem) must lie completely within the
|
||||
.Bx Free
|
||||
partitions (the "/" filesystem) must lie completely within the
|
||||
first 1024 cylinders; if this is not true, booting may fail.
|
||||
Non-bootable partitions do not have this restriction.
|
||||
.Pp
|
||||
@ -352,7 +357,9 @@ if one is present.
|
||||
.Pp
|
||||
The
|
||||
.Ar type
|
||||
is 165 for FreeBSD partitions. Specifying a partition type of zero is
|
||||
is 165 for
|
||||
.Bx Free
|
||||
partitions. Specifying a partition type of zero is
|
||||
the same as clearing the partition and marking it as unused; however,
|
||||
dummy values (such as "0") must still be specified for
|
||||
.Ar start
|
||||
@ -369,7 +376,9 @@ Example: to clear partition 4 and mark it as unused:
|
||||
p 4 0 0 0
|
||||
.fi
|
||||
.Pp
|
||||
Example: to set partition 1 to a FreeBSD partition, starting at sector 1
|
||||
Example: to set partition 1 to a
|
||||
.Bx Free
|
||||
partition, starting at sector 1
|
||||
for 2503871 sectors (note: these numbers will be rounded upwards and
|
||||
downwards to correspond to head and cylinder boundaries):
|
||||
.Pp
|
||||
@ -404,6 +413,8 @@ is used where it should actually be
|
||||
.Sq slice ,
|
||||
in order to conform with the terms used elsewhere.
|
||||
.Pp
|
||||
You cannot use this command to completely dedicate a disk to FreeBSD. The
|
||||
You cannot use this command to completely dedicate a disk to
|
||||
.Bx Free .
|
||||
The
|
||||
.Xr disklabel 8
|
||||
command must be used for this.
|
||||
|
@ -24,14 +24,20 @@
|
||||
* the rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/disklabel.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int iotest;
|
||||
@ -64,15 +70,13 @@ const char *disks[] =
|
||||
"/dev/rwd0", "/dev/rsd0", "/dev/rod0", 0
|
||||
};
|
||||
|
||||
char *name;
|
||||
|
||||
struct disklabel disklabel; /* disk parameters */
|
||||
|
||||
int cyls, sectors, heads, cylsecs, disksecs;
|
||||
|
||||
struct mboot
|
||||
{
|
||||
unsigned char padding[2]; /* force the longs to be long alligned */
|
||||
unsigned char padding[2]; /* force the longs to be long aligned */
|
||||
unsigned char bootinst[DOSPARTOFF];
|
||||
struct dos_partition parts[4];
|
||||
unsigned short int signature;
|
||||
@ -228,6 +232,7 @@ static int decimal(char *str, int *num, int deflt);
|
||||
static char *get_type(int type);
|
||||
static int read_config(char *config_file);
|
||||
static void reset_boot(void);
|
||||
static void usage(void);
|
||||
#if 0
|
||||
static int hex(char *str, int *num, int deflt);
|
||||
static int string(char *str, char **ans);
|
||||
@ -239,11 +244,6 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
name = *argv;
|
||||
{register char *cp = name;
|
||||
while (*cp) if (*cp++ == '/') name = cp;
|
||||
}
|
||||
|
||||
for ( argv++ ; --argc ; argv++ ) { register char *token = *argv;
|
||||
if (*token++ != '-' || !*token)
|
||||
break;
|
||||
@ -274,9 +274,7 @@ main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
goto usage;
|
||||
}
|
||||
usage();
|
||||
--argc;
|
||||
f_flag = *++argv;
|
||||
}
|
||||
@ -297,7 +295,7 @@ main(int argc, char *argv[])
|
||||
v_flag = 1;
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,11 +314,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (open_disk(u_flag) < 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot open disk %s (%s)\n",
|
||||
disk, sys_errlist[errno]);
|
||||
exit(1);
|
||||
}
|
||||
err(1, "cannot open disk %s", disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -333,11 +327,7 @@ main(int argc, char *argv[])
|
||||
if(rv != -2) break;
|
||||
}
|
||||
if(rv < 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot open any disk (%s)\n",
|
||||
sys_errlist[errno]);
|
||||
exit(1);
|
||||
}
|
||||
err(1, "cannot open any disk");
|
||||
}
|
||||
|
||||
printf("******* Working on device %s *******\n",disk);
|
||||
@ -408,10 +398,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
usage:
|
||||
printf("fdisk {-a|-i|-u} [-f <config file> [-t] [-v]] [-{1,2,3,4}] [disk]\n");
|
||||
return(1);
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: fdisk {-a|-i|-u} [-f <config file> [-t] [-v]] [-{1,2,3,4}] [disk]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -648,22 +642,19 @@ open_disk(int u_flag)
|
||||
struct stat st;
|
||||
|
||||
if (stat(disk, &st) == -1) {
|
||||
fprintf(stderr, "%s: Can't get file status of %s\n",
|
||||
name, disk);
|
||||
warnx("can't get file status of %s", disk);
|
||||
return -1;
|
||||
}
|
||||
if ( !(st.st_mode & S_IFCHR) )
|
||||
fprintf(stderr,"%s: Device %s is not character special\n",
|
||||
name, disk);
|
||||
warnx("device %s is not character special", disk);
|
||||
if ((fd = open(disk, a_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) {
|
||||
if(errno == ENXIO)
|
||||
return -2;
|
||||
fprintf(stderr,"%s: Can't open device %s\n", name, disk);
|
||||
warnx("can't open device %s", disk);
|
||||
return -1;
|
||||
}
|
||||
if (get_params(0) == -1) {
|
||||
fprintf(stderr, "%s: Can't get disk parameters on %s\n",
|
||||
name, disk);
|
||||
warnx("can't get disk parameters on %s", disk);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
@ -702,9 +693,7 @@ get_params()
|
||||
{
|
||||
|
||||
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
|
||||
fprintf(stderr,
|
||||
"%s: Can't get disk parameters on %s; supplying dummy ones\n",
|
||||
name, disk);
|
||||
warnx("can't get disk parameters on %s; supplying dummy ones", disk);
|
||||
dos_cyls = cyls = 1;
|
||||
dos_heads = heads = 1;
|
||||
dos_sectors = sectors = 1;
|
||||
@ -727,12 +716,11 @@ static int
|
||||
read_s0()
|
||||
{
|
||||
if (read_disk(0, (char *) mboot.bootinst) == -1) {
|
||||
fprintf(stderr, "%s: Can't read fdisk partition table\n", name);
|
||||
warnx("can't read fdisk partition table");
|
||||
return -1;
|
||||
}
|
||||
if (mboot.signature != BOOT_MAGIC) {
|
||||
fprintf(stderr, "%s: Invalid fdisk partition table found\n",
|
||||
name);
|
||||
warnx("invalid fdisk partition table found");
|
||||
/* So should we initialize things */
|
||||
return -1;
|
||||
}
|
||||
@ -756,11 +744,10 @@ write_s0()
|
||||
flag = 1;
|
||||
#ifdef NOT_NOW
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
perror("ioctl DIOCWLABEL");
|
||||
warn("ioctl DIOCWLABEL");
|
||||
#endif
|
||||
if (write_disk(0, (char *) mboot.bootinst) == -1) {
|
||||
fprintf(stderr, "%s: Can't write fdisk partition table\n",
|
||||
name);
|
||||
warnx("can't write fdisk partition table");
|
||||
return -1;
|
||||
flag = 0;
|
||||
#ifdef NOT_NOW
|
||||
@ -979,18 +966,17 @@ process_geometry(command)
|
||||
geom_processed = 1;
|
||||
if (part_processed)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: the geometry specification line must occur before\n\
|
||||
all partition specifications.\n",
|
||||
name, current_line_number);
|
||||
warnx(
|
||||
"ERROR line %d: the geometry specification line must occur before\n\
|
||||
all partition specifications",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
if (command->n_args != 3)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of geometry args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of geometry args",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
@ -1011,9 +997,9 @@ process_geometry(command)
|
||||
dos_sectors = command->args[i].arg_val;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: unknown geometry arg type: '%c' (0x%02x)\n",
|
||||
name, current_line_number, command->args[i].argtype,
|
||||
warnx(
|
||||
"ERROR line %d: unknown geometry arg type: '%c' (0x%02x)",
|
||||
current_line_number, command->args[i].argtype,
|
||||
command->args[i].argtype);
|
||||
status = 0;
|
||||
break;
|
||||
@ -1031,46 +1017,42 @@ process_geometry(command)
|
||||
*/
|
||||
if (dos_cyls < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of cylinders not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of cylinders not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
if (dos_cyls == 0 || dos_cyls > 1024)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: WARNING line %d: number of cylinders (%d) may be out-of-range\n\
|
||||
warnx(
|
||||
"WARNING line %d: number of cylinders (%d) may be out-of-range\n\
|
||||
(must be within 1-1024 for normal BIOS operation, unless the entire disk\n\
|
||||
is dedicated to FreeBSD).\n",
|
||||
name, current_line_number, dos_cyls);
|
||||
is dedicated to FreeBSD)",
|
||||
current_line_number, dos_cyls);
|
||||
}
|
||||
|
||||
if (dos_heads < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of heads not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of heads not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
else if (dos_heads < 1 || dos_heads > 256)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of heads must be within (1-256)\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of heads must be within (1-256)",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
|
||||
if (dos_sectors < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: number of sectors not specified\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of sectors not specified",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
else if (dos_sectors < 1 || dos_sectors > 63)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: number of sectors must be within (1-63)\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: number of sectors must be within (1-63)",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
}
|
||||
|
||||
@ -1093,16 +1075,15 @@ process_partition(command)
|
||||
part_processed = 1;
|
||||
if (command->n_args != 4)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of partition args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of partition args",
|
||||
current_line_number);
|
||||
break;
|
||||
}
|
||||
partition = command->args[0].arg_val;
|
||||
if (partition < 1 || partition > 4)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: invalid partition number %d\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: invalid partition number %d",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
partp = ((struct dos_partition *) &mboot.parts) + partition - 1;
|
||||
@ -1137,16 +1118,16 @@ process_partition(command)
|
||||
/*
|
||||
* Can't go past end of partition
|
||||
*/
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: unable to adjust start of partition %d to fall on\n\
|
||||
a cylinder boundary.\n",
|
||||
name, current_line_number, partition);
|
||||
warnx(
|
||||
"ERROR line %d: unable to adjust start of partition %d to fall on\n\
|
||||
a cylinder boundary",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"%s: WARNING: adjusting start offset of partition '%d' from %lu\n\
|
||||
to %lu, to round to an head boundary.\n",
|
||||
name, partition, (u_long)partp->dp_start, adj_size);
|
||||
warnx(
|
||||
"WARNING: adjusting start offset of partition '%d' from %lu\n\
|
||||
to %lu, to round to an head boundary",
|
||||
partition, (u_long)partp->dp_start, adj_size);
|
||||
partp->dp_start = adj_size;
|
||||
}
|
||||
|
||||
@ -1159,10 +1140,10 @@ process_partition(command)
|
||||
adj_size = chunks - partp->dp_start;
|
||||
if (adj_size != partp->dp_size)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: WARNING: adjusting size of partition '%d' from %lu to %lu,\n\
|
||||
to round to a cylinder boundary.\n",
|
||||
name, partition, (u_long)partp->dp_size, adj_size);
|
||||
warnx(
|
||||
"WARNING: adjusting size of partition '%d' from %lu to %lu,\n\
|
||||
to round to a cylinder boundary",
|
||||
partition, (u_long)partp->dp_size, adj_size);
|
||||
if (chunks > 0)
|
||||
{
|
||||
partp->dp_size = adj_size;
|
||||
@ -1174,9 +1155,8 @@ process_partition(command)
|
||||
}
|
||||
if (partp->dp_size < 1)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: size for partition '%d' is zero.\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: size for partition '%d' is zero",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1203,17 +1183,16 @@ process_active(command)
|
||||
active_processed = 1;
|
||||
if (command->n_args != 1)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: ERROR line %d: incorrect number of active args\n",
|
||||
name, current_line_number);
|
||||
warnx("ERROR line %d: incorrect number of active args",
|
||||
current_line_number);
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
partition = command->args[0].arg_val;
|
||||
if (partition < 1 || partition > 4)
|
||||
{
|
||||
fprintf(stderr, "%s: ERROR line %d: invalid partition number %d\n",
|
||||
name, current_line_number, partition);
|
||||
warnx("ERROR line %d: invalid partition number %d",
|
||||
current_line_number, partition);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user