Messages in this thread | | | Date | Sat, 22 Jul 2000 16:58:42 -0600 | From | Jim <> | Subject | msync bug or RTFM ?? |
| |
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/
| |