Re: How can I get the sector count in kernel?

From: Andreas Mohr
Date: Sun Nov 10 2013 - 16:46:05 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/