CFLAGS=-g -Wall # -Werror # -lefence
MOUNTPOINT=.
BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode \
- creat-open rename mapper queryfile mapper2
+ creat-open rename mapper queryfile mapper2 ftruncate-unlink
all: $(BINS)
--- /dev/null
+/*
+ * Copyright (c) 2003-2007 Erez Zadok
+ * Copyright (c) 2003-2006 Charles P. Wright
+ * Copyright (c) 2005-2007 Josef 'Jeff' Sipek
+ * Copyright (c) 2005-2006 Junjiro Okajima
+ * Copyright (c) 2005 Arun M. Krishnakumar
+ * Copyright (c) 2004-2006 David P. Quigley
+ * Copyright (c) 2003-2004 Mohammad Nayyer Zubair
+ * Copyright (c) 2003 Puja Gupta
+ * Copyright (c) 2003 Harikesavan Krishnan
+ * Copyright (c) 2003-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.
+ *
+ * This Copyright notice must be kept intact and distributed with all sources.
+ */
+
+/* ftruncate() an open but unlink'ed file */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+
+
+void usage(const char *argv) {
+ fprintf(stderr, "%s file size\n", argv);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ off_t size;
+ char *end;
+ int fd;
+
+ if (argc != 3) {
+ usage(argv[0]);
+ }
+ fd = open(argv[1], O_RDWR);
+ if (fd == -1) {
+ perror("open");
+ exit(1);
+ }
+ size = strtoul(argv[2], &end, 0);
+ if (*end) {
+ usage(argv[0]);
+ }
+ if (unlink(argv[1]) == -1) {
+ perror("unlink");
+ exit(1);
+ }
+ if (ftruncate(fd, size) == -1) {
+ perror("ftruncate");
+ exit(1);
+ }
+ if (close(fd) == -1) {
+ perror("close");
+ exit(1);
+ }
+ exit(0);
+}