fsavail - gets the available space in a file system

Miscellaneous tools
Post Reply
Message
Author
gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

fsavail - gets the available space in a file system

#1 Post by gyro »

'fsavail' takes a single parameter, the full path of an existing file or directory.
If the file or directory exists, it prints the available space of the filesystem that contains the file, in kilobytes (1024 bytes), and the exit code is 0.
If the file or directory does not exist, nothing is printed, and the exit code is 1.
If no parameter is provided it prints a small help message, and the exit code is 1.

This is a console program meant to be used in shell scripts as an alternative to processing the output of 'df'.
Advantages:
1) No 'grep'ing and 'cut'ing of the output is required.
2) The known path can be a mount point but does not have to be a mount point, and can be an ordinary file.

Advantage 2) is particularly useful when it is not known if the known path is a directory or a symbolic link to a directory.
'fsavail' will give the correct result for "/initrd/pup_rw" if it's a savefile or a savefolder, and if the savefolder is implemented as a bind mount or using symbolic links.
There is no code in 'fsavail' to distinguish these situations, it's all done by the "statfs()" function.

'fsavail' is a C program.
A gziped binary, compiled on Dpup Squeeze Exprimo 5.X.3.4.12, is attached.
A gziped source file is also attached.

gyro
Attachments
fsavail.gz
gunzip to produce the binary file.
(1.84 KiB) Downloaded 162 times
fsavail.c.gz
gunzip to produce the source file
(472 Bytes) Downloaded 151 times

Post Reply