statfs java_系统调用statfs()在大容量磁盘上会失败

昨天在客户现场部署一套录制时,遇到一个小问题,且记录下来。

系统启动后,日志会告警:

statfs error. strPath:/figure/datafile/recordfile5/FullRecord/StreamTS/1-1-东方卫视, Value too large for defined data type RepeatCount=34

经查问题如下:

(1)我们的系统开启了一个线程,不断的扫描系统磁盘的使用情况。使用的是系统调用 statfs();

struct statfs {

long f_type; /* type of file system (see below) */

long f_bsize; /* optimal transfer block size */

long f_blocks; /* total data blocks in file system */

long f_bfree; /* free blocks in fs */

long f_bavail; /* free blocks avail to unprivileged user */

long f_files; /* total file nodes in file system */

long f_ffree; /* free file nodes in fs */

fsid_t f_fsid; /* file system id */

long f_namelen; /* maximum length of filenames */

};

(2)现场使用的是NAS,容量达到35T;

(3)磁盘每个block为4k,则总计有9395240960个blocks;

(4)而目标平台上 sizeof(long) = sizeof(int) =4 bytes,能表示的最大数为:4294967296

(5)所以,在调用statfs时,会因为溢出而导致调用失败。

最后解决办法是:使用64位的statfs64.

struct statfs64 fs;

if (statfs64(strPath.c_str(), &fs) < 0)

{

LOG_PERIOD(LOG_TYPE_WARN, "statfs error. strPath:%s, %s", strPath.c_str(), strerror(errno));

return 100;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值