美文网首页
centos 7默认文件系统xfs,目录判断出错

centos 7默认文件系统xfs,目录判断出错

作者: typedef708 | 来源:发表于2016-10-01 18:03 被阅读545次

    centos7 的默认安装的文件系统是XFS 类型该类型对于大数据量,文件索引是非常高效的。

    但是使用原来的针对文件是否为目录的判定就是会失效

    bool isDir(path){

    DIR* pdir = NULL;

    structdirent *pfile = NULL;

    if(!(pdir = opendir(path.c_str())))

                returnfalse;

    while((pfile =readdir(pdir))){

    if(pfile->d_type==4 && strcmp(pfile->d_name,".") && strcmp(pfile->d_name,".."))

    {

      return true;

    }

    }

    上面这段代码 pfile->d_type==4在文件系统为ext3 nfs ext4是可以正常使用。但是在xfs上就没法判断了。

    boolIsDir(std::string path)

    {

    structstat sb;

    if(stat(path.c_str(), &sb) == -1)

              returnfalse;

    return S_ISDIR(sb.st_mode);

    }

    在XFS上只能用上面的方法来判断,才能判断正确


    文件系统的差异对比

    http://www.zhihu.com/question/24413471

    http://blog.csdn.net/nuli888/article/details/51870184

    相关文章

      网友评论

          本文标题:centos 7默认文件系统xfs,目录判断出错

          本文链接:https://www.haomeiwen.com/subject/hggryttx.html