From owner-freebsd-current Tue Oct 15 12:53:27 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 329A937B401 for ; Tue, 15 Oct 2002 12:53:25 -0700 (PDT) Received: from rootlabs.com (root.org [67.118.192.226]) by mx1.FreeBSD.org (Postfix) with SMTP id BAD1043E77 for ; Tue, 15 Oct 2002 12:53:24 -0700 (PDT) (envelope-from nate@rootlabs.com) Received: (qmail 37190 invoked by uid 1000); 15 Oct 2002 19:53:25 -0000 Date: Tue, 15 Oct 2002 12:53:25 -0700 (PDT) From: Nate Lawson To: Poul-Henning Kamp Cc: current@freebsd.org Subject: Re: GEOM/fdisk/USB drive problem In-Reply-To: <31480.1034710602@critter.freebsd.dk> Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-902143914-1034711605=:37181" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --0-902143914-1034711605=:37181 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 15 Oct 2002, Poul-Henning Kamp wrote: > In message , Nate Lawson wri > tes: > >fdisk against my USB flash drive crashes with divide by zero. It turns > >out that get_params() starts with some default values (since there is > >no disklabel) and then runs some ioctls: DIOCGFWSECTORS and DIOCGFWHEADS. > > > >The problem is that fdisk checks the error from that ioctl and then > >happily uses whatever parameters it returned. My question is, should I > >add the error checking in userland (error == 0 && sector != 0) or in > >g_dev_ioctl? IMO, it should be in g_dev_ioctl so that we only have to > >validate the data in one place instead of multiple utilities (fdisk, > >disklabel, ...?) > > I really think it belongs in userland and not in the kernel. > > The "FW" values are advisory, and if they are not there or not > sensible, userland should cope. > > I could agree to make g_dev_ioctl fail the ioctl with some errno > if they came back as zero, but not substituting another value. The attached patch makes everything work fine for my drive (64 MB USB flash). -Nate fdisk: can't get disk parameters on /dev/da0; supplying dummy ones ******* Working on device /dev/da0 ******* parameters extracted from in-core disklabel are: cylinders=129024 heads=1 sectors/track=1 (1 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=129024 heads=1 sectors/track=1 (1 blks/cyl) Media sector size is 512 Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 6 (0x06),(Primary 'big' DOS (>= 32MB)) start 32, size 128480 (62 Meg), flag 80 (active) beg: cyl 0/ head 1/ sector 1; end: cyl 250/ head 15/ sector 32 The data for partition 2 is: The data for partition 3 is: The data for partition 4 is: --0-902143914-1034711605=:37181 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="geom.patch" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="geom.patch" SW5kZXg6IHN5cy9nZW9tL2dlb21fZGV2LmMNCj09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT0NClJDUyBmaWxlOiAvaG9tZS9uY3ZzL3NyYy9zeXMvZ2VvbS9nZW9t X2Rldi5jLHYNCnJldHJpZXZpbmcgcmV2aXNpb24gMS4yNQ0KZGlmZiAtdSAt cjEuMjUgZ2VvbV9kZXYuYw0KLS0tIHN5cy9nZW9tL2dlb21fZGV2LmMJNyBP Y3QgMjAwMiAwNjoyNToyNiAtMDAwMAkxLjI1DQorKysgc3lzL2dlb20vZ2Vv bV9kZXYuYwkxNSBPY3QgMjAwMiAxMjo0NjozNSAtMDAwMA0KQEAgLTI0NSwx NSArMjQ1LDIzIEBADQogCXN3aXRjaCAoY21kKSB7DQogCWNhc2UgRElPQ0dT RUNUT1JTSVpFOg0KIAkJZXJyb3IgPSBnX2lvX2dldGF0dHIoIkdFT006OnNl Y3RvcnNpemUiLCBjcCwgJmksIGRhdGEpOw0KKwkJaWYgKGVycm9yID09IDAg JiYgKih1X2ludCAqKWRhdGEgPT0gMCkNCisJCQllcnJvciA9IEVJTlZBTDsN CiAJCWJyZWFrOw0KIAljYXNlIERJT0NHTUVESUFTSVpFOg0KIAkJZXJyb3Ig PSBnX2lvX2dldGF0dHIoIkdFT006Om1lZGlhc2l6ZSIsIGNwLCAmaSwgZGF0 YSk7DQorCQlpZiAoZXJyb3IgPT0gMCAmJiAqKHVfaW50ICopZGF0YSA9PSAw KQ0KKwkJCWVycm9yID0gRUlOVkFMOw0KIAkJYnJlYWs7DQogCWNhc2UgRElP Q0dGV1NFQ1RPUlM6DQogCQllcnJvciA9IGdfaW9fZ2V0YXR0cigiR0VPTTo6 ZndzZWN0b3JzIiwgY3AsICZpLCBkYXRhKTsNCisJCWlmIChlcnJvciA9PSAw ICYmICoodV9pbnQgKilkYXRhID09IDApDQorCQkJZXJyb3IgPSBFSU5WQUw7 DQogCQlicmVhazsNCiAJY2FzZSBESU9DR0ZXSEVBRFM6DQogCQllcnJvciA9 IGdfaW9fZ2V0YXR0cigiR0VPTTo6ZndoZWFkcyIsIGNwLCAmaSwgZGF0YSk7 DQorCQlpZiAoZXJyb3IgPT0gMCAmJiAqKHVfaW50ICopZGF0YSA9PSAwKQ0K KwkJCWVycm9yID0gRUlOVkFMOw0KIAkJYnJlYWs7DQogCWNhc2UgRElPQ0dG Uk9OVFNUVUZGOg0KIAkJZXJyb3IgPSBnX2lvX2dldGF0dHIoIkdFT006OmZy b250c3R1ZmYiLCBjcCwgJmksIGRhdGEpOw0K --0-902143914-1034711605=:37181-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message