diff -u -p -r1.31 totem-disc.c
--- src/plparse/totem-disc.c	25 May 2006 13:53:29 -0000	1.31
+++ src/plparse/totem-disc.c	25 May 2006 14:45:18 -0000
@@ -36,7 +36,6 @@
 #include <errno.h>
 #include <string.h>
 
-#include <sys/ioctl.h>
 #include <sys/stat.h>
 
 #include <glib.h>
@@ -74,73 +73,70 @@ typedef struct _CdCache {
   gboolean mounted;
 } CdCache;
 
-/* 
- * Resolve relative paths
- */
-
-static char *
-totem_disc_resolve_link (const char *dev, const char *buf)
-{
-  char *parent, *new, *result;
-
-  /* is it an absolute path? */
-  if (g_path_is_absolute (buf) != FALSE) {
-    result = realpath (buf, NULL);
-    if (result == NULL)
-      result = g_strdup (buf);
-  } else {
-    parent = g_path_get_dirname (dev);
-    new = g_build_filename (parent, buf, NULL);
-    result = realpath (new, NULL);
-    if (result == NULL)
-      result = g_strdup (new);
-    g_free (new);
-    g_free (parent);
-  }
-
-  return result;
-}
-
 /*
  * So, devices can be symlinks and that screws up.
  */
 
+const int MAX_LINK_LEVEL=8;
+
 static char *
 get_device (const char *device,
 	    GError     **error)
 {
-  char *buf;
-  char *dev = g_strdup (device);
-  struct stat st;
-
-  while (1) {
-    char *new;
-
-    if (lstat (dev, &st) != 0) {
-      g_set_error (error, 0, 0,
-          _("Failed to find real device node for %s: %s"),
-          dev, g_strerror (errno));
-      g_free (dev);
-      return NULL;
-    }
-
-    if (!S_ISLNK (st.st_mode))
-      break;
+        gint link_count;
+        GnomeVFSFileInfo *info;
+        char *followed;
+
+        g_return_val_if_fail (device != NULL, NULL);
+
+        info = gnome_vfs_file_info_new ();
+        gnome_vfs_get_file_info (device, info, GNOME_VFS_FILE_INFO_DEFAULT);
+
+        if (info->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) {
+                gnome_vfs_file_info_unref (info);
+                return g_strdup (device);
+        }
+
+        link_count = 0;
+        followed = g_strdup (device);
+        while (link_count < MAX_LINK_LEVEL) {
+                GnomeVFSURI *vfs_uri;
+                GnomeVFSURI *new_vfs_uri;
+                char *escaped_path;
+
+                vfs_uri = gnome_vfs_uri_new (followed);
+                escaped_path = gnome_vfs_escape_path_string (info->symlink_name);
+                new_vfs_uri = gnome_vfs_uri_resolve_relative (vfs_uri,
+                                                              escaped_path);
+                g_free (escaped_path);
+
+                g_free (followed);
+                followed = gnome_vfs_uri_to_string (new_vfs_uri,
+                                                    GNOME_VFS_URI_HIDE_NONE);
+                link_count++;
+
+                gnome_vfs_uri_unref (new_vfs_uri);
+                gnome_vfs_uri_unref (vfs_uri);
+
+                gnome_vfs_file_info_clear (info);
+                gnome_vfs_get_file_info (followed, info,
+                                         GNOME_VFS_FILE_INFO_DEFAULT);
+
+                if (info->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) {
+                        gnome_vfs_file_info_unref (info);
+                        return followed;
+                }
+        }
+
+        /* Too many symlinks */
+	g_set_error (error, 0, 0,
+		_("Too many symlinks to follow for %s"),
+		device);
 
-    if (!(buf = g_file_read_link (dev, NULL))) {
-      g_set_error (error, 0, 0,
-          _("Failed to read symbolic link %s: %s"),
-          dev, g_strerror (errno));
-      g_free (dev);
-      return NULL;
-    }
-    new = totem_disc_resolve_link (dev, buf);
-    g_free (dev);
-    g_free (buf);
-    dev = new;
-  }
+        gnome_vfs_file_info_unref (info);
 
-  return dev;
+        return NULL;
+  
 }
 
 static gboolean
@@ -287,7 +283,9 @@ cd_cache_new (const char *dev,
   char *mountpoint = NULL, *device, *local;
   GnomeVFSVolumeMonitor *mon;
   GnomeVFSDrive *drive = NULL;
+#ifdef HAVE_HAL
   LibHalContext *ctx = NULL;
+#endif
   gboolean found;
 
   if (g_str_has_prefix (dev, "file://") != FALSE)
@@ -340,7 +338,9 @@ cd_cache_new (const char *dev,
   cache->self_mounted = FALSE;
   cache->drive = drive;
   cache->is_media = TRUE;
+#ifdef HAVE_HAL
   cache->ctx = ctx;
+#endif
 
   return cache;
 }
