]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c3cfed0d | 2 | /*** |
96b2fb93 | 3 | Copyright © 2012 Kay Sievers <kay@vrfy.org> |
c3cfed0d | 4 | ***/ |
0bb91b50 | 5 | |
0bb91b50 | 6 | #include <fcntl.h> |
07630cea | 7 | #include <stdlib.h> |
0bb91b50 | 8 | #include <sys/ioctl.h> |
a2e22d07 | 9 | |
349cc4a5 | 10 | #if HAVE_LINUX_BTRFS_H |
dced1557 SM |
11 | #include <linux/btrfs.h> |
12 | #endif | |
0bb91b50 | 13 | |
3ffd4af2 | 14 | #include "fd-util.h" |
dced1557 | 15 | #include "missing.h" |
07630cea | 16 | #include "string-util.h" |
0bb91b50 KS |
17 | #include "udev.h" |
18 | ||
9ec6e95b | 19 | static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test) { |
a2e22d07 | 20 | struct btrfs_ioctl_vol_args args = {}; |
c8a202b7 | 21 | _cleanup_close_ int fd = -1; |
0bb91b50 KS |
22 | int err; |
23 | ||
24 | if (argc != 3 || !streq(argv[1], "ready")) | |
25 | return EXIT_FAILURE; | |
26 | ||
c8a202b7 | 27 | fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC); |
0bb91b50 KS |
28 | if (fd < 0) |
29 | return EXIT_FAILURE; | |
30 | ||
d5a89d7d | 31 | strscpy(args.name, sizeof(args.name), argv[2]); |
0bb91b50 | 32 | err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args); |
0bb91b50 KS |
33 | if (err < 0) |
34 | return EXIT_FAILURE; | |
35 | ||
cd1ddd54 | 36 | udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(err == 0)); |
0bb91b50 KS |
37 | return EXIT_SUCCESS; |
38 | } | |
39 | ||
40 | const struct udev_builtin udev_builtin_btrfs = { | |
41 | .name = "btrfs", | |
42 | .cmd = builtin_btrfs, | |
43 | .help = "btrfs volume management", | |
44 | }; |