Re: lokking for portable way to determine the size of harddisks
On Thu, Mar 08, 2001 at 12:07:06PM +0100, Russell Coker wrote:
> On Thursday 08 March 2001 00:21, Marcus Brinkmann wrote:
> > On Wed, Mar 07, 2001 at 08:38:54PM +0100, Thomas Lange wrote:
> > > I want to determine the size of the local harddisks in a shell. It
> > > must be portable so it runs on all hardware. First is used sfdisk,
> > > but it's only available on i386. Now I'm using /proc/partitions on a
> > > 2.2 kernel:
> > Using the proc filesystem only works on Linux. The only really portable
> > approach is to use statfs(), and that only works for a mounted filesystems,
> > which should be sufficient if you are not doing really system specific
> > stuff.
> statfs() isn't entirely accurate when you have the ability to resize devices
> and file systems. If you enlarge the space for a LV in LVM and have not yet
> enlarged the FS to match (or if you have reduced the size of the FS but not
> reduced the size of the LV) then the results won't be what you want.
> Also if you have spare unpartitioned space in reserve for future use then
> stating the file systems won't work.
Right, now that I think about it, statfs and df never report the size of the
actual device, but the size of the filesystem space available. Sorry for my
So, there is no portable way to determine the size of the hardware provided
stores at all. Thomas will have to live with /proc on Linux, open/stat on
device files in the Hurd etc. Both systems also provide kernel APIs (disk
geometry etc) that are used by programs like GNU parted.
`Rhubarb is no Egyptian god.' Debian http://www.debian.org email@example.com
Marcus Brinkmann GNU http://www.gnu.org firstname.lastname@example.org