basic C question

Henry Spencer henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org
Mon Jul 12 19:55:29 UTC 2004


On Mon, 12 Jul 2004 fcsoft-3Emkkp+1Olsmp8TqCH86vg at public.gmane.org wrote:
> Essentially the problem is how to detect that a file descriptor which was 
> previously successfully opened no longer points to a valid inode.

In normal operation, there is no way that can happen.

> Here is some code which uses a standard file which illustrates quite simply  
> that write() will not fail when the inode is removed after a successful 
> open().

An inode which is currently open *can't* be removed.  An inode exists
until the last directory entry for it goes away *and* the last descriptor
open on it goes away. 

> Repeat the test,  but after the first write go to another console and remove 
> the bob.dat file.      The second write will still not return an error.    
> ie. file it is supposedly writing to is gone but the write() apparently quite 
> happily succeeds.

The file's directory entry is gone, but the file still exists.  It will
cease to exist only when the descriptor is closed.  It no longer has a
*name*, and there's no way it can acquire one, but the file itself is
still there.  The write appears to succeed because it *did* succeed --
the data was written successfully to the now-anonymous file.

If you write something rather larger to the file, and use "df" to watch
the free space on the filesystem, you will see the space being used up as
the file grows, and then released when the descriptor is closed and the
file dies. 

                                                          Henry Spencer
                                                       henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list