Free disk space in Linux

Linux specific forum
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Free disk space in Linux

Post by whertz »

Does anyone know of a way to determine free disk space in Linux? I need to find out the free disk space of the drive when I specify a path. I'm porting one of my applications to Linux and this is the only hurdle stopping me. I use the Windows API call to get the free disk space on a particular drive, but with Linux I think it would be more complex as the folder could be mounted on any drive. Any help is appreciated! Thanks.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Free disk space in Linux

Post by uwekel »

Code: Select all

Structure Statvfs
  f_bsize.i ;file system block size
  f_frsize.i ;fragment size
  f_blocks.i ;size of fs in f_frsize units
  f_bfree.i ;free blocks
  f_bavail.i ;free blocks for unprivileged users
  f_files.i ;inodes
  f_ffree.i ;free inodes
  f_favail.i ;free inodes for unprivileged users
  f_fsid.i ;file system ID
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    __f_unused.l
  CompilerEndIf
  f_flag.i ;mount flags: 1=readonly 2= nosuid
  f_namemax.i ;maximum filename length
  __f_spare.l[6]
EndStructure

Structure DriveInfoResult
  Size.q
  Used.q
  Free.q
EndStructure

ImportC ""
  statvfs.l(Path.p-utf8, *value.Statvfs)
EndImport

Procedure.q DriveInfo(Path.s, *Result.DriveInfoResult)
  Protected v.statvfs
  Statvfs(Path, v)
  *Result\Size = v\f_blocks * v\f_frsize
  *Result\Used = (v\f_blocks - v\f_bfree) * v\f_frsize
  *Result\Free = v\f_bavail * v\f_frsize
EndProcedure

DriveInfo(GetHomeDirectory(), r.DriveInfoResult)
Debug r\Size
Debug r\Used
Debug r\Free
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
whertz
Enthusiast
Enthusiast
Posts: 124
Joined: Sat Jun 25, 2005 2:16 pm
Location: United Kingdom

Re: Free disk space in Linux

Post by whertz »

Thanks!!!
Post Reply