home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!att!cbnewsc!cbfsb!att-out!pacbell.com!pacbell!osc!vivekr
- From: vivekr@osc.COM (Vivek Rau)
- Newsgroups: comp.os.vms
- Subject: Flushing file buffers to disk in VAX C
- Message-ID: <5946@osc.COM>
- Date: 21 Jan 93 18:02:22 GMT
- Reply-To: vivekr@osc.UUCP (Vivek Rau)
- Organization: Versant Object Technology, Menlo Park, CA
- Lines: 77
-
- The problem:
- ------------
- I am running VMS 5.5-1 on a VAXstation 4000 model 60. I find that
- the C library call fsync() does not write the file buffers to disk
- as it is supposed to. Could someone else run the program below on
- this or earlier versions of VMS and check it? Run the program on
- one terminal, and when it stops to wait for input, kill the process
- using the STOP command from another terminal. If I understand the
- functionality of fsync() correctly, the buffers should have been
- flushed to disk - but when you look at the file after stopping the
- process, it is still empty. Is this a bug?
-
- Some more details:
- -----------------
-
- I am using VAX C version 3.2 - earlier versions of the RTL may not
- support the fsync() call. It is not documented in the RTL reference
- manual even in the current version, but it is available in the
- library. There is no other way to ensure that C file data has
- been written to disk and the disk version is up-to-date (short of
- closing the file).
-
- I do not think the bug is in the fsync() routine itself; you can verify
- that the routine calls the RMS routine sys$flush() internally, as you
- might expect. (You can check this out by stepping through the
- assembly instructions with the debugger). I have tried calling
- sys$flush() directly, and it returns without error - still
- without writing the buffers to the file. So is the error in RMS?
-
- Another puzzle which I wonder if someone could explain to me - the
- C write() routine does not call RMS sys$write() at all. It calls
- sys$read() instead! Is there something wrong with my debugger
- symbols or is this the right thing for write() to do? It works, i.e.
- the file does get written to normally. Does this have something
- to do with the above problem?
-
- Please reply to me by email if you have Internet access: vivekr@osc.com
- If anything interesting emerges I will summarize the results in another
- post to the net.
-
- ----------------- Source code begins here ----------------------------
- #include <stdio.h>
- #include <file.h>
-
- main()
- {
- int fd;
- char buf[] = "This is a test record\n";
- char testFileName[] = "chks.out";
-
- if ( (fd = open(testFileName, O_RDWR | O_CREAT)) < 0) {
- fprintf(stderr, "Error opening file. Exiting... \n");
- exit(0);
- }
-
- fprintf(stderr, "The file being used is %s\n\n", testFileName);
- fprintf(stderr, "%s%s%s%s%s",
- "A record has been written to the file and sync'ed. If the fsync()\n",
- "call works correctly the data should be in the file even if the\n",
- "process is stopped. You can now halt the process from another\n",
- "terminal or window using the STOP command, or hit any key to let\n",
- "it run to completion...\n"
- );
- fflush(stderr);
-
- write(fd, buf, sizeof(buf));
- fsync(fd);
-
- /**
- You can now stop the process from another terminal or
- window while it waits, or let it complete.
- **/
- getchar();
-
- close(fd);
- fprintf(stderr, "Wrote the record and closed the file\n");
- }
-