#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>

typedef struct _cData { int num; char str[12]; } cData ;
#define NUM 20

int main()
{
        cData m, *pm;
        int fd, n ;

        fd = open("test.dat", O_RDWR|O_CREAT|O_TRUNC, 0644) ;
        for(n=0; n<NUM; n++) {
                m.num = n ;
                sprintf(m.str, "Arminia %2d", n);
                write(fd, &m, sizeof(cData)) ;
        }
        close(fd) ;

               
        fd = open("test.dat", O_RDWR) ;
        m.num = 70 ;
        sprintf(m.str, "Arminia %2d", 70) ;
        lseek(fd, sizeof(cData)*10, SEEK_SET) ;
        write(fd, &m, sizeof(cData)) ;

        pm = (cData *) mmap(0, NUM*sizeof(cData), PROT_READ|PROT_WRITE,
                                MAP_SHARED, fd, 0) ;
        pm[15].num = 90 ;
        sprintf(pm[15].str, "Arminia %2d", 90) ;
        msync((void *)pm, NUM*sizeof(cData), MS_ASYNC);
        munmap((void *)pm, NUM*sizeof(cData)) ;
        close(fd);
        exit(0);
}