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

2016-10-01  本文已影响545人  typedef708

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

上一篇下一篇

猜你喜欢

热点阅读