Subject: Re: Filesystem semantics question
To: Greg Hudson <ghudson@mit.edu>
From: Giles Lean <giles@nemeton.com.au>
List: netbsd-help
Date: 12/05/1999 08:57:06
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <24805.944344606.1@nemeton.com.au>

On Sat, 04 Dec 1999 16:13:10 -0500  Greg Hudson wrote:

> You missed the part of my description where I said, "if the machines
> boot uncleanly after this process."

Mmm, I misread it actually.  Same result. :-)

> Thanks for the standards quote about fsync().  I think for the long
> term I will write a little fsync program to help with safely rewriting
> files inside shell scripts.

Only if you don't like the attached one, which I hereby place in the
public domain.

Regards,

Giles


------- =_aaaaaaaaaa0
Content-Type: text/plain; name="fsync.c"; charset="us-ascii"
Content-ID: <24805.944344606.2@nemeton.com.au>

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    int i;
    int error;

    error = 0;
    for (i = 1; i < argc; i++) {
	int fd;
	fd = open(argv[i], O_WRONLY);
	if (fd == -1) {
	    fprintf(stderr, "fsync: open: %s: %s\n", argv[i], strerror(errno));
	    error = 1;
	    continue;
	}
	if (fsync(fd) == - 1) {
	    fprintf(stderr, "fsync: %s: %s\n", argv[i], strerror(errno));
	    error = 1;
	    continue;
	}
	close(fd);
    }
    exit(error);
}

------- =_aaaaaaaaaa0--