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

717 views Asked by At

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?

2

There are 2 answers

2
bmargulies On BEST ANSWER

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.

0
AudioBubble On

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.