[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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[1]. 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
confusion.

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.

Marcus

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org
Marcus.Brinkmann@ruhr-uni-bochum.de
http://www.marcus-brinkmann.de



Reply to: