On Thu, 2003-10-23 at 19:20, Michael Hipp wrote: > Anyone know a simple call from c that will give the free space available > on a volume (e.g. /dev/hda1)?
I use the following in a program. It wants to know about free space on the disk where a data file is, as that is what we are interested in. It should be enough to get you started. It works on SVR4/5 and Linux. The comments are just what was there. int DiskFreeSpace() { struct statvfs fsbuf; // We use the name of the .set file, which always exists, and is // always on the same file system as all the other files created. // As the set file is not open, we use statvfs() to find out about // the file system on which the set file is being written. if (statvfs(set_name, &fsbuf) == ISERROR) return(0); // We use f_bavail to determine how many blocks are available. // f_bavail tells the # of free blocks available to non-superusers. // // As we want to return kilobytes free, f_bavail is divided by // f_frsize, which is the fndamental block size. This may be more // or less than 1024. As we want to stick with integer math, we do // a test for this so we can perform proper math. if (fsbuf.f_frsize < 1024) { return(fsbuf.f_bavail / (1024 / fsbuf.f_frsize)); } else { return(fsbuf.f_bavail * (fsbuf.f_frsize / 1024)); } } > > Thanks, > Michael > > _______________________________________________ > Linux-users mailing list > [EMAIL PROTECTED] > Unsubscribe/Suspend/Etc -> http://smtp.linux-sxs.org/mailman/listinfo/linux-users _______________________________________________ Linux-users mailing list [EMAIL PROTECTED] Unsubscribe/Suspend/Etc -> http://smtp.linux-sxs.org/mailman/listinfo/linux-users