4 Unix SMB/Netbios implementation.
7 Copyright (C) Andrew Tridgell 1997-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #define MAX_FILES 1000
30 static char buf
[70000];
31 extern int line_count
;
38 static struct cli_state
*c
;
40 static void sigsegv(int sig
)
43 printf("segv at line %d\n", line_count
);
44 slprintf(line
, sizeof(line
), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d",
50 void nb_setup(struct cli_state
*cli
)
52 signal(SIGSEGV
, sigsegv
);
53 /* to be like a true Windows client we need to negotiate oplocks */
54 cli
->use_oplocks
= True
;
59 void nb_unlink(char *fname
)
63 if (!cli_unlink(c
, fname
)) {
65 printf("(%d) unlink %s failed (%s)\n",
66 line_count
, fname
, cli_errstr(c
));
71 void nb_open(char *fname
, int handle
, int size
)
74 int flags
= O_RDWR
|O_CREAT
;
80 if (size
== 0) flags
|= O_TRUNC
;
82 fd
= cli_open(c
, fname
, flags
, DENY_NONE
);
85 printf("(%d) open %s failed for handle %d (%s)\n",
86 line_count
, fname
, handle
, cli_errstr(c
));
90 cli_getattrE(c
, fd
, NULL
, &st_size
, NULL
, NULL
, NULL
);
93 printf("(%d) needs expanding %s to %d from %d\n",
94 line_count
, fname
, size
, (int)st_size
);
96 } else if (size
< st_size
) {
98 printf("(%d) needs truncating %s to %d from %d\n",
99 line_count
, fname
, size
, (int)st_size
);
102 for (i
=0;i
<MAX_FILES
;i
++) {
103 if (ftable
[i
].handle
== 0) break;
105 if (i
== MAX_FILES
) {
106 printf("file table full for %s\n", fname
);
109 ftable
[i
].handle
= handle
;
111 if (count
++ % 100 == 0) {
116 void nb_write(int handle
, int size
, int offset
)
120 if (buf
[0] == 0) memset(buf
, 1, sizeof(buf
));
122 for (i
=0;i
<MAX_FILES
;i
++) {
123 if (ftable
[i
].handle
== handle
) break;
125 if (i
== MAX_FILES
) {
127 printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n",
128 line_count
, handle
, size
, offset
);
132 if (cli_smbwrite(c
, ftable
[i
].fd
, buf
, offset
, size
) != size
) {
133 printf("(%d) write failed on handle %d\n",
138 void nb_read(int handle
, int size
, int offset
)
142 for (i
=0;i
<MAX_FILES
;i
++) {
143 if (ftable
[i
].handle
== handle
) break;
145 if (i
== MAX_FILES
) {
146 printf("(%d) nb_read: handle %d was not open size=%d ofs=%d\n",
147 line_count
, handle
, size
, offset
);
150 if ((ret
=cli_read(c
, ftable
[i
].fd
, buf
, offset
, size
)) != size
) {
152 printf("(%d) read failed on handle %d ofs=%d size=%d res=%d\n",
153 line_count
, handle
, offset
, size
, ret
);
158 void nb_close(int handle
)
161 for (i
=0;i
<MAX_FILES
;i
++) {
162 if (ftable
[i
].handle
== handle
) break;
164 if (i
== MAX_FILES
) {
165 printf("(%d) nb_close: handle %d was not open\n",
169 cli_close(c
, ftable
[i
].fd
);
170 ftable
[i
].handle
= 0;
173 void nb_mkdir(char *fname
)
177 if (!cli_mkdir(c
, fname
)) {
179 printf("mkdir %s failed (%s)\n",
180 fname
, cli_errstr(c
));
185 void nb_rmdir(char *fname
)
189 if (!cli_rmdir(c
, fname
)) {
191 printf("rmdir %s failed (%s)\n",
192 fname
, cli_errstr(c
));
197 void nb_rename(char *old
, char *new)
202 if (!cli_rename(c
, old
, new)) {
204 printf("rename %s %s failed (%s)\n",
205 old
, new, cli_errstr(c
));
211 void nb_stat(char *fname
, int size
)
217 if (!cli_getatr(c
, fname
, NULL
, &st_size
, NULL
)) {
219 printf("(%d) nb_stat: %s size=%d %s\n",
220 line_count
, fname
, size
, cli_errstr(c
));
224 if (st_size
!= size
) {
226 printf("(%d) nb_stat: %s wrong size %d %d\n",
227 line_count
, fname
, (int)st_size
, size
);
232 void nb_create(char *fname
, int size
)
234 nb_open(fname
, 5000, size
);