系统调用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;


 

 

posted @ 2012-02-28 09:54    阅读(2617)  评论(0编辑  收藏  举报