1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3
* Copyright (C) 2011 David Zeuthen <zeuthen@gmail.com>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General
16
* Public License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
* Boston, MA 02111-1307, USA.
22
#include <glib/gi18n-lib.h>
24
#include "udisksclient.h"
25
#include "udiskserror.h"
26
#include "udisks-generated.h"
27
#include "udisksobjectinfo.h"
29
/* For __GNUC_PREREQ usage below */
31
# include <features.h>
35
* SECTION:udisksclient
36
* @title: UDisksClient
37
* @short_description: Utility routines for accessing the UDisks service
39
* #UDisksClient is used for accessing the UDisks service from a
43
G_LOCK_DEFINE_STATIC (init_lock);
48
* The #UDisksClient structure contains only private data and should
49
* only be accessed using the provided API.
53
GObject parent_instance;
55
gboolean is_initialized;
56
GError *initialization_error;
58
GDBusObjectManager *object_manager;
60
GMainContext *context;
62
GSource *changed_timeout_source;
67
GObjectClass parent_class;
83
static guint signals[LAST_SIGNAL] = { 0 };
85
static void initable_iface_init (GInitableIface *initable_iface);
86
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
88
static void on_object_added (GDBusObjectManager *manager,
92
static void on_object_removed (GDBusObjectManager *manager,
96
static void on_interface_added (GDBusObjectManager *manager,
98
GDBusInterface *interface,
101
static void on_interface_removed (GDBusObjectManager *manager,
103
GDBusInterface *interface,
106
static void on_interface_proxy_properties_changed (GDBusObjectManagerClient *manager,
107
GDBusObjectProxy *object_proxy,
108
GDBusProxy *interface_proxy,
109
GVariant *changed_properties,
110
const gchar *const *invalidated_properties,
113
static void maybe_emit_changed_now (UDisksClient *client);
115
static void init_interface_proxy (UDisksClient *client,
118
static UDisksPartitionTypeInfo *udisks_partition_type_info_new (void);
120
G_DEFINE_TYPE_WITH_CODE (UDisksClient, udisks_client, G_TYPE_OBJECT,
121
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
122
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
126
udisks_client_finalize (GObject *object)
128
UDisksClient *client = UDISKS_CLIENT (object);
130
if (client->changed_timeout_source != NULL)
131
g_source_destroy (client->changed_timeout_source);
133
if (client->initialization_error != NULL)
134
g_error_free (client->initialization_error);
136
g_signal_handlers_disconnect_by_func (client->object_manager,
137
G_CALLBACK (on_object_added),
139
g_signal_handlers_disconnect_by_func (client->object_manager,
140
G_CALLBACK (on_object_removed),
142
g_signal_handlers_disconnect_by_func (client->object_manager,
143
G_CALLBACK (on_interface_added),
145
g_signal_handlers_disconnect_by_func (client->object_manager,
146
G_CALLBACK (on_interface_removed),
148
g_signal_handlers_disconnect_by_func (client->object_manager,
149
G_CALLBACK (on_interface_proxy_properties_changed),
151
g_object_unref (client->object_manager);
153
if (client->context != NULL)
154
g_main_context_unref (client->context);
156
G_OBJECT_CLASS (udisks_client_parent_class)->finalize (object);
160
udisks_client_init (UDisksClient *client)
162
static volatile GQuark udisks_error_domain = 0;
163
/* this will force associating errors in the UDISKS_ERROR error
164
* domain with org.freedesktop.UDisks2.Error.* errors via
165
* g_dbus_error_register_error_domain().
167
udisks_error_domain = UDISKS_ERROR;
168
udisks_error_domain; /* shut up -Wunused-but-set-variable */
172
udisks_client_get_property (GObject *object,
177
UDisksClient *client = UDISKS_CLIENT (object);
181
case PROP_OBJECT_MANAGER:
182
g_value_set_object (value, udisks_client_get_object_manager (client));
186
g_value_set_object (value, udisks_client_get_manager (client));
190
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
196
udisks_client_class_init (UDisksClientClass *klass)
198
GObjectClass *gobject_class;
200
gobject_class = G_OBJECT_CLASS (klass);
201
gobject_class->finalize = udisks_client_finalize;
202
gobject_class->get_property = udisks_client_get_property;
205
* UDisksClient:object-manager:
207
* The #GDBusObjectManager used by the #UDisksClient instance.
209
g_object_class_install_property (gobject_class,
211
g_param_spec_object ("object-manager",
213
"The GDBusObjectManager used by the UDisksClient",
214
G_TYPE_DBUS_OBJECT_MANAGER,
216
G_PARAM_STATIC_STRINGS));
219
* UDisksClient:manager:
221
* The #UDisksManager interface on the well-known
222
* <literal>/org/freedesktop/UDisks2/Manager</literal> object
224
g_object_class_install_property (gobject_class,
226
g_param_spec_object ("manager",
231
G_PARAM_STATIC_STRINGS));
234
* UDisksClient::changed:
235
* @client: A #UDisksClient.
237
* This signal is emitted either when an object or interface is
238
* added or removed a when property has changed. Additionally,
239
* multiple received signals are coalesced into a single signal that
240
* is rate-limited to fire at most every 100ms.
242
* Note that calling udisks_client_settle() will cause this signal
243
* to fire if any changes are outstanding.
245
* For greater detail, connect to the
246
* #GDBusObjectManager::object-added,
247
* #GDBusObjectManager::object-removed,
248
* #GDBusObjectManager::interface-added,
249
* #GDBusObjectManager::interface-removed,
250
* #GDBusObjectManagerClient::interface-proxy-properties-changed and
251
* signals on the #UDisksClient:object-manager object.
253
signals[CHANGED_SIGNAL] = g_signal_new ("changed",
254
G_OBJECT_CLASS_TYPE (klass),
256
0, /* G_STRUCT_OFFSET */
258
NULL, /* accu data */
259
g_cclosure_marshal_generic,
267
* @cancellable: A #GCancellable or %NULL.
268
* @callback: Function that will be called when the result is ready.
269
* @user_data: Data to pass to @callback.
271
* Asynchronously gets a #UDisksClient. When the operation is
272
* finished, @callback will be invoked in the <link
273
* linkend="g-main-context-push-thread-default">thread-default main
274
* loop</link> of the thread you are calling this method from.
277
udisks_client_new (GCancellable *cancellable,
278
GAsyncReadyCallback callback,
281
g_async_initable_new_async (UDISKS_TYPE_CLIENT,
290
* udisks_client_new_finish:
291
* @res: A #GAsyncResult.
292
* @error: Return location for error or %NULL.
294
* Finishes an operation started with udisks_client_new().
296
* Returns: A #UDisksClient or %NULL if @error is set. Free with
297
* g_object_unref() when done with it.
300
udisks_client_new_finish (GAsyncResult *res,
304
GObject *source_object;
305
source_object = g_async_result_get_source_object (res);
306
ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);
307
g_object_unref (source_object);
309
return UDISKS_CLIENT (ret);
315
* udisks_client_new_sync:
316
* @cancellable: (allow-none): A #GCancellable or %NULL.
317
* @error: (allow-none): Return location for error or %NULL.
319
* Synchronously gets a #UDisksClient for the local system.
321
* Returns: A #UDisksClient or %NULL if @error is set. Free with
322
* g_object_unref() when done with it.
325
udisks_client_new_sync (GCancellable *cancellable,
329
ret = g_initable_new (UDISKS_TYPE_CLIENT,
334
return UDISKS_CLIENT (ret);
339
/* ---------------------------------------------------------------------------------------------------- */
342
initable_init (GInitable *initable,
343
GCancellable *cancellable,
346
UDisksClient *client = UDISKS_CLIENT (initable);
349
GList *interfaces, *ll;
353
/* This method needs to be idempotent to work with the singleton
354
* pattern. See the docs for g_initable_init(). We implement this by
358
if (client->is_initialized)
360
if (client->object_manager != NULL)
363
g_assert (client->initialization_error != NULL);
366
g_assert (client->initialization_error == NULL);
368
client->context = g_main_context_get_thread_default ();
369
if (client->context != NULL)
370
g_main_context_ref (client->context);
372
client->object_manager = udisks_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
373
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
374
"org.freedesktop.UDisks2",
375
"/org/freedesktop/UDisks2",
377
&client->initialization_error);
378
if (client->object_manager == NULL)
381
/* init all proxies */
382
objects = g_dbus_object_manager_get_objects (client->object_manager);
383
for (l = objects; l != NULL; l = l->next)
385
interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (l->data));
386
for (ll = interfaces; ll != NULL; ll = ll->next)
388
init_interface_proxy (client, G_DBUS_PROXY (ll->data));
390
g_list_foreach (interfaces, (GFunc) g_object_unref, NULL);
391
g_list_free (interfaces);
393
g_list_foreach (objects, (GFunc) g_object_unref, NULL);
394
g_list_free (objects);
396
g_signal_connect (client->object_manager,
398
G_CALLBACK (on_object_added),
400
g_signal_connect (client->object_manager,
402
G_CALLBACK (on_object_removed),
404
g_signal_connect (client->object_manager,
406
G_CALLBACK (on_interface_added),
408
g_signal_connect (client->object_manager,
410
G_CALLBACK (on_interface_removed),
412
g_signal_connect (client->object_manager,
413
"interface-proxy-properties-changed",
414
G_CALLBACK (on_interface_proxy_properties_changed),
420
client->is_initialized = TRUE;
423
g_assert (client->initialization_error != NULL);
424
g_propagate_error (error, g_error_copy (client->initialization_error));
426
G_UNLOCK (init_lock);
431
initable_iface_init (GInitableIface *initable_iface)
433
initable_iface->init = initable_init;
437
async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
439
/* Use default implementation (e.g. run GInitable code in a thread) */
443
* udisks_client_get_object_manager:
444
* @client: A #UDisksClient.
446
* Gets the #GDBusObjectManager used by @client.
448
* Returns: (transfer none): A #GDBusObjectManager. Do not free, the
449
* instance is owned by @client.
452
udisks_client_get_object_manager (UDisksClient *client)
454
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
455
return client->object_manager;
459
* udisks_client_get_manager:
460
* @client: A #UDisksClient.
462
* Gets the #UDisksManager interface on the well-known
463
* <literal>/org/freedesktop/UDisks2/Manager</literal> object.
465
* Returns: (transfer none): A #UDisksManager or %NULL if the udisksd
466
* daemon is not currently running. Do not free, the instance is owned
470
udisks_client_get_manager (UDisksClient *client)
472
UDisksManager *ret = NULL;
475
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
477
obj = g_dbus_object_manager_get_object (client->object_manager, "/org/freedesktop/UDisks2/Manager");
481
ret = udisks_object_peek_manager (UDISKS_OBJECT (obj));
482
g_object_unref (obj);
489
* udisks_client_settle:
490
* @client: A #UDisksClient.
492
* Blocks until all pending D-Bus messages have been delivered. Also
493
* emits the (rate-limited) #UDisksClient::changed signal if changes
494
* are currently pending.
496
* This is useful in two situations: 1. when using synchronous method
497
* calls since e.g. D-Bus signals received while waiting for the reply
498
* are queued up and dispatched after the synchronous call ends; and
499
* 2. when using asynchronous calls where the return value references
500
* a newly created object (such as the <link
501
* linkend="gdbus-method-org-freedesktop-UDisks2-Manager.LoopSetup">Manager.LoopSetup()</link> method).
504
udisks_client_settle (UDisksClient *client)
506
while (g_main_context_iteration (client->context, FALSE /* may_block */))
508
/* TODO: careful if on different thread... */
509
maybe_emit_changed_now (client);
512
/* ---------------------------------------------------------------------------------------------------- */
515
* udisks_client_get_object:
516
* @client: A #UDisksClient.
517
* @object_path: Object path.
519
* Convenience function for looking up an #UDisksObject for @object_path.
521
* Returns: (transfer full): A #UDisksObject corresponding to
522
* @object_path or %NULL if not found. The returned object must be
523
* freed with g_object_unref().
526
udisks_client_get_object (UDisksClient *client,
527
const gchar *object_path)
529
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
530
return (UDisksObject *) g_dbus_object_manager_get_object (client->object_manager, object_path);
534
* udisks_client_peek_object:
535
* @client: A #UDisksClient.
536
* @object_path: Object path.
538
* Like udisks_client_get_object() but doesn't increase the reference
539
* count on the returned #UDisksObject.
541
* <warning>The returned object is only valid until removed so it is only safe to use this function on the thread where @client was constructed. Use udisks_client_get_object() if on another thread.</warning>
543
* Returns: (transfer none): A #UDisksObject corresponding to
544
* @object_path or %NULL if not found.
547
udisks_client_peek_object (UDisksClient *client,
548
const gchar *object_path)
551
ret = udisks_client_get_object (client, object_path);
553
g_object_unref (ret);
557
/* ---------------------------------------------------------------------------------------------------- */
560
* udisks_client_get_block_for_label:
561
* @client: A #UDisksClient.
564
* Gets all the #UDisksBlock instances with the given label, if any.
566
* Returns: (transfer full) (element-type UDisksBlock): A list of #UDisksBlock instances. The
567
* returned list should be freed with g_list_free() after each
568
* element has been freed with g_object_unref().
571
udisks_client_get_block_for_label (UDisksClient *client,
575
GList *l, *object_proxies = NULL;
577
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
578
g_return_val_if_fail (label != NULL, NULL);
580
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
581
for (l = object_proxies; l != NULL; l = l->next)
583
UDisksObject *object = UDISKS_OBJECT (l->data);
586
block = udisks_object_get_block (object);
590
if (g_strcmp0 (udisks_block_get_id_label (block), label) == 0)
591
ret = g_list_prepend (ret, block);
593
g_object_unref (block);
596
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
597
g_list_free (object_proxies);
598
ret = g_list_reverse (ret);
602
/* ---------------------------------------------------------------------------------------------------- */
605
* udisks_client_get_block_for_uuid:
606
* @client: A #UDisksClient.
609
* Gets all the #UDisksBlock instances with the given uuid, if any.
611
* Returns: (transfer full) (element-type UDisksBlock): A list of #UDisksBlock instances. The
612
* returned list should be freed with g_list_free() after each
613
* element has been freed with g_object_unref().
616
udisks_client_get_block_for_uuid (UDisksClient *client,
620
GList *l, *object_proxies = NULL;
622
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
623
g_return_val_if_fail (uuid != NULL, NULL);
625
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
626
for (l = object_proxies; l != NULL; l = l->next)
628
UDisksObject *object = UDISKS_OBJECT (l->data);
631
block = udisks_object_get_block (object);
635
if (g_strcmp0 (udisks_block_get_id_uuid (block), uuid) == 0)
636
ret = g_list_prepend (ret, block);
638
g_object_unref (block);
641
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
642
g_list_free (object_proxies);
643
ret = g_list_reverse (ret);
647
/* ---------------------------------------------------------------------------------------------------- */
649
/* Note: The (type guint64) is a workaround for g-i mishandling dev_t, see
650
* https://bugzilla.gnome.org/show_bug.cgi?id=584517 */
653
* udisks_client_get_block_for_dev:
654
* @client: A #UDisksClient.
655
* @block_device_number: (type guint64): A #dev_t to get a #UDisksBlock for.
657
* Gets the #UDisksBlock corresponding to @block_device_number, if any.
659
* Returns: (transfer full): A #UDisksBlock or %NULL if not found.
662
udisks_client_get_block_for_dev (UDisksClient *client,
663
dev_t block_device_number)
665
UDisksBlock *ret = NULL;
666
GList *l, *object_proxies = NULL;
668
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
670
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
671
for (l = object_proxies; l != NULL; l = l->next)
673
UDisksObject *object = UDISKS_OBJECT (l->data);
676
block = udisks_object_get_block (object);
680
if (udisks_block_get_device_number (block) == block_device_number)
685
g_object_unref (block);
689
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
690
g_list_free (object_proxies);
694
/* ---------------------------------------------------------------------------------------------------- */
697
get_top_level_blocks_for_drive (UDisksClient *client,
698
const gchar *drive_object_path)
702
GList *object_proxies;
703
GDBusObjectManager *object_manager;
705
object_manager = udisks_client_get_object_manager (client);
706
object_proxies = g_dbus_object_manager_get_objects (object_manager);
709
for (l = object_proxies; l != NULL; l = l->next)
711
UDisksObject *object = UDISKS_OBJECT (l->data);
713
UDisksPartition *partition;
715
block = udisks_object_get_block (object);
716
partition = udisks_object_peek_partition (object);
720
if (g_strcmp0 (udisks_block_get_drive (block), drive_object_path) == 0 &&
723
ret = g_list_append (ret, g_object_ref (object));
725
g_object_unref (block);
727
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
728
g_list_free (object_proxies);
733
* udisks_client_get_block_for_drive:
734
* @client: A #UDisksClient.
735
* @drive: A #UDisksDrive.
736
* @get_physical: %TRUE to get a physical device, %FALSE to get the logical device.
738
* Gets a block device corresponding to @drive. The returned block
739
* device, if any, is for the whole disk drive, e.g. a partition block
740
* device is never returned.
742
* Set @get_physical to %TRUE if you need a block device that you can
743
* send low-level SCSI commands with (for multipath, this returns one
744
* of the physical paths). Set it to %FALSE if you need a block device
745
* that you can read/write data with (for multipath, this returns the
748
* Returns: (transfer full): A #UDisksBlock or %NULL if the requested
749
* kind of block device is not available - use g_object_unref() to
750
* free the returned object.
753
udisks_client_get_block_for_drive (UDisksClient *client,
755
gboolean get_physical)
757
UDisksBlock *ret = NULL;
759
GList *blocks = NULL;
762
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
763
g_return_val_if_fail (UDISKS_IS_DRIVE (drive), NULL);
765
object = g_dbus_interface_get_object (G_DBUS_INTERFACE (drive));
769
blocks = get_top_level_blocks_for_drive (client, g_dbus_object_get_object_path (object));
770
for (l = blocks; l != NULL; l = l->next)
772
UDisksBlock *block = udisks_object_peek_block (UDISKS_OBJECT (l->data));
775
/* TODO: actually look at @get_physical */
776
ret = g_object_ref (block);
782
g_list_foreach (blocks, (GFunc) g_object_unref, NULL);
783
g_list_free (blocks);
788
* udisks_client_get_drive_for_block:
789
* @client: A #UDisksClient.
790
* @block: A #UDisksBlock.
792
* Gets the #UDisksDrive that @block belongs to, if any.
794
* Returns: (transfer full): A #UDisksDrive or %NULL if there is no
795
* #UDisksDrive for @block - free the returned object with
799
udisks_client_get_drive_for_block (UDisksClient *client,
802
UDisksDrive *ret = NULL;
805
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
806
g_return_val_if_fail (UDISKS_IS_BLOCK (block), NULL);
808
object = g_dbus_object_manager_get_object (client->object_manager, udisks_block_get_drive (block));
810
ret = udisks_object_get_drive (UDISKS_OBJECT (object));
814
/* ---------------------------------------------------------------------------------------------------- */
817
* udisks_client_get_mdraid_for_block:
818
* @client: A #UDisksClient.
819
* @block: A #UDisksBlock.
821
* Gets the #UDisksMDRaid that @block is the block device for, if any.
823
* Returns: (transfer full): A #UDisksMDRaid or %NULL if there is no
824
* #UDisksMDRaid for @block or @block is not a MD-RAID block
825
* device. Free the returned object with g_object_unref().
830
udisks_client_get_mdraid_for_block (UDisksClient *client,
833
UDisksMDRaid *ret = NULL;
836
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
837
g_return_val_if_fail (UDISKS_IS_BLOCK (block), NULL);
839
object = g_dbus_object_manager_get_object (client->object_manager, udisks_block_get_mdraid (block));
841
ret = udisks_object_get_mdraid (UDISKS_OBJECT (object));
845
/* ---------------------------------------------------------------------------------------------------- */
848
* udisks_client_get_block_for_mdraid:
849
* @client: A #UDisksClient.
850
* @raid: A #UDisksMDRaid.
852
* Gets the RAID device (e.g. <filename>/dev/md0</filename>) for @raid.
854
* In the case of a <ulink
855
* url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain
856
* syndrome</ulink>, it is undefined which RAID device is
857
* returned. For example this can happen if
858
* <filename>/dev/sda</filename> and <filename>/dev/sdb</filename> are
859
* components of a two-disk RAID-1 and <filename>/dev/md0</filename>
860
* and <filename>/dev/md1</filename> are two degraded arrays, each one
861
* using exactly one of the two devices. Use
862
* udisks_client_get_all_blocks_for_mdraid() to get all RAID devices.
864
* Returns: (transfer full): A #UDisksBlock or %NULL if no RAID device is running.
869
udisks_client_get_block_for_mdraid (UDisksClient *client,
872
UDisksBlock *ret = NULL;
873
GList *l, *object_proxies = NULL;
874
GDBusObject *raid_object;
875
const gchar *raid_objpath;
877
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
878
g_return_val_if_fail (UDISKS_IS_MDRAID (raid), NULL);
880
raid_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (raid));
881
if (raid_object == NULL)
884
raid_objpath = g_dbus_object_get_object_path (raid_object);
886
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
887
for (l = object_proxies; l != NULL; l = l->next)
889
UDisksObject *object = UDISKS_OBJECT (l->data);
892
block = udisks_object_get_block (object);
896
/* ignore partitions */
897
if (udisks_object_peek_partition (object) != NULL)
900
if (g_strcmp0 (udisks_block_get_mdraid (block), raid_objpath) == 0)
905
g_object_unref (block);
909
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
910
g_list_free (object_proxies);
915
* udisks_client_get_all_blocks_for_mdraid:
916
* @client: A #UDisksClient.
917
* @raid: A #UDisksMDRaid.
919
* Gets all RAID devices (e.g. <filename>/dev/md0</filename> and <filename>/dev/md1</filename>) for @raid.
921
* This is usually only useful in <ulink
922
* url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain
923
* situations</ulink> — see udisks_client_get_block_for_mdraid() for
924
* an example — and is normally used only to convey the problem in an
927
* Returns: (transfer full) (element-type UDisksBlock): A list of #UDisksBlock instances. The
928
* returned list should be freed with g_list_free() after each
929
* element has been freed with g_object_unref().
934
udisks_client_get_all_blocks_for_mdraid (UDisksClient *client,
938
GList *l, *object_proxies = NULL;
939
GDBusObject *raid_object;
940
const gchar *raid_objpath;
942
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
943
g_return_val_if_fail (UDISKS_IS_MDRAID (raid), NULL);
945
raid_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (raid));
946
if (raid_object == NULL)
949
raid_objpath = g_dbus_object_get_object_path (raid_object);
951
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
952
for (l = object_proxies; l != NULL; l = l->next)
954
UDisksObject *object = UDISKS_OBJECT (l->data);
957
block = udisks_object_get_block (object);
961
/* ignore partitions */
962
if (udisks_object_peek_partition (object) != NULL)
965
if (g_strcmp0 (udisks_block_get_mdraid (block), raid_objpath) == 0)
967
ret = g_list_prepend (ret, block);
971
g_object_unref (block);
976
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
977
g_list_free (object_proxies);
978
ret = g_list_reverse (ret);
983
* udisks_client_get_members_for_mdraid:
984
* @client: A #UDisksClient.
985
* @raid: A #UDisksMDRaid.
987
* Gets the physical block devices that are part of @raid.
989
* Returns: (transfer full) (element-type UDisksBlock): A list of #UDisksBlock instances. The
990
* returned list should be freed with g_list_free() after each
991
* element has been freed with g_object_unref().
996
udisks_client_get_members_for_mdraid (UDisksClient *client,
1000
GList *l, *object_proxies = NULL;
1001
GDBusObject *raid_object;
1002
const gchar *raid_objpath;
1004
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1005
g_return_val_if_fail (UDISKS_IS_MDRAID (raid), NULL);
1007
raid_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (raid));
1008
if (raid_object == NULL)
1011
raid_objpath = g_dbus_object_get_object_path (raid_object);
1013
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
1014
for (l = object_proxies; l != NULL; l = l->next)
1016
UDisksObject *object = UDISKS_OBJECT (l->data);
1019
block = udisks_object_get_block (object);
1023
if (g_strcmp0 (udisks_block_get_mdraid_member (block), raid_objpath) == 0)
1025
ret = g_list_prepend (ret, block); /* adopts reference to block */
1029
g_object_unref (block);
1034
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
1035
g_list_free (object_proxies);
1039
/* ---------------------------------------------------------------------------------------------------- */
1042
add_item (gchar **items_str,
1045
gchar *orig = *items_str;
1046
if (*items_str == NULL)
1048
*items_str = g_strdup (item);
1053
*items_str = g_strdup_printf ("%s, %s", orig, item);
1059
* udisks_client_get_partition_info:
1060
* @client: A #UDisksClient.
1061
* @partition: # #UDisksPartition.
1063
* Gets information about @partition that is suitable to present in an
1064
* user interface in a single line of text.
1066
* The returned string is localized and includes things like the
1067
* partition type, flags (if any) and name (if any).
1069
* Returns: (transfer full): A string that should be freed with g_free().
1072
udisks_client_get_partition_info (UDisksClient *client,
1073
UDisksPartition *partition)
1076
const gchar *type_str = NULL;
1077
gchar *flags_str = NULL;
1078
UDisksPartitionTable *table = NULL;
1081
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1082
g_return_val_if_fail (UDISKS_IS_PARTITION (partition), NULL);
1084
table = udisks_client_get_partition_table (client, partition);
1088
flags = udisks_partition_get_flags (partition);
1089
if (g_strcmp0 (udisks_partition_table_get_type_ (table), "dos") == 0)
1093
/* Translators: Corresponds to the DOS/Master-Boot-Record "bootable" flag for a partition */
1094
add_item (&flags_str, C_("dos-part-flag", "Bootable"));
1097
else if (g_strcmp0 (udisks_partition_table_get_type_ (table), "gpt") == 0)
1099
if (flags & (1ULL<<0))
1101
/* Translators: Corresponds to the GPT "system" flag for a partition,
1102
* see http://en.wikipedia.org/wiki/GUID_Partition_Table
1104
add_item (&flags_str, C_("gpt-part-flag", "System"));
1106
if (flags & (1ULL<<2))
1108
/* Translators: Corresponds to the GPT "legacy bios bootable" flag for a partition,
1109
* see http://en.wikipedia.org/wiki/GUID_Partition_Table
1111
add_item (&flags_str, C_("gpt-part-flag", "Legacy BIOS Bootable"));
1113
if (flags & (1ULL<<60))
1115
/* Translators: Corresponds to the GPT "read-only" flag for a partition,
1116
* see http://en.wikipedia.org/wiki/GUID_Partition_Table
1118
add_item (&flags_str, C_("gpt-part-flag", "Read-only"));
1120
if (flags & (1ULL<<62))
1122
/* Translators: Corresponds to the GPT "hidden" flag for a partition,
1123
* see http://en.wikipedia.org/wiki/GUID_Partition_Table
1125
add_item (&flags_str, C_("gpt-part-flag", "Hidden"));
1127
if (flags & (1ULL<<63))
1129
/* Translators: Corresponds to the GPT "no automount" flag for a partition,
1130
* see http://en.wikipedia.org/wiki/GUID_Partition_Table
1132
add_item (&flags_str, C_("gpt-part-flag", "No Automount"));
1136
type_str = udisks_client_get_partition_type_for_display (client,
1137
udisks_partition_table_get_type_ (table),
1138
udisks_partition_get_type_ (partition));
1139
if (type_str == NULL)
1140
type_str = udisks_partition_get_type_ (partition);
1142
if (flags_str != NULL)
1144
/* Translators: Partition info. First %s is the type, second %s is a list of flags */
1145
ret = g_strdup_printf (C_("partition-info", "%s (%s)"), type_str, flags_str);
1149
ret = g_strdup (type_str);
1152
if (ret == NULL || strlen (ret) == 0)
1155
/* Translators: The Partition info when unknown */
1156
ret = g_strdup (C_("partition-info", "Unknown"));
1160
g_object_unref (table);
1165
/* ---------------------------------------------------------------------------------------------------- */
1168
* udisks_client_get_cleartext_block:
1169
* @client: A #UDisksClient.
1170
* @block: A #UDisksBlock.
1172
* If @block is an unlocked encrypted device, gets the cleartext device.
1174
* Returns: (transfer full): A #UDisksBlock or %NULL. Free with
1175
* g_object_unref() when done with it.
1178
udisks_client_get_cleartext_block (UDisksClient *client,
1181
UDisksBlock *ret = NULL;
1182
GDBusObject *object;
1183
const gchar *object_path;
1184
GList *objects = NULL;
1187
object = g_dbus_interface_get_object (G_DBUS_INTERFACE (block));
1191
object_path = g_dbus_object_get_object_path (object);
1192
objects = g_dbus_object_manager_get_objects (client->object_manager);
1193
for (l = objects; l != NULL; l = l->next)
1195
UDisksObject *iter_object = UDISKS_OBJECT (l->data);
1196
UDisksBlock *iter_block;
1198
iter_block = udisks_object_peek_block (iter_object);
1199
if (iter_block == NULL)
1202
if (g_strcmp0 (udisks_block_get_crypto_backing_device (iter_block), object_path) == 0)
1204
ret = g_object_ref (iter_block);
1210
g_list_foreach (objects, (GFunc) g_object_unref, NULL);
1211
g_list_free (objects);
1215
/* ---------------------------------------------------------------------------------------------------- */
1218
* udisks_client_get_drive_siblings:
1219
* @client: A #UDisksClient
1220
* @drive: A #UDisksDrive.
1222
* Gets all siblings for @drive.
1224
* Returns: (transfer full) (element-type UDisksDrive): A list of #UDisksDrive instances. The
1225
* returned list should be freed with g_list_free() after each element has been
1226
* freed with g_object_unref().
1231
udisks_client_get_drive_siblings (UDisksClient *client,
1235
const gchar *sibling_id = NULL;
1236
GList *l, *object_proxies = NULL;
1238
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1239
g_return_val_if_fail (UDISKS_IS_DRIVE (drive), NULL);
1241
sibling_id = udisks_drive_get_sibling_id (drive);
1242
if (sibling_id == NULL || strlen (sibling_id) == 0)
1245
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
1246
for (l = object_proxies; l != NULL; l = l->next)
1248
UDisksObject *object = UDISKS_OBJECT (l->data);
1249
UDisksDrive *iter_drive;
1251
iter_drive = udisks_object_get_drive (object);
1252
if (iter_drive == NULL)
1255
if (iter_drive != drive &&
1256
g_strcmp0 (udisks_drive_get_sibling_id (iter_drive), sibling_id) == 0)
1258
ret = g_list_prepend (ret, g_object_ref (iter_drive));
1261
g_object_unref (iter_drive);
1263
ret = g_list_reverse (ret);
1265
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
1266
g_list_free (object_proxies);
1270
/* ---------------------------------------------------------------------------------------------------- */
1273
* udisks_client_get_partitions:
1274
* @client: A #UDisksClient.
1275
* @table: A #UDisksPartitionTable.
1277
* Gets all partitions of @table.
1279
* Returns: (transfer full) (element-type UDisksPartition): A list of #UDisksPartition instances. The
1280
* returned list should be freed with g_list_free() after each
1281
* element has been freed with g_object_unref().
1284
udisks_client_get_partitions (UDisksClient *client,
1285
UDisksPartitionTable *table)
1288
GDBusObject *table_object;
1289
const gchar *table_object_path;
1290
GList *l, *object_proxies = NULL;
1292
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1293
g_return_val_if_fail (UDISKS_IS_PARTITION_TABLE (table), NULL);
1295
table_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (table));
1296
if (table_object == NULL)
1298
table_object_path = g_dbus_object_get_object_path (table_object);
1300
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
1301
for (l = object_proxies; l != NULL; l = l->next)
1303
UDisksObject *object = UDISKS_OBJECT (l->data);
1304
UDisksPartition *partition;
1306
partition = udisks_object_get_partition (object);
1307
if (partition == NULL)
1310
if (g_strcmp0 (udisks_partition_get_table (partition), table_object_path) == 0)
1311
ret = g_list_prepend (ret, g_object_ref (partition));
1313
g_object_unref (partition);
1315
ret = g_list_reverse (ret);
1317
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
1318
g_list_free (object_proxies);
1323
* udisks_client_get_partition_table:
1324
* @client: A #UDisksClient.
1325
* @partition: A #UDisksPartition.
1327
* Gets the #UDisksPartitionTable corresponding to @partition.
1329
* Returns: (transfer full): A #UDisksPartitionTable. Free with g_object_unref().
1331
UDisksPartitionTable *
1332
udisks_client_get_partition_table (UDisksClient *client,
1333
UDisksPartition *partition)
1335
UDisksPartitionTable *ret = NULL;
1336
UDisksObject *object;
1338
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1339
g_return_val_if_fail (UDISKS_IS_PARTITION (partition), NULL);
1341
object = udisks_client_get_object (client, udisks_partition_get_table (partition));
1345
ret = udisks_object_get_partition_table (object);
1346
g_object_unref (object);
1353
* udisks_client_get_loop_for_block:
1354
* @client: A #UDisksClient.
1355
* @block: A #UDisksBlock.
1357
* Gets the corresponding loop interface for @block.
1359
* This only works if @block itself is a loop device or a partition of
1362
* Returns: (transfer full): A #UDisksLoop or %NULL. Free with g_object_unref().
1365
udisks_client_get_loop_for_block (UDisksClient *client,
1368
UDisksPartition *partition;
1369
UDisksObject *object = NULL;
1370
UDisksLoop *ret = NULL;
1372
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1373
g_return_val_if_fail (UDISKS_IS_BLOCK (block), NULL);
1375
object = (UDisksObject *) g_dbus_interface_dup_object (G_DBUS_INTERFACE (block));
1379
ret = udisks_object_get_loop (object);
1383
/* Could be we're a partition of a loop device */
1384
partition = udisks_object_get_partition (object);
1385
if (partition != NULL)
1387
UDisksPartitionTable *partition_table;
1388
partition_table = udisks_client_get_partition_table (client, partition);
1389
if (partition_table != NULL)
1391
UDisksObject *partition_table_object;
1392
partition_table_object = (UDisksObject *) g_dbus_interface_dup_object (G_DBUS_INTERFACE (partition_table));
1393
if (partition_table_object != NULL)
1395
ret = udisks_object_get_loop (UDISKS_OBJECT (partition_table_object));
1396
g_object_unref (partition_table_object);
1398
g_object_unref (partition_table);
1400
g_object_unref (partition);
1404
g_clear_object (&object);
1408
/* ---------------------------------------------------------------------------------------------------- */
1411
* udisks_client_get_jobs_for_object:
1412
* @client: A #UDisksClient.
1413
* @object: A #UDisksObject.
1415
* Gets all the #UDisksJob instances that reference @object, if any.
1417
* Returns: (transfer full) (element-type UDisksJob): A list of #UDisksJob instances. The
1418
* returned list should be freed with g_list_free() after each
1419
* element has been freed with g_object_unref().
1422
udisks_client_get_jobs_for_object (UDisksClient *client,
1423
UDisksObject *object)
1426
const gchar *object_path;
1427
GList *l, *object_proxies = NULL;
1429
/* TODO: this is probably slow. Can optimize by maintaining a hash-table from object path to UDisksJob* */
1431
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
1432
g_return_val_if_fail (UDISKS_IS_OBJECT (object), NULL);
1434
object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));
1436
object_proxies = g_dbus_object_manager_get_objects (client->object_manager);
1437
for (l = object_proxies; l != NULL; l = l->next)
1439
UDisksObject *job_object = UDISKS_OBJECT (l->data);
1442
job = udisks_object_get_job (job_object);
1445
const gchar *const *object_paths;
1447
object_paths = udisks_job_get_objects (job);
1448
for (n = 0; object_paths != NULL && object_paths[n] != NULL; n++)
1450
if (g_strcmp0 (object_paths[n], object_path) == 0)
1451
ret = g_list_prepend (ret, g_object_ref (job));
1453
g_object_unref (job);
1456
ret = g_list_reverse (ret);
1458
g_list_foreach (object_proxies, (GFunc) g_object_unref, NULL);
1459
g_list_free (object_proxies);
1463
/* ---------------------------------------------------------------------------------------------------- */
1466
maybe_emit_changed_now (UDisksClient *client)
1468
if (client->changed_timeout_source == NULL)
1471
g_source_destroy (client->changed_timeout_source);
1472
client->changed_timeout_source = NULL;
1474
g_signal_emit (client, signals[CHANGED_SIGNAL], 0);
1482
on_changed_timeout (gpointer user_data)
1484
UDisksClient *client = UDISKS_CLIENT (user_data);
1485
client->changed_timeout_source = NULL;
1486
g_signal_emit (client, signals[CHANGED_SIGNAL], 0);
1487
return FALSE; /* remove source */
1491
* udisks_client_queue_changed:
1492
* @client: A #UDisksClient.
1494
* Queues up a #UDisksClient::changed signal and rate-limit it. See
1495
* the documentation for the #UDisksClient::changed property for more
1501
udisks_client_queue_changed (UDisksClient *client)
1503
g_return_if_fail (UDISKS_IS_CLIENT (client));
1505
if (client->changed_timeout_source != NULL)
1508
client->changed_timeout_source = g_timeout_source_new (100);
1509
g_source_set_callback (client->changed_timeout_source,
1510
(GSourceFunc) on_changed_timeout,
1512
NULL); /* destroy notify */
1513
g_source_attach (client->changed_timeout_source, client->context);
1514
g_source_unref (client->changed_timeout_source);
1521
on_object_added (GDBusObjectManager *manager,
1522
GDBusObject *object,
1525
UDisksClient *client = UDISKS_CLIENT (user_data);
1526
GList *interfaces, *l;
1528
interfaces = g_dbus_object_get_interfaces (object);
1529
for (l = interfaces; l != NULL; l = l->next)
1531
init_interface_proxy (client, G_DBUS_PROXY (l->data));
1533
g_list_foreach (interfaces, (GFunc) g_object_unref, NULL);
1534
g_list_free (interfaces);
1536
udisks_client_queue_changed (client);
1540
on_object_removed (GDBusObjectManager *manager,
1541
GDBusObject *object,
1544
UDisksClient *client = UDISKS_CLIENT (user_data);
1545
udisks_client_queue_changed (client);
1549
init_interface_proxy (UDisksClient *client,
1552
/* disable method timeouts */
1553
g_dbus_proxy_set_default_timeout (proxy, G_MAXINT);
1557
on_interface_added (GDBusObjectManager *manager,
1558
GDBusObject *object,
1559
GDBusInterface *interface,
1562
UDisksClient *client = UDISKS_CLIENT (user_data);
1564
init_interface_proxy (client, G_DBUS_PROXY (interface));
1566
udisks_client_queue_changed (client);
1570
on_interface_removed (GDBusObjectManager *manager,
1571
GDBusObject *object,
1572
GDBusInterface *interface,
1575
UDisksClient *client = UDISKS_CLIENT (user_data);
1576
udisks_client_queue_changed (client);
1580
on_interface_proxy_properties_changed (GDBusObjectManagerClient *manager,
1581
GDBusObjectProxy *object_proxy,
1582
GDBusProxy *interface_proxy,
1583
GVariant *changed_properties,
1584
const gchar *const *invalidated_properties,
1587
UDisksClient *client = UDISKS_CLIENT (user_data);
1588
udisks_client_queue_changed (client);
1591
/* ---------------------------------------------------------------------------------------------------- */
1593
#define KILOBYTE_FACTOR 1000.0
1594
#define MEGABYTE_FACTOR (1000.0 * 1000.0)
1595
#define GIGABYTE_FACTOR (1000.0 * 1000.0 * 1000.0)
1596
#define TERABYTE_FACTOR (1000.0 * 1000.0 * 1000.0 * 1000.0)
1598
#define KIBIBYTE_FACTOR 1024.0
1599
#define MEBIBYTE_FACTOR (1024.0 * 1024.0)
1600
#define GIBIBYTE_FACTOR (1024.0 * 1024.0 * 1024.0)
1601
#define TEBIBYTE_FACTOR (1024.0 * 1024.0 * 1024.0 * 10242.0)
1604
get_pow2_size (guint64 size)
1607
gdouble displayed_size;
1611
if (size < MEBIBYTE_FACTOR)
1613
displayed_size = (double) size / KIBIBYTE_FACTOR;
1616
else if (size < GIBIBYTE_FACTOR)
1618
displayed_size = (double) size / MEBIBYTE_FACTOR;
1621
else if (size < TEBIBYTE_FACTOR)
1623
displayed_size = (double) size / GIBIBYTE_FACTOR;
1628
displayed_size = (double) size / TEBIBYTE_FACTOR;
1632
if (displayed_size < 10.0)
1637
str = g_strdup_printf ("%.*f %s", digits, displayed_size, unit);
1643
get_pow10_size (guint64 size)
1646
gdouble displayed_size;
1650
if (size < MEGABYTE_FACTOR)
1652
displayed_size = (double) size / KILOBYTE_FACTOR;
1655
else if (size < GIGABYTE_FACTOR)
1657
displayed_size = (double) size / MEGABYTE_FACTOR;
1660
else if (size < TERABYTE_FACTOR)
1662
displayed_size = (double) size / GIGABYTE_FACTOR;
1667
displayed_size = (double) size / TERABYTE_FACTOR;
1671
if (displayed_size < 10.0)
1676
str = g_strdup_printf ("%.*f %s", digits, displayed_size, unit);
1682
* udisks_client_get_size_for_display:
1683
* @client: A #UDisksClient.
1684
* @size: Size in bytes
1685
* @use_pow2: Whether power-of-two units should be used instead of power-of-ten units.
1686
* @long_string: Whether to produce a long string.
1688
* Utility function to get a human-readable string that represents @size.
1690
* Returns: A string that should be freed with g_free().
1693
udisks_client_get_size_for_display (UDisksClient *client,
1696
gboolean long_string)
1703
size_str = g_strdup_printf ("%'" G_GINT64_FORMAT, size);
1707
pow2_str = get_pow2_size (size);
1708
/* Translators: The first %s is the size in power-of-2 units, e.g. '64 KiB'
1709
* the second %s is the size as a number e.g. '65,536' (always > 1)
1711
str = g_strdup_printf (C_("byte-size-pow2", "%s (%s bytes)"), pow2_str, size_str);
1717
pow10_str = get_pow10_size (size);
1718
/* Translators: The first %s is the size in power-of-10 units, e.g. '100 kB'
1719
* the second %s is the size as a number e.g. '100,000' (always > 1)
1721
str = g_strdup_printf (C_("byte-size-pow10", "%s (%s bytes)"), pow10_str, size_str);
1731
str = get_pow2_size (size);
1735
str = get_pow10_size (size);
1741
/* ---------------------------------------------------------------------------------------------------- */
1744
* udisks_client_get_media_compat_for_display:
1745
* @client: A #UDisksClient.
1746
* @media_compat: An array of media types.
1748
* Gets a human-readable string of the media described by
1749
* @media_compat. The returned information is localized.
1751
* Returns: A string that should be freed with g_free() or %NULL if
1755
udisks_client_get_media_compat_for_display (UDisksClient *client,
1756
const gchar* const *media_compat)
1759
gboolean optical_cd;
1760
gboolean optical_dvd;
1761
gboolean optical_bd;
1762
gboolean optical_hddvd;
1766
optical_dvd = FALSE;
1768
optical_hddvd = FALSE;
1770
result = g_string_new (NULL);
1772
for (n = 0; media_compat != NULL && media_compat[n] != NULL; n++)
1774
const gchar *media_name;
1777
media = media_compat[n];
1779
if (g_strcmp0 (media, "flash_cf") == 0)
1781
/* Translators: This word is used to describe the media inserted into a device */
1782
media_name = C_("media", "CompactFlash");
1784
else if (g_strcmp0 (media, "flash_ms") == 0)
1786
/* Translators: This word is used to describe the media inserted into a device */
1787
media_name = C_("media", "MemoryStick");
1789
else if (g_strcmp0 (media, "flash_sm") == 0)
1791
/* Translators: This word is used to describe the media inserted into a device */
1792
media_name = C_("media", "SmartMedia");
1794
else if (g_strcmp0 (media, "flash_sd") == 0)
1796
/* Translators: This word is used to describe the media inserted into a device */
1797
media_name = C_("media", "SecureDigital");
1799
else if (g_strcmp0 (media, "flash_sdhc") == 0)
1801
/* Translators: This word is used to describe the media inserted into a device */
1802
media_name = C_("media", "SD High Capacity");
1804
else if (g_strcmp0 (media, "floppy") == 0)
1806
/* Translators: This word is used to describe the media inserted into a device */
1807
media_name = C_("media", "Floppy");
1809
else if (g_strcmp0 (media, "floppy_zip") == 0)
1811
/* Translators: This word is used to describe the media inserted into a device */
1812
media_name = C_("media", "Zip");
1814
else if (g_strcmp0 (media, "floppy_jaz") == 0)
1816
/* Translators: This word is used to describe the media inserted into a device */
1817
media_name = C_("media", "Jaz");
1819
else if (g_str_has_prefix (media, "flash"))
1821
/* Translators: This word is used to describe the media inserted into a device */
1822
media_name = C_("media", "Flash");
1824
else if (g_str_has_prefix (media, "optical_cd"))
1828
else if (g_str_has_prefix (media, "optical_dvd"))
1832
else if (g_str_has_prefix (media, "optical_bd"))
1836
else if (g_str_has_prefix (media, "optical_hddvd"))
1838
optical_hddvd = TRUE;
1841
if (media_name != NULL)
1843
if (result->len > 0)
1844
g_string_append_c (result, '/');
1845
g_string_append (result, media_name);
1851
if (result->len > 0)
1852
g_string_append_c (result, '/');
1853
/* Translators: This word is used to describe the optical disc type, it may appear
1854
* in a slash-separated list e.g. 'CD/DVD/Blu-Ray'
1856
g_string_append (result, C_("disc-type", "CD"));
1860
if (result->len > 0)
1861
g_string_append_c (result, '/');
1862
/* Translators: This word is used to describe the optical disc type, it may appear
1863
* in a slash-separated list e.g. 'CD/DVD/Blu-Ray'
1865
g_string_append (result, C_("disc-type", "DVD"));
1869
if (result->len > 0)
1870
g_string_append_c (result, '/');
1871
/* Translators: This word is used to describe the optical disc type, it may appear
1872
* in a slash-separated list e.g. 'CD/DVD/Blu-Ray'
1874
g_string_append (result, C_("disc-type", "Blu-Ray"));
1878
if (result->len > 0)
1879
g_string_append_c (result, '/');
1880
/* Translators: This word is used to describe the optical disc type, it may appear
1881
* in a slash-separated list e.g. 'CD/DVD/Blu-Ray'
1883
g_string_append (result, C_("disc-type", "HDDVD"));
1886
if (result->len > 0)
1887
return g_string_free (result, FALSE);
1889
g_string_free (result, TRUE);
1893
/* ---------------------------------------------------------------------------------------------------- */
1899
const gchar *version;
1900
const gchar *long_name;
1901
const gchar *short_name;
1904
{"filesystem", "vfat", "FAT12", NC_("fs-type", "FAT (12-bit version)"), NC_("fs-type", "FAT")},
1905
{"filesystem", "vfat", "FAT16", NC_("fs-type", "FAT (16-bit version)"), NC_("fs-type", "FAT")},
1906
{"filesystem", "vfat", "FAT32", NC_("fs-type", "FAT (32-bit version)"), NC_("fs-type", "FAT")},
1907
{"filesystem", "ntfs", "*", NC_("fs-type", "FAT (version %s)"), NC_("fs-type", "FAT")},
1908
{"filesystem", "vfat", NULL, NC_("fs-type", "FAT"), NC_("fs-type", "FAT")},
1909
{"filesystem", "ntfs", "*", NC_("fs-type", "NTFS (version %s)"), NC_("fs-type", "NTFS")},
1910
{"filesystem", "ntfs", NULL, NC_("fs-type", "NTFS"), NC_("fs-type", "NTFS")},
1911
{"filesystem", "hfs", NULL, NC_("fs-type", "HFS"), NC_("fs-type", "HFS")},
1912
{"filesystem", "hfsplus", NULL, NC_("fs-type", "HFS+"), NC_("fs-type", "HFS+")},
1913
{"filesystem", "ext2", "*", NC_("fs-type", "Ext2 (version %s)"), NC_("fs-type", "Ext2")},
1914
{"filesystem", "ext2", NULL, NC_("fs-type", "Ext2"), NC_("fs-type", "Ext2")},
1915
{"filesystem", "ext3", "*", NC_("fs-type", "Ext3 (version %s)"), NC_("fs-type", "Ext3")},
1916
{"filesystem", "ext3", NULL, NC_("fs-type", "Ext3"), NC_("fs-type", "Ext3")},
1917
{"filesystem", "ext4", "*", NC_("fs-type", "Ext4 (version %s)"), NC_("fs-type", "Ext4")},
1918
{"filesystem", "ext4", NULL, NC_("fs-type", "Ext4"), NC_("fs-type", "Ext4")},
1919
{"filesystem", "jdb", "*", NC_("fs-type", "Journal for Ext (version %s)"), NC_("fs-type", "JDB")},
1920
{"filesystem", "jdb", "*", NC_("fs-type", "Journal for Ext"), NC_("fs-type", "JDB")},
1921
{"filesystem", "xfs", "*", NC_("fs-type", "XFS (version %s)"), NC_("fs-type", "XFS")},
1922
{"filesystem", "xfs", NULL, NC_("fs-type", "XFS"), NC_("fs-type", "XFS")},
1923
/* TODO: No ID_FS_VERSION yet for btrfs... */
1924
{"filesystem", "btrfs", NULL, NC_("fs-type", "Btrfs"), NC_("fs-type", "Btrfs")},
1925
{"filesystem", "iso9660", "*", NC_("fs-type", "ISO 9660 (version %s)"), NC_("fs-type", "ISO9660")},
1926
{"filesystem", "iso9660", NULL, NC_("fs-type", "ISO 9660"), NC_("fs-type", "ISO9660")},
1927
{"filesystem", "udf", "*", NC_("fs-type", "UDF (version %s)"), NC_("fs-type", "UDF")},
1928
{"filesystem", "udf", NULL, NC_("fs-type", "UDF"), NC_("fs-type", "UDF")},
1929
{"filesystem", "exfat", NULL, NC_("fs-type", "exFAT"), NC_("fs-type", "exFAT")},
1930
{"filesystem", "exfat", "*", NC_("fs-type", "exFAT (version %s)"), NC_("fs-type", "exFAT")},
1931
{"other", "swap", "*", NC_("fs-type", "Swap (version %s)"), NC_("fs-type", "Swap")},
1932
{"other", "swap", NULL, NC_("fs-type", "Swap"), NC_("fs-type", "Swap")},
1933
{"raid", "LVM2_member", "*", NC_("fs-type", "LVM2 Physical Volume (%s)"), NC_("fs-type", "LVM2 PV")},
1934
{"raid", "LVM2_member", NULL, NC_("fs-type", "LVM2 Physical Volume"), NC_("fs-type", "LVM2 PV")},
1935
{"raid", "linux_raid_member", "*", NC_("fs-type", "Linux RAID Member (version %s)"), NC_("fs-type", "Linux RAID Member")},
1936
{"raid", "linux_raid_member", NULL, NC_("fs-type", "Linux RAID Member"), NC_("fs-type", "Linux RAID Member")},
1937
{"raid", "zfs_member", "*", NC_("fs-type", "ZFS Device (ZPool version %s)"), NC_("fs-type", "ZFS (v%s)")},
1938
{"raid", "zfs_member", NULL, NC_("fs-type", "ZFS Device"), NC_("fs-type", "ZFS")},
1939
{"raid", "isw_raid_member", "*", NC_("fs-type", "Intel Matrix RAID Member (version %s)"), NC_("fs-type", "IMSM RAID Member (%s)")},
1940
{"raid", "isw_raid_member", NULL, NC_("fs-type", "Intel Matrix RAID Member"), NC_("fs-type", "IMSM RAID")},
1941
{"crypto", "crypto_LUKS", "*", NC_("fs-type", "LUKS Encryption (version %s)"), NC_("fs-type", "LUKS")},
1942
{"crypto", "crypto_LUKS", NULL, NC_("fs-type", "LUKS Encryption"), NC_("fs-type", "LUKS")},
1943
{"filesystem", "VMFS", "*", NC_("fs-type", "VMFS (version %s)"), NC_("fs-type", "VMFS (v%s)")},
1944
{"filesystem", "VMFS", NULL, NC_("fs-type", "VMFS"), NC_("fs-type", "VMFS")},
1945
{"raid", "VMFS_volume_member", "*", NC_("fs-type", "VMFS Volume Member (version %s)"), NC_("fs-type", "VMFS Member (v%s)")},
1946
{"raid", "VMFS_volume_member", NULL, NC_("fs-type", "VMFS Volume Member"), NC_("fs-type", "VMFS Member")},
1947
{NULL, NULL, NULL, NULL}
1951
* udisks_client_get_id_for_display:
1952
* @client: A #UDisksClient.
1953
* @usage: Usage id e.g. "filesystem" or "crypto".
1954
* @type: Type e.g. "ext4" or "crypto_LUKS"
1955
* @version: Version.
1956
* @long_string: Whether to produce a long string.
1958
* Gets a human readable localized string for @usage, @type and @version.
1960
* Returns: A string that should be freed with g_free().
1963
udisks_client_get_id_for_display (UDisksClient *client,
1966
const gchar *version,
1967
gboolean long_string)
1974
for (n = 0; id_type[n].usage != NULL; n++)
1976
if (g_strcmp0 (id_type[n].usage, usage) == 0 &&
1977
g_strcmp0 (id_type[n].type, type) == 0)
1979
if ((id_type[n].version == NULL && strlen (version) == 0))
1982
ret = g_strdup (g_dpgettext2 (GETTEXT_PACKAGE, "fs-type", id_type[n].long_name));
1984
ret = g_strdup (g_dpgettext2 (GETTEXT_PACKAGE, "fs-type", id_type[n].short_name));
1987
else if ((g_strcmp0 (id_type[n].version, version) == 0 && strlen (version) > 0) ||
1988
(g_strcmp0 (id_type[n].version, "*") == 0 && strlen (version) > 0))
1990
/* we know better than the compiler here */
1991
#ifdef __GNUC_PREREQ
1992
# if __GNUC_PREREQ(4,6)
1993
# pragma GCC diagnostic push
1994
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
1998
ret = g_strdup_printf (g_dpgettext2 (GETTEXT_PACKAGE, "fs-type", id_type[n].long_name), version);
2000
ret = g_strdup_printf (g_dpgettext2 (GETTEXT_PACKAGE, "fs-type", id_type[n].short_name), version);
2002
#ifdef __GNUC_PREREQ
2003
# if __GNUC_PREREQ(4,6)
2004
# pragma GCC diagnostic pop
2013
if (strlen (version) > 0)
2015
/* Translators: Shown for unknown filesystem types.
2016
* First %s is the raw filesystem type obtained from udev, second %s is version.
2018
ret = g_strdup_printf (C_("fs-type", "Unknown (%s %s)"), type, version);
2022
if (strlen (type) > 0)
2024
/* Translators: Shown for unknown filesystem types.
2025
* First %s is the raw filesystem type obtained from udev.
2027
ret = g_strdup_printf (C_("fs-type", "Unknown (%s)"), type);
2031
/* Translators: Shown for unknown filesystem types.
2033
ret = g_strdup (C_("fs-type", "Unknown"));
2039
if (strlen (type) > 0)
2041
ret = g_strdup (type);
2045
/* Translators: Shown for unknown filesystem types.
2047
ret = g_strdup (C_("fs-type", "Unknown"));
2055
/* ---------------------------------------------------------------------------------------------------- */
2061
} known_partition_table_types[] =
2063
/* Translators: name of partition table format */
2064
{"dos", N_("Master Boot Record")},
2065
/* Translators: name of partition table format */
2066
{"gpt", N_("GUID Partition Table")},
2067
/* Translators: name of partition table format */
2068
{"apm", N_("Apple Partition Map")},
2073
* udisks_client_get_partition_table_type_for_display:
2074
* @client: A #UDisksClient.
2075
* @partition_table_type: A partition table type e.g. 'dos' or 'gpt'.
2077
* Gets a human readable localized string for @partition_table_type.
2079
* Returns: A description of @partition_table_type or %NULL.
2082
udisks_client_get_partition_table_type_for_display (UDisksClient *client,
2083
const gchar *partition_table_type)
2085
const gchar *ret = NULL;
2088
for (n = 0; known_partition_table_types[n].type != NULL; n++)
2090
if (g_strcmp0 (known_partition_table_types[n].type, partition_table_type) == 0)
2092
ret = _(known_partition_table_types[n].name);
2101
/* ---------------------------------------------------------------------------------------------------- */
2106
const gchar *subtype;
2108
} known_partition_table_subtypes[] =
2110
/* Translators: name of partition table format */
2111
{"dos", "generic", NC_("partition-subtype", "Generic")},
2112
{"dos", "linux", NC_("partition-subtype", "Linux")},
2113
{"dos", "microsoft", NC_("partition-subtype", "Windows")},
2114
{"dos", "other", NC_("partition-subtype", "Other")},
2116
{"gpt", "generic", NC_("partition-subtype", "Generic")},
2117
{"gpt", "linux", NC_("partition-subtype", "Linux")},
2118
{"gpt", "microsoft", NC_("partition-subtype", "Windows")},
2119
{"gpt", "apple", NC_("partition-subtype", "Mac OS X")},
2120
{"gpt", "other", NC_("partition-subtype", "Other")},
2122
{"apm", "apple", NC_("partition-subtype", "Mac OS X")},
2123
{"apm", "microsoft", NC_("partition-subtype", "Windows")},
2128
* udisks_client_get_partition_table_subtype_for_display:
2129
* @client: A #UDisksClient.
2130
* @partition_table_type: A partition table type e.g. 'dos' or 'gpt'.
2131
* @partition_table_subtype: A partition table type e.g. 'dos' or 'gpt'.
2133
* Gets a human readable localized string for @partition_table_type and @partition_table_subtype.
2135
* Returns: A description of @partition_table_type and @partition_table_subtype or %NULL.
2138
udisks_client_get_partition_table_subtype_for_display (UDisksClient *client,
2139
const gchar *partition_table_type,
2140
const gchar *partition_table_subtype)
2142
const gchar *ret = NULL;
2145
for (n = 0; known_partition_table_subtypes[n].type != NULL; n++)
2147
if (g_strcmp0 (known_partition_table_subtypes[n].type, partition_table_type) == 0 &&
2148
g_strcmp0 (known_partition_table_subtypes[n].subtype, partition_table_subtype) == 0)
2150
ret = g_dpgettext2 (GETTEXT_PACKAGE, "partition-subtype", known_partition_table_subtypes[n].name);
2160
* udisks_client_get_partition_table_subtypes:
2161
* @client: A #UDisksClient.
2162
* @partition_table_type: A partition table type e.g. 'dos' or 'gpt'.
2164
* Gets all known subtypes for @partition_table_type.
2166
* Returns: (transfer container): A %NULL-terminated array of
2167
* strings. Only the container should be freed with g_free().
2170
udisks_client_get_partition_table_subtypes (UDisksClient *client,
2171
const gchar *partition_table_type)
2176
p = g_ptr_array_new();
2177
for (n = 0; known_partition_table_subtypes[n].type != NULL; n++)
2179
if (g_strcmp0 (known_partition_table_subtypes[n].type, partition_table_type) == 0)
2181
g_ptr_array_add (p, (gpointer) known_partition_table_subtypes[n].subtype);
2184
g_ptr_array_add (p, NULL);
2186
return (const gchar **) g_ptr_array_free (p, FALSE);
2189
/* ---------------------------------------------------------------------------------------------------- */
2192
#define F_SWAP UDISKS_PARTITION_TYPE_INFO_FLAGS_SWAP
2193
#define F_RAID UDISKS_PARTITION_TYPE_INFO_FLAGS_RAID
2194
#define F_HIDDEN UDISKS_PARTITION_TYPE_INFO_FLAGS_HIDDEN
2195
#define F_CONLY UDISKS_PARTITION_TYPE_INFO_FLAGS_CREATE_ONLY
2196
#define F_SYSTEM UDISKS_PARTITION_TYPE_INFO_FLAGS_SYSTEM
2200
const gchar *table_type;
2201
const gchar *table_subtype;
2204
UDisksPartitionTypeInfoFlags flags;
2205
} known_partition_types[] =
2207
/* see http://en.wikipedia.org/wiki/GUID_Partition_Table */
2209
/* Not associated with any OS */
2210
{"gpt", "generic", "024dee41-33e7-11d3-9d69-0008c781f39f", NC_("part-type", "MBR Partition Scheme"), F_SYSTEM},
2211
{"gpt", "generic", "c12a7328-f81f-11d2-ba4b-00a0c93ec93b", NC_("part-type", "EFI System"), F_SYSTEM},
2212
{"gpt", "generic", "21686148-6449-6e6f-744e-656564454649", NC_("part-type", "BIOS Boot"), F_SYSTEM},
2213
{"gpt", "generic", "6a898cc3-1dd2-11b2-99a6-080020736631", NC_("part-type", "ZFS"), 0}, /* see also Apple, Sol. */
2215
{"gpt", "linux", "0fc63daf-8483-4772-8e79-3d69d8477de4", NC_("part-type", "Linux Filesystem"), 0},
2216
{"gpt", "linux", "a19d880f-05fc-4d3b-a006-743f0f84911e", NC_("part-type", "Linux RAID"), F_RAID},
2217
{"gpt", "linux", "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f", NC_("part-type", "Linux Swap"), F_SWAP},
2218
{"gpt", "linux", "e6d6d379-f507-44c2-a23c-238f2a3df928", NC_("part-type", "Linux LVM"), F_RAID},
2219
{"gpt", "linux", "8da63339-0007-60c0-c436-083ac8230908", NC_("part-type", "Linux Reserved"), 0},
2221
{"gpt", "microsoft", "ebd0a0a2-b9e5-4433-87c0-68b6b72699c7", NC_("part-type", "Basic Data"), 0},
2222
{"gpt", "microsoft", "e3c9e316-0b5c-4db8-817d-f92df00215ae", NC_("part-type", "Microsoft Reserved"), 0},
2223
{"gpt", "microsoft", "5808c8aa-7e8f-42e0-85d2-e1e90434cfb3", NC_("part-type", "Microsoft LDM metadata"), 0},
2224
{"gpt", "microsoft", "af9b60a0-1431-4f62-bc68-3311714a69ad", NC_("part-type", "Microsoft LDM data"), 0},
2225
{"gpt", "microsoft", "de94bba4-06d1-4d40-a16a-bfd50179d6ac", NC_("part-type", "Microsoft Windows Recovery Environment"), 0},
2227
{"gpt", "apple", "48465300-0000-11aa-aa11-00306543ecac", NC_("part-type", "Apple HFS/HFS+"), 0},
2228
{"gpt", "apple", "55465300-0000-11aa-aa11-00306543ecac", NC_("part-type", "Apple UFS"), 0},
2229
{"gpt", "apple", "6a898cc3-1dd2-11b2-99a6-080020736631", NC_("part-type", "Apple ZFS"), 0}, /* same as ZFS */
2230
{"gpt", "apple", "52414944-0000-11aa-aa11-00306543ecac", NC_("part-type", "Apple RAID"), F_RAID},
2231
{"gpt", "apple", "52414944-5f4f-11aa-aa11-00306543ecac", NC_("part-type", "Apple RAID (offline)"), F_RAID},
2232
{"gpt", "apple", "426f6f74-0000-11aa-aa11-00306543ecac", NC_("part-type", "Apple Boot"), F_SYSTEM},
2233
{"gpt", "apple", "4c616265-6c00-11aa-aa11-00306543ecac", NC_("part-type", "Apple Label"), 0},
2234
{"gpt", "apple", "5265636f-7665-11aa-aa11-00306543ecac", NC_("part-type", "Apple TV Recovery"), F_SYSTEM},
2235
{"gpt", "apple", "53746f72-6167-11aa-aa11-00306543ecac", NC_("part-type", "Apple Core Storage"), F_RAID},
2237
{"gpt", "other", "75894c1e-3aeb-11d3-b7c1-7b03a0000000", NC_("part-type", "HP-UX Data"), 0},
2238
{"gpt", "other", "e2a1e728-32e3-11d6-a682-7b03a0000000", NC_("part-type", "HP-UX Service"), 0},
2240
{"gpt", "other", "83bd6b9d-7f41-11dc-be0b-001560b84f0f", NC_("part-type", "FreeBSD Boot"), 0},
2241
{"gpt", "other", "516e7cb4-6ecf-11d6-8ff8-00022d09712b", NC_("part-type", "FreeBSD Data"), 0},
2242
{"gpt", "other", "516e7cb5-6ecf-11d6-8ff8-00022d09712b", NC_("part-type", "FreeBSD Swap"), F_SWAP},
2243
{"gpt", "other", "516e7cb6-6ecf-11d6-8ff8-00022d09712b", NC_("part-type", "FreeBSD UFS"), 0},
2244
{"gpt", "other", "516e7cb8-6ecf-11d6-8ff8-00022d09712b", NC_("part-type", "FreeBSD Vinum"), F_RAID},
2245
{"gpt", "other", "516e7cba-6ecf-11d6-8ff8-00022d09712b", NC_("part-type", "FreeBSD ZFS"), 0},
2247
{"gpt", "other", "6a82cb45-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Boot"), 0},
2248
{"gpt", "other", "6a85cf4d-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Root"), 0},
2249
{"gpt", "other", "6a87c46f-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Swap"), F_SWAP},
2250
{"gpt", "other", "6a8b642b-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Backup"), 0},
2251
{"gpt", "other", "6a898cc3-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris /usr"), 0}, /* same as ZFS */
2252
{"gpt", "other", "6a8ef2e9-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris /var"), 0},
2253
{"gpt", "other", "6a90ba39-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris /home"), 0},
2254
{"gpt", "other", "6a9283a5-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Alternate Sector"), 0},
2255
{"gpt", "other", "6a945a3b-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Reserved"), 0},
2256
{"gpt", "other", "6a9630d1-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Reserved (2)"), 0},
2257
{"gpt", "other", "6a980767-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Reserved (3)"), 0},
2258
{"gpt", "other", "6a96237f-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Reserved (4)"), 0},
2259
{"gpt", "other", "6a8d2ac7-1dd2-11b2-99a6-080020736631", NC_("part-type", "Solaris Reserved (5)"), 0},
2261
{"gpt", "other", "49f48d32-b10e-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD Swap"), F_SWAP},
2262
{"gpt", "other", "49f48d5a-b10e-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD FFS"), 0},
2263
{"gpt", "other", "49f48d82-b10e-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD LFS"), 0},
2264
{"gpt", "other", "49f48daa-b10e-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD RAID"), F_RAID},
2265
{"gpt", "other", "2db519c4-b10f-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD Concatenated"), 0},
2266
{"gpt", "other", "2db519ec-b10f-11dc-b99b-0019d1879648", NC_("part-type", "NetBSD Encrypted"), 0},
2267
/* VMWare, see http://blogs.vmware.com/vsphere/2011/08/vsphere-50-storage-features-part-7-gpt.html */
2268
{"gpt", "other", "aa31e02a-400f-11db-9590-000c2911d1b8", NC_("part-type", "VMWare VMFS"), 0},
2269
{"gpt", "other", "9d275380-40ad-11db-bf97-000c2911d1b8", NC_("part-type", "VMWare vmkcore"), 0},
2270
/* ChromeOS, see http://www.chromium.org/chromium-os/chromiumos-design-docs/disk-format */
2271
{"gpt", "other", "cab6e88e-abf3-4102-a07a-d4bb9be3c1d3", NC_("part-type", "ChromeOS Firmware"), 0},
2272
{"gpt", "other", "fe3a2a5d-4f32-41a7-b725-accc3285a309", NC_("part-type", "ChromeOS Kernel"), 0},
2273
{"gpt", "other", "3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec", NC_("part-type", "ChromeOS Root Filesystem"), 0},
2274
{"gpt", "other", "2e0a753d-9e48-43b0-8337-b15192cb1b5e", NC_("part-type", "ChromeOS Reserved"), 0},
2276
/* see http://developer.apple.com/documentation/mac/devices/devices-126.html
2277
* http://lists.apple.com/archives/Darwin-drivers/2003/May/msg00021.html */
2278
{"apm", "apple", "Apple_Unix_SVR2", NC_("part-type", "Apple UFS"), 0},
2279
{"apm", "apple", "Apple_HFS", NC_("part-type", "Apple HFS/HFS"), 0},
2280
{"apm", "apple", "Apple_partition_map", NC_("part-type", "Apple Partition Map"), 0},
2281
{"apm", "apple", "Apple_Free", NC_("part-type", "Unused"), 0},
2282
{"apm", "apple", "Apple_Scratch", NC_("part-type", "Empty"), 0},
2283
{"apm", "apple", "Apple_Driver", NC_("part-type", "Driver"), 0},
2284
{"apm", "apple", "Apple_Driver43", NC_("part-type", "Driver 4.3"), 0},
2285
{"apm", "apple", "Apple_PRODOS", NC_("part-type", "ProDOS file system"), 0},
2286
{"apm", "microsoft", "DOS_FAT_12", NC_("part-type", "FAT 12"), 0},
2287
{"apm", "microsoft", "DOS_FAT_16", NC_("part-type", "FAT 16"), 0},
2288
{"apm", "microsoft", "DOS_FAT_32", NC_("part-type", "FAT 32"), 0},
2289
{"apm", "microsoft", "Windows_FAT_16", NC_("part-type", "FAT 16 (Windows)"), 0},
2290
{"apm", "microsoft", "Windows_FAT_32", NC_("part-type", "FAT 32 (Windows)"), 0},
2292
/* see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */
2293
{"dos", "generic", "0x05", NC_("part-type", "Extended"), F_CONLY},
2294
{"dos", "generic", "0xee", NC_("part-type", "EFI GPT"), F_SYSTEM},
2295
{"dos", "generic", "0xef", NC_("part-type", "EFI (FAT-12/16/32)"), F_SYSTEM},
2296
{"dos", "linux", "0x82", NC_("part-type", "Linux swap"), F_SWAP},
2297
{"dos", "linux", "0x83", NC_("part-type", "Linux"), 0},
2298
{"dos", "linux", "0x85", NC_("part-type", "Linux Extended"), F_CONLY},
2299
{"dos", "linux", "0x8e", NC_("part-type", "Linux LVM"), F_RAID},
2300
{"dos", "linux", "0xfd", NC_("part-type", "Linux RAID auto"), F_RAID},
2301
{"dos", "microsoft", "0x01", NC_("part-type", "FAT12"), 0},
2302
{"dos", "microsoft", "0x04", NC_("part-type", "FAT16 <32M"), 0},
2303
{"dos", "microsoft", "0x06", NC_("part-type", "FAT16"), 0},
2304
{"dos", "microsoft", "0x07", NC_("part-type", "HPFS/NTFS"), 0},
2305
{"dos", "microsoft", "0x0b", NC_("part-type", "W95 FAT32"), 0},
2306
{"dos", "microsoft", "0x0c", NC_("part-type", "W95 FAT32 (LBA)"), 0},
2307
{"dos", "microsoft", "0x0e", NC_("part-type", "W95 FAT16 (LBA)"), 0},
2308
{"dos", "microsoft", "0x0f", NC_("part-type", "W95 Ext d (LBA)"), F_CONLY},
2309
{"dos", "microsoft", "0x11", NC_("part-type", "Hidden FAT12"), F_HIDDEN},
2310
{"dos", "microsoft", "0x14", NC_("part-type", "Hidden FAT16 <32M"), F_HIDDEN},
2311
{"dos", "microsoft", "0x16", NC_("part-type", "Hidden FAT16"), F_HIDDEN},
2312
{"dos", "microsoft", "0x17", NC_("part-type", "Hidden HPFS/NTFS"), F_HIDDEN},
2313
{"dos", "microsoft", "0x1b", NC_("part-type", "Hidden W95 FAT32"), F_HIDDEN},
2314
{"dos", "microsoft", "0x1c", NC_("part-type", "Hidden W95 FAT32 (LBA)"), F_HIDDEN},
2315
{"dos", "microsoft", "0x1e", NC_("part-type", "Hidden W95 FAT16 (LBA)"), F_HIDDEN},
2316
{"dos", "other", "0x10", NC_("part-type", "OPUS"), 0},
2317
{"dos", "other", "0x12", NC_("part-type", "Compaq diagnostics"), 0},
2318
{"dos", "other", "0x3c", NC_("part-type", "PartitionMagic"), 0},
2319
{"dos", "other", "0x81", NC_("part-type", "Minix"), 0}, /* cf. http://en.wikipedia.org/wiki/MINIX_file_system */
2320
{"dos", "other", "0x84", NC_("part-type", "Hibernation"), 0},
2321
{"dos", "other", "0xa0", NC_("part-type", "Hibernation"), 0},
2322
{"dos", "other", "0xa5", NC_("part-type", "FreeBSD"), 0},
2323
{"dos", "other", "0xa6", NC_("part-type", "OpenBSD"), 0},
2324
{"dos", "other", "0xa8", NC_("part-type", "Mac OS X"), 0},
2325
{"dos", "other", "0xaf", NC_("part-type", "Mac OS X"), 0},
2326
{"dos", "other", "0xbe", NC_("part-type", "Solaris boot"), 0},
2327
{"dos", "other", "0xbf", NC_("part-type", "Solaris"), 0},
2328
{"dos", "other", "0xeb", NC_("part-type", "BeOS BFS"), 0},
2329
{"dos", "other", "0xec", NC_("part-type", "SkyOS SkyFS"), 0},
2334
* udisks_client_get_partition_type_infos:
2335
* @client: A #UDisksClient.
2336
* @partition_table_type: A partition table type e.g. 'dos' or 'gpt'.
2337
* @partition_table_subtype: (allow-none): A partition table subtype or %NULL to get all known types.
2339
* Gets information about all known partition types for @partition_table_type and @partition_table_subtype.
2341
* Returns: (transfer full) (element-type UDisksPartitionTypeInfo): A list of
2342
* #UDisksPartitionTypeInfo instances. The returned list should be freed
2343
* with g_list_free() after freeing each element with udisks_partition_type_info_free().
2346
udisks_client_get_partition_type_infos (UDisksClient *client,
2347
const gchar *partition_table_type,
2348
const gchar *partition_table_subtype)
2353
for (n = 0; known_partition_types[n].name != NULL; n++)
2355
if (g_strcmp0 (known_partition_types[n].table_type, partition_table_type) == 0 &&
2356
(partition_table_subtype == NULL ||
2357
g_strcmp0 (known_partition_types[n].table_subtype, partition_table_subtype) == 0))
2359
UDisksPartitionTypeInfo *info = udisks_partition_type_info_new ();
2360
info->table_type = known_partition_types[n].table_type;
2361
info->table_subtype = known_partition_types[n].table_subtype;
2362
info->type = known_partition_types[n].type;
2363
info->flags = known_partition_types[n].flags;
2364
ret = g_list_prepend (ret, info);
2367
ret = g_list_reverse (ret);
2372
* udisks_client_get_partition_type_for_display:
2373
* @client: A #UDisksClient.
2374
* @partition_table_type: A partitioning type e.g. 'dos' or 'gpt'.
2375
* @partition_type: A partition type.
2377
* Gets a human readable localized string for @partiton_table_type and @partition_type.
2379
* Returns: A description of @partition_type or %NULL if unknown.
2382
udisks_client_get_partition_type_for_display (UDisksClient *client,
2383
const gchar *partition_table_type,
2384
const gchar *partition_type)
2386
const gchar *ret = NULL;
2389
for (n = 0; known_partition_types[n].name != NULL; n++)
2391
if (g_strcmp0 (known_partition_types[n].table_type, partition_table_type) == 0 &&
2392
g_strcmp0 (known_partition_types[n].type, partition_type) == 0)
2394
ret = g_dpgettext2 (GETTEXT_PACKAGE, "part-type", known_partition_types[n].name);
2404
* udisks_client_get_partition_type_and_subtype_for_display:
2405
* @client: A #UDisksClient.
2406
* @partition_table_type: A partitioning type e.g. 'dos' or 'gpt'.
2407
* @partition_table_subtype: A partitioning subtype or %NULL.
2408
* @partition_type: A partition type.
2410
* Like udisks_client_get_partition_type_for_display() but also takes
2411
* the partition table subtype into account, if available. This is
2412
* useful in scenarios where different subtypes is using the same
2415
* Returns: A description of @partition_type or %NULL if unknown.
2420
udisks_client_get_partition_type_and_subtype_for_display (UDisksClient *client,
2421
const gchar *partition_table_type,
2422
const gchar *partition_table_subtype,
2423
const gchar *partition_type)
2425
const gchar *ret = NULL;
2428
for (n = 0; known_partition_types[n].name != NULL; n++)
2430
if (g_strcmp0 (known_partition_types[n].table_type, partition_table_type) == 0 &&
2431
g_strcmp0 (known_partition_types[n].type, partition_type) == 0)
2433
if (partition_table_subtype != NULL &&
2434
g_strcmp0 (known_partition_types[n].table_subtype, partition_table_subtype) != 0)
2436
ret = g_dpgettext2 (GETTEXT_PACKAGE, "part-type", known_partition_types[n].name);
2445
/* ---------------------------------------------------------------------------------------------------- */
2448
* udisks_client_get_job_description:
2449
* @client: A #UDisksClient.
2450
* @job: A #UDisksJob.
2452
* Gets a human-readable and localized text string describing the
2453
* operation of @job.
2455
* For known job types, see the documentation for the
2456
* <link linkend="gdbus-property-org-freedesktop-UDisks2-Job.Operation">Job:Operation</link>
2459
* Returns: A string that should be freed with g_free().
2462
udisks_client_get_job_description (UDisksClient *client,
2465
static gsize once = 0;
2466
static GHashTable *hash = NULL;
2467
const gchar *operation = NULL;
2470
g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
2472
if (g_once_init_enter (&once))
2474
hash = g_hash_table_new (g_str_hash, g_str_equal);
2475
g_hash_table_insert (hash, (gpointer) "ata-smart-selftest", (gpointer) C_("job", "SMART self-test"));
2476
g_hash_table_insert (hash, (gpointer) "drive-eject", (gpointer) C_("job", "Ejecting Medium"));
2477
g_hash_table_insert (hash, (gpointer) "encrypted-unlock", (gpointer) C_("job", "Unlocking Device"));
2478
g_hash_table_insert (hash, (gpointer) "encrypted-lock", (gpointer) C_("job", "Locking Device"));
2479
g_hash_table_insert (hash, (gpointer) "encrypted-modify", (gpointer) C_("job", "Modifying Encrypted Device"));
2480
g_hash_table_insert (hash, (gpointer) "swapspace-start", (gpointer) C_("job", "Starting Swap Device"));
2481
g_hash_table_insert (hash, (gpointer) "swapspace-stop", (gpointer) C_("job", "Stopping Swap Device"));
2482
g_hash_table_insert (hash, (gpointer) "filesystem-mount", (gpointer) C_("job", "Mounting Filesystem"));
2483
g_hash_table_insert (hash, (gpointer) "filesystem-unmount", (gpointer) C_("job", "Unmounting Filesystem"));
2484
g_hash_table_insert (hash, (gpointer) "filesystem-modify", (gpointer) C_("job", "Modifying Filesystem"));
2485
g_hash_table_insert (hash, (gpointer) "format-erase", (gpointer) C_("job", "Erasing Device"));
2486
g_hash_table_insert (hash, (gpointer) "format-mkfs", (gpointer) C_("job", "Creating Filesystem"));
2487
g_hash_table_insert (hash, (gpointer) "loop-setup", (gpointer) C_("job", "Setting Up Loop Device"));
2488
g_hash_table_insert (hash, (gpointer) "partition-modify", (gpointer) C_("job", "Modifying Partition"));
2489
g_hash_table_insert (hash, (gpointer) "partition-delete", (gpointer) C_("job", "Deleting Partition"));
2490
g_hash_table_insert (hash, (gpointer) "partition-create", (gpointer) C_("job", "Creating Partition"));
2491
g_hash_table_insert (hash, (gpointer) "cleanup", (gpointer) C_("job", "Cleaning Up"));
2492
g_hash_table_insert (hash, (gpointer) "ata-secure-erase", (gpointer) C_("job", "ATA Secure Erase"));
2493
g_hash_table_insert (hash, (gpointer) "ata-enhanced-secure-erase", (gpointer) C_("job", "ATA Enhanced Secure Erase"));
2494
g_hash_table_insert (hash, (gpointer) "md-raid-stop", (gpointer) C_("job", "Stopping RAID Array"));
2495
g_hash_table_insert (hash, (gpointer) "md-raid-start", (gpointer) C_("job", "Starting RAID Array"));
2496
g_hash_table_insert (hash, (gpointer) "md-raid-fault-device", (gpointer) C_("job", "Marking Device as Faulty"));
2497
g_hash_table_insert (hash, (gpointer) "md-raid-remove-device",(gpointer) C_("job", "Removing Device from Array"));
2498
g_hash_table_insert (hash, (gpointer) "md-raid-add-device", (gpointer) C_("job", "Adding Device to Array"));
2499
g_hash_table_insert (hash, (gpointer) "md-raid-set-bitmap", (gpointer) C_("job", "Setting Write-Intent Bitmap"));
2500
g_hash_table_insert (hash, (gpointer) "md-raid-create", (gpointer) C_("job", "Creating RAID Array"));
2501
g_once_init_leave (&once, (gsize) 1);
2504
operation = udisks_job_get_operation (job);
2505
if (operation != NULL)
2506
ret = g_strdup (g_hash_table_lookup (hash, operation));
2508
ret = g_strdup_printf (C_("unknown-job", "Unknown (%s)"), udisks_job_get_operation (job));
2513
/* ---------------------------------------------------------------------------------------------------- */
2515
static UDisksPartitionTypeInfo *
2516
udisks_partition_type_info_new (void)
2518
UDisksPartitionTypeInfo *ret;
2519
ret = g_slice_new0 (UDisksPartitionTypeInfo);
2523
static UDisksPartitionTypeInfo *
2524
udisks_partition_type_info_copy (UDisksPartitionTypeInfo *info)
2526
UDisksPartitionTypeInfo *ret;
2527
ret = udisks_partition_type_info_new ();
2528
memcpy (ret, info, sizeof (UDisksPartitionTypeInfo));
2533
* udisks_partition_type_info_free:
2534
* @info: A #UDisksPartitionTypeInfo.
2539
udisks_partition_type_info_free (UDisksPartitionTypeInfo *info)
2541
g_slice_free (UDisksPartitionTypeInfo, info);
2544
G_DEFINE_BOXED_TYPE (UDisksPartitionTypeInfo, udisks_partition_type_info, udisks_partition_type_info_copy, udisks_partition_type_info_free);