代码如下:
#include <sys/statvfs.h>
double get_disk_capacity ( char * path)
{
struct statvfs sfs;
unsigned long long result = 0;
double disk_capacity = 0;
if ( statvfs ( path, &sfs) != -1 )
{
result = (unsigned long long)sfs.f_frsize * sfs.f_blocks;
if (result > 0)
{
disk_capacity = (double)result/(1024*1024);
}
}
return disk_capacity;
}
- (void)printf {
// Sum the size of the two logical partitions (root + user space)
double total_capacity = get_disk_capacity("/") + get_disk_capacity("/private/var");
printf( "%.2f MB", total_capacity);
}
方法2: