]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/udev-builtin-btrfs.c
udev: add emacs header line
[thirdparty/systemd.git] / src / udev / udev-builtin-btrfs.c
CommitLineData
3f65d731
ZJS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
c3cfed0d
KS
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***/
0bb91b50 21
0bb91b50 22#include <fcntl.h>
07630cea 23#include <stdlib.h>
0bb91b50 24#include <sys/ioctl.h>
a2e22d07 25
dced1557
SM
26#ifdef HAVE_LINUX_BTRFS_H
27#include <linux/btrfs.h>
28#endif
0bb91b50 29
3ffd4af2 30#include "fd-util.h"
dced1557 31#include "missing.h"
07630cea 32#include "string-util.h"
0bb91b50
KS
33#include "udev.h"
34
9ec6e95b 35static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test) {
a2e22d07 36 struct btrfs_ioctl_vol_args args = {};
c8a202b7 37 _cleanup_close_ int fd = -1;
0bb91b50
KS
38 int err;
39
40 if (argc != 3 || !streq(argv[1], "ready"))
41 return EXIT_FAILURE;
42
c8a202b7 43 fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
0bb91b50
KS
44 if (fd < 0)
45 return EXIT_FAILURE;
46
d5a89d7d 47 strscpy(args.name, sizeof(args.name), argv[2]);
0bb91b50 48 err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
0bb91b50
KS
49 if (err < 0)
50 return EXIT_FAILURE;
51
cd1ddd54 52 udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(err == 0));
0bb91b50
KS
53 return EXIT_SUCCESS;
54}
55
56const struct udev_builtin udev_builtin_btrfs = {
57 .name = "btrfs",
58 .cmd = builtin_btrfs,
59 .help = "btrfs volume management",
60};