]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udev-builtin-btrfs.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / udev / udev-builtin-btrfs.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright © 2012 Kay Sievers <kay@vrfy.org>
4 ***/
5
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <sys/ioctl.h>
9
10 #if HAVE_LINUX_BTRFS_H
11 #include <linux/btrfs.h>
12 #endif
13
14 #include "fd-util.h"
15 #include "missing.h"
16 #include "string-util.h"
17 #include "udev.h"
18
19 static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test) {
20 struct btrfs_ioctl_vol_args args = {};
21 _cleanup_close_ int fd = -1;
22 int err;
23
24 if (argc != 3 || !streq(argv[1], "ready"))
25 return EXIT_FAILURE;
26
27 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
28 if (fd < 0)
29 return EXIT_FAILURE;
30
31 strscpy(args.name, sizeof(args.name), argv[2]);
32 err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
33 if (err < 0)
34 return EXIT_FAILURE;
35
36 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(err == 0));
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 };