Newsgroups: comp.lang.c Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!ephemeral.ai.toronto.edu!bradb From: bradb@ai.toronto.edu (Brad Brown) Subject: Re: Bug in MS C unlink() ? Message-ID: <89Mar13.100742est.10755@ephemeral.ai.toronto.edu> Keywords: unlink MS clusters Turbo_I-Net Organization: Department of Computer Science, University of Toronto References: <1032@infmx.UUCP> Date: Mon, 13 Mar 89 10:07:29 EST In article <1032@infmx.UUCP> aland@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@ai.toronto.edu