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;
37 static struct cli_state *c;
39 static void sigsegv(int sig)
42 printf("segv at line %d\n", line_count);
43 slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d",
44 (int)getpid(), (int)getpid());
49 void nb_setup(struct cli_state *cli)
51 signal(SIGSEGV, sigsegv);
56 void nb_unlink(char *fname)
60 if (!cli_unlink(c, fname)) {
62 printf("(%d) unlink %s failed (%s)\n",
63 line_count, fname, cli_errstr(c));
68 void nb_open(char *fname, int handle, int size)
71 int flags = O_RDWR|O_CREAT;
77 if (size == 0) flags |= O_TRUNC;
79 fd = cli_open(c, fname, flags, DENY_NONE);
82 printf("(%d) open %s failed for handle %d (%s)\n",
83 line_count, fname, handle, cli_errstr(c));
87 cli_getattrE(c, fd, NULL, &st_size, NULL, NULL, NULL);
90 printf("(%d) needs expanding %s to %d from %d\n",
91 line_count, fname, size, (int)st_size);
93 } else if (size < st_size) {
95 printf("(%d) needs truncating %s to %d from %d\n",
96 line_count, fname, size, (int)st_size);
99 for (i=0;i<MAX_FILES;i++) {
100 if (ftable[i].handle == 0) break;
102 if (i == MAX_FILES) {
103 printf("file table full for %s\n", fname);
106 ftable[i].handle = handle;
108 if (count++ % 100 == 0) {
113 void nb_write(int handle, int size, int offset)
117 if (buf[0] == 0) memset(buf, 1, sizeof(buf));
119 for (i=0;i<MAX_FILES;i++) {
120 if (ftable[i].handle == handle) break;
122 if (i == MAX_FILES) {
124 printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n",
125 line_count, handle, size, offset);
129 if (cli_smbwrite(c, ftable[i].fd, buf, offset, size) != size) {
130 printf("(%d) write failed on handle %d, fd %d \
131 errno %d (%s)\n", line_count, handle, ftable[i].fd, errno, strerror(errno));
132 if (errno == ENOSPC) {
133 printf("Halting.\n");
141 void nb_read(int handle, int size, int offset)
145 for (i=0;i<MAX_FILES;i++) {
146 if (ftable[i].handle == handle) break;
148 if (i == MAX_FILES) {
149 printf("(%d) nb_read: handle %d was not open size=%d ofs=%d\n",
150 line_count, handle, size, offset);
153 if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != size) {
155 printf("(%d) read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n",
156 line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno));
161 void nb_close(int handle)
164 for (i=0;i<MAX_FILES;i++) {
165 if (ftable[i].handle == handle) break;
167 if (i == MAX_FILES) {
168 printf("(%d) nb_close: handle %d was not open\n",
172 cli_close(c, ftable[i].fd);
173 ftable[i].handle = 0;
176 void nb_mkdir(char *fname)
180 if (!cli_mkdir(c, fname)) {
182 printf("mkdir %s failed (%s)\n",
183 fname, cli_errstr(c));
188 void nb_rmdir(char *fname)
192 if (!cli_rmdir(c, fname)) {
194 printf("rmdir %s failed (%s)\n",
195 fname, cli_errstr(c));
200 void nb_rename(char *old, char *new)
205 if (!cli_rename(c, old, new)) {
207 printf("rename %s %s failed (%s)\n",
208 old, new, cli_errstr(c));
214 void nb_stat(char *fname, int size)
220 if (!cli_getatr(c, fname, NULL, &st_size, NULL)) {
222 printf("(%d) nb_stat: %s size=%d %s\n",
223 line_count, fname, size, cli_errstr(c));
227 if (st_size != size) {
229 printf("(%d) nb_stat: %s wrong size %d %d\n",
230 line_count, fname, (int)st_size, size);
235 void nb_create(char *fname, int size)
237 nb_open(fname, 5000, size);