btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of, FS_TREE
[platform/upstream/btrfs-progs.git] / ioctl-test.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public
4  * License v2 as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9  * General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the
13  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14  * Boston, MA 021110-1307, USA.
15  */
16
17 #include "kerncompat.h"
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 #include "ioctl.h"
22 #include "ctree.h"
23
24 #define LIST_32_COMPAT                          \
25         ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL_32)
26
27 #define LIST_64_COMPAT                          \
28         ONE(BTRFS_IOC_SEND_64)
29
30 #define LIST_BASE                               \
31         ONE(BTRFS_IOC_SNAP_CREATE)              \
32         ONE(BTRFS_IOC_DEFRAG)                   \
33         ONE(BTRFS_IOC_RESIZE)                   \
34         ONE(BTRFS_IOC_SCAN_DEV)                 \
35         ONE(BTRFS_IOC_TRANS_START)              \
36         ONE(BTRFS_IOC_TRANS_END)                \
37         ONE(BTRFS_IOC_SYNC)                     \
38         ONE(BTRFS_IOC_CLONE)                    \
39         ONE(BTRFS_IOC_ADD_DEV)                  \
40         ONE(BTRFS_IOC_RM_DEV)                   \
41         ONE(BTRFS_IOC_BALANCE)                  \
42         ONE(BTRFS_IOC_CLONE_RANGE)              \
43         ONE(BTRFS_IOC_SUBVOL_CREATE)            \
44         ONE(BTRFS_IOC_SNAP_DESTROY)             \
45         ONE(BTRFS_IOC_DEFRAG_RANGE)             \
46         ONE(BTRFS_IOC_TREE_SEARCH)              \
47         ONE(BTRFS_IOC_TREE_SEARCH_V2)           \
48         ONE(BTRFS_IOC_INO_LOOKUP)               \
49         ONE(BTRFS_IOC_DEFAULT_SUBVOL)           \
50         ONE(BTRFS_IOC_SPACE_INFO)               \
51         ONE(BTRFS_IOC_START_SYNC)               \
52         ONE(BTRFS_IOC_WAIT_SYNC)                \
53         ONE(BTRFS_IOC_SNAP_CREATE_V2)           \
54         ONE(BTRFS_IOC_SUBVOL_CREATE_V2)         \
55         ONE(BTRFS_IOC_SUBVOL_GETFLAGS)          \
56         ONE(BTRFS_IOC_SUBVOL_SETFLAGS)          \
57         ONE(BTRFS_IOC_SCRUB)                    \
58         ONE(BTRFS_IOC_SCRUB_CANCEL)             \
59         ONE(BTRFS_IOC_SCRUB_PROGRESS)           \
60         ONE(BTRFS_IOC_DEV_INFO)                 \
61         ONE(BTRFS_IOC_FS_INFO)                  \
62         ONE(BTRFS_IOC_BALANCE_V2)               \
63         ONE(BTRFS_IOC_BALANCE_CTL)              \
64         ONE(BTRFS_IOC_BALANCE_PROGRESS)         \
65         ONE(BTRFS_IOC_INO_PATHS)                \
66         ONE(BTRFS_IOC_LOGICAL_INO)              \
67         ONE(BTRFS_IOC_SET_RECEIVED_SUBVOL)      \
68         ONE(BTRFS_IOC_SEND)                     \
69         ONE(BTRFS_IOC_DEVICES_READY)            \
70         ONE(BTRFS_IOC_QUOTA_CTL)                \
71         ONE(BTRFS_IOC_QGROUP_ASSIGN)            \
72         ONE(BTRFS_IOC_QGROUP_CREATE)            \
73         ONE(BTRFS_IOC_QGROUP_LIMIT)             \
74         ONE(BTRFS_IOC_QUOTA_RESCAN)             \
75         ONE(BTRFS_IOC_QUOTA_RESCAN_STATUS)      \
76         ONE(BTRFS_IOC_QUOTA_RESCAN_WAIT)        \
77         ONE(BTRFS_IOC_GET_FSLABEL)              \
78         ONE(BTRFS_IOC_SET_FSLABEL)              \
79         ONE(BTRFS_IOC_GET_DEV_STATS)            \
80         ONE(BTRFS_IOC_DEV_REPLACE)              \
81         ONE(BTRFS_IOC_FILE_EXTENT_SAME)         \
82         ONE(BTRFS_IOC_GET_FEATURES)             \
83         ONE(BTRFS_IOC_SET_FEATURES)             \
84         ONE(BTRFS_IOC_GET_SUPPORTED_FEATURES)   \
85         ONE(BTRFS_IOC_RM_DEV_V2)
86
87 #define LIST                                    \
88         LIST_BASE                               \
89         LIST_32_COMPAT                          \
90         LIST_64_COMPAT
91
92 struct ioctl_number {
93         unsigned long defined;
94         unsigned long expected;
95 };
96
97 static struct ioctl_number expected_list[] = {
98         { BTRFS_IOC_SNAP_CREATE,                    0x0050009401 },
99         { BTRFS_IOC_DEFRAG,                         0x0050009402 },
100         { BTRFS_IOC_RESIZE,                         0x0050009403 },
101         { BTRFS_IOC_SCAN_DEV,                       0x0050009404 },
102         { BTRFS_IOC_TRANS_START,                    0x0000009406 },
103         { BTRFS_IOC_TRANS_END,                      0x0000009407 },
104         { BTRFS_IOC_SYNC,                           0x0000009408 },
105         { BTRFS_IOC_CLONE,                          0x0040049409 },
106         { BTRFS_IOC_ADD_DEV,                        0x005000940a },
107         { BTRFS_IOC_RM_DEV,                         0x005000940b },
108         { BTRFS_IOC_BALANCE,                        0x005000940c },
109         { BTRFS_IOC_CLONE_RANGE,                    0x004020940d },
110         { BTRFS_IOC_SUBVOL_CREATE,                  0x005000940e },
111         { BTRFS_IOC_SNAP_DESTROY,                   0x005000940f },
112         { BTRFS_IOC_DEFRAG_RANGE,                   0x0040309410 },
113         { BTRFS_IOC_TREE_SEARCH,                    0x00d0009411 },
114         { BTRFS_IOC_TREE_SEARCH_V2,                 0x00c0709411 },
115         { BTRFS_IOC_INO_LOOKUP,                     0x00d0009412 },
116         { BTRFS_IOC_DEFAULT_SUBVOL,                 0x0040089413 },
117         { BTRFS_IOC_SPACE_INFO,                     0x00c0109414 },
118         { BTRFS_IOC_START_SYNC,                     0x0080089418 },
119         { BTRFS_IOC_WAIT_SYNC,                      0x0040089416 },
120         { BTRFS_IOC_SNAP_CREATE_V2,                 0x0050009417 },
121         { BTRFS_IOC_SUBVOL_CREATE_V2,               0x0050009418 },
122         { BTRFS_IOC_SUBVOL_GETFLAGS,                0x0080089419 },
123         { BTRFS_IOC_SUBVOL_SETFLAGS,                0x004008941a },
124         { BTRFS_IOC_SCRUB,                          0x00c400941b },
125         { BTRFS_IOC_SCRUB_CANCEL,                   0x000000941c },
126         { BTRFS_IOC_SCRUB_PROGRESS,                 0x00c400941d },
127         { BTRFS_IOC_DEV_INFO,                       0x00d000941e },
128         { BTRFS_IOC_FS_INFO,                        0x008400941f },
129         { BTRFS_IOC_BALANCE_V2,                     0x00c4009420 },
130         { BTRFS_IOC_BALANCE_CTL,                    0x0040049421 },
131         { BTRFS_IOC_BALANCE_PROGRESS,               0x0084009422 },
132         { BTRFS_IOC_INO_PATHS,                      0x00c0389423 },
133         { BTRFS_IOC_LOGICAL_INO,                    0x00c0389424 },
134         { BTRFS_IOC_SET_RECEIVED_SUBVOL,            0x00c0c89425 },
135 #ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
136         { BTRFS_IOC_SET_RECEIVED_SUBVOL_32,         0x00c0c09425 },
137 #endif
138 #if BITS_PER_LONG == 32
139         { BTRFS_IOC_SEND,                           0x0040449426 },
140 #elif BITS_PER_LONG == 64
141         { BTRFS_IOC_SEND,                           0x0040489426 },
142 #endif
143 #ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
144         { BTRFS_IOC_SEND_64,                        0x0040489426 },
145 #endif
146         { BTRFS_IOC_DEVICES_READY,                  0x0090009427 },
147         { BTRFS_IOC_QUOTA_CTL,                      0x00c0109428 },
148         { BTRFS_IOC_QGROUP_ASSIGN,                  0x0040189429 },
149         { BTRFS_IOC_QGROUP_CREATE,                  0x004010942a },
150         { BTRFS_IOC_QGROUP_LIMIT,                   0x008030942b },
151         { BTRFS_IOC_QUOTA_RESCAN,                   0x004040942c },
152         { BTRFS_IOC_QUOTA_RESCAN_STATUS,            0x008040942d },
153         { BTRFS_IOC_QUOTA_RESCAN_WAIT,              0x000000942e },
154         { BTRFS_IOC_GET_FSLABEL,                    0x0081009431 },
155         { BTRFS_IOC_SET_FSLABEL,                    0x0041009432 },
156         { BTRFS_IOC_GET_DEV_STATS,                  0x00c4089434 },
157         { BTRFS_IOC_DEV_REPLACE,                    0x00ca289435 },
158         { BTRFS_IOC_FILE_EXTENT_SAME,               0x00c0189436 },
159         { BTRFS_IOC_GET_FEATURES,                   0x0080189439 },
160         { BTRFS_IOC_SET_FEATURES,                   0x0040309439 },
161         { BTRFS_IOC_GET_SUPPORTED_FEATURES,         0x0080489439 },
162         { BTRFS_IOC_RM_DEV_V2,                      0x005000943a },
163 };
164
165 static struct btrfs_ioctl_vol_args used_vol_args __attribute__((used));
166 static struct btrfs_ioctl_vol_args_v2 used_vol_args2 __attribute__((used));
167 static struct btrfs_ioctl_clone_range_args used_clone_args __attribute__((used));
168 static struct btrfs_ioctl_defrag_range_args used_defrag_args __attribute__((used));
169 static struct btrfs_ioctl_search_args used_search_args __attribute__((used));
170 static struct btrfs_ioctl_search_args_v2 used_search_args2 __attribute__((used));
171 static struct btrfs_ioctl_ino_lookup_args used_ino_lookup __attribute__((used));
172 static struct btrfs_ioctl_space_args used_space_args __attribute__((used));
173 static struct btrfs_ioctl_scrub_args used_scrub_args __attribute__((used));
174 static struct btrfs_ioctl_dev_info_args used_dev_info_args __attribute__((used));
175 static struct btrfs_ioctl_fs_info_args used_fs_info_args __attribute__((used));
176 static struct btrfs_ioctl_balance_args used_balance_args __attribute__((used));
177 static struct btrfs_ioctl_ino_path_args used_path_args __attribute__((used));
178 static struct btrfs_ioctl_logical_ino_args used_logical_args __attribute__((used));
179 static struct btrfs_ioctl_received_subvol_args used_received_args __attribute__((used));
180 #ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32_COMPAT_DEFINED
181 static struct btrfs_ioctl_received_subvol_args_32 used_received_args32 __attribute__((used));
182 #endif
183 static struct btrfs_ioctl_send_args used_send_args __attribute__((used));
184 #ifdef BTRFS_IOC_SEND_64_COMPAT_DEFINED
185 static struct btrfs_ioctl_send_args_64 used_send_args64 __attribute__((used));
186 #endif
187 static struct btrfs_ioctl_quota_ctl_args used_qgctl_args __attribute__((used));
188 static struct btrfs_ioctl_qgroup_assign_args used_qgassign_args __attribute__((used));
189 static struct btrfs_ioctl_qgroup_create_args used_qgcreate_args __attribute__((used));
190 static struct btrfs_ioctl_qgroup_limit_args used_qglimit_args __attribute__((used));
191 static struct btrfs_ioctl_quota_rescan_args used_qgrescan_args __attribute__((used));
192 static struct btrfs_ioctl_get_dev_stats used_dev_stats_args __attribute__((used));
193 static struct btrfs_ioctl_dev_replace_args used_replace_args __attribute__((used));
194 static struct btrfs_ioctl_same_args used_same_args __attribute__((used));
195 static struct btrfs_ioctl_feature_flags used_feature_flags __attribute__((used));
196
197 const char* value_to_string(unsigned long num)
198 {
199 #define ONE(x)  case x: return #x;
200         switch (num) {
201         LIST_BASE
202         }
203
204         switch (num) {
205         LIST_32_COMPAT
206         }
207
208         switch (num) {
209         LIST_64_COMPAT
210         }
211 #undef ONE
212         return "UNKNOWN";
213 }
214
215 int main(int ac, char **av)
216 {
217         int i;
218         int errors = 0;
219
220         value_to_string(random());
221
222         printf("Sizeof long long:  %zu\n", sizeof(unsigned long long));
223         printf("Sizeof long:       %zu\n", sizeof(unsigned long));
224         printf("Sizeof pointer:    %zu\n", sizeof(void*));
225         printf("Alignof long long: %zu\n", __alignof__(unsigned long long));
226         printf("Alignof long:      %zu\n", __alignof__(unsigned long));
227         printf("Alignof pointer:   %zu\n", __alignof__(void*));
228         printf("Raw ioctl numbers:\n");
229
230 #define ONE(n)  printf("%-38s   0x%010lx\n", #n, (unsigned long)n);
231         LIST
232 #undef ONE
233
234         for (i = 0; i < ARRAY_SIZE(expected_list); i++) {
235                 if (expected_list[i].defined != expected_list[i].expected) {
236                         printf("ERROR: wrong value for %s, defined=0x%lx expected=0x%lx\n",
237                                         value_to_string(expected_list[i].defined),
238                                         expected_list[i].defined,
239                                         expected_list[i].expected);
240                         errors++;
241                 }
242         }
243
244         if (!errors) {
245                 printf("All ok\n");
246         } else {
247                 printf("Found %d errors in definitions\n", errors);
248         }
249
250         return !!errors;
251 }
252