[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: read() on a deleted file

> This is what I understand now, if I delete the file, the kernel
> guarantees that the file data is preserved till the last reference (in
> the form of an open filehandle maybe) lingers. If I shred the file,
> the read succeeds till the buffering is done.

Actually, you can't delete a file while there are references to it. You can
remove it from its directory, which reduces the reference count by one, but
that's it. That's why the system call in UNIX is called "unlink" rather than

A file is automatically deleted when its reference count goes to zero.
Putting a file in a directory adds one to its reference count. Opening a
file adds one.

> This, however sounds wierd to me, what we are essentially saying is
> that the open/read might not return the latest data!!!! AFAIK the
> buffer cache/inode cache that the kernel maintains is refreshed as
> soon the file is modified. Please clarify.

It's impossible to clarify unless you tell us more precisely what you are
doing. For example, you use the term "shred", but that can mean way more
than one thing. Also, when you talk about "reading" a file, that could mean
the "read" system call, but it could also mean the "fread" library function.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]