source: trunk/server/source4/torture/raw/seek.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 7.8 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 seek test suite
4 Copyright (C) Andrew Tridgell 2003
5
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 3 of the License, or
9 (at your option) any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "includes.h"
21#include "system/filesys.h"
22#include "libcli/libcli.h"
23#include "torture/util.h"
24
25#define CHECK_STATUS(status, correct) do { \
26 if (!NT_STATUS_EQUAL(status, correct)) { \
27 printf("(%d) Incorrect status %s - should be %s\n", \
28 __LINE__, nt_errstr(status), nt_errstr(correct)); \
29 ret = false; \
30 goto done; \
31 }} while (0)
32
33#define CHECK_VALUE(v, correct) do { \
34 if ((v) != (correct)) { \
35 printf("(%d) Incorrect value %s=%d - should be %d\n", \
36 __LINE__, #v, (int)v, (int)correct); \
37 ret = false; \
38 goto done; \
39 }} while (0)
40
41#define BASEDIR "\\testseek"
42
43/*
44 test seek ops
45*/
46static bool test_seek(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
47{
48 union smb_seek io;
49 union smb_fileinfo finfo;
50 union smb_setfileinfo sfinfo;
51 NTSTATUS status;
52 bool ret = true;
53 int fnum, fnum2;
54 const char *fname = BASEDIR "\\test.txt";
55 uint8_t c[2];
56
57 if (!torture_setup_dir(cli, BASEDIR)) {
58 return false;
59 }
60
61 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
62 if (fnum == -1) {
63 printf("Failed to open test.txt - %s\n", smbcli_errstr(cli->tree));
64 ret = false;
65 goto done;
66 }
67
68 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
69 finfo.position_information.in.file.fnum = fnum;
70
71 printf("Trying bad handle\n");
72 io.lseek.in.file.fnum = fnum+1;
73 io.lseek.in.mode = SEEK_MODE_START;
74 io.lseek.in.offset = 0;
75 status = smb_raw_seek(cli->tree, &io);
76 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
77
78 printf("Trying simple seek\n");
79 io.lseek.in.file.fnum = fnum;
80 io.lseek.in.mode = SEEK_MODE_START;
81 io.lseek.in.offset = 17;
82 status = smb_raw_seek(cli->tree, &io);
83 CHECK_STATUS(status, NT_STATUS_OK);
84 CHECK_VALUE(io.lseek.out.offset, 17);
85 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
86 CHECK_STATUS(status, NT_STATUS_OK);
87 CHECK_VALUE(finfo.position_information.out.position, 0);
88
89 printf("Trying relative seek\n");
90 io.lseek.in.file.fnum = fnum;
91 io.lseek.in.mode = SEEK_MODE_CURRENT;
92 io.lseek.in.offset = -3;
93 status = smb_raw_seek(cli->tree, &io);
94 CHECK_STATUS(status, NT_STATUS_OK);
95 CHECK_VALUE(io.lseek.out.offset, 14);
96
97 printf("Trying end seek\n");
98 io.lseek.in.file.fnum = fnum;
99 io.lseek.in.mode = SEEK_MODE_END;
100 io.lseek.in.offset = 0;
101 status = smb_raw_seek(cli->tree, &io);
102 CHECK_STATUS(status, NT_STATUS_OK);
103 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
104 finfo.all_info.in.file.fnum = fnum;
105 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
106 CHECK_STATUS(status, NT_STATUS_OK);
107 CHECK_VALUE(io.lseek.out.offset, finfo.all_info.out.size);
108
109 printf("Trying max seek\n");
110 io.lseek.in.file.fnum = fnum;
111 io.lseek.in.mode = SEEK_MODE_START;
112 io.lseek.in.offset = -1;
113 status = smb_raw_seek(cli->tree, &io);
114 CHECK_STATUS(status, NT_STATUS_OK);
115 CHECK_VALUE(io.lseek.out.offset, 0xffffffff);
116
117 printf("Testing position information change\n");
118 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
119 finfo.position_information.in.file.fnum = fnum;
120 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
121 CHECK_STATUS(status, NT_STATUS_OK);
122 CHECK_VALUE(finfo.position_information.out.position, 0);
123
124 printf("Trying max overflow\n");
125 io.lseek.in.file.fnum = fnum;
126 io.lseek.in.mode = SEEK_MODE_CURRENT;
127 io.lseek.in.offset = 1000;
128 status = smb_raw_seek(cli->tree, &io);
129 CHECK_STATUS(status, NT_STATUS_OK);
130 CHECK_VALUE(io.lseek.out.offset, 999);
131
132 printf("Testing position information change\n");
133 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
134 finfo.position_information.in.file.fnum = fnum;
135 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
136 CHECK_STATUS(status, NT_STATUS_OK);
137 CHECK_VALUE(finfo.position_information.out.position, 0);
138
139 printf("trying write to update offset\n");
140 ZERO_STRUCT(c);
141 if (smbcli_write(cli->tree, fnum, 0, c, 0, 2) != 2) {
142 printf("Write failed - %s\n", smbcli_errstr(cli->tree));
143 ret = false;
144 goto done;
145 }
146
147 printf("Testing position information change\n");
148 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
149 finfo.position_information.in.file.fnum = fnum;
150 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
151 CHECK_STATUS(status, NT_STATUS_OK);
152 CHECK_VALUE(finfo.position_information.out.position, 0);
153
154 io.lseek.in.file.fnum = fnum;
155 io.lseek.in.mode = SEEK_MODE_CURRENT;
156 io.lseek.in.offset = 0;
157 status = smb_raw_seek(cli->tree, &io);
158 CHECK_STATUS(status, NT_STATUS_OK);
159 CHECK_VALUE(io.lseek.out.offset, 2);
160
161 if (smbcli_read(cli->tree, fnum, c, 0, 1) != 1) {
162 printf("Read failed - %s\n", smbcli_errstr(cli->tree));
163 ret = false;
164 goto done;
165 }
166
167 printf("Testing position information change\n");
168 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
169 finfo.position_information.in.file.fnum = fnum;
170 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
171 CHECK_STATUS(status, NT_STATUS_OK);
172 CHECK_VALUE(finfo.position_information.out.position, 1);
173
174 status = smb_raw_seek(cli->tree, &io);
175 CHECK_STATUS(status, NT_STATUS_OK);
176 CHECK_VALUE(io.lseek.out.offset, 1);
177
178 printf("Testing position information\n");
179 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
180 if (fnum2 == -1) {
181 printf("2nd open failed - %s\n", smbcli_errstr(cli->tree));
182 ret = false;
183 goto done;
184 }
185 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
186 sfinfo.position_information.in.file.fnum = fnum2;
187 sfinfo.position_information.in.position = 25;
188 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
189 CHECK_STATUS(status, NT_STATUS_OK);
190
191 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
192 finfo.position_information.in.file.fnum = fnum2;
193 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
194 CHECK_STATUS(status, NT_STATUS_OK);
195 CHECK_VALUE(finfo.position_information.out.position, 25);
196
197 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
198 finfo.position_information.in.file.fnum = fnum;
199 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
200 CHECK_STATUS(status, NT_STATUS_OK);
201 CHECK_VALUE(finfo.position_information.out.position, 1);
202
203 printf("position_information via paths\n");
204
205 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
206 sfinfo.position_information.in.file.path = fname;
207 sfinfo.position_information.in.position = 32;
208 status = smb_raw_setpathinfo(cli->tree, &sfinfo);
209 CHECK_STATUS(status, NT_STATUS_OK);
210
211 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
212 finfo.position_information.in.file.fnum = fnum2;
213 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
214 CHECK_STATUS(status, NT_STATUS_OK);
215 CHECK_VALUE(finfo.position_information.out.position, 25);
216
217 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
218 finfo.position_information.in.file.path = fname;
219 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
220 CHECK_STATUS(status, NT_STATUS_OK);
221 CHECK_VALUE(finfo.position_information.out.position, 0);
222
223
224done:
225 smb_raw_exit(cli->session);
226 smbcli_deltree(cli->tree, BASEDIR);
227 return ret;
228}
229
230
231/*
232 basic testing of seek calls
233*/
234bool torture_raw_seek(struct torture_context *torture, struct smbcli_state *cli)
235{
236 bool ret = true;
237
238 ret &= test_seek(cli, torture);
239
240 return ret;
241}
Note: See TracBrowser for help on using the repository browser.