Is it possible to check if a file exists without making a request to hard disk in Linux?

StackOverflow https://stackoverflow.com/questions/8886214

  •  16-04-2021
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

It will have to at least access the hard disk to see if it is there. Now actually opening the file? I would think not.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top