4 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 1997-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define MAX_FILES 1000
29 static char buf[70000];
30 extern int line_count;
40 double bytes_in, bytes_out;
45 double nbio_total(void)
49 for (i=0;i<nprocs;i++) {
50 total += children[i].bytes_out + children[i].bytes_in;
58 int lines=0, num_clients=0;
59 if (nbio_id != -1) return;
61 for (i=0;i<nprocs;i++) {
62 lines += children[i].line;
63 if (!children[i].done) num_clients++;
66 printf("%4d %8d %.2f MB/sec\r", num_clients, lines/nprocs, 1.0e-6 * nbio_total() / end_timer());
68 signal(SIGALRM, nb_alarm);
72 void nbio_shmem(int n)
75 children = shm_setup(sizeof(*children) * nprocs);
77 printf("Failed to setup shared memory!\n");
82 static int find_handle(int handle)
85 children[nbio_id].line = line_count;
86 for (i=0;i<MAX_FILES;i++) {
87 if (ftable[i].handle == handle) return i;
89 printf("(%d) ERROR: handle %d was not found\n",
93 return -1; /* Not reached */
97 static struct cli_state *c;
99 static void sigsegv(int sig)
102 printf("segv at line %d\n", line_count);
103 slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d",
104 (int)getpid(), (int)getpid());
109 void nb_setup(struct cli_state *cli)
111 signal(SIGSEGV, sigsegv);
114 children[nbio_id].done = 0;
118 void nb_unlink(char *fname)
120 if (!cli_unlink(c, fname)) {
122 printf("(%d) unlink %s failed (%s)\n",
123 line_count, fname, cli_errstr(c));
129 void nb_createx(char *fname,
130 unsigned create_options, unsigned create_disposition, int handle)
133 uint32 desired_access;
135 if (create_options & FILE_DIRECTORY_FILE) {
136 desired_access = FILE_READ_DATA;
138 desired_access = FILE_READ_DATA | FILE_WRITE_DATA;
141 fd = cli_nt_create_full(c, fname,
144 FILE_SHARE_READ|FILE_SHARE_WRITE,
147 if (fd == -1 && handle != -1) {
148 printf("ERROR: cli_nt_create_full failed for %s - %s\n",
149 fname, cli_errstr(c));
152 if (fd != -1 && handle == -1) {
153 printf("ERROR: cli_nt_create_full succeeded for %s\n", fname);
156 if (fd == -1) return;
158 for (i=0;i<MAX_FILES;i++) {
159 if (ftable[i].handle == 0) break;
161 if (i == MAX_FILES) {
162 printf("(%d) file table full for %s\n", line_count,
166 ftable[i].handle = handle;
170 void nb_writex(int handle, int offset, int size, int ret_size)
174 if (buf[0] == 0) memset(buf, 1, sizeof(buf));
176 i = find_handle(handle);
177 if (cli_write(c, ftable[i].fd, 0, buf, offset, size) != ret_size) {
178 printf("(%d) ERROR: write failed on handle %d, fd %d \
179 errno %d (%s)\n", line_count, handle, ftable[i].fd, errno, strerror(errno));
183 children[nbio_id].bytes_out += ret_size;
186 void nb_readx(int handle, int offset, int size, int ret_size)
190 i = find_handle(handle);
191 if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != ret_size) {
192 printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n",
193 line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno));
196 children[nbio_id].bytes_in += ret_size;
199 void nb_close(int handle)
202 i = find_handle(handle);
203 if (!cli_close(c, ftable[i].fd)) {
204 printf("(%d) close failed on handle %d\n", line_count, handle);
207 ftable[i].handle = 0;
210 void nb_rmdir(char *fname)
212 if (!cli_rmdir(c, fname)) {
213 printf("ERROR: rmdir %s failed (%s)\n",
214 fname, cli_errstr(c));
219 void nb_rename(char *old, char *new)
221 if (!cli_rename(c, old, new)) {
222 printf("ERROR: rename %s %s failed (%s)\n",
223 old, new, cli_errstr(c));
229 void nb_qpathinfo(char *fname)
231 cli_qpathinfo(c, fname, NULL, NULL, NULL, NULL, NULL);
234 void nb_qfileinfo(int fnum)
237 i = find_handle(fnum);
238 cli_qfileinfo(c, ftable[i].fd, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
241 void nb_qfsinfo(int level)
243 int bsize, total, avail;
244 /* this is not the right call - we need cli_qfsinfo() */
245 cli_dskattr(c, &bsize, &total, &avail);
248 static void find_fn(file_info *finfo, const char *name, void *state)
253 void nb_findfirst(char *mask)
255 cli_list(c, mask, 0, find_fn, NULL);
258 void nb_flush(int fnum)
261 i = find_handle(fnum);
262 /* hmmm, we don't have cli_flush() yet */
265 static int total_deleted;
267 static void delete_fn(file_info *finfo, const char *name, void *state)
270 if (finfo->name[0] == '.') return;
274 asprintf(&s, "%s%s", n, finfo->name);
275 if (finfo->mode & aDIR) {
277 asprintf(&s2, "%s\\*", s);
278 cli_list(c, s2, aDIR, delete_fn, NULL);
288 void nb_deltree(char *dname)
291 asprintf(&mask, "%s\\*", dname);
294 cli_list(c, mask, aDIR, delete_fn, NULL);
298 if (total_deleted) printf("WARNING: Cleaned up %d files\n", total_deleted);
302 void nb_cleanup(void)
304 cli_rmdir(c, "clients");
305 children[nbio_id].done = 1;