basic C question

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Mon Jul 12 19:54:40 UTC 2004


On Mon, Jul 12, 2004 at 03:54:28PM -0400, fcsoft-3Emkkp+1Olsmp8TqCH86vg at public.gmane.org wrote:
> I've been struggling off and on with problems of this nature for a
> while.
> 
> Essentially the problem is how to detect that a file descriptor which
> was previously successfully opened no longer points to a valid inode.
> 
> 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().
> 
> Compile this code and run it.      It will write "go1" and "go2" into
> a file called bob.dat separated by a sleep of 20 sec.
> 
> 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 question remains how can we verify the veracity of the file
> descriptor we are about to write to before we actually allow the write
> to "succeed" regardless.

My understanding is that inode does not get removed if it's still being
used.  So, the name 'bob.dat' is unlinked and no longer exist.  But, the
file (ie. inode that was file 'bob.dat') still exist, and will be
removed after your program exits.

-- 
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Toronto, Ontario, Canada
--
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