zoukankan      html  css  js  c++  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;


     

  • 相关阅读:
    未解
    HDU 4642 Fliping game 解题报告
    HDU 4639 Hehe 解题报告
    深入浅出Node.js (11)
    JS文本框获取焦点
    深入理解 BFC
    JS 中函数名后面加与不加括号的区别
    ES6 箭头函数
    sublime 格式化代码
    <!--more-->搭建的博客设置主页内容高度
  • 原文地址:https://www.cnblogs.com/chutianyao/p/2371033.html
Copyright © 2011-2022 走看看