2 * W32 disk modules finder for acquiration installation utility
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
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; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
24 #include <glib/ghash.h>
25 #include <glib/glist.h>
26 #include <libgnomevfs/gnome-vfs-uri.h>
27 #include "../libcaptive-install/proc_partitions.h"
33 #define FILENAME_ETC_MTAB "/etc/mtab"
36 struct mod_uri_libntfs_proc_partitions_foreach_param {
37 GHashTable *proc_partitions_ntfs_hash;
38 GList *uri_list; /* of (GnomeVFSURI *) */
41 static void mod_uri_libntfs_proc_partitions_foreach(const gchar *device /* key */,const gchar *vol_name /* value */,
42 struct mod_uri_libntfs_proc_partitions_foreach_param *foreach_param /* user_data */)
44 GnomeVFSURI *uri_device,*uri_libntfs;
45 static gboolean libntfs_warned=FALSE;
47 g_return_if_fail(device!=NULL);
48 g_return_if_fail(vol_name!=NULL);
49 g_return_if_fail(foreach_param!=NULL);
51 uri_libntfs=gnome_vfs_uri_new("libntfs:///");
53 if (!libntfs_warned) {
55 g_warning(_("'libntfs' GnomeVFS method not supported; install package 'ntfsprogs-gnomevfs' >=%s"),"1.8.0beta2");
59 g_assert(uri_libntfs->parent==NULL);
61 uri_device=gnome_vfs_uri_new("file:///");
62 g_assert(uri_device!=NULL);
63 uri_device=gnome_vfs_uri_append_path(uri_device,device);
64 g_assert(uri_device->parent==NULL);
66 uri_libntfs->parent=uri_device;
68 foreach_param->uri_list=g_list_prepend(foreach_param->uri_list,uri_libntfs);
71 static GList * /* of (GnomeVFSURI *) */ mod_uri_libntfs_proc_partitions(void)
73 /* map: (gchar *)device -> (gchar *)vol_name */
74 GHashTable *proc_partitions_ntfs_hash;
75 struct mod_uri_libntfs_proc_partitions_foreach_param foreach_param;
77 proc_partitions_ntfs_hash=proc_partitions_ntfs_hash_get(optarg_verbose);
79 foreach_param.proc_partitions_ntfs_hash=proc_partitions_ntfs_hash;
80 foreach_param.uri_list=NULL;
81 g_hash_table_foreach(proc_partitions_ntfs_hash,
82 (GHFunc)mod_uri_libntfs_proc_partitions_foreach, /* func */
83 &foreach_param); /* user_data */
84 g_hash_table_destroy(proc_partitions_ntfs_hash);
86 return foreach_param.uri_list;
90 static GList * /* of (GnomeVFSURI *) */ mod_uri_mtab(void)
92 struct mntent *mntent;
94 GList *uri_list; /* of (GnomeVFSURI *) */
97 if (!(mntentfiler=setmntent(FILENAME_ETC_MTAB,"r"))) {
98 g_warning(_("Cannot open \"%s\" for reading: %m"),FILENAME_ETC_MTAB);
102 while ((mntent=getmntent(mntentfiler))) {
103 if (!strcmp(mntent->mnt_type,"proc")) /* optimize... */
105 uri=gnome_vfs_uri_new("file:///");
107 uri=gnome_vfs_uri_append_path(uri,mntent->mnt_dir);
108 uri_list=g_list_prepend(uri_list,uri);
110 if (1!=endmntent(mntentfiler))
111 g_warning(_("Cannot close \"%s\" after reading: %m"),FILENAME_ETC_MTAB);
116 static GList * /* of (GnomeVFSURI *) */ filter_non_local_uri(GList * /* of (GnomeVFSURI *) */ uri_list)
120 /* Filter-out non-local URIs */
121 for (uril=uri_list;uril;) {
122 GnomeVFSURI *uri=uril->data;
125 if (!gnome_vfs_uri_is_local(uri)) {
126 if (optarg_verbose) {
129 uri_string=gnome_vfs_uri_to_string(uri,GNOME_VFS_URI_HIDE_PASSWORD);
130 g_message(_("Ignoring URI in auto-search as it is not local: %s"),uri_string);
135 gnome_vfs_uri_unref(uri);
136 /* It is safe to be used during traversal this way: */
137 uri_list=g_list_remove_link(uri_list,uril_remove);
138 /* Prevent auto-traversal to the next list item: */
146 GList * /* of (GnomeVFSURI *) */ mod_uri_list(void)
152 uri_list=g_list_concat(uri_list,mod_uri_mtab());
153 uri_list=g_list_concat(uri_list,mod_uri_libntfs_proc_partitions());
155 uri_list=filter_non_local_uri(uri_list);