2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2012-09-16 23:31:11 +02:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
2019-04-10 12:55:53 +02:00
|
|
|
#include <linux/btrfs.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <stdlib.h>
|
2012-09-16 23:31:11 +02:00
|
|
|
#include <sys/ioctl.h>
|
2014-12-12 02:34:12 +01:00
|
|
|
|
2018-10-23 20:13:54 +02:00
|
|
|
#include "device-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2018-08-29 09:12:22 +02:00
|
|
|
#include "strxcpyx.h"
|
|
|
|
#include "udev-builtin.h"
|
|
|
|
#include "util.h"
|
2012-09-16 23:31:11 +02:00
|
|
|
|
2018-10-13 18:22:14 +02:00
|
|
|
static int builtin_btrfs(sd_device *dev, int argc, char *argv[], bool test) {
|
2014-12-12 02:34:12 +01:00
|
|
|
struct btrfs_ioctl_vol_args args = {};
|
2014-02-13 14:59:56 +01:00
|
|
|
_cleanup_close_ int fd = -1;
|
2018-10-23 11:26:06 +02:00
|
|
|
int r;
|
2012-09-16 23:31:11 +02:00
|
|
|
|
|
|
|
if (argc != 3 || !streq(argv[1], "ready"))
|
2019-01-13 09:50:47 +01:00
|
|
|
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
|
2012-09-16 23:31:11 +02:00
|
|
|
|
2014-02-13 14:59:56 +01:00
|
|
|
fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
|
2012-09-16 23:31:11 +02:00
|
|
|
if (fd < 0)
|
2018-10-23 20:13:54 +02:00
|
|
|
return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
|
2012-09-16 23:31:11 +02:00
|
|
|
|
2013-01-09 19:06:46 +01:00
|
|
|
strscpy(args.name, sizeof(args.name), argv[2]);
|
2018-10-23 11:26:06 +02:00
|
|
|
r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
|
|
|
|
if (r < 0)
|
2018-10-23 20:13:54 +02:00
|
|
|
return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
|
2012-09-16 23:31:11 +02:00
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(r == 0));
|
|
|
|
return 0;
|
2012-09-16 23:31:11 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 01:21:11 +02:00
|
|
|
const UdevBuiltin udev_builtin_btrfs = {
|
2012-09-16 23:31:11 +02:00
|
|
|
.name = "btrfs",
|
|
|
|
.cmd = builtin_btrfs,
|
|
|
|
.help = "btrfs volume management",
|
|
|
|
};
|