Hoping to be able to do a disklabel -B again, I just built a kernel with
N O_GEOM. However, I ran into an interesting problem with 'fdisk' when
trying to debug my other "Boot error" problems that boot1 is giving me.


edgemaster# fdisk ad1
Floating exception (core dumped)

In get_params, we have:
...
780             error = ioctl(fd, DIOCGFWSECTORS, &u);
781             if (error == 0)
782                     sectors = dos_sectors = u;
783             error = ioctl(fd, DIOCGFWHEADS, &u);
784             if (error == 0)
785                     heads = dos_heads = u;
786
787             dos_cylsecs = cylsecs = heads * sectors;
788             disksecs = cyls * heads * sectors;
...
794             error = ioctl(fd, DIOCGMEDIASIZE, &o);
795             if (error == 0) {
796                     disksecs = o / u;
797                     cyls = dos_cyls = o / (u * dos_heads * dos_sectors);
798             }
...

What happens if the ioctls in lines 780 and/or 783 fail? When we get to
line 797, we're snagged with division by zero.

I shall demonstrate:
Script started on Sun Jan 12 21:57:23 2003
(gdb) break get_parmams
Breakpoint 1 at 0x8049666: file fdisk.c, line 780.
(gdb) run ad1
Starting program: /usr/src/sbin/fdisk/fdisk ad1

Breakpoint 1, get_params () at fdisk.c:780
780             error = ioctl(fd, DIOCGFWSECTORS, &u);
(gdb) s
781             if (error == 0)
(gdb) p error
$1 = -1
(gdb) s
783             error = ioctl(fd, DIOCGFWHEADS, &u);
(gdb) s
784             if (error == 0)
(gdb) p error
$2 = -1
(gdb) s
787             dos_cylsecs = cylsecs = heads * sectors;
(gdb) print heads
$3 = 0
(gdb) p sectors
$4 = 0
(gdb) s
788             disksecs = cyls * heads * sectors;
(gdb) s
790             error = ioctl(fd, DIOCGSECTORSIZE, &u);
(gdb) s
791             if (error != 0)
(gdb) p error
$5 = 0
(gdb) s
794             error = ioctl(fd, DIOCGMEDIASIZE, &o);
(gdb) p u
$6 = 512
(gdb) s
795             if (error == 0) {
(gdb) p error
$7 = 0
(gdb) p o
$8 = 60022480896
(gdb) s
796                     disksecs = o / u;
(gdb) s
797                     cyls = dos_cyls = o / (u * dos_heads * dos_sectors);
(gdb) p disksecs
$9 = 117231408
(gdb) s

Program received signal SIGFPE, Arithmetic exception.
0x0804ac43 in __divdi3 ()
(gdb) p dos_heads
$10 = 0
(gdb) p dos_sectors
$11 = 0
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) quit
Script done on Sun Jan 12 21:58:56 2003

I think I might just get out a small magnet and fix my booting problems
manually.

-- 
Sean Kelly         | PGP KeyID: D2E5E296
[EMAIL PROTECTED] | http://www.zombie.org

Attachment: msg50060/pgp00000.pgp
Description: PGP signature

Reply via email to