]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udev-builtin-btrfs.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[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 #if HAVE_LINUX_BTRFS_H
8 #include <linux/btrfs.h>
9 #endif
10
11 #include "device-util.h"
12 #include "fd-util.h"
13 #include "missing.h"
14 #include "string-util.h"
15 #include "strxcpyx.h"
16 #include "udev-builtin.h"
17 #include "util.h"
18
19 static int builtin_btrfs(sd_device *dev, int argc, char *argv[], bool test) {
20 struct btrfs_ioctl_vol_args args = {};
21 _cleanup_close_ int fd = -1;
22 int r;
23
24 if (argc != 3 || !streq(argv[1], "ready"))
25 return log_device_error_errno(dev, EINVAL, "Invalid arguments");
26
27 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
28 if (fd < 0)
29 return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
30
31 strscpy(args.name, sizeof(args.name), argv[2]);
32 r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
33 if (r < 0)
34 return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
35
36 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(r == 0));
37 return 0;
38 }
39
40 const struct udev_builtin udev_builtin_btrfs = {
41 .name = "btrfs",
42 .cmd = builtin_btrfs,
43 .help = "btrfs volume management",
44 };