chiark / gitweb /
hwdb: OUI - use ID_OUI_FROM_DATABASE=
[elogind.git] / src / udev / udev-builtin-btrfs.c
1 /*
2  * btrfs - volume management
3  *
4  * Copyright (C) 2012 Kay Sievers <kay@vrfy.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  */
11
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdio.h>
16 #include <fcntl.h>
17 #include <errno.h>
18 #include <sys/ioctl.h>
19
20 #include "udev.h"
21
22 #define BTRFS_PATH_NAME_MAX 4087
23 struct btrfs_ioctl_vol_args {
24         int64_t fd;
25         char name[BTRFS_PATH_NAME_MAX + 1];
26 };
27 #define BTRFS_IOCTL_MAGIC 0x94
28 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, struct btrfs_ioctl_vol_args)
29
30 static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool test)
31 {
32         struct  btrfs_ioctl_vol_args args;
33         int fd;
34         int err;
35
36         if (argc != 3 || !streq(argv[1], "ready"))
37                 return EXIT_FAILURE;
38
39         fd = open("/dev/btrfs-control", O_RDWR);
40         if (fd < 0)
41                 return EXIT_FAILURE;
42
43         util_strscpy(args.name, sizeof(args.name), argv[2]);
44         err = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
45         close(fd);
46         if (err < 0)
47                 return EXIT_FAILURE;
48
49         udev_builtin_add_property(dev, test, "ID_BTRFS_READY", err == 0 ? "1" : "0");
50         return EXIT_SUCCESS;
51 }
52
53 const struct udev_builtin udev_builtin_btrfs = {
54         .name = "btrfs",
55         .cmd = builtin_btrfs,
56         .help = "btrfs volume management",
57 };