msync bug or RTFM ??

From: Jim (jaschut@flash.net)
Date: Sat Jul 22 2000 - 17:58:42 EST


Hi,

Based on what I've read in the man pages for
mmap/msync/munmap, and Stevens' APITUE, I think the following
program should create a file with scribbles in it. What I get
is a zero length file (on 2.2.1[46]).

Is this pointing to a bug in msync, or is there some other ;)
FM I should R ? Or maybe someone can give me a hint if I
misunderstood something I supposedly read?

TIA -- Jim

----------

#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>

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

        int fd, i = 0, flen = 500;
        unsigned char *ptr, *start;

        fd = open ("scribble.dat", O_RDWR | O_CREAT | O_TRUNC,
                   S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH );
        if (fd < 0) {
                perror ("Couldn't open output file");
                exit (-1);
        }
        ptr = start = mmap (0, flen, PROT_WRITE, MAP_PRIVATE, fd, 0);
        if ((long)ptr == -1) {
                perror ("couldn't mmap output file");
                exit (-1);
        }
        while (i++ < flen) *ptr++ = i%256;

        if (msync (start, flen, MS_SYNC)) {
                perror ("Couldn't sync output file");
                exit (-1);
        }
        if (munmap (start, flen)) {
                perror ("couldn't unmap ouput file");
                exit (-1);
        }
        if (close(fd)) {
                perror ("couldn't close output file");
                exit (-1);
        }
        exit (0);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jul 23 2000 - 21:00:19 EST