@@ -17,6 +17,48 @@ over time and in some cases get promoted to a VFS-level ioctl once other
1717filesystems adopt the functionality. Backward compatibility is maintained
1818and a formerly private ioctl number could become available on the VFS level.
1919
20+ OVERVIEW
21+ --------
22+
23+ The ioctls are defined by a number and associated with a data structure that
24+ contains further information. All ioctls use file descriptor (*fd *) as a reference
25+ point, it could be the filesystem or a directory inside the filesystem.
26+
27+ An ioctl can be used in the following schematic way:
28+
29+ .. code-block :: c
30+
31+ struct btrfs_ioctl_args args;
32+
33+ memset(&args, 0, sizeof(args));
34+ args.key = value;
35+ ret = ioctl(fd, BTRFS_IOC_NUMBER, &args);
36+
37+ The *fd * is the entry point to the filesystem and for most ioctls it does not
38+ matter which directory is that. A distinction between files and directories sometimes
39+ matter, when it matters it's explicitly mentioned. The *args * is the
40+ associated data structure for the request. It's strongly recommended to
41+ initialize the whole structure to zeros as this is future-proof when the ioctl
42+ gets further extensions. Not doing that could lead to mismatch of old userspace
43+ and new kernel versions, or vice versa. The *BTRFS_IOC_NUMBER * is says which
44+ operation should be done on the given arguments. Some ioctls take a specific
45+ data structure, some of them share a common one, no argument structure ioctls
46+ exist too. The data passed to an ioctl can be input, output or both.
47+
48+ The library *libbtrfsutil * wraps a few ioctls for convenience. Using raw ioctls
49+ is not discouraged but may be cumbersome though it does not need additional
50+ library dependency. Backward compatibility is guaranteed and incompatible
51+ changes usually lead to a new version of the ioctl. Enhancements of existing
52+ ioctls can happen and depend on additional flags to be set. Zeroed unused
53+ space is commonly understood as a mechanism to communicate the compatibility
54+ between kernel and userspace and thus *zeroing is really important *. In exceptional
55+ cases this is not enough and further flags need to be passed to distinguish
56+ between zero as implicit unused initialization and a valid zero value. Such
57+ cases are documented.
58+
59+ File descriptors of regular files are obtained by ``int fd = open() ``, directories
60+ opened as ``DIR *dir = opendir() `` can be converted to the corresponding
61+ file descriptor by ``fd = dirfd(dir) ``.
2062
2163DATA STRUCTURES AND DEFINITIONS
2264-------------------------------
@@ -235,48 +277,6 @@ DATA STRUCTURES AND DEFINITIONS
235277 * - BTRFS_FIRST_FREE_OBJECTID
236278 - 256
237279
238- OVERVIEW
239- --------
240-
241- The ioctls are defined by a number and associated with a data structure that
242- contains further information. All ioctls use file descriptor (fd) as a reference
243- point, it could be the filesystem or a directory inside the filesystem.
244-
245- An ioctl can be used in the following schematic way:
246-
247- .. code-block :: c
248-
249- struct btrfs_ioctl_args args;
250-
251- memset(&args, 0, sizeof(args));
252- args.key = value;
253- ret = ioctl(fd, BTRFS_IOC_NUMBER, &args);
254-
255- The 'fd' is the entry point to the filesystem and for most ioctls it does not
256- matter which file or directory is that. Where it matters it's explicitly
257- mentioned. The 'args' is the associated data structure for the request. It's
258- strongly recommended to initialize the whole structure to zeros as this is
259- future-proof when the ioctl gets further extensions. Not doing that could lead
260- to mismatch of old userspace and new kernel versions, or vice versa.
261- The 'BTRFS_IOC_NUMBER' is says which operation should be done on the given
262- arguments. Some ioctls take a specific data structure, some of them share a
263- common one, no argument structure ioctls exist too.
264-
265- The library *libbtrfsutil * wraps a few ioctls for convenience. Using raw ioctls
266- is not discouraged but may be cumbersome though it does not need additional
267- library dependency. Backward compatibility is guaranteed and incompatible
268- changes usually lead to a new version of the ioctl. Enhancements of existing
269- ioctls can happen and depend on additional flags to be set. Zeroed unused
270- space is commonly understood as a mechanism to communicate the compatibility
271- between kernel and userspace and thus *zeroing is really important *. In exceptional
272- cases this is not enough and further flags need to be passed to distinguish
273- between zero as implicit unused initialization and a valid zero value. Such
274- cases are documented.
275-
276- File descriptors of regular files are obtained by ``int fd = open() ``, directories
277- opened as ``DIR *dir = opendir() `` can be converted to the corresponding
278- file descriptor by ``fd = dirfd(dir) ``.
279-
280280LIST OF IOCTLS
281281--------------
282282
0 commit comments