在不断录像的应用程序中,为了有剩余的磁盘空间,并保存最新的录制文件,因此需要获得每个录制频道所在路径的磁盘ID以及它的剩作空间,这样就可以根据要求进行综判断,删除多少陈旧的录制文件。用statvfs()函数可获取此设备总的磁盘空间以及剩余空间。
#include <gtk/gtk.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
int main (int argc, char *argv[])
{
int retval;
char *path;
struct statvfs ts;
struct stat ss;
gfloat freesize;
gfloat totalsize;
path = "/root";
retval = statvfs(path, &ts);
if (!retval)
{
freesize = ts.f_bfree *(ts.f_bsize/1024)/1024;//MHZ
totalsize = ts.f_blocks*(ts.f_bsize/1024)/1024;//MHZ
printf("free size : %fMZ/n",freesize );
printf("total size : %fMZ/n",totalsize);
printf("free space percent:%f/n",100.0 - (totalsize-freesize)/totalsize *100);
}
retval = stat(path, &ss);
if(!retval)
{
printf("device ID is:%d/n", (int)ss.st_dev);
}
return 0;
}
#include <gtk/gtk.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
int main (int argc, char *argv[])
{
int retval;
char *path;
struct statvfs ts;
struct stat ss;
gfloat freesize;
gfloat totalsize;
path = "/root";
retval = statvfs(path, &ts);
if (!retval)
{
freesize = ts.f_bfree *(ts.f_bsize/1024)/1024;//MHZ
totalsize = ts.f_blocks*(ts.f_bsize/1024)/1024;//MHZ
printf("free size : %fMZ/n",freesize );
printf("total size : %fMZ/n",totalsize);
printf("free space percent:%f/n",100.0 - (totalsize-freesize)/totalsize *100);
}
retval = stat(path, &ss);
if(!retval)
{
printf("device ID is:%d/n", (int)ss.st_dev);
}
return 0;
}