2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define CHECK_STATUS(status, correct) do { \
24 if (!NT_STATUS_EQUAL(status, correct)) { \
25 printf("(%d) Incorrect status %s - should be %s\n", \
26 __LINE__, nt_errstr(status), nt_errstr(correct)); \
31 #define CHECK_VALUE(v, correct) do { \
32 if ((v) != (correct)) { \
33 printf("(%d) Incorrect value %s=%d - should be %d\n", \
34 __LINE__, #v, (int)v, (int)correct); \
39 #define BASEDIR "\\testseek"
44 static BOOL test_seek(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
47 union smb_fileinfo finfo;
48 union smb_setfileinfo sfinfo;
52 const char *fname = BASEDIR "\\test.txt";
55 if (!torture_setup_dir(cli, BASEDIR)) {
59 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
61 printf("Failed to open test.txt - %s\n", smbcli_errstr(cli->tree));
66 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
67 finfo.position_information.in.fnum = fnum;
69 printf("Trying bad handle\n");
71 io.in.mode = SEEK_MODE_START;
73 status = smb_raw_seek(cli->tree, &io);
74 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
76 printf("Trying simple seek\n");
78 io.in.mode = SEEK_MODE_START;
80 status = smb_raw_seek(cli->tree, &io);
81 CHECK_STATUS(status, NT_STATUS_OK);
82 CHECK_VALUE(io.out.offset, 17);
83 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
84 CHECK_STATUS(status, NT_STATUS_OK);
85 CHECK_VALUE(finfo.position_information.out.position, 0);
87 printf("Trying relative seek\n");
89 io.in.mode = SEEK_MODE_CURRENT;
91 status = smb_raw_seek(cli->tree, &io);
92 CHECK_STATUS(status, NT_STATUS_OK);
93 CHECK_VALUE(io.out.offset, 14);
95 printf("Trying end seek\n");
97 io.in.mode = SEEK_MODE_END;
99 status = smb_raw_seek(cli->tree, &io);
100 CHECK_STATUS(status, NT_STATUS_OK);
101 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
102 finfo.all_info.in.fnum = fnum;
103 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
104 CHECK_STATUS(status, NT_STATUS_OK);
105 CHECK_VALUE(io.out.offset, finfo.all_info.out.size);
107 printf("Trying max seek\n");
109 io.in.mode = SEEK_MODE_START;
111 status = smb_raw_seek(cli->tree, &io);
112 CHECK_STATUS(status, NT_STATUS_OK);
113 CHECK_VALUE(io.out.offset, 0xffffffff);
115 printf("Testing position information change\n");
116 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
117 finfo.position_information.in.fnum = fnum;
118 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
119 CHECK_STATUS(status, NT_STATUS_OK);
120 CHECK_VALUE(finfo.position_information.out.position, 0);
122 printf("Trying max overflow\n");
124 io.in.mode = SEEK_MODE_CURRENT;
126 status = smb_raw_seek(cli->tree, &io);
127 CHECK_STATUS(status, NT_STATUS_OK);
128 CHECK_VALUE(io.out.offset, 999);
130 printf("Testing position information change\n");
131 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
132 finfo.position_information.in.fnum = fnum;
133 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
134 CHECK_STATUS(status, NT_STATUS_OK);
135 CHECK_VALUE(finfo.position_information.out.position, 0);
137 printf("trying write to update offset\n");
139 if (smbcli_write(cli->tree, fnum, 0, c, 0, 2) != 2) {
140 printf("Write failed - %s\n", smbcli_errstr(cli->tree));
145 printf("Testing position information change\n");
146 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
147 finfo.position_information.in.fnum = fnum;
148 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
149 CHECK_STATUS(status, NT_STATUS_OK);
150 CHECK_VALUE(finfo.position_information.out.position, 0);
153 io.in.mode = SEEK_MODE_CURRENT;
155 status = smb_raw_seek(cli->tree, &io);
156 CHECK_STATUS(status, NT_STATUS_OK);
157 CHECK_VALUE(io.out.offset, 2);
159 if (smbcli_read(cli->tree, fnum, c, 0, 1) != 1) {
160 printf("Read failed - %s\n", smbcli_errstr(cli->tree));
165 printf("Testing position information change\n");
166 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
167 finfo.position_information.in.fnum = fnum;
168 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
169 CHECK_STATUS(status, NT_STATUS_OK);
170 CHECK_VALUE(finfo.position_information.out.position, 1);
172 status = smb_raw_seek(cli->tree, &io);
173 CHECK_STATUS(status, NT_STATUS_OK);
174 CHECK_VALUE(io.out.offset, 1);
176 printf("Testing position information\n");
177 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
179 printf("2nd open failed - %s\n", smbcli_errstr(cli->tree));
183 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
184 sfinfo.position_information.file.fnum = fnum2;
185 sfinfo.position_information.in.position = 25;
186 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
187 CHECK_STATUS(status, NT_STATUS_OK);
189 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
190 finfo.position_information.in.fnum = fnum2;
191 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
192 CHECK_STATUS(status, NT_STATUS_OK);
193 CHECK_VALUE(finfo.position_information.out.position, 25);
195 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
196 finfo.position_information.in.fnum = fnum;
197 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
198 CHECK_STATUS(status, NT_STATUS_OK);
199 CHECK_VALUE(finfo.position_information.out.position, 1);
201 printf("position_information via paths\n");
203 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
204 sfinfo.position_information.file.fname = fname;
205 sfinfo.position_information.in.position = 32;
206 status = smb_raw_setpathinfo(cli->tree, &sfinfo);
207 CHECK_STATUS(status, NT_STATUS_OK);
209 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
210 finfo.position_information.in.fnum = fnum2;
211 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
212 CHECK_STATUS(status, NT_STATUS_OK);
213 CHECK_VALUE(finfo.position_information.out.position, 25);
215 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
216 finfo.position_information.in.fname = fname;
217 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
218 CHECK_STATUS(status, NT_STATUS_OK);
219 CHECK_VALUE(finfo.position_information.out.position, 0);
223 smb_raw_exit(cli->session);
224 smbcli_deltree(cli->tree, BASEDIR);
230 basic testing of seek calls
232 BOOL torture_raw_seek(void)
234 struct smbcli_state *cli;
238 if (!torture_open_connection(&cli)) {
242 mem_ctx = talloc_init("torture_raw_seek");
244 if (!test_seek(cli, mem_ctx)) {
248 torture_close_connection(cli);
249 talloc_free(mem_ctx);