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, v, correct); \
39 #define BASEDIR "\\testseek"
44 static BOOL test_seek(struct cli_state *cli, TALLOC_CTX *mem_ctx)
47 union smb_fileinfo finfo;
51 const char *fname = BASEDIR "\\test.txt";
53 if (cli_deltree(cli, BASEDIR) == -1 ||
54 !cli_mkdir(cli, BASEDIR)) {
55 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli));
59 fnum = create_complex_file(cli, mem_ctx, fname);
61 printf("Failed to open test.txt - %s\n", cli_errstr(cli));
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("Trying max overflow\n");
117 io.in.mode = SEEK_MODE_CURRENT;
119 status = smb_raw_seek(cli->tree, &io);
120 CHECK_STATUS(status, NT_STATUS_OK);
121 CHECK_VALUE(io.out.offset, 999);
124 smb_raw_exit(cli->session);
125 cli_deltree(cli, BASEDIR);
131 basic testing of seek calls
133 BOOL torture_raw_seek(int dummy)
135 struct cli_state *cli;
139 if (!torture_open_connection(&cli)) {
143 mem_ctx = talloc_init("torture_raw_seek");
145 if (!test_seek(cli, mem_ctx)) {
149 torture_close_connection(cli);
150 talloc_destroy(mem_ctx);