189029Sjhb#include <sys/types.h>
289029Sjhb#include <sys/fcntl.h>
389029Sjhb#include <sys/mman.h>
489029Sjhb#include <unistd.h>
589029Sjhb
689029Sjhbint main(int argc, char** argv)
789029Sjhb{
889029Sjhb    int fd, fd2;
989029Sjhb    caddr_t addr;
1089029Sjhb    char zeros[4096];
1189029Sjhb    char ones[200];
1289029Sjhb
1389029Sjhb    memset(zeros, 0, sizeof zeros);
1489029Sjhb    memset(ones, 1, sizeof ones);
1589029Sjhb#if 0
1689029Sjhb    unlink("test2.data");
1789029Sjhb    fd = open("test2.data", O_RDWR|O_CREAT, 0666);
1894929Sgerald    if (fd < 0)
1994929Sgerald	err(1, "creating file");
2094929Sgerald    if (write(fd, zeros, sizeof zeros) < 0)
2194929Sgerald	err(1, "writing zeros");
2289029Sjhb    close(fd);
2389029Sjhb#endif
2489029Sjhb
2589029Sjhb    fd = open("test2.data", O_RDWR);
2689029Sjhb    if (fd < 0)
2789029Sjhb	err(1, "opening file");
2889029Sjhb    if (lseek(fd, 600, SEEK_SET) < 0)
2989029Sjhb	err(1, "seeking");
3089029Sjhb
3189029Sjhb    if (write(fd, ones, sizeof ones) < 0)
3289029Sjhb	err(1, "writing ones");
3389029Sjhb
34147276Smarius    addr = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
35147276Smarius    if (addr == MAP_FAILED)
36143311Sobrien	err(1, "mapping");
37143311Sobrien    unlink("test2.scratch");
38147276Smarius    fd2 = open("test2.scratch", O_RDWR|O_CREAT, 0666);
39143311Sobrien    if (fd2 < 0)
40143311Sobrien	err(1, "creating scratch");
41147276Smarius
42147276Smarius    if (write(fd2, addr, 4096) < 0)
4389029Sjhb	err(1, "writing scratch");
44147276Smarius}
45147276Smarius