1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3
* Copyright (C) 2007-2010 David Zeuthen <zeuthen@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program 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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <glib/gi18n.h>
26
#include <sys/types.h>
31
#include <udisks/udisks.h>
34
lookup_object_for_block (UDisksClient *client,
43
objects = g_dbus_object_manager_get_objects (udisks_client_get_object_manager (client));
44
for (l = objects; l != NULL; l = l->next)
46
UDisksObject *object = UDISKS_OBJECT (l->data);
49
block = udisks_object_peek_block (object);
52
if (block_device == udisks_block_get_device_number (block))
54
ret = g_object_ref (object);
61
g_list_foreach (objects, (GFunc) g_object_unref, NULL);
62
g_list_free (objects);
68
main (int argc, char *argv[])
76
UDisksFilesystem *filesystem;
77
GVariantBuilder builder;
85
if (argc < 2 || strlen (argv[1]) == 0)
87
g_printerr ("%s: this program is only supposed to be invoked by umount(8).\n", argv[0]);
91
if (stat (argv[1], &statbuf) < 0)
93
g_printerr ("%s: error calling stat on %s: %m\n", argv[0], argv[1]);
97
if (S_ISBLK (statbuf.st_mode))
98
block_device = statbuf.st_rdev;
100
block_device = statbuf.st_dev;
103
client = udisks_client_new_sync (NULL, /* GCancellable */
107
g_printerr ("Error connecting to the udisks daemon: %s\n", error->message);
108
g_error_free (error);
112
object = lookup_object_for_block (client, block_device);
115
g_printerr ("Error finding object for block device %d:%d\n", major (block_device), minor (block_device));
119
filesystem = udisks_object_peek_filesystem (object);
120
if (filesystem == NULL)
122
g_printerr ("Block device %d:%d is not a mountable filesystem.\n", major (block_device), minor (block_device));
127
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
128
if (!udisks_filesystem_call_unmount_sync (filesystem,
129
g_variant_builder_end (&builder), /* options */
130
NULL, /* GCancellable */
133
g_printerr ("Error unmounting block device %d:%d: %s\n", major (block_device), minor (block_device), error->message);
134
g_error_free (error);
142
g_object_unref (object);
144
g_object_unref (client);