]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/udev-builtin-btrfs.c
homed: make it easier to run multiple instances of homed
[thirdparty/systemd.git] / src / udev / udev-builtin-btrfs.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
0bb91b50 2
0bb91b50 3#include <fcntl.h>
01234e1f 4#include <linux/btrfs.h>
07630cea 5#include <stdlib.h>
0bb91b50 6#include <sys/ioctl.h>
a2e22d07 7
5ad71e44 8#include "device-util.h"
3ffd4af2 9#include "fd-util.h"
07630cea 10#include "string-util.h"
07a26e42
YW
11#include "strxcpyx.h"
12#include "udev-builtin.h"
13#include "util.h"
0bb91b50 14
3fc2e9a2 15static int builtin_btrfs(sd_device *dev, int argc, char *argv[], bool test) {
a2e22d07 16 struct btrfs_ioctl_vol_args args = {};
c8a202b7 17 _cleanup_close_ int fd = -1;
d354690e 18 int r;
0bb91b50
KS
19
20 if (argc != 3 || !streq(argv[1], "ready"))
a1193286 21 return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
0bb91b50 22
c8a202b7 23 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
0bb91b50 24 if (fd < 0)
5ad71e44 25 return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
0bb91b50 26
d5a89d7d 27 strscpy(args.name, sizeof(args.name), argv[2]);
d354690e
YW
28 r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
29 if (r < 0)
5ad71e44 30 return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
0bb91b50 31
d354690e
YW
32 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(r == 0));
33 return 0;
0bb91b50
KS
34}
35
25de7aa7 36const UdevBuiltin udev_builtin_btrfs = {
0bb91b50
KS
37 .name = "btrfs",
38 .cmd = builtin_btrfs,
39 .help = "btrfs volume management",
40};