home *** CD-ROM | disk | FTP | other *** search
- 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
- From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
- Newsgroups: comp.os.vms
- Subject: Re: Flushing file buffers to disk in VAX C
- Date: 22 Jan 1993 13:24:20 GMT
- Organization: HST Wide Field/Planetary Camera
- Lines: 67
- Distribution: world
- Message-ID: <1josi4INN32k@gap.caltech.edu>
- References: <5946@osc.COM>
- Reply-To: carl@SOL1.GPS.CALTECH.EDU
- NNTP-Posting-Host: sol1.gps.caltech.edu
-
- In article <5946@osc.COM>, vivekr@osc.COM (Vivek Rau) writes:
- =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?
- =
- =#include <stdio.h>
- =#include <file.h>
- =
- =main()
- ={
- = int fd;
-
- FILE *fp;
-
- = 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));
-
- fp = fdopen(fd, "w");
- fflush(fp);
-
- = 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");
- =}
-
- Hope that helps. As we discussed in gory detail quite recently, you need to
- perform an fflush() before the fsync().
- --------------------------------------------------------------------------------
- Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
-
- Disclaimer: Hey, I understand VAXen and VMS. That's what I get paid for. My
- understanding of astronomy is purely at the amateur level (or below). So
- unless what I'm saying is directly related to VAX/VMS, don't hold me or my
- organization responsible for it. If it IS related to VAX/VMS, you can try to
- hold me responsible for it, but my organization had nothing to do with it.
-