add mmap-write master
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 15 May 2014 15:36:49 +0000 (11:36 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 15 May 2014 15:36:49 +0000 (11:36 -0400)
progs/.gitignore
progs/Makefile
progs/mmap-write.c [new file with mode: 0644]

index 40b68a0b5f7ea2ced100824eaa041ec42f9738d9..8a3d8ac59120efa4dc63bc9e723d17b2c545173f 100644 (file)
@@ -1,10 +1,15 @@
+bug418
+chdir-open
 creat-open
-open-unlink
 flock-copyup
 fsync
-truncate
-bug418
-rmdircheckinode
-rename
+ftruncate-unlink
 mapper
+mapper2
+mmap-write
+open-unlink
 queryfile
+rename
+rmdir-open
+rmdircheckinode
+truncate
index 54dedb6d7d45f7f5d3fce2edf8e99df8ad1724e7..d396ad967ac5c63585c51d2a26938c7793a77493 100644 (file)
@@ -20,7 +20,7 @@ CFLAGS=-g -Wall # -Werror # -lefence
 MOUNTPOINT=.
 BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode \
        creat-open rename mapper queryfile mapper2 ftruncate-unlink \
-       rmdir-open chdir-open
+       rmdir-open chdir-open mmap-write
 
 all: $(BINS)
 
diff --git a/progs/mmap-write.c b/progs/mmap-write.c
new file mode 100644 (file)
index 0000000..a442726
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * mmap-write.c (courtesy Theodore Ts'o <tytso@mit.edu>)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv)
+{
+  int fd;
+  char *map;
+
+  fd = open(argv[1], O_RDWR|O_CREAT, 0666);
+  if (fd < 0) {
+    perror("open");
+    exit(1);
+  }
+  if (ftruncate(fd, 4096) < 0) {
+    perror("ftruncate");
+    exit(1);
+  }
+  map = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+  if (map == MAP_FAILED) {
+    perror("mmap");
+    exit(1);
+  }
+  strcpy(map,
+        "Murphy Magic. The SeCrEt of the UnIvErSe is 43, NOT 42.\n");
+  if (msync(map, 4096, MS_SYNC)  < 0) {
+    perror("msync");
+    exit(1);
+  }
+  exit(0);
+}