3 Copyright (C) Andrew Tridgell 1999
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #define MAX_FILES 1000
28 /* emulate a single SMB packet exchange */
29 static void do_packets(struct child_struct *child, int send_size, int recv_size)
31 struct sockio *sockio = (struct sockio *)child->private;
32 uint32 *ubuf = (uint32 *)sockio->buf;
34 ubuf[0] = htonl(send_size-4);
35 ubuf[1] = htonl(recv_size-4);
37 if (write_sock(sockio->sock, sockio->buf, send_size) != send_size) {
38 printf("error writing %d bytes\n", (int)send_size);
42 if (read_sock(sockio->sock, sockio->buf, 4) != 4) {
43 printf("error reading header\n");
47 if (ntohl(ubuf[0]) != (unsigned)(recv_size-4)) {
48 printf("lost sync (%d %d)\n",
49 (int)recv_size-4, (int)ntohl(ubuf[0]));
53 if (recv(sockio->sock, sockio->buf, recv_size-4, MSG_WAITALL|MSG_TRUNC) !=
55 printf("error reading %d bytes\n", (int)recv_size-4);
59 if (ntohl(ubuf[0]) != (unsigned)(recv_size-4)) {
60 printf("lost sync (%d %d)\n",
61 (int)recv_size-4, (int)ntohl(ubuf[0]));
66 static void sio_setup(struct child_struct *child)
68 struct sockio *sockio;
69 sockio = calloc(1, sizeof(struct sockio));
70 child->private = sockio;
71 child->rate.last_time = timeval_current();
72 child->rate.last_bytes = 0;
74 sockio->sock = open_socket_out(options.server, TCP_PORT);
75 if (sockio->sock == -1) {
76 printf("client %d failed to start\n", child->id);
79 set_socket_options(sockio->sock, options.tcp_options);
81 do_packets(child, 8, 8);
85 static void sio_unlink(struct dbench_op *op)
87 do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39);
90 static void sio_mkdir(struct dbench_op *op)
92 do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39);
95 static void sio_rmdir(struct dbench_op *op)
97 do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39);
100 static void sio_createx(struct dbench_op *op)
102 do_packets(op->child, 70+2+strlen(op->fname)*2+2, 39+12*4);
105 static void sio_writex(struct dbench_op *op)
107 int size = op->params[2];
108 do_packets(op->child, 39+20+size, 39+16);
109 op->child->bytes += size;
112 static void sio_readx(struct dbench_op *op)
114 int ret_size = op->params[3];
115 do_packets(op->child, 39+20, 39+20+ret_size);
116 op->child->bytes += ret_size;
119 static void sio_close(struct dbench_op *op)
121 do_packets(op->child, 39+8, 39);
124 static void sio_rename(struct dbench_op *op)
126 const char *old = op->fname;
127 const char *new = op->fname2;
128 do_packets(op->child, 39+8+2*strlen(old)+2*strlen(new), 39);
131 static void sio_flush(struct dbench_op *op)
133 do_packets(op->child, 39+2, 39);
136 static void sio_qpathinfo(struct dbench_op *op)
138 do_packets(op->child, 39+16+2*strlen(op->fname), 39+32);
141 static void sio_qfileinfo(struct dbench_op *op)
143 do_packets(op->child, 39+20, 39+32);
146 static void sio_qfsinfo(struct dbench_op *op)
148 do_packets(op->child, 39+20, 39+32);
151 static void sio_findfirst(struct dbench_op *op)
153 int count = op->params[2];
154 do_packets(op->child, 39+20+strlen(op->fname)*2, 39+90*count);
157 static void sio_cleanup(struct child_struct *child)
162 static void sio_deltree(struct dbench_op *op)
167 static void sio_sfileinfo(struct dbench_op *op)
169 do_packets(op->child, 39+32, 39+8);
172 static void sio_lockx(struct dbench_op *op)
174 do_packets(op->child, 39+12, 39);
177 static void sio_unlockx(struct dbench_op *op)
179 do_packets(op->child, 39+12, 39);
182 static struct backend_op ops[] = {
183 { "Deltree", sio_deltree },
184 { "Flush", sio_flush },
185 { "Close", sio_close },
186 { "LockX", sio_lockx },
187 { "Rmdir", sio_rmdir },
188 { "Mkdir", sio_mkdir },
189 { "Rename", sio_rename },
190 { "ReadX", sio_readx },
191 { "WriteX", sio_writex },
192 { "Unlink", sio_unlink },
193 { "UnlockX", sio_unlockx },
194 { "FIND_FIRST", sio_findfirst },
195 { "SET_FILE_INFORMATION", sio_sfileinfo },
196 { "QUERY_FILE_INFORMATION", sio_qfileinfo },
197 { "QUERY_PATH_INFORMATION", sio_qpathinfo },
198 { "QUERY_FS_INFORMATION", sio_qfsinfo },
199 { "NTCreateX", sio_createx },
203 struct nb_operations sockio_ops = {
204 .backend_name = "tbench",
206 .cleanup = sio_cleanup,