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.
22 #include "torture/torture.h"
23 #include "system/filesys.h"
24 #include "libcli/raw/libcliraw.h"
26 #define CHECK_STATUS(status, correct) do { \
27 if (!NT_STATUS_EQUAL(status, correct)) { \
28 printf("(%d) Incorrect status %s - should be %s\n", \
29 __LINE__, nt_errstr(status), nt_errstr(correct)); \
34 #define CHECK_VALUE(v, correct) do { \
35 if ((v) != (correct)) { \
36 printf("(%d) Incorrect value %s=%d - should be %d\n", \
37 __LINE__, #v, (int)v, (int)correct); \
42 #define BASEDIR "\\testseek"
47 static BOOL test_seek(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
50 union smb_fileinfo finfo;
51 union smb_setfileinfo sfinfo;
55 const char *fname = BASEDIR "\\test.txt";
58 if (!torture_setup_dir(cli, BASEDIR)) {
62 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
64 printf("Failed to open test.txt - %s\n", smbcli_errstr(cli->tree));
69 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
70 finfo.position_information.in.fnum = fnum;
72 printf("Trying bad handle\n");
74 io.in.mode = SEEK_MODE_START;
76 status = smb_raw_seek(cli->tree, &io);
77 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
79 printf("Trying simple seek\n");
81 io.in.mode = SEEK_MODE_START;
83 status = smb_raw_seek(cli->tree, &io);
84 CHECK_STATUS(status, NT_STATUS_OK);
85 CHECK_VALUE(io.out.offset, 17);
86 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
87 CHECK_STATUS(status, NT_STATUS_OK);
88 CHECK_VALUE(finfo.position_information.out.position, 0);
90 printf("Trying relative seek\n");
92 io.in.mode = SEEK_MODE_CURRENT;
94 status = smb_raw_seek(cli->tree, &io);
95 CHECK_STATUS(status, NT_STATUS_OK);
96 CHECK_VALUE(io.out.offset, 14);
98 printf("Trying end seek\n");
100 io.in.mode = SEEK_MODE_END;
102 status = smb_raw_seek(cli->tree, &io);
103 CHECK_STATUS(status, NT_STATUS_OK);
104 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
105 finfo.all_info.in.fnum = fnum;
106 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
107 CHECK_STATUS(status, NT_STATUS_OK);
108 CHECK_VALUE(io.out.offset, finfo.all_info.out.size);
110 printf("Trying max seek\n");
112 io.in.mode = SEEK_MODE_START;
114 status = smb_raw_seek(cli->tree, &io);
115 CHECK_STATUS(status, NT_STATUS_OK);
116 CHECK_VALUE(io.out.offset, 0xffffffff);
118 printf("Testing position information change\n");
119 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
120 finfo.position_information.in.fnum = fnum;
121 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
122 CHECK_STATUS(status, NT_STATUS_OK);
123 CHECK_VALUE(finfo.position_information.out.position, 0);
125 printf("Trying max overflow\n");
127 io.in.mode = SEEK_MODE_CURRENT;
129 status = smb_raw_seek(cli->tree, &io);
130 CHECK_STATUS(status, NT_STATUS_OK);
131 CHECK_VALUE(io.out.offset, 999);
133 printf("Testing position information change\n");
134 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
135 finfo.position_information.in.fnum = fnum;
136 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
137 CHECK_STATUS(status, NT_STATUS_OK);
138 CHECK_VALUE(finfo.position_information.out.position, 0);
140 printf("trying write to update offset\n");
142 if (smbcli_write(cli->tree, fnum, 0, c, 0, 2) != 2) {
143 printf("Write failed - %s\n", smbcli_errstr(cli->tree));
148 printf("Testing position information change\n");
149 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
150 finfo.position_information.in.fnum = fnum;
151 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
152 CHECK_STATUS(status, NT_STATUS_OK);
153 CHECK_VALUE(finfo.position_information.out.position, 0);
156 io.in.mode = SEEK_MODE_CURRENT;
158 status = smb_raw_seek(cli->tree, &io);
159 CHECK_STATUS(status, NT_STATUS_OK);
160 CHECK_VALUE(io.out.offset, 2);
162 if (smbcli_read(cli->tree, fnum, c, 0, 1) != 1) {
163 printf("Read failed - %s\n", smbcli_errstr(cli->tree));
168 printf("Testing position information change\n");
169 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
170 finfo.position_information.in.fnum = fnum;
171 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
172 CHECK_STATUS(status, NT_STATUS_OK);
173 CHECK_VALUE(finfo.position_information.out.position, 1);
175 status = smb_raw_seek(cli->tree, &io);
176 CHECK_STATUS(status, NT_STATUS_OK);
177 CHECK_VALUE(io.out.offset, 1);
179 printf("Testing position information\n");
180 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
182 printf("2nd open failed - %s\n", smbcli_errstr(cli->tree));
186 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
187 sfinfo.position_information.file.fnum = fnum2;
188 sfinfo.position_information.in.position = 25;
189 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
190 CHECK_STATUS(status, NT_STATUS_OK);
192 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
193 finfo.position_information.in.fnum = fnum2;
194 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
195 CHECK_STATUS(status, NT_STATUS_OK);
196 CHECK_VALUE(finfo.position_information.out.position, 25);
198 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
199 finfo.position_information.in.fnum = fnum;
200 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
201 CHECK_STATUS(status, NT_STATUS_OK);
202 CHECK_VALUE(finfo.position_information.out.position, 1);
204 printf("position_information via paths\n");
206 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
207 sfinfo.position_information.file.fname = fname;
208 sfinfo.position_information.in.position = 32;
209 status = smb_raw_setpathinfo(cli->tree, &sfinfo);
210 CHECK_STATUS(status, NT_STATUS_OK);
212 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
213 finfo.position_information.in.fnum = fnum2;
214 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
215 CHECK_STATUS(status, NT_STATUS_OK);
216 CHECK_VALUE(finfo.position_information.out.position, 25);
218 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
219 finfo.position_information.in.fname = fname;
220 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
221 CHECK_STATUS(status, NT_STATUS_OK);
222 CHECK_VALUE(finfo.position_information.out.position, 0);
226 smb_raw_exit(cli->session);
227 smbcli_deltree(cli->tree, BASEDIR);
233 basic testing of seek calls
235 BOOL torture_raw_seek(void)
237 struct smbcli_state *cli;
241 if (!torture_open_connection(&cli)) {
245 mem_ctx = talloc_init("torture_raw_seek");
247 if (!test_seek(cli, mem_ctx)) {
251 torture_close_connection(cli);
252 talloc_free(mem_ctx);