From: Erez Zadok Date: Wed, 30 Mar 2011 03:45:35 +0000 (-0400) Subject: ftruncate tests X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=38101a6c906212e4ae34857fcd015c44243487f0;p=unionfs-regression.git ftruncate tests Signed-off-by: Erez Zadok --- diff --git a/progs/Makefile b/progs/Makefile index b2c448a..bfcb5c1 100644 --- a/progs/Makefile +++ b/progs/Makefile @@ -19,7 +19,7 @@ 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) diff --git a/progs/ftruncate-unlink.c b/progs/ftruncate-unlink.c new file mode 100644 index 0000000..380e8aa --- /dev/null +++ b/progs/ftruncate-unlink.c @@ -0,0 +1,64 @@ +/* + * 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 +#include +#include +#include +#include + + +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); +}