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.
23 #include "torture/torture.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/libcli.h"
28 #define BASEDIR "\\rawioctl"
30 #define CHECK_STATUS(status, correct) do { \
31 if (!NT_STATUS_EQUAL(status, correct)) { \
32 printf("(%d) Incorrect status %s - should be %s\n", \
33 __LINE__, nt_errstr(status), nt_errstr(correct)); \
39 /* test some ioctls */
40 static BOOL test_ioctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
46 const char *fname = BASEDIR "\\test.dat";
48 printf("TESTING IOCTL FUNCTIONS\n");
50 fnum = create_complex_file(cli, mem_ctx, fname);
52 printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
57 printf("Trying 0xFFFF\n");
58 ctl.ioctl.level = RAW_IOCTL_IOCTL;
59 ctl.ioctl.in.fnum = fnum;
60 ctl.ioctl.in.request = 0xFFFF;
62 status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
63 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
65 printf("Trying QUERY_JOB_INFO\n");
66 ctl.ioctl.level = RAW_IOCTL_IOCTL;
67 ctl.ioctl.in.fnum = fnum;
68 ctl.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
70 status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
71 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
73 printf("Trying bad handle\n");
74 ctl.ioctl.in.fnum = fnum+1;
75 status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
76 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
79 smbcli_close(cli->tree, fnum);
83 /* test some filesystem control functions */
84 static BOOL test_fsctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
89 const char *fname = BASEDIR "\\test.dat";
92 printf("\nTESTING FSCTL FUNCTIONS\n");
94 fnum = create_complex_file(cli, mem_ctx, fname);
96 printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
101 printf("trying sparse file\n");
102 nt.ioctl.level = RAW_IOCTL_NTIOCTL;
103 nt.ntioctl.in.function = FSCTL_SET_SPARSE;
104 nt.ntioctl.in.fnum = fnum;
105 nt.ntioctl.in.fsctl = True;
106 nt.ntioctl.in.filter = 0;
108 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
109 CHECK_STATUS(status, NT_STATUS_OK);
111 printf("trying batch oplock\n");
112 nt.ioctl.level = RAW_IOCTL_NTIOCTL;
113 nt.ntioctl.in.function = (FSCTL_FILESYSTEM | (2<<2));
114 nt.ntioctl.in.fnum = fnum;
115 nt.ntioctl.in.fsctl = True;
116 nt.ntioctl.in.filter = 0;
118 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
119 if (NT_STATUS_IS_OK(status)) {
120 printf("Server supports batch oplock upgrades on open files\n");
122 printf("Server does not support batch oplock upgrades on open files\n");
125 printf("Trying bad handle\n");
126 nt.ntioctl.in.fnum = fnum+1;
127 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
128 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
131 nt.ntioctl.in.fnum = fnum;
132 for (i=0;i<100;i++) {
133 nt.ntioctl.in.function = FSCTL_FILESYSTEM + (i<<2);
134 status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
135 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
136 printf("filesystem fsctl 0x%x - %s\n",
137 i, nt_errstr(status));
143 smbcli_close(cli->tree, fnum);
148 basic testing of some ioctl calls
150 BOOL torture_raw_ioctl(void)
152 struct smbcli_state *cli;
156 if (!torture_open_connection(&cli)) {
160 mem_ctx = talloc_init("torture_raw_ioctl");
162 if (!torture_setup_dir(cli, BASEDIR)) {
166 if (!test_ioctl(cli, mem_ctx)) {
170 if (!test_fsctl(cli, mem_ctx)) {
174 smb_raw_exit(cli->session);
175 smbcli_deltree(cli->tree, BASEDIR);
177 torture_close_connection(cli);
178 talloc_free(mem_ctx);