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

  1. Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!att!cbnewsc!cbfsb!att-out!pacbell.com!pacbell!osc!vivekr
  2. From: vivekr@osc.COM (Vivek Rau)
  3. Newsgroups: comp.os.vms
  4. Subject: Flushing file buffers to disk in VAX C
  5. Message-ID: <5946@osc.COM>
  6. Date: 21 Jan 93 18:02:22 GMT
  7. Reply-To: vivekr@osc.UUCP (Vivek Rau)
  8. Organization: Versant Object Technology, Menlo Park, CA
  9. Lines: 77
  10.  
  11. The problem:
  12. ------------
  13. I am running VMS 5.5-1 on a VAXstation 4000 model 60. I find that
  14. the C library call fsync() does not write the file buffers to disk
  15. as it is supposed to. Could someone else run the program below on 
  16. this or earlier versions of VMS and check it? Run the program on 
  17. one terminal, and when it stops to wait for input, kill the process
  18. using the STOP command from another terminal. If I understand the
  19. functionality of fsync() correctly, the buffers should have been
  20. flushed to disk - but when you look at the file after stopping the
  21. process, it is still empty. Is this a bug? 
  22.  
  23. Some more details:
  24. -----------------
  25.  
  26. I am using VAX C version 3.2 - earlier versions of the RTL may not 
  27. support the fsync() call. It is not documented in the RTL reference
  28. manual even in the current version, but it is available in the
  29. library. There is no other way to ensure that C file data has
  30. been written to disk and the disk version is up-to-date (short of
  31. closing the file).
  32.  
  33. I do not think the bug is in the fsync() routine itself; you can verify 
  34. that the routine calls the RMS routine sys$flush() internally, as you
  35. might expect. (You can check this out by stepping through the
  36. assembly instructions with the debugger). I have tried calling
  37. sys$flush() directly, and it returns without error - still
  38. without writing the buffers to the file. So is the error in RMS?
  39.  
  40. Another puzzle which I wonder if someone could explain to me - the
  41. C write() routine does not call RMS sys$write() at all. It calls
  42. sys$read() instead! Is there something wrong with my debugger
  43. symbols or is this the right thing for write() to do? It works, i.e.
  44. the file does get written to normally. Does this have something
  45. to do with the above problem?
  46.  
  47. Please reply to me by email if you have Internet access: vivekr@osc.com
  48. If anything interesting emerges I will summarize the results in another
  49. post to the net.
  50.  
  51. ----------------- Source code begins here ----------------------------
  52. #include <stdio.h>
  53. #include <file.h>
  54.  
  55. main()
  56. {
  57.     int fd;
  58.     char buf[] = "This is a test record\n";
  59.     char testFileName[] = "chks.out";
  60.  
  61.     if ( (fd = open(testFileName, O_RDWR | O_CREAT)) < 0) {
  62.         fprintf(stderr, "Error opening file. Exiting... \n");
  63.         exit(0);
  64.     }
  65.  
  66.     fprintf(stderr, "The file being used is %s\n\n", testFileName);
  67.     fprintf(stderr, "%s%s%s%s%s",
  68.     "A record has been written to the file and sync'ed. If the fsync()\n",
  69.     "call works correctly the data should be in the file even if the\n",
  70.     "process is stopped. You can now halt the process from another\n",
  71.     "terminal or window using the STOP command, or hit any key to let\n",
  72.     "it run to completion...\n"
  73.         );
  74.     fflush(stderr);
  75.  
  76.     write(fd, buf, sizeof(buf));
  77.     fsync(fd);
  78.  
  79.     /**
  80.         You can now stop the process from another terminal or
  81.         window while it waits, or let it complete.
  82.     **/
  83.     getchar();
  84.  
  85.     close(fd);
  86.     fprintf(stderr, "Wrote the record and closed the file\n");
  87. }
  88.