From owner-freebsd-hackers Tue Aug 29 04:57:11 1995 Return-Path: hackers-owner Received: (from majordom@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id EAA25420 for hackers-outgoing; Tue, 29 Aug 1995 04:57:11 -0700 Received: from who.cdrom.com (who.cdrom.com [192.216.222.3]) by freefall.FreeBSD.org (8.6.11/8.6.6) with ESMTP id EAA25414 for ; Tue, 29 Aug 1995 04:57:10 -0700 Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by who.cdrom.com (8.6.11/8.6.11) with ESMTP id EAA29886 for ; Tue, 29 Aug 1995 04:56:35 -0700 Received: from sax.sax.de by irz301.inf.tu-dresden.de (8.6.12/8.6.12-s1) with ESMTP id NAA17504; Tue, 29 Aug 1995 13:51:46 +0200 Received: by sax.sax.de (8.6.11/8.6.12-s1) with UUCP id NAA20427; Tue, 29 Aug 1995 13:51:45 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.6.11/8.6.9) id NAA18961; Tue, 29 Aug 1995 13:14:25 +0200 From: J Wunsch Message-Id: <199508291114.NAA18961@uriah.heep.sax.de> Subject: Re: fdisk & disklabel troubles To: luigi@labinfo.iet.unipi.it (Luigi Rizzo) Date: Tue, 29 Aug 1995 13:14:24 +0200 (MET DST) Cc: hackers@freebsd.org In-Reply-To: <199508290749.JAA04925@labinfo.iet.unipi.it> from "Luigi Rizzo" at Aug 29, 95 09:49:29 am Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) X-Phone: +49-351-2012 669 X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Length: 3825 Sender: hackers-owner@freebsd.org Precedence: bulk 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 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 #include #include +#include #include #include #include @@ -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. ;-)