当前位置: 技术问答>linux和unix
c语言里如何获得磁盘剩余空间,急
来源: 互联网 发布时间:2015-12-24
本文导语: c语言里如何获得磁盘剩余空间,急 | struct BF_TYPE { char notes[20]; char bf_path[80]; char newfile_name[40]; time_t newfile_time; time_t current_time; double bf_...
c语言里如何获得磁盘剩余空间,急
|
struct BF_TYPE
{
char notes[20];
char bf_path[80];
char newfile_name[40];
time_t newfile_time;
time_t current_time;
double bf_size;
double bf_free;
double f_size;
time_t scan_time;
char chck_usr[16];
};
struct BF_LISTTYPE
{
char bf_path[80];
char bf_chkstr[20];
char notes[20];
int timediff;
char other2[16];
}; /*其它不必理会,你的例子只要bf_path*/
int get_statfs(struct BF_TYPE *bf,struct BF_LISTTYPE *bl)
{
struct statfs myfs;
strcpy(bf->notes,bl->notes);
if (statfs(bl->bf_path,&myfs)==-1) { perror("statfs error!!"); return(-1); }
strcpy(bf->bf_path,bl->bf_path);
bf->bf_size =(double)myfs.f_blocks*(double)myfs.f_bsize/1024;
bf->bf_free =(double)myfs.f_bavail*(double)myfs.f_bsize/1024;
return(bf->bf_free*100/bf->bf_size);
}
{
char notes[20];
char bf_path[80];
char newfile_name[40];
time_t newfile_time;
time_t current_time;
double bf_size;
double bf_free;
double f_size;
time_t scan_time;
char chck_usr[16];
};
struct BF_LISTTYPE
{
char bf_path[80];
char bf_chkstr[20];
char notes[20];
int timediff;
char other2[16];
}; /*其它不必理会,你的例子只要bf_path*/
int get_statfs(struct BF_TYPE *bf,struct BF_LISTTYPE *bl)
{
struct statfs myfs;
strcpy(bf->notes,bl->notes);
if (statfs(bl->bf_path,&myfs)==-1) { perror("statfs error!!"); return(-1); }
strcpy(bf->bf_path,bl->bf_path);
bf->bf_size =(double)myfs.f_blocks*(double)myfs.f_bsize/1024;
bf->bf_free =(double)myfs.f_bavail*(double)myfs.f_bsize/1024;
return(bf->bf_free*100/bf->bf_size);
}