]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udev-builtin-btrfs.c
udev: add emacs header line
[thirdparty/systemd.git] / src / udev / udev-builtin-btrfs.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2012 Kay Sievers <kay@vrfy.org>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <fcntl.h>
23 #include <stdlib.h>
24 #include <sys/ioctl.h>
25
26 #ifdef HAVE_LINUX_BTRFS_H
27 #include <linux/btrfs.h>
28 #endif
29
30 #include "fd-util.h"
31 #include "missing.h"
32 #include "string-util.h"
33 #include "udev.h"
34
35 static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test) {
36 struct btrfs_ioctl_vol_args args = {};
37 _cleanup_close_ int fd = -1;
38 int err;
39
40 if (argc != 3 || !streq(argv[1], "ready"))
41 return EXIT_FAILURE;
42
43 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
44 if (fd < 0)
45 return EXIT_FAILURE;
46
47 strscpy(args.name, sizeof(args.name), argv[2]);
48 err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
49 if (err < 0)
50 return EXIT_FAILURE;
51
52 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(err == 0));
53 return EXIT_SUCCESS;
54 }
55
56 const struct udev_builtin udev_builtin_btrfs = {
57 .name = "btrfs",
58 .cmd = builtin_btrfs,
59 .help = "btrfs volume management",
60 };