| 1 |
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2015 Peter Hatina <[email protected]> |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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 |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
|
| 22 |
#include <blockdev/btrfs.h> |
| 23 |
#include "udisksbtrfsutil.h" |
| 24 |
|
| 25 |
const gchar *btrfs_subvolume_fmt = "(tts)"; |
| 26 |
const gchar *btrfs_subvolumes_fmt = "a(tts)"; |
| 27 |
|
| 28 |
GVariant * |
| 29 |
btrfs_subvolumes_to_gvariant (BDBtrfsSubvolumeInfo **subvolumes_info, |
| 30 |
gint *subvolumes_cnt) |
| 31 |
{ |
| 32 |
BDBtrfsSubvolumeInfo **infos; |
| 33 |
GVariantBuilder builder; |
| 34 |
|
| 35 |
g_variant_builder_init (&builder, G_VARIANT_TYPE (btrfs_subvolumes_fmt)); |
| 36 |
if (! subvolumes_info) |
| 37 |
return g_variant_builder_end (&builder); |
| 38 |
|
| 39 |
*subvolumes_cnt = 0; |
| 40 |
|
| 41 |
for (infos = subvolumes_info; *infos; ++infos, ++*subvolumes_cnt) |
| 42 |
{ |
| 43 |
g_variant_builder_add (&builder, |
| 44 |
btrfs_subvolume_fmt, |
| 45 |
(*infos)->id, |
| 46 |
(*infos)->parent_id, |
| 47 |
(*infos)->path); |
| 48 |
} |
| 49 |
|
| 50 |
return g_variant_builder_end (&builder); |
| 51 |
} |
| 52 |
|
| 53 |
void |
| 54 |
btrfs_free_subvolumes_info (BDBtrfsSubvolumeInfo **subvolumes_info) |
| 55 |
{ |
| 56 |
BDBtrfsSubvolumeInfo **infos = NULL; |
| 57 |
|
| 58 |
if (! subvolumes_info) |
| 59 |
return; |
| 60 |
|
| 61 |
for (infos = subvolumes_info; *infos; ++infos) |
| 62 |
bd_btrfs_subvolume_info_free (*infos); |
| 63 |
g_free ((gpointer) subvolumes_info); |
| 64 |
} |