home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1762 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: tim@delluk.uucp (Tim Wright)
  2. Newsgroups: alt.sources
  3. Subject: Re: ELVIS WARNING - LOST CLUSTERS ON PC's
  4. Message-ID: <tim.652116245@holly>
  5. Date: 31 Aug 90 15:24:05 GMT
  6.  
  7. In <689@aut.UUCP> nbladt@aut.UUCP (Norbert Bladt) writes:
  8.  
  9. >tjr@cbnewsc.att.com (thomas.j.roberts) writes:
  10.  
  11. >>Following up to my previous posting on successfully building elvis:
  12.  
  13. >>BEWARE! elvis is NOT cleaning up properly - it leaves LOST CLUSTERS
  14. >>on the temp disk.
  15. ...
  16. >I had the same problem with a program ported from UNIX to MS-DOS.
  17. >On UNIX (every flavour) it is possible to do the following (this
  18. >may not be correct on UNIX, just to give you the idea what happens,
  19. >no runtime checks included):
  20.  
  21.  
  22. >    char *TmpFileName, mktemp();
  23. >    FILE TmpFile, fopen();
  24.  
  25. >        /* Create a unique name for temp. file */
  26. >    TmpFileName = mktemp ("/tmp/pipapoXXXXXX");
  27.  
  28. >        /* open temp. file */
  29. >    TmpFile = fopen (TmpFileName, "r+");
  30.  
  31. >    unlink (TmpFileName);    /* delete temporary file.
  32. >                   However, it is NOT deleted,
  33. >                   because it has been opened by
  34. >                   an application, i.e. this program !
  35. >                */
  36.  
  37. >    /* Do the usual fread and fwrite operations here */
  38.  
  39. >    exit();    /* this will close and delete the temporary file */
  40.  
  41. >If you do this on MS-DOS it will create lost clusters.
  42. >On VMS it simply doesn't work (error reported by unlink).
  43. >If you ignore the error code of the unlink (which most programs do :-( )
  44. >the temporary file is still existing after your application did exit.
  45. >Since it is the temp disk you are having problems with, this rang a bell
  46. >in me.
  47.  
  48. This style of programming is *perfectly* valid under UNIX. It is part
  49. of the UNIX filesystem semantics and is a good way of creating a
  50. temporary file that nobody can mess up (excepting race conditions),
  51. even without the BSD-style protected tmp directories. It also avoids
  52. leaving the temporary file around in the case of the process
  53. receiving a kill -9. However, as you noted, this causes problems
  54. elsewhere (although what DOS does just shows how poor DOS is). NFS has
  55. a special work around for this case, since it is used in other UNIX
  56. code, and cannot be properly handled by a truly stateless server.
  57. I'm sure it will be helpful to people that to know where the problem
  58. lies. Thanks,
  59.  
  60. Tim
  61. --
  62. Tim Wright, Unix Support               | Email: ...!ukc!delluk!tim
  63. Dell Computer Corp. (UK), Bracknell    | (pending domain registration).
  64.