1999-02-18 03:07:26 +03:00
|
|
|
|
/* Mount/umount support for the Midnight Commander
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1998-1999 The Free Software Foundation
|
|
|
|
|
*
|
1999-02-19 00:43:07 +03:00
|
|
|
|
* Authors: Miguel de Icaza <miguel@nuclecu.unam.mx>
|
|
|
|
|
* Federico Mena <federico@nuclecu.unam.mx>
|
1999-02-18 03:07:26 +03:00
|
|
|
|
*/
|
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
#include <config.h>
|
1999-02-27 03:04:40 +03:00
|
|
|
|
#include <stdio.h>
|
1999-02-17 05:18:12 +03:00
|
|
|
|
|
|
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#else
|
|
|
|
|
void free (void *ptr);
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
#include <sys/fs_types.h>
|
|
|
|
|
#endif /* MOUNTED_GETFSSTAT */
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
|
|
|
|
#include <mntent.h>
|
|
|
|
|
#if !defined(MOUNTED)
|
|
|
|
|
#if defined(MNT_MNTTAB) /* HP-UX. */
|
|
|
|
|
#define MOUNTED MNT_MNTTAB
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(MNTTABNAME) /* Dynix. */
|
|
|
|
|
#define MOUNTED MNTTABNAME
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
#include <sys/fs_types.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_FREAD /* SVR2. */
|
|
|
|
|
#include <mnttab.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
|
|
|
|
|
#include <mnttab.h>
|
|
|
|
|
#include <sys/fstyp.h>
|
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
|
|
|
|
#include <sys/mnttab.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef MOUNTED_VMOUNT /* AIX. */
|
|
|
|
|
#include <fshelp.h>
|
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* 4.4BSD2 derived systems */
|
|
|
|
|
#if defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
|
|
|
|
|
# ifndef MOUNT_UFS
|
|
|
|
|
# define xBSD
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* void error (void); FIXME -- needed? */
|
|
|
|
|
|
|
|
|
|
#ifdef DOLPHIN
|
|
|
|
|
/* So special that it's not worth putting this in autoconf. */
|
|
|
|
|
#undef MOUNTED_FREAD_FSTYP
|
|
|
|
|
#define MOUNTED_GETMNTTBL
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-17 07:03:32 +04:00
|
|
|
|
#ifdef HAVE_CORBA
|
1999-09-14 09:21:39 +04:00
|
|
|
|
#include <libgnorba/gnorba.h>
|
|
|
|
|
#include "magicdev.h"
|
1999-09-17 07:03:32 +04:00
|
|
|
|
#endif HAVE_CORBA
|
1999-09-14 09:21:39 +04:00
|
|
|
|
|
1999-02-19 00:43:07 +03:00
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <gnome.h>
|
|
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
|
#include "dialog.h"
|
|
|
|
|
#include "gdesktop.h"
|
1999-02-17 05:18:12 +03:00
|
|
|
|
#include "gmount.h"
|
1999-02-19 00:43:07 +03:00
|
|
|
|
#include "util.h"
|
1999-04-13 21:41:48 +04:00
|
|
|
|
#include "i18n.h"
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Information for a mountable device */
|
1999-02-26 12:12:17 +03:00
|
|
|
|
typedef struct {
|
|
|
|
|
char *devname;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
char *mount_point;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
/* This is just a good guess */
|
|
|
|
|
enum {
|
|
|
|
|
TYPE_UNKNOWN,
|
1999-03-09 06:56:54 +03:00
|
|
|
|
TYPE_CDROM,
|
|
|
|
|
TYPE_NFS
|
1999-02-26 12:12:17 +03:00
|
|
|
|
} type;
|
|
|
|
|
} devname_info_t;
|
1999-02-17 05:18:12 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
|
1999-02-23 09:14:02 +03:00
|
|
|
|
static gboolean
|
|
|
|
|
option_has_user (char *str)
|
|
|
|
|
{
|
1999-02-23 12:57:52 +03:00
|
|
|
|
char *p;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
if ((p = strstr (str, "user")) != NULL) {
|
|
|
|
|
if ((p - 2) >= str) {
|
1999-02-23 09:14:02 +03:00
|
|
|
|
if (strncmp (p - 2, "nouser", 6) == 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
#ifdef MOUNTED_GETMNTENT1
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
/* Returns whether devname is mountable: NULL if it is not or g_strdup()ed
|
|
|
|
|
* string with the mount point.
|
1999-02-23 04:56:09 +03:00
|
|
|
|
*/
|
|
|
|
|
char *
|
1999-03-09 06:56:54 +03:00
|
|
|
|
is_block_device_mountable (char *mount_point)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
struct mntent *mnt;
|
1999-02-23 04:56:09 +03:00
|
|
|
|
char *retval = NULL;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
f = setmntent ("/etc/fstab", "r");
|
|
|
|
|
if (f == NULL)
|
1999-02-23 12:57:52 +03:00
|
|
|
|
return NULL;
|
1999-02-17 05:18:12 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
while ((mnt = getmntent (f)) != NULL) {
|
|
|
|
|
if (strcmp (mnt->mnt_dir, mount_point) != 0) {
|
|
|
|
|
/* This second test is for compatibility with older
|
|
|
|
|
* desktops that might be using this.
|
1999-03-09 06:56:54 +03:00
|
|
|
|
*/
|
|
|
|
|
if (strcmp (mnt->mnt_dir, mount_point) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
if (getuid () == 0) {
|
1999-04-10 04:40:32 +04:00
|
|
|
|
retval = g_strdup (mnt->mnt_dir);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
if (option_has_user (mnt->mnt_opts)) {
|
1999-02-23 04:56:09 +03:00
|
|
|
|
retval = g_strdup (mnt->mnt_dir);
|
1999-02-17 05:18:12 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
endmntent (f);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
is_block_device_mounted (char *filename)
|
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
struct mntent *mnt;
|
|
|
|
|
gboolean retval = FALSE;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
f = setmntent ("/etc/mtab", "r");
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
while ((mnt = getmntent (f)) != NULL) {
|
1999-03-09 06:56:54 +03:00
|
|
|
|
if (strcmp (mnt->mnt_dir, filename) == 0)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
retval = TRUE;
|
|
|
|
|
}
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
endmntent (f);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
1999-02-19 03:18:25 +03:00
|
|
|
|
static GList *
|
|
|
|
|
get_mountable_devices (void)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
struct mntent *mnt;
|
|
|
|
|
GList *list = NULL;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
f = setmntent ("/etc/fstab", "r");
|
1999-09-10 23:24:57 +04:00
|
|
|
|
if (f == NULL) {
|
1999-03-15 02:31:50 +03:00
|
|
|
|
message (1, MSG_ERROR, _("Could not open the /etc/fstab file"));
|
1999-02-17 05:18:12 +03:00
|
|
|
|
return NULL;
|
1999-03-15 02:31:50 +03:00
|
|
|
|
}
|
1999-02-17 05:18:12 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
while ((mnt = getmntent (f)) != NULL) {
|
|
|
|
|
if (option_has_user (mnt->mnt_opts)) {
|
1999-02-26 12:12:17 +03:00
|
|
|
|
devname_info_t *dit;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
dit = g_new0 (devname_info_t, 1);
|
|
|
|
|
dit->devname = g_strdup (mnt->mnt_fsname);
|
1999-03-09 06:56:54 +03:00
|
|
|
|
dit->mount_point = g_strdup (mnt->mnt_dir);
|
1999-02-26 12:12:17 +03:00
|
|
|
|
dit->type = TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
if (strcmp (mnt->mnt_type, "iso9660") == 0)
|
|
|
|
|
dit->type = TYPE_CDROM;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
|
|
|
|
|
if (strcmp (mnt->mnt_type, "nfs") == 0)
|
|
|
|
|
dit->type = TYPE_NFS;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
list = g_list_prepend (list, dit);
|
1999-02-17 05:18:12 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-08-06 00:58:36 +04:00
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
endmntent (f);
|
1999-08-06 00:58:36 +04:00
|
|
|
|
|
|
|
|
|
list = g_list_reverse (list);
|
1999-02-17 05:18:12 +03:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-11 10:53:26 +03:00
|
|
|
|
char *
|
|
|
|
|
mount_point_to_device (char *mount_point)
|
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
struct mntent *mnt;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-03-11 10:53:26 +03:00
|
|
|
|
f = setmntent ("/etc/fstab", "r");
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
while ((mnt = getmntent (f))) {
|
|
|
|
|
if (strcmp (mnt->mnt_dir, mount_point) == 0) {
|
1999-03-11 10:53:26 +03:00
|
|
|
|
char *v;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-03-11 10:53:26 +03:00
|
|
|
|
v = g_strdup (mnt->mnt_fsname);
|
|
|
|
|
endmntent (f);
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
endmntent (f);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
|
#else
|
|
|
|
|
|
1999-02-23 04:56:09 +03:00
|
|
|
|
char *
|
1999-03-09 06:56:54 +03:00
|
|
|
|
is_block_device_mountable (char *mount_point)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
{
|
1999-02-23 04:56:09 +03:00
|
|
|
|
return NULL;
|
1999-02-17 05:18:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-19 03:18:25 +03:00
|
|
|
|
static GList *
|
|
|
|
|
get_mountable_devices (void)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
1999-03-09 06:56:54 +03:00
|
|
|
|
is_block_device_mounted (char *mount_point)
|
1999-02-17 05:18:12 +03:00
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-11 10:53:26 +03:00
|
|
|
|
char *
|
|
|
|
|
mount_point_to_device (char *mount_point)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-02-17 05:18:12 +03:00
|
|
|
|
#endif
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
/* Returns whether our supported automounter is running */
|
|
|
|
|
static gboolean
|
|
|
|
|
automounter_is_running (void)
|
|
|
|
|
{
|
1999-09-17 07:03:32 +04:00
|
|
|
|
#if defined(HAVE_CORBA)
|
1999-09-14 09:21:39 +04:00
|
|
|
|
CORBA_Object server;
|
|
|
|
|
CORBA_Environment ev;
|
|
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
|
|
CORBA_exception_init (&ev);
|
|
|
|
|
|
|
|
|
|
server = goad_server_activate_with_id (NULL,
|
|
|
|
|
"GOAD:magicdev:19990913",
|
|
|
|
|
GOAD_ACTIVATE_EXISTING_ONLY,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (!CORBA_Object_is_nil (server, &ev)) {
|
|
|
|
|
result = GNOME_MagicDev_is_running (server, &ev);
|
|
|
|
|
if (ev._major != CORBA_NO_EXCEPTION)
|
|
|
|
|
result = FALSE;
|
|
|
|
|
|
|
|
|
|
CORBA_Object_release (server, &ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
1999-09-17 07:03:32 +04:00
|
|
|
|
#else /* !HAVE_CORBA */
|
1999-09-14 09:21:39 +04:00
|
|
|
|
return FALSE;
|
1999-09-17 07:03:32 +04:00
|
|
|
|
#endif /* HAVE_CORBA */
|
1999-09-10 23:24:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Cleans up the desktop directory from device files. Includes block devices
|
|
|
|
|
* and printers.
|
1999-02-25 08:11:35 +03:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
desktop_cleanup_devices (void)
|
1999-02-19 00:43:07 +03:00
|
|
|
|
{
|
|
|
|
|
DIR *dir;
|
|
|
|
|
struct dirent *dent;
|
|
|
|
|
|
|
|
|
|
dir = mc_opendir (desktop_directory);
|
|
|
|
|
if (!dir) {
|
|
|
|
|
g_warning ("Could not clean up desktop devices");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1999-02-25 08:11:35 +03:00
|
|
|
|
gnome_metadata_lock ();
|
1999-02-19 00:43:07 +03:00
|
|
|
|
while ((dent = mc_readdir (dir)) != NULL) {
|
|
|
|
|
char *full_name;
|
|
|
|
|
char *buf;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
full_name = g_concat_dir_and_file (desktop_directory, dent->d_name);
|
|
|
|
|
if (gnome_metadata_get (full_name, "is-desktop-device", &size, &buf) == 0) {
|
|
|
|
|
mc_unlink (full_name);
|
|
|
|
|
gnome_metadata_delete (full_name);
|
|
|
|
|
g_free (buf);
|
|
|
|
|
}
|
|
|
|
|
g_free (full_name);
|
|
|
|
|
}
|
1999-02-25 08:11:35 +03:00
|
|
|
|
gnome_metadata_unlock ();
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-19 00:43:07 +03:00
|
|
|
|
mc_closedir (dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Creates the desktop link for the specified device */
|
|
|
|
|
static void
|
1999-09-10 23:24:57 +04:00
|
|
|
|
create_device_link (char *dev_name, char *short_dev_name, char *caption, char *icon,
|
|
|
|
|
gboolean ejectable)
|
1999-02-19 00:43:07 +03:00
|
|
|
|
{
|
|
|
|
|
char *full_name;
|
1999-02-26 12:12:17 +03:00
|
|
|
|
char *icon_full;
|
1999-02-25 08:11:35 +03:00
|
|
|
|
char type = 'D';
|
1999-03-09 06:56:54 +03:00
|
|
|
|
char ejectable_c = ejectable;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
icon_full = g_concat_dir_and_file (ICONDIR, icon);
|
1999-02-19 00:43:07 +03:00
|
|
|
|
full_name = g_concat_dir_and_file (desktop_directory, short_dev_name);
|
|
|
|
|
if (mc_symlink (dev_name, full_name) != 0) {
|
|
|
|
|
message (FALSE,
|
|
|
|
|
_("Warning"),
|
|
|
|
|
_("Could not symlink %s to %s; "
|
|
|
|
|
"will not have such a desktop device icon."),
|
|
|
|
|
dev_name, full_name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
gnome_metadata_set (full_name, "icon-filename", strlen (icon_full) + 1, icon_full);
|
1999-02-19 00:43:07 +03:00
|
|
|
|
gnome_metadata_set (full_name, "icon-caption", strlen (caption) + 1, caption);
|
1999-03-09 06:56:54 +03:00
|
|
|
|
gnome_metadata_set (full_name, "device-is-ejectable", 1, &ejectable_c);
|
1999-02-25 08:11:35 +03:00
|
|
|
|
gnome_metadata_set (full_name, "is-desktop-device", 1, &type); /* hack a boolean value */
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
|
|
|
|
g_free (full_name);
|
1999-02-26 12:12:17 +03:00
|
|
|
|
g_free (icon_full);
|
1999-02-19 00:43:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Creates the desktop links to the mountable devices */
|
|
|
|
|
static void
|
|
|
|
|
setup_devices (void)
|
|
|
|
|
{
|
|
|
|
|
GList *list, *l;
|
|
|
|
|
int floppy_count;
|
|
|
|
|
int hd_count;
|
1999-02-26 12:12:17 +03:00
|
|
|
|
int cdrom_count;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
int generic_count;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
int nfs_count;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
int automounter;
|
|
|
|
|
|
1999-02-19 03:18:25 +03:00
|
|
|
|
list = get_mountable_devices ();
|
1999-09-10 23:24:57 +04:00
|
|
|
|
automounter = automounter_is_running ();
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
hd_count = 0;
|
|
|
|
|
cdrom_count = 0;
|
|
|
|
|
floppy_count = 0;
|
|
|
|
|
generic_count = 0;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
|
|
|
|
for (l = list; l; l = l->next) {
|
1999-02-26 12:12:17 +03:00
|
|
|
|
devname_info_t *dit = l->data;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
char *dev_name;
|
|
|
|
|
char *short_dev_name;
|
|
|
|
|
char *format;
|
|
|
|
|
char *icon;
|
|
|
|
|
int count;
|
|
|
|
|
char buffer[128];
|
1999-03-09 06:56:54 +03:00
|
|
|
|
gboolean release_format;
|
|
|
|
|
gboolean ejectable;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
gboolean do_create;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
|
1999-02-26 12:12:17 +03:00
|
|
|
|
dev_name = dit->devname;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
short_dev_name = x_basename (dev_name);
|
|
|
|
|
|
1999-03-09 06:56:54 +03:00
|
|
|
|
release_format = FALSE;
|
|
|
|
|
ejectable = FALSE;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
do_create = TRUE;
|
|
|
|
|
|
1999-02-19 00:43:07 +03:00
|
|
|
|
/* Create the format/icon/count. This could use better heuristics. */
|
1999-09-10 23:24:57 +04:00
|
|
|
|
if (dit->type == TYPE_CDROM || strncmp (short_dev_name, "cdrom", 5) == 0) {
|
1999-02-26 12:12:17 +03:00
|
|
|
|
format = _("CD-ROM %d");
|
|
|
|
|
icon = "i-cdrom.png";
|
|
|
|
|
count = cdrom_count++;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
ejectable = TRUE;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
|
|
|
|
|
/* If our supported automounter is running, then we can
|
|
|
|
|
* be nice and create only the links for CD-ROMS that
|
|
|
|
|
* are actually mounted.
|
|
|
|
|
*/
|
1999-09-14 09:21:39 +04:00
|
|
|
|
if (automounter && !is_block_device_mounted (dit->mount_point))
|
1999-09-10 23:24:57 +04:00
|
|
|
|
do_create = FALSE;
|
1999-02-26 12:12:17 +03:00
|
|
|
|
} else if (strncmp (short_dev_name, "fd", 2) == 0) {
|
1999-02-19 00:43:07 +03:00
|
|
|
|
format = _("Floppy %d");
|
|
|
|
|
icon = "i-floppy.png";
|
|
|
|
|
count = floppy_count++;
|
1999-03-09 06:56:54 +03:00
|
|
|
|
ejectable = TRUE;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
} else if (strncmp (short_dev_name, "hd", 2) == 0
|
|
|
|
|
|| strncmp (short_dev_name, "sd", 2) == 0) {
|
|
|
|
|
format = _("Disk %d");
|
|
|
|
|
icon = "i-blockdev.png";
|
|
|
|
|
count = hd_count++;
|
1999-09-10 23:24:57 +04:00
|
|
|
|
} else if (dit->type == TYPE_NFS) {
|
1999-03-09 06:56:54 +03:00
|
|
|
|
release_format = TRUE;
|
|
|
|
|
format = g_strdup_printf (_("NFS dir %s"), dit->mount_point);
|
1999-03-11 10:53:26 +03:00
|
|
|
|
icon = "i-nfs.png";
|
1999-03-09 06:56:54 +03:00
|
|
|
|
count = nfs_count++;
|
1999-02-19 00:43:07 +03:00
|
|
|
|
} else {
|
|
|
|
|
format = _("Device %d");
|
|
|
|
|
icon = "i-blockdev.png";
|
|
|
|
|
count = generic_count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), format, count);
|
1999-09-10 23:24:57 +04:00
|
|
|
|
if (release_format) {
|
1999-03-09 06:56:54 +03:00
|
|
|
|
g_free (format);
|
|
|
|
|
format = NULL;
|
|
|
|
|
}
|
1999-02-19 00:43:07 +03:00
|
|
|
|
|
|
|
|
|
/* Create the actual link */
|
|
|
|
|
|
1999-09-10 23:24:57 +04:00
|
|
|
|
if (do_create)
|
|
|
|
|
create_device_link (dit->mount_point, short_dev_name,
|
|
|
|
|
buffer, icon, ejectable);
|
1999-02-26 12:12:17 +03:00
|
|
|
|
|
|
|
|
|
g_free (dit->devname);
|
1999-03-09 06:56:54 +03:00
|
|
|
|
g_free (dit->mount_point);
|
1999-02-26 12:12:17 +03:00
|
|
|
|
g_free (dit);
|
1999-02-19 00:43:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-23 04:56:09 +03:00
|
|
|
|
g_list_free (list);
|
1999-02-19 00:43:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-02-25 08:11:35 +03:00
|
|
|
|
gmount_setup_devices (void)
|
1999-02-19 00:43:07 +03:00
|
|
|
|
{
|
|
|
|
|
setup_devices ();
|
|
|
|
|
}
|