目标文件夹修改后的 POSIXeekdir() 和telldir() 行为
考虑以下任务:
1)读取目标目录内容,将每个找到的不同结构传递给某个过滤器函数,并以某种方式记住过滤后的元素以供以后处理
2)一段时间后,迭代过滤后的元素并处理它们(做一些我/ O)
最明显的方法是保存子目录的名称。
但是,我希望将内存使用量保持在最低限度并避免额外的 I/O。
根据 POSIX 手册,我可以使用telldir() 保存每个目录条目的位置,并在以后使用seekdir() 恢复它们。为了保持这些位置有效,我必须保持目标目录打开并且不使用 rewinddir() 调用。
保持目录流打开并存储目录位置列表(长整型)似乎是一个合适的解决方案。
但是,尚不清楚文件夹修改后存储的位置是否仍然有效。我在 POSIX 标准中没有找到对这些条件的任何评论。
- 1) 仅添加/删除新目录条目时,存储位置是否仍然有效?
- 2) 在删除某些过滤目录条目的情况下,未修改目录条目的存储位置是否仍然有效?
- 3) 文件夹修改后存储位置是否可以指向另一个目录项?
对于特定系统来说,测试并找到这些问题的答案很容易,但我想知道关于这个主题的标准是什么
谢谢
consider the following task :
1) read a target directory contents, pass each found dirent structure to some filter function and remember filtered elements somehow for the later processing
2) some time later, iterate through the filtered elements and process them (do some I/O)
The most obvious way is to save names of sub-directories.
However, I want to keep memory usage to the minimum and to avoid additional I/O.
According to POSIX manuals, I can save position of each directory entry using telldir() and restore them later using seekdir(). To keep these positions valid, I have to keep target directory opened and to not use rewinddir() call.
Keeping a directory stream open and storing a list of dir positions(long int`s) seems to be an appropriate solution.
However, it is unclear whether stored positions remain valid after folder modification. I didn`t found any comments on these conditions in the POSIX standard.
- 1) Whether stored positions remain valid when only new directory entries are added/removed ?
- 2) Whether stored positions of unmodified directory entries remain valid in case of some of the filtered directory entries were removed ?
- 3) Is it possible for the stored position to point to another directory entry after folder modification ?
It is easy to test and find out the answer on these questions for the particular system, but I would like to know what standards say on this topic
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用
rewinddir
或关闭并重新打开目录之前,您对目录内容的视图不应改变。抱歉,我手边没有参考资料。如果你需要的话我稍后会找到它。Until you call
rewinddir
or close and reopen the directory, your view of the directory contents should not change. Sorry I don't have the reference handy. I'll find it later if you need it.