Messages in this thread | | | Date | Sun, 10 Nov 2013 22:45:35 +0100 | From | Andreas Mohr <> | Subject | Re: How can I get the sector count in kernel? |
| |
Hi again :)
> I need the count of sector,but I don't know how to get it. > Could you give me some favour?
First, you should ask yourself whether you really need this drive-specific information.
Such information can (more or less) be gathered via the HDIO_GETGEO ioctl. But be advised that this ioctl is known to be unreliable/undesirable and will be handled differently (and with differing reliability!!!) by various I/O layers. E.g. this will be handled by a callback, which in the case of libata will return values that are hard-coded for *LBA-specific* disk geometry (255 heads). Good luck if your disk happens to be using CHS or ECHS, where this value likely is NOT the proper one. Especially in the case of ntfsclone / partclone.ntfsfixboot combo this is a major nuisance (and you'll probably end up having to manually specify the actually correct values in order to finally get that f***in' thing to boot properly).
Also, you should make sure to be using the EDD BIOS service (see modinfo edd), for the kernel to be able to forward actual BIOS-side drive geometry information.
Another way to be gathering a geometry is by parsing geometry output of fdisk / cfdisk.
HTH,
Andreas Mohr
| |