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;


     

  • 相关阅读:
    0601 新的冲刺
    0527 演示内容
    0525 项目回顾7.0
    0523 Scrum项目6.0
    0518 Scrum项目5.0
    Scrum 4.0
    0512 操作系统进程调度实验
    0511 backlog 项目管理
    复利计算器之单元测试
    操作系统的实验一实验报告
  • 原文地址:https://www.cnblogs.com/chutianyao/p/2371033.html
Copyright © 2011-2022 走看看