存储子目录的引用

发布于 2024-12-13 22:28:40 字数 324 浏览 4 评论 0原文

在项目中,程序必须将目录的每个子目录的引用/标识符存储在其变量(例如堆栈)中。即,一旦读取目录,程序就不得再次对每个子级执行路径查找。

我不太确定该怎么做。因为如果存储了inode号,那么该inode就无法访问相应的文件/目录对吧?

将不胜感激一些指针

感谢

编辑:我“不得再次执行路径查找”的原因......一个线程正在以深度优先的方式读取文件系统树,当它读取目录时......其子级的标识符被保存以再次以深度优先的方式遵循它。为什么我保存标识符是因为已读取的目录可能会被并发线程移动到文件系统的另一部分,并且移动目录下的子树可能不会被读取,因为树的该部分已经被遍历。

In a project, the program must store references/identifiers of each child of a directory in its variables(say a stack). i.e the program must not perform pathlookup again for every child once a directory is read.

I am not very sure how to do that. Because if inode numbers are stored, the corresponding file/directory cannot be accessed by the inode right?

Will be gratefull for some pointers

Thanks

Edit: My reasons for "must not perform pathlookup again".....a thread is reading the file system tree in a depth first manner and when it reads a directory...identifiers of its children are saved to follow it in a depth first manner again. Why I save the indentifiers is because a directory that has been read may be moved to another part of the file system by a concurrent thread and the subtree under the moved directory may not be read as that part of the tree has already been traversed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼疼热情 2024-12-20 22:28:40

这听起来像家庭作业,只不过以前没有办法做到这一点。现在是可能的,但只能通过使用相当新的 openat 系统调用及其朋友(请参阅该联机帮助页底部的“另请参阅”列表)。您是正确的,您不能通过文件的索引节点号打开文件;但使用 *at 函数,您可以按名称​​相对于目录打开文件,您有一个打开的文件描述符(不是 <代码>DIR*)。

This smells like homework, except there didn't used to be a way to do this; it is possible now, but only by using the fairly new openat system call and its friends (see the "see also" list at the bottom of that manpage). You are correct that you cannot open a file by its inode number; but using the *at functions, you can open a file by name relative to a directory that you have an open file descriptor (not a DIR*) for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文