summaryrefslogtreecommitdiff
path: root/ioctl-test.c
blob: 65d584be9a862136838466653dd7e9a4616a7c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License v2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 021110-1307, USA.
 */

#include "kerncompat.h"
#include <stdio.h>
#include <stdlib.h>

#include "ioctl.h"
#include "ctree.h"

#define LIST_32_COMPAT				\
	ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL_32)

#define LIST_64_COMPAT				\
	ONE(BTRFS_IOC_SEND_64)

#define LIST_BASE				\
	ONE(BTRFS_IOC_SNAP_CREATE)		\
	ONE(BTRFS_IOC_DEFRAG)			\
	ONE(BTRFS_IOC_RESIZE)			\
	ONE(BTRFS_IOC_SCAN_DEV)			\
	ONE(BTRFS_IOC_TRANS_START)		\
	ONE(BTRFS_IOC_TRANS_END)		\
	ONE(BTRFS_IOC_SYNC)			\
	ONE(BTRFS_IOC_CLONE)			\
	ONE(BTRFS_IOC_ADD_DEV)			\
	ONE(BTRFS_IOC_RM_DEV)			\
	ONE(BTRFS_IOC_BALANCE)			\
	ONE(BTRFS_IOC_CLONE_RANGE)		\
	ONE(BTRFS_IOC_SUBVOL_CREATE)		\
	ONE(BTRFS_IOC_SNAP_DESTROY)		\
	ONE(BTRFS_IOC_DEFRAG_RANGE)		\
	ONE(BTRFS_IOC_TREE_SEARCH)		\
	ONE(BTRFS_IOC_TREE_SEARCH_V2)		\
	ONE(BTRFS_IOC_INO_LOOKUP)		\
	ONE(BTRFS_IOC_DEFAULT_SUBVOL)		\
	ONE(BTRFS_IOC_SPACE_INFO)		\
	ONE(BTRFS_IOC_START_SYNC)		\
	ONE(BTRFS_IOC_WAIT_SYNC)		\
	ONE(BTRFS_IOC_SNAP_CREATE_V2)		\
	ONE(BTRFS_IOC_SUBVOL_CREATE_V2)		\
	ONE(BTRFS_IOC_SUBVOL_GETFLAGS)		\
	ONE(BTRFS_IOC_SUBVOL_SETFLAGS)		\
	ONE(BTRFS_IOC_SCRUB)			\
	ONE(BTRFS_IOC_SCRUB_CANCEL)		\
	ONE(BTRFS_IOC_SCRUB_PROGRESS)		\
	ONE(BTRFS_IOC_DEV_INFO)			\
	ONE(BTRFS_IOC_FS_INFO)			\
	ONE(BTRFS_IOC_BALANCE_V2)		\
	ONE(BTRFS_IOC_BALANCE_CTL)		\
	ONE(BTRFS_IOC_BALANCE_PROGRESS)		\
	ONE(BTRFS_IOC_INO_PATHS)		\
	ONE(BTRFS_IOC_LOGICAL_INO)		\
	ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL)	\
	ONE(BTRFS_IOC_SEND)			\
	ONE(BTRFS_IOC_DEVICES_READY)		\
	ONE(BTRFS_IOC_QUOTA_CTL)		\
	ONE(BTRFS_IOC_QGROUP_ASSIGN)		\
	ONE(BTRFS_IOC_QGROUP_CREATE)		\
	ONE(BTRFS_IOC_QGROUP_LIMIT)		\
	ONE(BTRFS_IOC_QUOTA_RESCAN)		\
	ONE(BTRFS_IOC_QUOTA_RESCAN_STATUS)	\
	ONE(BTRFS_IOC_QUOTA_RESCAN_WAIT)	\
	ONE(BTRFS_IOC_GET_FSLABEL)		\
	ONE(BTRFS_IOC_SET_FSLABEL)		\
	ONE(BTRFS_IOC_GET_DEV_STATS)		\
	ONE(BTRFS_IOC_DEV_REPLACE)		\
	ONE(BTRFS_IOC_FILE_EXTENT_SAME)		\
	ONE(BTRFS_IOC_GET_FEATURES)		\
	ONE(BTRFS_IOC_SET_FEATURES)		\
	ONE(BTRFS_IOC_GET_SUPPORTED_FEATURES)	\
	ONE(BTRFS_IOC_RM_DEV_V2)

#define LIST					\
	LIST_BASE				\
	LIST_32_COMPAT				\
	LIST_64_COMPAT

struct ioctl_number {
	unsigned long defined;
	unsigned long expected;
};

static struct ioctl_number expected_list[] = {
	{ BTRFS_IOC_SNAP_CREATE,                    0x0050009401 },
	{ BTRFS_IOC_DEFRAG,                         0x0050009402 },
	{ BTRFS_IOC_RESIZE,                         0x0050009403 },
	{ BTRFS_IOC_SCAN_DEV,                       0x0050009404 },
	{ BTRFS_IOC_TRANS_START,                    0x0000009406 },
	{ BTRFS_IOC_TRANS_END,                      0x0000009407 },
	{ BTRFS_IOC_SYNC,                           0x0000009408 },
	{ BTRFS_IOC_CLONE,                          0x0040049409 },
	{ BTRFS_IOC_ADD_DEV,                        0x005000940a },
	{ BTRFS_IOC_RM_DEV,                         0x005000940b },
	{ BTRFS_IOC_BALANCE,                        0x005000940c },
	{ BTRFS_IOC_CLONE_RANGE,                    0x004020940d },
	{ BTRFS_IOC_SUBVOL_CREATE,                  0x005000940e },
	{ BTRFS_IOC_SNAP_DESTROY,                   0x005000940f },
	{ BTRFS_IOC_DEFRAG_RANGE,                   0x0040309410 },
	{ BTRFS_IOC_TREE_SEARCH,                    0x00d0009411 },
	{ BTRFS_IOC_TREE_SEARCH_V2,                 0x00c0709411 },
	{ BTRFS_IOC_INO_LOOKUP,                     0x00d0009412 },
	{ BTRFS_IOC_DEFAULT_SUBVOL,                 0x0040089413 },
	{ BTRFS_IOC_SPACE_INFO,                     0x00c0109414 },
	{ BTRFS_IOC_START_SYNC,                     0x0080089418 },
	{ BTRFS_IOC_WAIT_SYNC,                      0x0040089416 },
	{ BTRFS_IOC_SNAP_CREATE_V2,                 0x0050009417 },
	{ BTRFS_IOC_SUBVOL_CREATE_V2,               0x0050009418 },
	{ BTRFS_IOC_SUBVOL_GETFLAGS,                0x0080089419 },
	{ BTRFS_IOC_SUBVOL_SETFLAGS,                0x004008941a },
	{ BTRFS_IOC_SCRUB,                          0x00c400941b },
	{ BTRFS_IOC_SCRUB_CANCEL,                   0x000000941c },
	{ BTRFS_IOC_SCRUB_PROGRESS,                 0x00c400941d },
	{ BTRFS_IOC_DEV_INFO,                       0x00d000941e },
	{ BTRFS_IOC_FS_INFO,                        0x008400941f },
	{ BTRFS_IOC_BALANCE_V2,                     0x00c4009420 },
	{ BTRFS_IOC_BALANCE_CTL,                    0x0040049421 },
	{ BTRFS_IOC_BALANCE_PROGRESS,               0x0084009422 },
	{ BTRFS_IOC_INO_PATHS,                      0x00c0389423 },
	{ BTRFS_IOC_LOGICAL_INO,                    0x00c0389424 },
	{ BTRFS_IOC_SET_RECEIVED_SUBVOL,            0x00c0c89425 },
#ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
	{ BTRFS_IOC_SET_RECEIVED_SUBVOL_32,         0x00c0c09425 },
#endif
#if BITS_PER_LONG == 32
	{ BTRFS_IOC_SEND,                           0x0040449426 },
#elif BITS_PER_LONG == 64
	{ BTRFS_IOC_SEND,                           0x0040489426 },
#endif
#ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
	{ BTRFS_IOC_SEND_64,                        0x0040489426 },
#endif
	{ BTRFS_IOC_DEVICES_READY,                  0x0090009427 },
	{ BTRFS_IOC_QUOTA_CTL,                      0x00c0109428 },
	{ BTRFS_IOC_QGROUP_ASSIGN,                  0x0040189429 },
	{ BTRFS_IOC_QGROUP_CREATE,                  0x004010942a },
	{ BTRFS_IOC_QGROUP_LIMIT,                   0x008030942b },
	{ BTRFS_IOC_QUOTA_RESCAN,                   0x004040942c },
	{ BTRFS_IOC_QUOTA_RESCAN_STATUS,            0x008040942d },
	{ BTRFS_IOC_QUOTA_RESCAN_WAIT,              0x000000942e },
	{ BTRFS_IOC_GET_FSLABEL,                    0x0081009431 },
	{ BTRFS_IOC_SET_FSLABEL,                    0x0041009432 },
	{ BTRFS_IOC_GET_DEV_STATS,                  0x00c4089434 },
	{ BTRFS_IOC_DEV_REPLACE,                    0x00ca289435 },
	{ BTRFS_IOC_FILE_EXTENT_SAME,               0x00c0189436 },
	{ BTRFS_IOC_GET_FEATURES,                   0x0080189439 },
	{ BTRFS_IOC_SET_FEATURES,                   0x0040309439 },
	{ BTRFS_IOC_GET_SUPPORTED_FEATURES,         0x0080489439 },
	{ BTRFS_IOC_RM_DEV_V2,                      0x005000943a },
};

static struct btrfs_ioctl_vol_args used_vol_args __attribute__((used));
static struct btrfs_ioctl_vol_args_v2 used_vol_args2 __attribute__((used));
static struct btrfs_ioctl_clone_range_args used_clone_args __attribute__((used));
static struct btrfs_ioctl_defrag_range_args used_defrag_args __attribute__((used));
static struct btrfs_ioctl_search_args used_search_args __attribute__((used));
static struct btrfs_ioctl_search_args_v2 used_search_args2 __attribute__((used));
static struct btrfs_ioctl_ino_lookup_args used_ino_lookup __attribute__((used));
static struct btrfs_ioctl_space_args used_space_args __attribute__((used));
static struct btrfs_ioctl_scrub_args used_scrub_args __attribute__((used));
static struct btrfs_ioctl_dev_info_args used_dev_info_args __attribute__((used));
static struct btrfs_ioctl_fs_info_args used_fs_info_args __attribute__((used));
static struct btrfs_ioctl_balance_args used_balance_args __attribute__((used));
static struct btrfs_ioctl_ino_path_args used_path_args __attribute__((used));
static struct btrfs_ioctl_logical_ino_args used_logical_args __attribute__((used));
static struct btrfs_ioctl_received_subvol_args used_received_args __attribute__((used));
#ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
static struct btrfs_ioctl_received_subvol_args_32 used_received_args32 __attribute__((used));
#endif
static struct btrfs_ioctl_send_args used_send_args __attribute__((used));
#ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
static struct btrfs_ioctl_send_args_64 used_send_args64 __attribute__((used));
#endif
static struct btrfs_ioctl_quota_ctl_args used_qgctl_args __attribute__((used));
static struct btrfs_ioctl_qgroup_assign_args used_qgassign_args __attribute__((used));
static struct btrfs_ioctl_qgroup_create_args used_qgcreate_args __attribute__((used));
static struct btrfs_ioctl_qgroup_limit_args used_qglimit_args __attribute__((used));
static struct btrfs_ioctl_quota_rescan_args used_qgrescan_args __attribute__((used));
static struct btrfs_ioctl_get_dev_stats used_dev_stats_args __attribute__((used));
static struct btrfs_ioctl_dev_replace_args used_replace_args __attribute__((used));
static struct btrfs_ioctl_same_args used_same_args __attribute__((used));
static struct btrfs_ioctl_feature_flags used_feature_flags __attribute__((used));

const char* value_to_string(unsigned long num)
{
#define ONE(x)	case x: return #x;
	switch (num) {
	LIST_BASE
	}

	switch (num) {
	LIST_32_COMPAT
	}

	switch (num) {
	LIST_64_COMPAT
	}
#undef ONE
	return "UNKNOWN";
}

int main(int ac, char **av)
{
	int i;
	int errors = 0;

	value_to_string(random());

	printf("Sizeof long long:  %zu\n", sizeof(unsigned long long));
	printf("Sizeof long:       %zu\n", sizeof(unsigned long));
	printf("Sizeof pointer:    %zu\n", sizeof(void*));
	printf("Alignof long long: %zu\n", __alignof__(unsigned long long));
	printf("Alignof long:      %zu\n", __alignof__(unsigned long));
	printf("Alignof pointer:   %zu\n", __alignof__(void*));
	printf("Raw ioctl numbers:\n");

#define ONE(n)	printf("%-38s   0x%010lx\n", #n, (unsigned long)n);
	LIST
#undef ONE

	for (i = 0; i < ARRAY_SIZE(expected_list); i++) {
		if (expected_list[i].defined != expected_list[i].expected) {
			printf("ERROR: wrong value for %s, defined=0x%lx expected=0x%lx\n",
					value_to_string(expected_list[i].defined),
					expected_list[i].defined,
					expected_list[i].expected);
			errors++;
		}
	}

	if (!errors) {
		printf("All ok\n");
	} else {
		printf("Found %d errors in definitions\n", errors);
	}

	return !!errors;
}