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


     

  • 相关阅读:
    python2.7下同步华为云照片的爬虫程序实现
    python 下字符串格式时间比较
    C# Socket通信 小案例
    win 10 安装 mysql解压版 步骤
    Android 连接 SQL Server (jtds方式)——下
    Android 连接 SQL Server (jtds方式)——上
    Android 项目建立步骤
    ubuntu 配置android开发环境
    ubuntu 安装eclipse
    ubuntu 配置Java jdk
  • 原文地址:https://www.cnblogs.com/chutianyao/p/2371033.html
Copyright © 2020-2023  润新知