config root man

Current Path : /usr/src/tools/regression/nfsmmap/test2/

FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64
Upload File :
Current File : //usr/src/tools/regression/nfsmmap/test2/test2.c

#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    int fd, fd2;
    caddr_t addr;
    char zeros[4096];
    char ones[200];

    memset(zeros, 0, sizeof zeros);
    memset(ones, 1, sizeof ones);
#if 0
    unlink("test2.data");
    fd = open("test2.data", O_RDWR|O_CREAT, 0666);
    if (fd < 0)
	err(1, "creating file");
    if (write(fd, zeros, sizeof zeros) < 0)
	err(1, "writing zeros");
    close(fd);
#endif

    fd = open("test2.data", O_RDWR);
    if (fd < 0)
	err(1, "opening file");
    if (lseek(fd, 600, SEEK_SET) < 0)
	err(1, "seeking");
	
    if (write(fd, ones, sizeof ones) < 0)
	err(1, "writing ones");

    addr = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
    if (addr == MAP_FAILED)
	err(1, "mapping");
    unlink("test2.scratch");
    fd2 = open("test2.scratch", O_RDWR|O_CREAT, 0666);
    if (fd2 < 0)
	err(1, "creating scratch");
    
    if (write(fd2, addr, 4096) < 0)
	err(1, "writing scratch");
}

Man Man