English 中文(简体)
静态回归微粒价值
原标题:Statfs return strange values

I m currently trying to get disk space in byte en used space in byte with statfs(). I made a small function but i get really strange values. (I m working on a ubuntu 32bit system)

该守则是:

bool
CheckDiskSpace( const CLString &devPath, ulonglong &diskSize, ulonglong &totalFreeBytes )
{
bool retVal = false;
struct statfs fs;
if( ( statfs( devPath.c_str(), &fs ) ) < 0 ) {
    printf( "Failed to stat %s: %s
", devPath.c_str() ,strerror( errno ) );
    return false;
} else {
    diskSize = fs.f_blocks * fs.f_bsize;
    totalFreeBytes = fs.f_bfree * fs.f_bsize;
    retVal = true;
}
return retVal;
}

int main()
{
  ulonglong diskSize, totalFreeBytes;
  CheckDiskSpace( "/dev/sda5", diskSize, totalFreeBytes );
  printf( "Disk size: %llu Byte
", diskSize );
  printf( "Free size: %llu Byte
", totalFreeBytes );
}

我得到:

Disk size: 1798447104 Byte
Free size: 1798443008 Byte

我确实不理解这一结果,因为“df”指挥我得到:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda5            111148848  47454952  58047832  45% /
udev                   1756296         4   1756292   1% /dev
tmpfs                   705324       912    704412   1% /run
none                      5120         0      5120   0% /run/lock
none                   1763300      1460   1761840   1% /run/shm

Any help is very appeciated !

PS:我有120英镑,我的分治在外。

EDIT: ulonglong is a predifined type:

typedef unsigned long long ulonglong;
最佳回答

您正在获得在<代码>/dev上安装的标语结果,因为/dev/sda5正在这一文档系统中。 如欲了解您的原始档案系统,仅使用<代码>/<>/code>或<代码>上的任何途径。

问题回答

i 认为你想要的是:

CheckDiskSpace( "/dev/sda5", &diskSize, &totalFreeBytes );

由于磁盘和总数 在米斯克航天公司,自由布局与贵方的代码没有变化。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签