From: MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 23-JAN-1993 22:36:33.89 To: info-vax@kl.sri.com CC: Subj: Re: Flushing file buffers to disk in VAX C 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 =#include = =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.