【发布时间】:2017-10-04 18:23:30
【问题描述】:
我正在为 FUSE 中的 ramdisk 编写代码。在我挂载我的 ramdisk(我指定它的大小作为参数)之后,我希望使用 df -h 来查看我的 ramdisk 占用的空间是否与我作为参数提到的大小相同。
为此,我在 fuse-2.9.7 的“examples”文件夹中使用了 statfs() 函数,例如 fusexmp.c 中给出的函数:
static int ramdisk_statfs(const char *path, struct statvfs *stbuf)
{
int res;
res = statvfs(path, stbuf);
if (res == -1)
return -errno;
return 0;
}
但是,我在“df -h”命令的输出中得到的大小不是我在安装 ramdisk 时提到的大小。
例如,假设我使用以下方式安装我的 ramdisk:
./ramdisk /mnt/ram 2
(where 2 is the size I specify for my ramdisk.)
在此之后,我使用“df -h”并得到:
Filesystem Size Used Avail Use% Mounted on
ramdisk 46G 5.8G 37G 14% /mnt/ram
(but this is not the size specified by me above for my ramdisk.)
在此之后我使用“free -h”查看空闲 RAM,我得到:
total used free shared buffers cached
Mem: 1.7G 806M 954M 5.5M 85M 296M
-/+ buffers/cache: 424M 1.3G
Swap: 3.9G 0B 3.9G
如果我不在我的文件系统代码中使用 statfs() 函数,而我使用 "df -h /mnt/ram" ,我会得到:
Filesystem Size Used Avail Use% Mounted on
ramdisk 0 0 0 0 /mnt/ram
我想问一下上面给出的statfs()的实现是不是错了?代码应该怎么写才能让“df -h”显示正确的内存值?
【问题讨论】:
-
statvfsfor/mnt/ram将提供该文件夹所在的 fs 的统计信息(可能是/,但也可以是/mnt)
标签: c filesystems fuse