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;
46 g_return_if_fail(device!=NULL);
47 g_return_if_fail(vol_name!=NULL);
48 g_return_if_fail(foreach_param!=NULL);
50 uri_device=gnome_vfs_uri_new("file:///");
51 uri_device=gnome_vfs_uri_append_path(uri_device,device);
52 g_assert(uri_device->parent==NULL);
53 uri_libntfs=gnome_vfs_uri_new("libntfs:///");
54 g_assert(uri_libntfs->parent==NULL);
56 uri_libntfs->parent=uri_device;
58 foreach_param->uri_list=g_list_prepend(foreach_param->uri_list,uri_libntfs);
61 static GList * /* of (GnomeVFSURI *) */ mod_uri_libntfs_proc_partitions(void)
63 /* map: (gchar *)device -> (gchar *)vol_name */
64 GHashTable *proc_partitions_ntfs_hash;
65 struct mod_uri_libntfs_proc_partitions_foreach_param foreach_param;
67 proc_partitions_ntfs_hash=proc_partitions_ntfs_hash_get(optarg_verbose);
69 foreach_param.proc_partitions_ntfs_hash=proc_partitions_ntfs_hash;
70 foreach_param.uri_list=NULL;
71 g_hash_table_foreach(proc_partitions_ntfs_hash,
72 (GHFunc)mod_uri_libntfs_proc_partitions_foreach, /* func */
73 &foreach_param); /* user_data */
74 g_hash_table_destroy(proc_partitions_ntfs_hash);
76 return foreach_param.uri_list;
80 static GList * /* of (GnomeVFSURI *) */ mod_uri_mtab(void)
82 struct mntent *mntent;
84 GList *uri_list; /* of (GnomeVFSURI *) */
87 if (!(mntentfiler=setmntent(FILENAME_ETC_MTAB,"r"))) {
88 g_warning(_("Cannot open \"%s\" for reading: %m"),FILENAME_ETC_MTAB);
92 while ((mntent=getmntent(mntentfiler))) {
93 if (!strcmp(mntent->mnt_type,"proc")) /* optimize... */
95 uri=gnome_vfs_uri_new("file:///");
96 uri=gnome_vfs_uri_append_path(uri,mntent->mnt_dir);
97 uri_list=g_list_prepend(uri_list,uri);
99 if (1!=endmntent(mntentfiler))
100 g_warning(_("Cannot close \"%s\" after reading: %m"),FILENAME_ETC_MTAB);
105 static GList * /* of (GnomeVFSURI *) */ filter_non_local_uri(GList * /* of (GnomeVFSURI *) */ uri_list)
109 /* Filter-out non-local URIs */
110 for (uril=uri_list;uril;) {
111 GnomeVFSURI *uri=uril->data;
113 if (!gnome_vfs_uri_is_local(uri)) {
114 if (optarg_verbose) {
117 uri_string=gnome_vfs_uri_to_string(uri,GNOME_VFS_URI_HIDE_PASSWORD);
118 g_message(_("Ignoring URI in auto-search as it is not local: %s"),uri_string);
121 gnome_vfs_uri_unref(uri);
122 /* It is safe to be used during traversal this way: */
124 uri_list=g_list_remove_link(uri_list,uril);
125 /* Prevent auto-traversal to the next list item: */
133 GList * /* of (GnomeVFSURI *) */ mod_uri_list(void)
139 uri_list=g_list_concat(uri_list,mod_uri_mtab());
140 uri_list=g_list_concat(uri_list,mod_uri_libntfs_proc_partitions());
142 uri_list=filter_non_local_uri(uri_list);