home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 21727 < prev    next >
Encoding:
Text File  |  1993-01-22  |  2.8 KB  |  81 lines

  1. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!sgiblab!adagio.panasonic.com!nntp-server.caltech.edu!SOL1.GPS.CALTECH.EDU!CARL
  2. From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
  3. Newsgroups: comp.os.vms
  4. Subject: Re: Flushing file buffers to disk in VAX C
  5. Date: 22 Jan 1993 13:24:20 GMT
  6. Organization: HST Wide Field/Planetary Camera
  7. Lines: 67
  8. Distribution: world
  9. Message-ID: <1josi4INN32k@gap.caltech.edu>
  10. References: <5946@osc.COM>
  11. Reply-To: carl@SOL1.GPS.CALTECH.EDU
  12. NNTP-Posting-Host: sol1.gps.caltech.edu
  13.  
  14. In article <5946@osc.COM>, vivekr@osc.COM (Vivek Rau) writes:
  15. =The problem:
  16. =------------
  17. =I am running VMS 5.5-1 on a VAXstation 4000 model 60. I find that
  18. =the C library call fsync() does not write the file buffers to disk
  19. =as it is supposed to. Could someone else run the program below on 
  20. =this or earlier versions of VMS and check it? Run the program on 
  21. =one terminal, and when it stops to wait for input, kill the process
  22. =using the STOP command from another terminal. If I understand the
  23. =functionality of fsync() correctly, the buffers should have been
  24. =flushed to disk - but when you look at the file after stopping the
  25. =process, it is still empty. Is this a bug? 
  26. =
  27. =#include <stdio.h>
  28. =#include <file.h>
  29. =
  30. =main()
  31. ={
  32. =    int fd;
  33.  
  34.     FILE *fp;
  35.  
  36. =    char buf[] = "This is a test record\n";
  37. =    char testFileName[] = "chks.out";
  38. =
  39. =    if ( (fd = open(testFileName, O_RDWR | O_CREAT)) < 0) {
  40. =        fprintf(stderr, "Error opening file. Exiting... \n");
  41. =        exit(0);
  42. =    }
  43. =
  44. =    fprintf(stderr, "The file being used is %s\n\n", testFileName);
  45. =    fprintf(stderr, "%s%s%s%s%s",
  46. =    "A record has been written to the file and sync'ed. If the fsync()\n",
  47. =    "call works correctly the data should be in the file even if the\n",
  48. =    "process is stopped. You can now halt the process from another\n",
  49. =    "terminal or window using the STOP command, or hit any key to let\n",
  50. =    "it run to completion...\n"
  51. =        );
  52. =    fflush(stderr);
  53. =
  54. =    write(fd, buf, sizeof(buf));
  55.  
  56.     fp = fdopen(fd, "w");
  57.     fflush(fp);
  58.  
  59. =    fsync(fd);
  60. =
  61. =    /**
  62. =        You can now stop the process from another terminal or
  63. =        window while it waits, or let it complete.
  64. =    **/
  65. =    getchar();
  66. =
  67. =    close(fd);
  68. =    fprintf(stderr, "Wrote the record and closed the file\n");
  69. =}
  70.  
  71. Hope that helps.  As we discussed in gory detail quite recently, you need to
  72. perform an fflush() before the fsync().
  73. --------------------------------------------------------------------------------
  74. Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
  75.  
  76. Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
  77. understanding of astronomy is purely at the amateur level (or below).  So
  78. unless what I'm saying is directly related to VAX/VMS, don't hold me or my
  79. organization responsible for it.  If it IS related to VAX/VMS, you can try to
  80. hold me responsible for it, but my organization had nothing to do with it.
  81.