Linux 中是否可以在不向硬盘发出请求的情况下检查文件是否存在?
这是我在这里发表的第一篇文章。
我想检查文件是否存在但不使用硬盘。例如看看这段代码:
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
据我所知 ext4 是日志文件系统。这是否意味着脚本可以通过查看日志(即主内存)来检查文件是否存在,而无需接触硬盘?
感谢您抽出时间。
UPD。
是否有任何文件系统可以将硬盘的日志保留在主内存中,以便可以在不访问硬盘的情况下完成文件存在的操作?
This is my first post here.
I want to check if a file exists but without using hard disk. For example look at this code:
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
As far as I know ext4 is journaling file system. Does it mean that the script can check if the file exists by looking into it journal, that is main memory without touching hard disk?
Thanks for your time.
UPD.
Is there any filesystem that keeps hard disk's journal in main memory, so that file exist's operation can be done without accessing the hard disk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
日志 (a) 存在于磁盘上,并且 (b) 完全解决了另一个问题。
当你进行这样的调用时,内核将询问文件系统。如果文件结构的必要块缓存在内存中,则它不会访问磁盘。如果不是,它也会的。
The journal (a) lives on the disk, and (b) solves another problem entirely.
When you make a call like this, the kernel will ask the file system. If the necessary blocks of the file structure are cached in memory, it won't access the disk. If they're not, it will.
不会。文件系统日志不会完全保存在内存中,并且在任何情况下都不包含文件系统中的所有元数据。它仅用作一种工具,可以更快地从不干净的卸载中恢复。
No. A filesystem journal is not kept entirely in memory, and in any event does not contain all metadata in the file system. It's solely used as a tool to make recovery from an unclean unmount faster.