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",
45 (int)getpid(), (int)getpid());
50 void nb_setup(struct cli_state
*cli
)
52 signal(SIGSEGV
, sigsegv
);
57 void nb_unlink(char *fname
)
61 if (!cli_unlink(c
, fname
)) {
63 printf("(%d) unlink %s failed (%s)\n",
64 line_count
, fname
, cli_errstr(c
));
69 void nb_open(char *fname
, int handle
, int size
)
72 int flags
= O_RDWR
|O_CREAT
;
78 if (size
== 0) flags
|= O_TRUNC
;
80 fd
= cli_open(c
, fname
, flags
, DENY_NONE
);
83 printf("(%d) open %s failed for handle %d (%s)\n",
84 line_count
, fname
, handle
, cli_errstr(c
));
88 cli_getattrE(c
, fd
, NULL
, &st_size
, NULL
, NULL
, NULL
);
91 printf("(%d) needs expanding %s to %d from %d\n",
92 line_count
, fname
, size
, (int)st_size
);
94 } else if (size
< st_size
) {
96 printf("(%d) needs truncating %s to %d from %d\n",
97 line_count
, fname
, size
, (int)st_size
);
100 for (i
=0;i
<MAX_FILES
;i
++) {
101 if (ftable
[i
].handle
== 0) break;
103 if (i
== MAX_FILES
) {
104 printf("file table full for %s\n", fname
);
107 ftable
[i
].handle
= handle
;
109 if (count
++ % 100 == 0) {
114 void nb_write(int handle
, int size
, int offset
)
118 if (buf
[0] == 0) memset(buf
, 1, sizeof(buf
));
120 for (i
=0;i
<MAX_FILES
;i
++) {
121 if (ftable
[i
].handle
== handle
) break;
123 if (i
== MAX_FILES
) {
125 printf("(%d) nb_write: handle %d was not open size=%d ofs=%d\n",
126 line_count
, handle
, size
, offset
);
130 if (cli_smbwrite(c
, ftable
[i
].fd
, buf
, offset
, size
) != size
) {
131 printf("(%d) write failed on handle %d, fd %d \
132 errno %d (%s)\n", line_count
, handle
, ftable
[i
].fd
, errno
, strerror(errno
));
133 if (errno
== ENOSPC
) {
134 printf("Halting.\n");
142 void nb_read(int handle
, int size
, int offset
)
146 for (i
=0;i
<MAX_FILES
;i
++) {
147 if (ftable
[i
].handle
== handle
) break;
149 if (i
== MAX_FILES
) {
150 printf("(%d) nb_read: handle %d was not open size=%d ofs=%d\n",
151 line_count
, handle
, size
, offset
);
154 if ((ret
=cli_read(c
, ftable
[i
].fd
, buf
, offset
, size
)) != size
) {
156 printf("(%d) read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n",
157 line_count
, handle
, offset
, size
, ret
, ftable
[i
].fd
, errno
, strerror(errno
));
162 void nb_close(int handle
)
165 for (i
=0;i
<MAX_FILES
;i
++) {
166 if (ftable
[i
].handle
== handle
) break;
168 if (i
== MAX_FILES
) {
169 printf("(%d) nb_close: handle %d was not open\n",
173 cli_close(c
, ftable
[i
].fd
);
174 ftable
[i
].handle
= 0;
177 void nb_mkdir(char *fname
)
181 if (!cli_mkdir(c
, fname
)) {
183 printf("mkdir %s failed (%s)\n",
184 fname
, cli_errstr(c
));
189 void nb_rmdir(char *fname
)
193 if (!cli_rmdir(c
, fname
)) {
195 printf("rmdir %s failed (%s)\n",
196 fname
, cli_errstr(c
));
201 void nb_rename(char *old
, char *new)
206 if (!cli_rename(c
, old
, new)) {
208 printf("rename %s %s failed (%s)\n",
209 old
, new, cli_errstr(c
));
215 void nb_stat(char *fname
, int size
)
221 if (!cli_getatr(c
, fname
, NULL
, &st_size
, NULL
)) {
223 printf("(%d) nb_stat: %s size=%d %s\n",
224 line_count
, fname
, size
, cli_errstr(c
));
228 if (st_size
!= size
) {
230 printf("(%d) nb_stat: %s wrong size %d %d\n",
231 line_count
, fname
, (int)st_size
, size
);
236 void nb_create(char *fname
, int size
)
238 nb_open(fname
, 5000, size
);