]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udev-builtin-btrfs.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / udev / udev-builtin-btrfs.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <sys/ioctl.h>
6
7 #include "device-util.h"
8 #include "fd-util.h"
9 #include "missing.h"
10 #include "string-util.h"
11 #include "strxcpyx.h"
12 #include "udev-builtin.h"
13 #include "util.h"
14
15 static int builtin_btrfs(sd_device *dev, int argc, char *argv[], bool test) {
16 struct btrfs_ioctl_vol_args args = {};
17 _cleanup_close_ int fd = -1;
18 int r;
19
20 if (argc != 3 || !streq(argv[1], "ready"))
21 return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
22
23 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
24 if (fd < 0)
25 return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
26
27 strscpy(args.name, sizeof(args.name), argv[2]);
28 r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
29 if (r < 0)
30 return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
31
32 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(r == 0));
33 return 0;
34 }
35
36 const struct udev_builtin udev_builtin_btrfs = {
37 .name = "btrfs",
38 .cmd = builtin_btrfs,
39 .help = "btrfs volume management",
40 };