hmm, on Wed, Apr 15, 2009 at 10:15:00PM -0600, Tobias Weingartner said that > > Frantisek Holop wrote: > > > > > > i am reading the fdisk source to have a better understanding > > > what is what... it is not going really well i am afraid :] > > Please read up on hale landis' "how it works" series. It's roughly > the best I've found on the subject. http://www.ata-atapi.com/hiwmbr.html > Once you're understood that, then we can discuss more of what is going on.
thanks, i have already seen this site :] i found this one the best: http://www.geocities.com/thestarman3/asm/mbr/ i see that my question was kind of a real mail-sent-at-4am :] to answer your question Theo, no i don't care only about pc's, although the code path i am studying at the moment is for ata disks on i386... i am trying to understand why atactl's c/h/s output is different from fdisk's, when as i read the source, the same ata command is executed in the end: fdisk's DISK_getmetrics() uses the DIOCGPDINFO ioctl. i found this ioctl defined for ata disks (which are my concern at the moment) in /sys/dev/ata/wd.c where wd_get_params() calls ata_get_params() from /sys/dev/ata/ata.c:64. this function tries to identify the drive using the ata command WDCC_IDENTIFY: 78 if (drvp->drive_flags & DRIVE_ATA) { 79 wdc_c.r_command = WDCC_IDENTIFY; 80 wdc_c.r_st_bmask = WDCS_DRDY; 81 wdc_c.r_st_pmask = 0; 82 wdc_c.timeout = 3000; /* 3s */ now on the other hand atactl in device_identify() of /usr/src/sbin/atactl/atactl.c does (i think) the same: 750 req.flags = ATACMD_READ; 751 req.command = WDCC_IDENTIFY; 752 req.databuf = (caddr_t) inbuf; 753 req.datalen = sizeof(inbuf); 754 req.timeout = 1000; 755 756 ata_command(&req); but the c/h/s info is different: $ sudo fdisk wd0 Disk: wd0 geometry: 486/255/63 [7815024 Sectors] $ sudo atactl wd0 Cylinders: 7753, heads: 16, sec/track: 63, total sectors: 7815024 in a nutshell, that was my question, what am i reading wrong here? > > > the other issue i have been pondering is, the user mode -chs in fdisk. > > > i remember back then when i had this clash of geometries (between say > > > partition magic, and openbsd) i was inclined to use the partion magic > > > one... so i had a geometry i wanted to use to override the one openbsd > > > was giving me. but even if i specified it with -chs, fdisk still used > > > the one it found. now i see in the source, that the user given geometry > > > is considered, but only if there is no geometry found by the system, if > > > the system finds one, it simply overwrites the user defined values. > > > is this intentional? if the user is brave enough to supply a geometry, > > > shouldn't it be used over the detected one? > > You better read the code again. In particular, read the DISK_getmetrics() > function. As far as I can tell, if user supplied metrics (geometry) is > supplied, it's the one that is used. yes i read it wrong, you are right. > If the system gave you a geometry, that's the one you want to you. > You can't just make up whatever geometry you want. This is not some > sort of negotiable thing. If 'partition magic' used it's own, different > geometry from what the bios was/is using, and it worked, it was a simple > *ACCIDENT*. external usb disks are not set-up by bios... consider the following case: this was a 160G external usb disk used both by windows xp and openbsd. i wanted to have both fat32 and ffs on this disk. so i created the fat32 using PM (partition magic) and wanted to do ffs in openbsd. PM said the disk is like this: Disk Geometry Information for Disk 2: 19457 Cylinders, 255 Heads, 63 Sectors/Track System but openbsd fdisk said: fdisk: sysctl(machdep.bios.diskinfo): Device not configured Disk: sd0 geometry: 152627/64/32 [312581808 Sectors] so this was really a "blind", arbitrary n/64/32 geometry set by openbsd (later changed to n/255/32). this was the case where i wanted to enter a user geometry and override whatever openbsd found. because this way i could safely add partitions to an already populated mbr as the cylinder boundaries would match. but i can't remember why it did not work when i supplied a user geometry. it was some years ago. why just not use lba everywhere? the horrible c/h/s could disappear. -f -- call me blind but i didnt see it coming.