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 child_struct *child, const char *fname, int attr, const char *status)
90 do_packets(child, 39+2+strlen(fname)*2+2, 39);
93 static void sio_mkdir(struct child_struct *child, const char *dname, const char *status)
97 do_packets(child, 39+2+strlen(dname)*2+2, 39);
100 static void sio_rmdir(struct child_struct *child, const char *fname, const char *status)
104 do_packets(child, 39+2+strlen(fname)*2+2, 39);
107 static void sio_createx(struct child_struct *child, const char *fname,
108 uint32_t create_options, uint32_t create_disposition, int fnum,
112 (void)create_options;
113 (void)create_disposition;
116 do_packets(child, 70+2+strlen(fname)*2+2, 39+12*4);
119 static void sio_writex(struct child_struct *child, int handle, int offset,
120 int size, int ret_size, const char *status)
127 do_packets(child, 39+20+size, 39+16);
128 child->bytes += size;
131 static void sio_readx(struct child_struct *child, int handle, int offset,
132 int size, int ret_size, const char *status)
139 do_packets(child, 39+20, 39+20+ret_size);
140 child->bytes += ret_size;
143 static void sio_close(struct child_struct *child, int handle, const char *status)
148 do_packets(child, 39+8, 39);
151 static void sio_rename(struct child_struct *child, const char *old, const char *new, const char *status)
155 do_packets(child, 39+8+2*strlen(old)+2*strlen(new), 39);
158 static void sio_flush(struct child_struct *child, int handle, const char *status)
163 do_packets(child, 39+2, 39);
166 static void sio_qpathinfo(struct child_struct *child, const char *fname, int level,
172 do_packets(child, 39+16+2*strlen(fname), 39+32);
175 static void sio_qfileinfo(struct child_struct *child, int handle, int level, const char *status)
181 do_packets(child, 39+20, 39+32);
184 static void sio_qfsinfo(struct child_struct *child, int level, const char *status)
189 do_packets(child, 39+20, 39+32);
192 static void sio_findfirst(struct child_struct *child, const char *fname, int level, int maxcnt,
193 int count, const char *status)
199 do_packets(child, 39+20+strlen(fname)*2, 39+90*count);
202 static void sio_cleanup(struct child_struct *child)
207 static void sio_deltree(struct child_struct *child, const char *dname)
213 static void sio_sfileinfo(struct child_struct *child, int handle, int level, const char *status)
219 do_packets(child, 39+32, 39+8);
222 static void sio_lockx(struct child_struct *child, int handle, uint32_t offset, int size,
230 do_packets(child, 39+12, 39);
233 static void sio_unlockx(struct child_struct *child,
234 int handle, uint32_t offset, int size, const char *status)
241 do_packets(child, 39+12, 39);
244 void nb_sleep(struct child_struct *child, int usec, const char *status)
252 struct nb_operations nb_ops = {
254 .deltree = sio_deltree,
255 .cleanup = sio_cleanup,
262 .rename = sio_rename,
264 .writex = sio_writex,
265 .unlink = sio_unlink,
266 .unlockx = sio_unlockx,
267 .findfirst = sio_findfirst,
268 .sfileinfo = sio_sfileinfo,
269 .qfileinfo = sio_qfileinfo,
270 .qpathinfo = sio_qpathinfo,
271 .qfsinfo = sio_qfsinfo,
272 .createx = sio_createx,