~behda/+junk/udisks2.original

« back to all changes in this revision

Viewing changes to src/udisksfstabentry.c

  • Committer: behda
  • Date: 2014-05-24 15:15:11 UTC
  • Revision ID: pauvitk@gmail.com-20140524151511-3vtr0uubjewx3z2j
Initial commit of source code and Debian packaging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 
2
 *
 
3
 * Copyright (C) 2008 David Zeuthen <zeuthen@gmail.com>
 
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
 
 
21
#include "config.h"
 
22
#include <glib/gi18n-lib.h>
 
23
 
 
24
#include <stdlib.h>
 
25
#include <stdio.h>
 
26
#include <signal.h>
 
27
#include <errno.h>
 
28
#include <string.h>
 
29
#include <sys/types.h>
 
30
#include <sys/stat.h>
 
31
#include <mntent.h>
 
32
 
 
33
#include <glib.h>
 
34
#include <glib-object.h>
 
35
 
 
36
#include "udisksfstabentry.h"
 
37
#include "udisksprivate.h"
 
38
 
 
39
/**
 
40
 * UDisksFstabEntry:
 
41
 *
 
42
 * The #UDisksFstabEntry structure contains only private data and should
 
43
 * only be accessed using the provided API.
 
44
 */
 
45
struct _UDisksFstabEntry
 
46
{
 
47
  GObject parent_instance;
 
48
 
 
49
  gchar *fsname;
 
50
  gchar *dir;
 
51
  gchar *type;
 
52
  gchar *opts;
 
53
  gint freq;
 
54
  gint passno;
 
55
};
 
56
 
 
57
typedef struct _UDisksFstabEntryClass UDisksFstabEntryClass;
 
58
 
 
59
struct _UDisksFstabEntryClass
 
60
{
 
61
  GObjectClass parent_class;
 
62
};
 
63
 
 
64
G_DEFINE_TYPE (UDisksFstabEntry, udisks_fstab_entry, G_TYPE_OBJECT);
 
65
 
 
66
static void
 
67
udisks_fstab_entry_finalize (GObject *object)
 
68
{
 
69
  UDisksFstabEntry *entry = UDISKS_FSTAB_ENTRY (object);
 
70
 
 
71
  g_free (entry->fsname);
 
72
  g_free (entry->dir);
 
73
  g_free (entry->type);
 
74
  g_free (entry->opts);
 
75
 
 
76
  if (G_OBJECT_CLASS (udisks_fstab_entry_parent_class)->finalize)
 
77
    G_OBJECT_CLASS (udisks_fstab_entry_parent_class)->finalize (object);
 
78
}
 
79
 
 
80
static void
 
81
udisks_fstab_entry_init (UDisksFstabEntry *fstab_entry)
 
82
{
 
83
}
 
84
 
 
85
static void
 
86
udisks_fstab_entry_class_init (UDisksFstabEntryClass *klass)
 
87
{
 
88
  GObjectClass *gobject_class;
 
89
 
 
90
  gobject_class = G_OBJECT_CLASS (klass);
 
91
  gobject_class->finalize = udisks_fstab_entry_finalize;
 
92
}
 
93
 
 
94
UDisksFstabEntry *
 
95
_udisks_fstab_entry_new (const struct mntent *mntent)
 
96
{
 
97
  UDisksFstabEntry *entry;
 
98
 
 
99
  entry = UDISKS_FSTAB_ENTRY (g_object_new (UDISKS_TYPE_FSTAB_ENTRY, NULL));
 
100
  entry->fsname = g_strdup (mntent->mnt_fsname);
 
101
  entry->dir = g_strdup (mntent->mnt_dir);
 
102
  entry->type = g_strdup (mntent->mnt_type);
 
103
  entry->opts = g_strdup (mntent->mnt_opts);
 
104
  entry->freq = mntent->mnt_freq;
 
105
  entry->passno = mntent->mnt_passno;
 
106
 
 
107
  return entry;
 
108
}
 
109
 
 
110
/**
 
111
 * udisks_fstab_entry_compare:
 
112
 * @entry: A #UDisksFstabEntry
 
113
 * @other_entry: Another #UDisksFstabEntry.
 
114
 *
 
115
 * Comparison function for comparing two #UDisksFstabEntry objects.
 
116
 *
 
117
 * Returns: Negative value if @entry < @other_entry; zero if @entry = @other_entry; positive value if @entry > @other_entry.
 
118
 */
 
119
gint
 
120
udisks_fstab_entry_compare (UDisksFstabEntry  *entry,
 
121
                            UDisksFstabEntry  *other_entry)
 
122
{
 
123
  gint ret;
 
124
 
 
125
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), 0);
 
126
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (other_entry), 0);
 
127
 
 
128
  ret = g_strcmp0 (other_entry->fsname, entry->fsname);
 
129
  if (ret != 0)
 
130
    goto out;
 
131
 
 
132
  ret = g_strcmp0 (other_entry->dir, entry->dir);
 
133
  if (ret != 0)
 
134
    goto out;
 
135
 
 
136
  ret = g_strcmp0 (other_entry->type, entry->type);
 
137
  if (ret != 0)
 
138
    goto out;
 
139
 
 
140
  ret = g_strcmp0 (other_entry->opts, entry->opts);
 
141
  if (ret != 0)
 
142
    goto out;
 
143
 
 
144
  ret = entry->freq - other_entry->freq;
 
145
  if (ret != 0)
 
146
    goto out;
 
147
 
 
148
  ret = entry->passno - other_entry->passno;
 
149
 
 
150
 out:
 
151
  return ret;
 
152
}
 
153
 
 
154
/**
 
155
 * udisks_fstab_entry_get_fsname:
 
156
 * @entry: A #UDisksFstabEntry.
 
157
 *
 
158
 * Gets the fsname field of @entry.
 
159
 *
 
160
 * Returns: The fsname field.
 
161
 */
 
162
const gchar *
 
163
udisks_fstab_entry_get_fsname (UDisksFstabEntry *entry)
 
164
{
 
165
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), NULL);
 
166
  return entry->fsname;
 
167
}
 
168
 
 
169
/**
 
170
 * udisks_fstab_entry_get_dir:
 
171
 * @entry: A #UDisksFstabEntry.
 
172
 *
 
173
 * Gets the dir field of @entry.
 
174
 *
 
175
 * Returns: The dir field.
 
176
 */
 
177
const gchar *
 
178
udisks_fstab_entry_get_dir (UDisksFstabEntry *entry)
 
179
{
 
180
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), NULL);
 
181
  return entry->dir;
 
182
}
 
183
 
 
184
/**
 
185
 * udisks_fstab_entry_get_fstype:
 
186
 * @entry: A #UDisksFstabEntry.
 
187
 *
 
188
 * Gets the type field of @entry.
 
189
 *
 
190
 * Returns: The type field.
 
191
 */
 
192
const gchar *
 
193
udisks_fstab_entry_get_fstype (UDisksFstabEntry *entry)
 
194
{
 
195
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), NULL);
 
196
  return entry->type;
 
197
}
 
198
 
 
199
/**
 
200
 * udisks_fstab_entry_get_opts:
 
201
 * @entry: A #UDisksFstabEntry.
 
202
 *
 
203
 * Gets the opts field of @entry.
 
204
 *
 
205
 * Returns: The opts field.
 
206
 */
 
207
const gchar *
 
208
udisks_fstab_entry_get_opts (UDisksFstabEntry *entry)
 
209
{
 
210
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), NULL);
 
211
  return entry->opts;
 
212
}
 
213
 
 
214
/**
 
215
 * udisks_fstab_entry_get_freq:
 
216
 * @entry: A #UDisksFstabEntry.
 
217
 *
 
218
 * Gets the freq field of @entry.
 
219
 *
 
220
 * Returns: The freq field.
 
221
 */
 
222
gint
 
223
udisks_fstab_entry_get_freq (UDisksFstabEntry *entry)
 
224
{
 
225
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), 0);
 
226
  return entry->freq;
 
227
}
 
228
 
 
229
/**
 
230
 * udisks_fstab_entry_get_passno:
 
231
 * @entry: A #UDisksFstabEntry.
 
232
 *
 
233
 * Gets the passno field of @entry.
 
234
 *
 
235
 * Returns: The passno field.
 
236
 */
 
237
gint
 
238
udisks_fstab_entry_get_passno (UDisksFstabEntry *entry)
 
239
{
 
240
  g_return_val_if_fail (UDISKS_IS_FSTAB_ENTRY (entry), 0);
 
241
  return entry->passno;
 
242
}