3 Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
4 Copyright (C) 2001 by Martin Pool <mbp@samba.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static char buf[70000];
28 extern int sync_open, sync_dirs;
35 static int find_handle(struct child_struct *child, int handle)
38 for (i=0;i<MAX_FILES;i++) {
39 if (ftable[i].handle == handle) return i;
41 printf("(%d) ERROR: handle %d was not found\n",
47 /* Find the directory holding a file, and flush it to disk. We do
48 this in -S mode after a directory-modifying mode, to simulate the
49 way knfsd tries to flush directories. MKDIR and similar operations
50 are meant to be synchronous on NFSv2. */
51 void sync_parent(char *fname)
57 if (strchr(fname, '/')) {
58 copy_name = strdup(fname);
59 slash = strrchr(copy_name, '/');
62 copy_name = strdup(".");
65 dir_fd = open(copy_name, O_RDONLY);
67 printf("open directory \"%s\" for sync failed: %s\n",
71 if (fdatasync(dir_fd) == -1) {
72 printf("datasync directory \"%s\" failed: %s\n",
76 if (close(dir_fd) == -1) {
77 printf("close directory failed: %s\n",
85 void nb_setup(struct child_struct *child)
88 sprintf(path, "/bin/rm -rf clients/client%d", child->id);
92 void nb_unlink(struct child_struct *child, char *fname)
94 if (unlink(fname) != 0) {
95 printf("(%d) unlink %s failed (%s)\n",
96 child->line, fname, strerror(errno));
98 if (sync_dirs) sync_parent(fname);
101 void nb_rmdir(struct child_struct *child, char *fname)
103 if (rmdir(fname) != 0) {
104 printf("(%d) rmdir %s failed (%s)\n",
105 child->line, fname, strerror(errno));
107 if (sync_dirs) sync_parent(fname);
110 void nb_createx(struct child_struct *child, char *fname,
111 unsigned create_options, unsigned create_disposition, int fnum)
116 if (sync_open) flags |= O_SYNC;
118 if (create_disposition == FILE_CREATE) {
122 if (create_disposition == FILE_OVERWRITE ||
123 create_disposition == FILE_OVERWRITE_IF) {
124 flags |= O_CREAT | O_TRUNC;
127 if (create_options & FILE_DIRECTORY_FILE) {
128 /* not strictly correct, but close enough */
132 if (create_options & FILE_DIRECTORY_FILE) flags = O_RDONLY|O_DIRECTORY;
134 fd = open(fname, flags, 0600);
137 printf("(%d) open %s failed for handle %d (%s)\n",
138 child->line, fname, fnum, strerror(errno));
143 printf("(%d) open %s succeeded for handle %d\n",
144 child->line, fname, fnum);
149 for (i=0;i<MAX_FILES;i++) {
150 if (ftable[i].handle == 0) break;
152 if (i == MAX_FILES) {
153 printf("file table full for %s\n", fname);
156 ftable[i].handle = fnum;
160 void nb_writex(struct child_struct *child, int handle, int offset,
161 int size, int ret_size)
163 int i = find_handle(child, handle);
165 if (buf[0] == 0) memset(buf, 1, sizeof(buf));
167 if (pwrite(ftable[i].fd, buf, size, offset) != ret_size) {
168 printf("write failed on handle %d\n", handle);
172 child->bytes_out += size;
175 void nb_readx(struct child_struct *child, int handle, int offset,
176 int size, int ret_size)
178 int i = find_handle(child, handle);
180 if (pread(ftable[i].fd, buf, size, offset) != ret_size) {
181 printf("read failed on handle %d\n", handle);
184 child->bytes_in += size;
187 void nb_close(struct child_struct *child, int handle)
189 int i = find_handle(child, handle);
191 ftable[i].handle = 0;
194 void nb_rename(struct child_struct *child, char *old, char *new)
196 if (rename(old, new) != 0) {
197 printf("rename %s %s failed (%s)\n",
198 old, new, strerror(errno));
201 if (sync_dirs) sync_parent(new);
204 void nb_flush(struct child_struct *child, int handle)
206 find_handle(child, handle);
210 void nb_qpathinfo(struct child_struct *child, const char *fname)
216 void nb_qfileinfo(struct child_struct *child, int handle)
219 int i = find_handle(child, handle);
220 fstat(ftable[i].fd, &st);
223 void nb_qfsinfo(struct child_struct *child, int level)
225 /* hmm, should do this one */
228 void nb_findfirst(struct child_struct *child, char *fname)
233 p = strrchr(fname, '/');
236 dir = opendir(fname);
238 while ((d = readdir(dir))) ;
242 void nb_cleanup(struct child_struct *child)