/* dbench version 2 Copyright (C) by Andrew Tridgell 1999, 2001 Copyright (C) 2001 by Martin Pool This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Wrappers for system calls that catch errors. */ #include "dbench.h" #define MAX_FILES 1000 static char buf[70000]; extern int line_count; static struct { int fd; int handle; } ftable[MAX_FILES]; void do_unlink(char *fname) { strupper(fname); if (unlink(fname) != 0) { printf("(%d) unlink %s failed (%s)\n", line_count, fname, strerror(errno)); } } void expand_file(int fd, int size) { int s; while (size) { s = MIN(sizeof(buf), size); write(fd, buf, s); size -= s; } } void do_open(char *fname, int handle, int size) { int fd, i; int flags = O_RDWR|O_CREAT; struct stat st; static int count; strupper(fname); if (size == 0) flags |= O_TRUNC; fd = open(fname, flags, 0600); if (fd == -1) { printf("(%d) open %s failed for handle %d (%s)\n", line_count, fname, handle, strerror(errno)); return; } fstat(fd, &st); if (size > st.st_size) { #if DEBUG printf("(%d) expanding %s to %d from %d\n", line_count, fname, size, (int)st.st_size); #endif expand_file(fd, size - st.st_size); } else if (size < st.st_size) { printf("truncating %s to %d from %d\n", fname, size, (int)st.st_size); ftruncate(fd, size); } for (i=0;i