2 Unix SMB/CIFS implementation.
3 ioctl individual test suite
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define BASEDIR "\\rawioctl"
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)); \
35 /* test some ioctls */
36 static BOOL test_ioctl(struct cli_state *cli, TALLOC_CTX *mem_ctx)
42 const char *fname = BASEDIR "\\test.dat";
44 printf("TESTING IOCTL FUNCTIONS\n");
46 fnum = create_complex_file(cli, mem_ctx, fname);
48 printf("Failed to create test.dat - %s\n", cli_errstr(cli));
53 printf("Trying QUERY_JOB_INFO\n");
54 ctl.ioctl.level = RAW_IOCTL_IOCTL;
55 ctl.ioctl.in.fnum = fnum;
56 ctl.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
58 status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
59 CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
61 printf("Trying bad handle\n");
62 ctl.ioctl.in.fnum = fnum+1;
63 status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
64 CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
71 /* test some filesystem control functions */
72 static BOOL test_fsctl(struct cli_state *cli, TALLOC_CTX *mem_ctx)
77 const char *fname = BASEDIR "\\test.dat";
80 printf("\nTESTING FSCTL FUNCTIONS\n");
82 fnum = create_complex_file(cli, mem_ctx, fname);
84 printf("Failed to create test.dat - %s\n", cli_errstr(cli));
89 printf("trying sparse file\n");
90 nt.ioctl.level = RAW_IOCTL_NTIOCTL;
91 nt.ntioctl.in.function = FSCTL_SET_SPARSE;
92 nt.ntioctl.in.fnum = fnum;
93 nt.ntioctl.in.fsctl = True;
94 nt.ntioctl.in.filter = 0;
96 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
97 CHECK_STATUS(status, NT_STATUS_OK);
99 printf("Trying bad handle\n");
100 nt.ntioctl.in.fnum = fnum+1;
101 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
102 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
105 nt.ntioctl.in.fnum = fnum;
106 for (i=0;i<100;i++) {
107 nt.ntioctl.in.function = FSCTL_FILESYSTEM + (i<<2);
108 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
109 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
110 printf("filesystem fsctl 0x%x - %s\n",
111 i, nt_errstr(status));
117 cli_close(cli, fnum);
122 basic testing of some ioctl calls
124 BOOL torture_raw_ioctl(int dummy)
126 struct cli_state *cli;
130 if (!torture_open_connection(&cli)) {
134 mem_ctx = talloc_init("torture_raw_ioctl");
136 if (cli_deltree(cli, BASEDIR) == -1) {
137 printf("Failed to clean " BASEDIR "\n");
140 if (!cli_mkdir(cli, BASEDIR)) {
141 printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli));
145 if (!test_ioctl(cli, mem_ctx)) {
149 if (!test_fsctl(cli, mem_ctx)) {
153 smb_raw_exit(cli->session);
154 cli_deltree(cli, BASEDIR);
156 torture_close_connection(cli);
157 talloc_destroy(mem_ctx);