Hacker News new | ask | show | jobs
by combatentropy 2283 days ago
The kernel returns EOF "if k is the current file position and m is the size of a file, performing a read() when k >= m..."

So, is the length of each file stored as an integer, along with the other metadata? This reminds me of how in JavaScript the length of an array is a property, instead of a function that counts it right then, like say in PHP.

Apparently it works. I've never heard of a situation where the file size number did not match the actual file size, nor of a time when the JavaScript array length got messed up. But it seems fragile. File operations would need to be ACID-compliant, like database operations (and likewise do JavaScript array operations). It seems like you would have to guard against race conditions.

Does anyone have a favorite resource that explains how such things are implemented safely?

1 comments

You are not thinking about it clearly. Ask yourself this: Filesystem formats use blocking and deblocking. How would a filesystem know the file size without having metadata for it?