Date: Tue, 29 Aug 1995 13:14:24 +0200 (MET DST) From: J Wunsch <j@uriah.heep.sax.de> To: luigi@labinfo.iet.unipi.it (Luigi Rizzo) Cc: hackers@freebsd.org Subject: Re: fdisk & disklabel troubles Message-ID: <199508291114.NAA18961@uriah.heep.sax.de> In-Reply-To: <199508290749.JAA04925@labinfo.iet.unipi.it> from "Luigi Rizzo" at Aug 29, 95 09:49:29 am
next in thread | previous in thread | raw e-mail | index | archive | help
As Luigi Rizzo wrote:
>
> * fdisk cannot write the partition table either (or at least, it cannot
> be read back!). I tried to set the correct parameters and write to
> disk, fdisk did not write any error message but reading again the
> partition table shows the same old values.
> (cannot do further experiments with working fdisks, but my setting is
> easily reproducible).
Fdisk works on the wrong partition/slice.
Try the patch below. I don't claim this being optimal, but a better
approach than the current one. It adds the following features:
o either wd0 and sd0 are being probed until one is found not yielding
ENXIO (the list is extendable); this represents the typical BIOS
boot search sequence (unless somebody has both, wd0 and sd0, but
hasn't registered wd0 with the BIOS in order to boot off sd0).
o the "/dev/wd0d" crock has been eliminated -- it's plain wrong now
o you can provide a `bare disk name' as command line argument, without
the leading /dev/r, just like in disklabel(8)
> Luckily, fdisk does not kill the system. With disklabel, things seem to
I think it didn't do anything since it hasn't even seen the entire
disk, only FreeBSD's slice?
> be worse: whenever I try to write a label, the system reboots.
Bruce has fixed this yesterday.
For dedicated disks, you don't even have to run fdisk at all. Here's
my standard sequence:
Create a disktab entry; for SCSI disks, this one does also contain an
`su' (sectors per unit) tag describing the total number of sectors
available (slightly more than c*h*s); the `c' partition starts at
offset 0 and covers the entire disk (yes, even the supposed fdisk
table).
disklabel -r -w sd0 <myentry>
disklabel -B sd0
(both commands complain about the invalid partition table; no magic)
newfs
I'm planning to integrate this into libdisk, so it can be available
from sysinstall for the (A)ll FreeBSD option.
Note that such a disk should NEVER get in contact with DOS 6.X's fdisk
command!
Index: fdisk/fdisk.c
===================================================================
RCS file: /home/cvs/src/sbin/i386/fdisk/fdisk.c,v
retrieving revision 1.7
diff -u -r1.7 fdisk.c
--- 1.7 1995/05/30 06:09:12
+++ fdisk.c 1995/08/29 11:01:30
@@ -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 @@
#define SECSIZE 512
-char *disk = "/dev/rwd0d";
+const char *disk;
+const char *disks[] =
+{
+ "/dev/rwd0", "/dev/rsd0", 0
+};
+
char *name;
struct disklabel disklabel; /* disk parameters */
@@ -215,10 +221,41 @@
}
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)
@@ -465,6 +502,8 @@
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;
}
--
cheers, J"org
joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199508291114.NAA18961>
