diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2005-08-14 14:01:38 +0000 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2005-08-14 14:01:38 +0000 |
commit | 9874e8a148616604502696317e2c080e15acec7c (patch) | |
tree | 38c221cffbb0dbe1abcb6173a5324d6d8b36042c /libgphoto2_port/disk | |
parent | dd6bd82baa8f27deb8ac94179c79e528d18fe49b (diff) | |
download | libgphoto2-9874e8a148616604502696317e2c080e15acec7c.tar.gz |
* read /etc/fstab and /etc/mtab if we have no HAL.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@8206 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port/disk')
-rw-r--r-- | libgphoto2_port/disk/disk.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/libgphoto2_port/disk/disk.c b/libgphoto2_port/disk/disk.c index 46102747f..f928d31cb 100644 --- a/libgphoto2_port/disk/disk.c +++ b/libgphoto2_port/disk/disk.c @@ -33,8 +33,11 @@ #include <sys/param.h> #include <dirent.h> #include <string.h> +#include <mntent.h> +#ifdef HAVE_HAL #include <hal/libhal.h> +#endif #include <gphoto2-port.h> #include <gphoto2-port-result.h> @@ -75,13 +78,14 @@ int gp_port_library_list (GPPortInfoList *list) { GPPortInfo info; +#ifdef HAVE_HAL LibHalContext *ctx; + DBusError error; + DBusConnection *dbus_connection; int i; int num_volumes; char **volumes; char *udi; - DBusError error; - DBusConnection *dbus_connection; ctx = libhal_ctx_new (); if (!ctx) { @@ -171,7 +175,58 @@ gp_port_library_list (GPPortInfoList *list) libhal_ctx_free(ctx); dbus_connection_unref(dbus_connection); +#else + FILE *mnt; + struct mntent *mntent; + char path[1024]; + struct stat stbuf; + + info.type = GP_PORT_DISK; + + mnt = setmntent ("/etc/fstab", "r"); + while ((mntent = getmntent (mnt))) { + /* detect floppies so we don't access them with the stat() below */ + if ( (NULL != strstr(mntent->mnt_fsname,"fd")) || + (NULL != strstr(mntent->mnt_fsname,"floppy")) + ) + continue; + snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir); + if (-1 == stat(path, &stbuf)) { + snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir); + if (-1 == stat(path, &stbuf)) + continue; + } + snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname), + snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir); + if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK) + continue; + CHECK (gp_port_info_list_append (list, info)); + } + endmntent(mnt); + mnt = setmntent ("/etc/mtab", "r"); + while ((mntent = getmntent (mnt))) { + /* detect floppies so we don't access them with the stat() below */ + if ( (NULL != strstr(mntent->mnt_fsname,"fd")) || + (NULL != strstr(mntent->mnt_fsname,"floppy")) + ) + continue; + + snprintf (path, sizeof(path), "%s/DCIM", mntent->mnt_dir); + if (-1 == stat(path, &stbuf)) { + snprintf (path, sizeof(path), "%s/dcim", mntent->mnt_dir); + if (-1 == stat(path, &stbuf)) + continue; + } + info.type = GP_PORT_DISK; + snprintf (info.name, sizeof(info.name), _("Media '%s'"), mntent->mnt_fsname), + snprintf (info.path, sizeof(info.path), "disk:%s", mntent->mnt_dir); + if (gp_port_info_list_lookup_path (list, info.path) >= GP_OK) + continue; + CHECK (gp_port_info_list_append (list, info)); + } + endmntent(mnt); +#endif return GP_OK; } |