小弟我是新手,最近要在程序中获取sd卡和U盘的总容量和剩余容量,请各位大侠帮帮忙,谢谢。
|
int GetStorageInfo(char * MountPoint, int *Capacity, int type)
{
struct statfs statFS;
U64 usedBytes = 0;
U64 freeBytes = 0;
U64 totalBytes = 0;
U64 endSpace = 0;
if (statfs(MountPoint, &statFS) == -1){
printf("statfs failed for path->[%s]n", MountPoint);
return(-1);
}
totalBytes = (U64)statFS.f_blocks * (U64)statFS.f_frsize;
freeBytes = (U64)statFS.f_bfree * (U64)statFS.f_frsize;
usedBytes = (U64)(totalBytes - freeBytes);
switch( type )
{
case 1:
endSpace = totalBytes/1024;
break;
case 2:
endSpace = usedBytes/1024;
break;
case 3:
endSpace