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)
--- /dev/null
+/*
+ * 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);
+}