From: Erez Zadok Date: Wed, 30 Mar 2011 03:46:35 +0000 (-0400) Subject: added missing progs/mapper2.c file X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=3ae2094cf7a102fce94d821476af7c3f21bbfb64;p=unionfs-regression.git added missing progs/mapper2.c file Signed-off-by: Erez Zadok --- diff --git a/progs/mapper2.c b/progs/mapper2.c new file mode 100644 index 0000000..7022e60 --- /dev/null +++ b/progs/mapper2.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 1997-2007 Erez Zadok + * Copyright (c) 2001-2007 Stony Brook University + * Copyright (c) 2003-2007 The Research Foundation of SUNY + * + * For specific licensing information, see the COPYING file distributed with + * this package, or get one from + * ftp://ftp.filesystems.org/pub/fistgen/COPYING. + * + * This Copyright notice must be kept intact and distributed with all + * fistgen sources INCLUDING sources generated by fistgen. + * + * + * File: mapper.c + * + * Usage: mapper -r file + * Usage: mapper -w file + * -r will open file for reading only + * -w will open file for reading anf writing, and will change the file + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BASE 0 + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif /* not MAP_FAILED */ + +void usage(void) +{ + fprintf(stderr, "Usage: mapper -r filename\n"); + fprintf(stderr, " mapper -w filename\n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + int fd; + caddr_t pa; + int rw_flag = -1; /* 0=read, 1=read+write */ + char *filename, byte; + int i, size; +#if 0 + struct stat buf; +#endif + + i=0; + /* check input args */ + if (argc != 3) + usage(); + if (strcmp(argv[1], "-w") == 0) + rw_flag = 1; + else if (strcmp(argv[1], "-r") == 0) + rw_flag = 0; + else + usage(); + + filename = argv[2]; + +#if 0 + /* find size of file */ + if (stat(filename, &buf) < 0) { + perror("stat"); + exit(1); + } + size = buf.st_size; +#else + size = 3; +#endif + /* open input file */ + if (rw_flag) + fd = open(filename, O_RDWR); + else + fd = open(filename, O_RDONLY); + if (fd < 0) { + perror(filename); + exit(1); + } + printf("opened file %s\n", filename); + + /* mmap the input file */ + pa = mmap((caddr_t) 0, + size, + (rw_flag ? (PROT_READ | PROT_WRITE) : PROT_READ), + MAP_SHARED, + fd, + BASE); + if (pa == MAP_FAILED) { + perror("mmap"); + exit(1); + } + printf("file is mapped with address %p\n", pa); + +#if 0 + /* now read every 1024-th byte */ + for (i=0; i