Bug in MS C unlink() ?

Brad Brown bradb at ai.toronto.edu
Tue Mar 14 01:07:29 AEST 1989


In article <1032 at infmx.UUCP> aland at infmx.UUCP (Dr. Scump) writes:
>I ran into a nasty problem with unlink() in Microsoft C's unlink()
>call (MS C 4.0 and 5.1).  It seems that if one unlinks an *open*
>file on a hard disk, the result is lost clusters!   the unlink()
>call itself returns 0.
>

This makes sense, given how the operating system works.  (That's not to say
that PC users (like myself) would not be much better off with a *real* 
operating system :-)  I don't think this is a bug, just an evilness on the
part of the operating system.

The problem occurs for the following reason:  DOS is not smart enough to
hold an unlink()ed file open until it is close()d, so the file just
dissapears from the FAT and directory.  Your program, however, still has
what it thinks is an open file handle that includes some FAT information.
When you close the file or terminate the program, the FAT information in 
the file handle is written out but THE DIRECTORY IS NOT UPDATED, which is
eq. to producing lost clusters (since these clusters are not part of any
file and are not part of the free cluster chain...)

Unfortunately, compatability constraints and general dumbness of the 
operating system preclude an easy answer.

					(-:  Brad Brown  :-)
					bradb at ai.toronto.edu





More information about the Comp.lang.c mailing list