summaryrefslogtreecommitdiffstats
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1995-09-01 18:00:14 +0000
committerjoerg <joerg@FreeBSD.org>1995-09-01 18:00:14 +0000
commit79384fe51ba855fe3a49375f8f23ce361c63021c (patch)
tree10dadc1f442a282ce75d7cf93d3f8c7c540b1bbb /sbin/fdisk
parent9bf6ddb952e4f678e84988f0b18ad3ae6c1a2f5c (diff)
downloadFreeBSD-src-79384fe51ba855fe3a49375f8f23ce361c63021c.zip
FreeBSD-src-79384fe51ba855fe3a49375f8f23ce361c63021c.tar.gz
Update to the slices era. Make /dev/rfoo0 the defaults, not
/dev/rfoo0d. Scan a list of devices instead of insisting on all the world being wd0. Allow for disk names to be specified (e.g. `sd0') instead of full path names only. Sync the man page with the reality.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/fdisk.845
-rw-r--r--sbin/fdisk/fdisk.c51
2 files changed, 81 insertions, 15 deletions
diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8
index 5eb2dea..1d0d8eb 100644
--- a/sbin/fdisk/fdisk.8
+++ b/sbin/fdisk/fdisk.8
@@ -8,13 +8,34 @@
.Nm
.Op Fl i
.Op Fl u
+.Op Fl a
+.Op Fl 0123
.Op disk
.Bl -tag -width time
-.It Fl i
-Initializes sector 0 of the disk.
.It Fl u
Is used for updating (editing) sector 0 of the disk.
+.It Fl i
+Initializes sector 0 of the disk. This implies
+.Fl u .
+.It Fl a
+Change the active partition only.
+.It Fl 0123
+Operate on a single fdisk entry only.
.El
+.Pp
+The final disk name can be provided as a
+.Sq bare
+disk name only, e.g.
+.Ql sd0 ,
+or as a fully qualified device node under
+.Pa /dev .
+If omitted, the disks
+.Ql wd0 ,
+.Ql sd0 ,
+and
+.Ql od0
+are being searched in that order, until one is
+being found responding.
.Sh PROLOGUE
In order for the BIOS to boot the kernel,
certain conventions must be adhered to.
@@ -39,14 +60,14 @@ The DOS
program can be used to divide space on the disk into partitions and set one
.Em active.
.Sh DESCRIPTION
-The 386bsd program
+The FreeBSD program
.Nm
serves a similar purpose to the DOS program.
When called with no arguments, it prints the sector 0 partition table.
An example follows:
.Bd -literal
- ******* Working on device /dev/rwd0d *******
+ ******* Working on device /dev/rwd0 *******
parameters extracted from in-core disklabel are:
cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
@@ -56,7 +77,7 @@ An example follows:
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 0 is:
- sysid 165,(386BSD)
+ sysid 165,(FreeBSD/NetBSD/386BSD)
start 495, size 380160 (185 Meg), flag 0
beg: cyl 1/ sector 1/ head 0;
end: cyl 768/ sector 33/ head 14
@@ -79,7 +100,7 @@ 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. 386bsd reserves the
+is used to label the partition. FreeBSD reserves the
magic number 165 decimal (A5 in hex).
.It Em "start and size"
fields provide the start address
@@ -147,7 +168,7 @@ 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 386bsd;
+it will setup the last BIOS partition to use the whole disk for FreeBSD;
and make it active.
.Sh NOTES
.Pp
@@ -160,7 +181,7 @@ 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 386bsd partition starts on a cylinder boundary.
+please make sure that the FreeBSD partition starts on a cylinder boundary.
A number of decisions made later may assume this.
(This might not be necessary later.)
.Pp
@@ -175,4 +196,10 @@ that are not fully explained in this manual page.
.Sh SEE ALSO
.Xr disklabel 8
.Sh BUGS
-One less now, but probably more
+The entire program should be made more user-friendly.
+.Pp
+Throughout this man page, the term
+.Sq partition
+is used where it should actually be
+.Sq slice ,
+in order to conform with the terms used elsewhere.
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index 2d0397f..6b3fb11 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/disklabel.h>
#include <stdio.h>
+#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
@@ -53,7 +54,12 @@ static char lbuf[LBUF];
#define SECSIZE 512
-char *disk = "/dev/rwd0d";
+const char *disk;
+const char *disks[] =
+{
+ "/dev/rwd0", "/dev/rsd0", "/dev/rod0", 0
+};
+
char *name;
struct disklabel disklabel; /* disk parameters */
@@ -174,7 +180,7 @@ struct part_type
main(argc, argv)
char **argv;
{
-int i;
+ int i;
name = *argv;
{register char *cp = name;
@@ -215,10 +221,41 @@ int i;
}
if (argc > 0)
- disk = argv[0];
+ {
+ static char realname[12];
+
+ if(strncmp(argv[0], "/dev", 4) == 0)
+ disk = argv[0];
+ else
+ {
+ snprintf(realname, 12, "/dev/r%s", argv[0]);
+ disk = realname;
+ }
+
+ if (open_disk(u_flag) < 0)
+ {
+ fprintf(stderr, "Cannot open disk %s (%s)\n",
+ disk, sys_errlist[errno]);
+ exit(1);
+ }
+ }
+ else
+ {
+ int i, rv;
- if (open_disk(u_flag) < 0)
- exit(1);
+ for(i = 0; disks[i]; i++)
+ {
+ disk = disks[i];
+ rv = open_disk(u_flag);
+ if(rv != -2) break;
+ }
+ if(rv < 0)
+ {
+ fprintf(stderr, "Cannot open any disk (%s)\n",
+ sys_errlist[errno]);
+ exit(1);
+ }
+ }
printf("******* Working on device %s *******\n",disk);
if(u_flag)
@@ -255,7 +292,7 @@ int i;
exit(0);
usage:
- printf("fdisk {-a|-i|-r} {disk}\n");
+ printf("fdisk {-a|-i|-u} [-{0,1,2,3}] [disk]\n");
}
print_s0(which)
@@ -465,6 +502,8 @@ struct stat st;
fprintf(stderr,"%s: Device %s is not character special\n",
name, 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);
return -1;
}
OpenPOWER on IntegriCloud