- 论坛徽章:
- 0
|
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! |
|