1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2020 Tomas Bzatek <tbzatek@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "config.h"
#include <blockdev/blockdev.h>
#include <src/udisksdaemon.h>
#include <src/udiskslogging.h>
#include <src/udiskslinuxdevice.h>
#include <src/udisksmodulemanager.h>
#include <src/udisksmodule.h>
#include <src/udisksmoduleobject.h>
#include <src/udiskslinuxblockobject.h>
#include "udiskslinuxmodulebtrfs.h"
#include "udiskslinuxmanagerbtrfs.h"
#include "udiskslinuxfilesystembtrfs.h"
/**
* SECTION:udiskslinuxmodulebtrfs
* @title: UDisksLinuxModuleBTRFS
* @short_description: BTRFS module.
*
* The BTRFS module.
*/
/**
* UDisksLinuxModuleBTRFS:
*
* The #UDisksLinuxModuleBTRFS structure contains only private data
* and should only be accessed using the provided API.
*/
struct _UDisksLinuxModuleBTRFS {
UDisksModule parent_instance;
};
typedef struct _UDisksLinuxModuleBTRFSClass UDisksLinuxModuleBTRFSClass;
struct _UDisksLinuxModuleBTRFSClass {
UDisksModuleClass parent_class;
};
static void initable_iface_init (GInitableIface *initable_iface);
G_DEFINE_TYPE_WITH_CODE (UDisksLinuxModuleBTRFS, udisks_linux_module_btrfs, UDISKS_TYPE_MODULE,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));
static void
udisks_linux_module_btrfs_init (UDisksLinuxModuleBTRFS *module)
{
}
static void
udisks_linux_module_btrfs_constructed (GObject *object)
{
if (G_OBJECT_CLASS (udisks_linux_module_btrfs_parent_class)->constructed)
G_OBJECT_CLASS (udisks_linux_module_btrfs_parent_class)->constructed (object);
}
static void
udisks_linux_module_btrfs_finalize (GObject *object)
{
if (G_OBJECT_CLASS (udisks_linux_module_btrfs_parent_class)->finalize)
G_OBJECT_CLASS (udisks_linux_module_btrfs_parent_class)->finalize (object);
}
gchar *
udisks_module_id (void)
{
return g_strdup (BTRFS_MODULE_NAME);
}
/**
* udisks_module_btrfs_new:
* @daemon: A #UDisksDaemon.
* @cancellable: (nullable): A #GCancellable or %NULL
* @error: Return location for error or %NULL.
*
* Creates new #UDisksLinuxModuleBTRFS object.
*
* Returns: (transfer full) (type UDisksLinuxModuleBTRFS): A
* #UDisksLinuxModuleBTRFS object or %NULL if @error is set. Free
* with g_object_unref().
*/
UDisksModule *
udisks_module_btrfs_new (UDisksDaemon *daemon,
GCancellable *cancellable,
GError **error)
{
GInitable *initable;
g_return_val_if_fail (UDISKS_IS_DAEMON (daemon), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
initable = g_initable_new (UDISKS_TYPE_LINUX_MODULE_BTRFS,
cancellable,
error,
"daemon", daemon,
"name", BTRFS_MODULE_NAME,
NULL);
if (initable == NULL)
return NULL;
else
return UDISKS_MODULE (initable);
}
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
/* NULL means no specific so_name (implementation) */
BDPluginSpec btrfs_plugin = { BD_PLUGIN_BTRFS, NULL };
BDPluginSpec *plugins[] = { &btrfs_plugin, NULL };
if (! bd_is_plugin_available (BD_PLUGIN_BTRFS))
{
if (! bd_reinit (plugins, FALSE, NULL, error))
return FALSE;
}
return TRUE;
}
static void
initable_iface_init (GInitableIface *initable_iface)
{
initable_iface->init = initable_init;
}
/* ---------------------------------------------------------------------------------------------------- */
static GDBusInterfaceSkeleton *
udisks_linux_module_btrfs_new_manager (UDisksModule *module)
{
UDisksLinuxManagerBTRFS *manager;
g_return_val_if_fail (UDISKS_IS_LINUX_MODULE_BTRFS (module), NULL);
manager = udisks_linux_manager_btrfs_new (UDISKS_LINUX_MODULE_BTRFS (module));
return G_DBUS_INTERFACE_SKELETON (manager);
}
/* ---------------------------------------------------------------------------------------------------- */
static GType *
udisks_linux_module_btrfs_get_block_object_interface_types (UDisksModule *module)
{
static GType block_object_interface_types[2];
g_return_val_if_fail (UDISKS_IS_LINUX_MODULE_BTRFS (module), NULL);
if (g_once_init_enter (&block_object_interface_types[0]))
g_once_init_leave (&block_object_interface_types[0], UDISKS_TYPE_LINUX_FILESYSTEM_BTRFS);
return block_object_interface_types;
}
static GDBusInterfaceSkeleton *
udisks_linux_module_btrfs_new_block_object_interface (UDisksModule *module,
UDisksLinuxBlockObject *object,
GType interface_type)
{
GDBusInterfaceSkeleton *interface = NULL;
UDisksLinuxDevice *device;
const gchar *fs_type;
g_return_val_if_fail (UDISKS_IS_LINUX_MODULE_BTRFS (module), NULL);
if (interface_type == UDISKS_TYPE_LINUX_FILESYSTEM_BTRFS)
{
/* Check filesystem type from udev property. */
device = udisks_linux_block_object_get_device (UDISKS_LINUX_BLOCK_OBJECT (object));
fs_type = g_udev_device_get_property (device->udev_device, "ID_FS_TYPE");
if (g_strcmp0 (fs_type, "btrfs") == 0)
{
interface = G_DBUS_INTERFACE_SKELETON (udisks_linux_filesystem_btrfs_new (UDISKS_LINUX_MODULE_BTRFS (module), object));
}
g_object_unref (device);
}
else
{
udisks_error ("Invalid interface type");
}
return interface;
}
/* ---------------------------------------------------------------------------------------------------- */
static void
udisks_linux_module_btrfs_class_init (UDisksLinuxModuleBTRFSClass *klass)
{
GObjectClass *gobject_class;
UDisksModuleClass *module_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructed = udisks_linux_module_btrfs_constructed;
gobject_class->finalize = udisks_linux_module_btrfs_finalize;
module_class = UDISKS_MODULE_CLASS (klass);
module_class->new_manager = udisks_linux_module_btrfs_new_manager;
module_class->get_block_object_interface_types = udisks_linux_module_btrfs_get_block_object_interface_types;
module_class->new_block_object_interface = udisks_linux_module_btrfs_new_block_object_interface;
}
|