Quantcast
Channel: Debian User Forums
Viewing all articles
Browse latest Browse all 2681

General Questions • Re: [Software] Disk name muddled somehow

$
0
0
Hello,

According to the source code of udisks2 [1], the name of the mount point is the one you are experiencing (partition label followed by a number) if there is another file/directory with the same name as the label you want to mount under the path /media/$USER/ :

Code:

static gchar *calculate_mount_point (UDisksDaemon  *daemon,                       UDisksBlock   *block,                       uid_t          uid,                       gid_t          gid,                       const gchar   *user_name,                       const gchar   *fs_type,                       gboolean      *persistent,                       GError       **error){  UDisksLinuxBlockObject *object = NULL;  gboolean fs_shared = FALSE;  const gchar *label = NULL;  const gchar *uuid = NULL;  gchar *escaped_user_name = NULL;  gchar *mount_dir = NULL;  gchar *mount_point = NULL;  gchar *orig_mount_point;  GString *str;  gchar *s;  guint n;  label = NULL;  uuid = NULL;  if (block != NULL)    {      label = udisks_block_get_id_label (block);      uuid = udisks_block_get_id_uuid (block);    }  object = udisks_daemon_util_dup_object (block, NULL);  if (object != NULL)    {      UDisksLinuxDevice *device = udisks_linux_block_object_get_device (object);      if (device != NULL)        {          if (device->udev_device != NULL)            {              /* TODO: maybe introduce Block:HintFilesystemShared instead of pulling it directly from the udev device */              fs_shared = g_udev_device_get_property_as_boolean (device->udev_device, "UDISKS_FILESYSTEM_SHARED");            }          g_object_unref (device);        }    }  /* If we know the user-name and it doesn't have any '/' character in   * it, mount in MOUNT_BASE/$USER   */  if (!fs_shared && (user_name != NULL && strstr (user_name, "/") == NULL))    {      mount_dir = g_strdup_printf (MOUNT_BASE "/%s", user_name);      *persistent = MOUNT_BASE_PERSISTENT;      if (!g_file_test (mount_dir, G_FILE_TEST_EXISTS))        {          /* First ensure that MOUNT_BASE exists */          if (g_mkdir (MOUNT_BASE, 0755) != 0 && errno != EEXIST)            {              g_set_error (error,                           UDISKS_ERROR,                           UDISKS_ERROR_FAILED,                           "Error creating directory " MOUNT_BASE ": %m");              goto out;            }          /* Then create the per-user MOUNT_BASE/$USER */#ifdef HAVE_ACL          if (g_mkdir (mount_dir, 0700) != 0 && errno != EEXIST)#else          if (g_mkdir (mount_dir, 0750) != 0 && errno != EEXIST)#endif            {              g_set_error (error,                           UDISKS_ERROR,                           UDISKS_ERROR_FAILED,                           "Error creating directory `%s': %m",                           mount_dir);              goto out;            }          /* Finally, add the read+execute ACL for $USER */#ifdef HAVE_ACL          if (!add_acl (mount_dir, uid, error))            {#else          if (chown (mount_dir, -1, gid) == -1)            {               g_set_error (error, G_IO_ERROR,                            g_io_error_from_errno (errno),                            "Failed to change gid to %d for %s: %m",                            (gint) gid, mount_dir);#endif              if (rmdir (mount_dir) != 0)                udisks_warning ("Error calling rmdir() on %s: %m", mount_dir);              goto out;            }        }    }  /* otherwise fall back to mounting in /media */  if (mount_dir == NULL)    {      mount_dir = g_strdup ("/media");      *persistent = TRUE;    }  /* NOTE: UTF-8 has the nice property that valid UTF-8 strings only contains   *       the byte 0x2F if it's for the '/' character (U+002F SOLIDUS).   *   *       See http://en.wikipedia.org/wiki/UTF-8 for details.   */  if (label != NULL && strlen (label) > 0)    {      str = g_string_new (NULL);      g_string_append_printf (str, "%s/", mount_dir);      s = ensure_utf8 (label);      for (n = 0; s[n] != '\0'; n++)        {          gint c = s[n];          if (c == '/')            g_string_append_c (str, '_');          else            g_string_append_c (str, c);        }      mount_point = g_string_free (str, FALSE);      g_free (s);    }  else if (uuid != NULL && strlen (uuid) > 0)    {      str = g_string_new (NULL);      g_string_append_printf (str, "%s/", mount_dir);      s = ensure_utf8 (uuid);      for (n = 0; s[n] != '\0'; n++)        {          gint c = s[n];          if (c == '/')            g_string_append_c (str, '_');          else            g_string_append_c (str, c);        }      mount_point = g_string_free (str, FALSE);      g_free (s);    }  else    {      mount_point = g_strdup_printf ("%s/disk", mount_dir);    }  /* ... then uniqify the mount point */  orig_mount_point = g_strdup (mount_point);  n = 1;  while (TRUE)    {      if (!g_file_test (mount_point, G_FILE_TEST_EXISTS))        {          break;        }      else        {          g_free (mount_point);          mount_point = g_strdup_printf ("%s%u", orig_mount_point, n++);        }    }  g_free (orig_mount_point); out:  g_free (mount_dir);  g_clear_object (&object);  g_free (escaped_user_name);  return mount_point;}
This is the relevant part of the function:

Code:

[..]  /* ... then uniqify the mount point */  orig_mount_point = g_strdup (mount_point);  n = 1;  while (TRUE)    {      if (!g_file_test (mount_point, G_FILE_TEST_EXISTS))        {          break;        }      else        {          g_free (mount_point);          mount_point = g_strdup_printf ("%s%u", orig_mount_point, n++);        }    }[..]
As you can see, the code checks if the directory name is already in use, and if so, adds an integer number starting from 1 to the name of the mount point until it finds an unused file name.

So you can check the contents of /media/$USER before mounting your "Data" disk to see if a similar file or directory already exists, i.e. using the command:

Code:

ls -lR /media/
There may be an old file or directory named "Data".

The same thing happens if the same partition is mounted more than once (without un-mounting it); the first time the mount point will be /media/Data, the second /media/Data1, the third /media/Data2, and so on.

Hope this helps.

--
[1] static gchar * calculate_mount_point( ... )

Statistics: Posted by Aki — 2025-02-20 03:38



Viewing all articles
Browse latest Browse all 2681

Trending Articles