~ubuntu-branches/ubuntu/hardy/pcmanfm/hardy-backports

« back to all changes in this revision

Viewing changes to src/vfs/vfs-volume-hal-options.c

  • Committer: Bazaar Package Importer
  • Author(s): J?r?me Guelfucci
  • Date: 2008-07-01 00:40:37 UTC
  • mfrom: (5.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701004037-q6pfacskp0xnk10k
Tags: 0.4.3-1~hardy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include <config.h>
 
3
#endif
 
4
 
 
5
#include "vfs-volume-hal-options.h"
 
6
 
 
7
#include <string.h>
 
8
#include <unistd.h> /* for getuid() */
 
9
#include <sys/types.h>
 
10
 
 
11
#include <locale.h> /* for setlocale() */
 
12
 
 
13
#define CONFIG_FILE     PACKAGE_DATA_DIR "/mount.rules"
 
14
 
 
15
gboolean vfs_volume_hal_get_options( const char* fs, VFSVolumeOptions* ret )
 
16
{
 
17
    GKeyFile* f;
 
18
    if( fs == NULL || ! *fs)
 
19
        return FALSE;
 
20
    g_return_val_if_fail( ret != NULL, FALSE );
 
21
 
 
22
    f = g_key_file_new();
 
23
    if( g_key_file_load_from_file( f, CONFIG_FILE, 0, NULL) )
 
24
    {
 
25
        gsize n = 0;
 
26
        int i;
 
27
        ret->mount_options = g_key_file_get_string_list( f, fs, "mount_options", &n, NULL );
 
28
        ret->fstype_override = g_key_file_get_string(f, fs, "fstype_override", NULL );
 
29
 
 
30
        for( i = 0; i < n; ++i )
 
31
        {
 
32
            /* replace "uid=" with "uid=<actual uid>" */
 
33
#ifndef __FreeBSD__
 
34
            if (strcmp (ret->mount_options[i], "uid=") == 0) {
 
35
                g_free (ret->mount_options[i]);
 
36
                ret->mount_options[i] = g_strdup_printf ("uid=%u", getuid ());
 
37
            }
 
38
#else
 
39
            if (strcmp (ret->mount_options[i], "-u=") == 0) {
 
40
                g_free (ret->mount_options[i]);
 
41
                ret->mount_options[i] = g_strdup_printf ("-u=%u", getuid ());
 
42
            }
 
43
#endif
 
44
            /* for ntfs-3g */
 
45
            if (strcmp (ret->mount_options[i], "locale=") == 0) {
 
46
                g_free (ret->mount_options[i]);
 
47
                ret->mount_options[i] = g_strdup_printf ("locale=%s", setlocale (LC_ALL, ""));
 
48
            }
 
49
        }
 
50
    }
 
51
    else
 
52
    {
 
53
        ret->mount_options = NULL;
 
54
        ret->fstype_override = NULL;
 
55
    }
 
56
    g_key_file_free(f);
 
57
    return (ret->mount_options || ret->fstype_override);
 
58
}