test1.c revision 303975
1178431Sscf#include <sys/types.h> 2178431Sscf#include <sys/fcntl.h> 3178431Sscf#include <sys/mman.h> 4178431Sscf#include <unistd.h> 5178431Sscf 6178431Sscfint main(int argc, char** argv) 7178431Sscf{ 8178431Sscf int fd, fd2; 9178431Sscf caddr_t addr; 10178431Sscf char zeros[4096]; 11178431Sscf char ones[200]; 12178431Sscf 13178431Sscf memset(zeros, 0, sizeof zeros); 14178431Sscf memset(ones, 1, sizeof ones); 15178431Sscf#if 0 16178431Sscf unlink("test1.data"); 17178431Sscf fd = open("test1.data", O_RDWR|O_CREAT, 0666); 18178431Sscf if (fd < 0) 19178431Sscf err(1, "creating file"); 20178431Sscf if (write(fd, zeros, sizeof zeros) < 0) 21178431Sscf err(1, "writing zeros"); 22178431Sscf close(fd); 23178431Sscf#endif 24178431Sscf 25178431Sscf fd = open("test1.data", O_RDWR); 26178431Sscf if (fd < 0) 27178431Sscf err(1, "opening file"); 28178431Sscf if (lseek(fd, 600, SEEK_SET) < 0) 29178431Sscf err(1, "seeking"); 30178431Sscf 31228545Sbapt if (write(fd, ones, sizeof ones) < 0) 32228545Sbapt err(1, "writing ones"); 33184831Sscf 34228545Sbapt fsync(fd); 35228545Sbapt 36228545Sbapt addr = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); 37178431Sscf if (addr == MAP_FAILED) 38178431Sscf err(1, "mapping"); 39184831Sscf unlink("test1.scratch"); 40228545Sbapt fd2 = open("test1.scratch", O_RDWR|O_CREAT, 0666); 41178431Sscf if (fd2 < 0) 42178431Sscf err(1, "creating scratch"); 43178431Sscf 44178431Sscf if (write(fd2, addr, 4096) < 0) 45228545Sbapt err(1, "writing scratch"); 46178431Sscf} 47228545Sbapt