免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4878 | 回复: 0
打印 上一主题 下一主题

readlink函数的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-15 16:39 |只看该作者 |倒序浏览
char buf[20];
readlink("/home/test",buf,10);
其中"/home/test"是一个指向"/usr/src/bsdoc"目录的软连接
在path_walk过程中,发现test文件是一个symbolic link之后,不会从/usr开始查找,而是从bsdoc这个目录开始

[code]
int Client::path_walk(const filepath& origpath, Inode **final, bool followsym)
{
  cout<<" enter path_walk\n ";
  filepath path = origpath;
  Inode *cur = cwd;
  assert(cur);

  //dout(10)
  cout << "path_walk " << path << std::endl;//dendl;

  for (unsigned i=0; i<path.depth() && cur; i++) {
    const string &dname = path[i];    /*取路径的目录名*/
    //dout(10)
    cout<< " " << i << " " << *cur << " " << dname <<std::endl;//dendl;
    Inode *next;
    int r = _lookup(cur, dname.c_str(), &next);/* _lookup函数查找文件路径 */
    if (r < 0)
      return r;
    cur = next;/*cur为查找到的目录索引节点next*/
    if (i == path.depth() - 1 && followsym &&
        cur && cur->is_symlink())
    {/*如果遍历到最后一个目录,当前索引节点为符号链接*/
      
      if (cur->symlink[0] == '/')
      {/*如果symlink[0]的内容是‘/’*/
        path = cur->symlink.c_str();/*文件路径path为symlink的内容*/
        cur = root;                    /*cur为root*/
       }
       else
       {
        filepath more(cur->symlink.c_str());/*否则追加到path路径后面*/
        path.append(more);
       }
      cout<<"after reset, new  path is: "<<path<<std::endl;
    }
  }
  if (!cur)
    return -ENOENT;/*cur为空则返回文件不存在*/
  if (final)
    *final = cur; /* final指向文件的索引节点*/
  cout<<"path_walk done!\n";
  return 0;
}

但是怎么readlink总是返回 No such file or directory这样的错误?
我认为是不是在path_walk函数里面的变量i有问题????
thank you if you can help me resolve this problem!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP