static void g_local_file_monitor_mounts_changed (GUnixMountMonitor *mount_monitor, gpointer user_data) { GLocalFileMonitor *local_monitor = user_data; GUnixMountEntry *mount; gboolean is_mounted; GFile *file; /* Emulate unmount detection */ mount = g_unix_mount_at (local_monitor->source->dirname, NULL); is_mounted = mount != NULL; if (mount) g_unix_mount_free (mount); if (local_monitor->was_mounted != is_mounted) { if (local_monitor->was_mounted && !is_mounted) { file = g_file_new_for_path (local_monitor->source->dirname); g_file_monitor_emit_event (G_FILE_MONITOR (local_monitor), file, NULL, G_FILE_MONITOR_EVENT_UNMOUNTED); g_object_unref (file); } local_monitor->was_mounted = is_mounted; } }
static GObject * g_local_directory_monitor_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GObject *obj; GLocalDirectoryMonitorClass *klass; GObjectClass *parent_class; GLocalDirectoryMonitor *local_monitor; const gchar *dirname = NULL; gint i; klass = G_LOCAL_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_DIRECTORY_MONITOR)); parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); obj = parent_class->constructor (type, n_construct_properties, construct_properties); local_monitor = G_LOCAL_DIRECTORY_MONITOR (obj); for (i = 0; i < n_construct_properties; i++) { if (strcmp ("dirname", g_param_spec_get_name (construct_properties[i].pspec)) == 0) { g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value)); dirname = g_value_get_string (construct_properties[i].value); break; } } local_monitor->dirname = g_strdup (dirname); if (!klass->mount_notify) { #ifdef G_OS_WIN32 /*claim everything was mounted */ local_monitor->was_mounted = TRUE; #else GUnixMountEntry *mount; /* Emulate unmount detection */ mount = g_unix_mount_at (local_monitor->dirname, NULL); local_monitor->was_mounted = mount != NULL; if (mount) g_unix_mount_free (mount); local_monitor->mount_monitor = g_unix_mount_monitor_new (); g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed", G_CALLBACK (mounts_changed), local_monitor, 0); #endif } return obj; }
static VALUE unixmount_at(G_GNUC_UNUSED VALUE self, VALUE mount_path) { guint64 time_read; GUnixMountEntry *mount; mount = g_unix_mount_at(RVAL2CSTR(mount_path), &time_read); return rb_assoc_new(GUNIXMOUNTENTRY2RVAL(mount), GUINT642RVAL(time_read)); }
static GMount * get_mount_for_mount_path (const char *mount_path, GCancellable *cancellable) { GUnixMountEntry *mount_entry; GUnixMount *mount; mount_entry = g_unix_mount_at (mount_path, NULL); if (!mount_entry) return NULL; /* TODO: Set mountable volume? */ mount = _g_unix_mount_new (NULL, mount_entry, NULL); g_unix_mount_free (mount_entry); return G_MOUNT (mount); }
static void mounts_changed (GUnixMountMonitor *mount_monitor, gpointer user_data) { GLocalDirectoryMonitor *local_monitor = user_data; GUnixMountEntry *mount; gboolean is_mounted; GFile *file; /* Emulate unmount detection */ #ifdef G_OS_WIN32 mount = NULL; /*claim everything was mounted */ is_mounted = TRUE; #else mount = g_unix_mount_at (local_monitor->dirname, NULL); is_mounted = mount != NULL; if (mount) g_unix_mount_free (mount); #endif if (local_monitor->was_mounted != is_mounted) { if (local_monitor->was_mounted && !is_mounted) { file = g_file_new_for_path (local_monitor->dirname); g_file_monitor_emit_event (G_FILE_MONITOR (local_monitor), file, NULL, G_FILE_MONITOR_EVENT_UNMOUNTED); g_object_unref (file); } local_monitor->was_mounted = is_mounted; } }
static gchar * mount_guess_content_type (GMount *mount, gboolean *is_optical, gboolean *is_multimedia, gboolean *is_blank) { gchar *content_type = NULL; gchar **guess_type; *is_optical = FALSE; *is_multimedia = FALSE; *is_blank = FALSE; /* This function has 2 purposes: * * 1. Detect if we are using optical media * 2. Detect if we are video or music, we can't index those types * * We try to determine the content type because we don't want * to store Volume information in Tracker about DVDs and media * which has no real data for us to mine. * * Generally, if is_multimedia is TRUE then we end up ignoring * the media. */ guess_type = g_mount_guess_content_type_sync (mount, TRUE, NULL, NULL); if (guess_type) { gint i = 0; while (!content_type && guess_type[i]) { if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) { /* Images */ content_type = g_strdup (guess_type[i]); } else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") || !g_strcmp0 (guess_type[i], "x-content/video-dvd") || !g_strcmp0 (guess_type[i], "x-content/video-hddvd") || !g_strcmp0 (guess_type[i], "x-content/video-svcd") || !g_strcmp0 (guess_type[i], "x-content/video-vcd")) { /* Videos */ *is_multimedia = TRUE; content_type = g_strdup (guess_type[i]); } else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") || !g_strcmp0 (guess_type[i], "x-content/audio-dvd") || !g_strcmp0 (guess_type[i], "x-content/audio-player")) { /* Audios */ *is_multimedia = TRUE; content_type = g_strdup (guess_type[i]); } else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") || !g_strcmp0 (guess_type[i], "x-content/blank-cd") || !g_strcmp0 (guess_type[i], "x-content/blank-dvd") || !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) { /* Blank */ *is_blank = TRUE; content_type = g_strdup (guess_type[i]); } else if (!g_strcmp0 (guess_type[i], "x-content/software") || !g_strcmp0 (guess_type[i], "x-content/unix-software") || !g_strcmp0 (guess_type[i], "x-content/win32-software")) { /* NOTE: This one is a guess, can we * have this content type on * none-optical mount points? */ content_type = g_strdup (guess_type[i]); } else { /* else, keep on with the next guess, if any */ i++; } } /* If we didn't have an exact match on possible guessed content types, * then use the first one returned (best guess always first) if any */ if (!content_type && guess_type[0]) { content_type = g_strdup (guess_type[0]); } g_strfreev (guess_type); } if (content_type) { if (strstr (content_type, "vcd") || strstr (content_type, "cdda") || strstr (content_type, "dvd") || strstr (content_type, "bluray")) { *is_optical = TRUE; } } else { GUnixMountEntry *entry; gchar *mount_path; GFile *mount_root; /* No content type was guessed, try to find out * at least whether it's an optical media or not */ mount_root = g_mount_get_root (mount); mount_path = g_file_get_path (mount_root); /* FIXME: Try to assume we have a unix mount :( * EEK, once in a while, I have to write crack, oh well */ if (mount_path && (entry = g_unix_mount_at (mount_path, NULL)) != NULL) { const gchar *filesystem_type; gchar *device_path = NULL; GVolume *volume; volume = g_mount_get_volume (mount); filesystem_type = g_unix_mount_get_fs_type (entry); g_debug (" Using filesystem type:'%s'", filesystem_type); /* Volume may be NULL */ if (volume) { device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_debug (" Using device path:'%s'", device_path); g_object_unref (volume); } /* NOTE: This code was taken from guess_mount_type() * in GIO's gunixmounts.c and adapted purely for * guessing optical media. We don't use the guessing * code for other types such as MEMSTICKS, ZIPs, * IPODs, etc. * * This code may need updating over time since it is * very situational depending on how distributions * mount their devices and how devices are named in * /dev. */ if (strcmp (filesystem_type, "udf") == 0 || strcmp (filesystem_type, "iso9660") == 0 || strcmp (filesystem_type, "cd9660") == 0 || (device_path && (g_str_has_prefix (device_path, "/dev/cdrom") || g_str_has_prefix (device_path, "/dev/acd") || g_str_has_prefix (device_path, "/dev/cd")))) { *is_optical = TRUE; } else if (device_path && g_str_has_prefix (device_path, "/vol/")) { const gchar *name; name = mount_path + strlen ("/"); if (g_str_has_prefix (name, "cdrom")) { *is_optical = TRUE; } } else { gchar *basename = g_path_get_basename (mount_path); if (g_str_has_prefix (basename, "cdr") || g_str_has_prefix (basename, "cdwriter") || g_str_has_prefix (basename, "burn") || g_str_has_prefix (basename, "dvdr")) { *is_optical = TRUE; } g_free (basename); } g_free (device_path); g_free (mount_path); g_unix_mount_free (entry); } else { g_debug (" No GUnixMountEntry found, needed for detecting if optical media... :("); g_free (mount_path); } g_object_unref (mount_root); } return content_type; }
static gboolean ldsm_check_all_mounts (gpointer data) { GList *mounts; GList *l; GList *check_mounts = NULL; GList *full_mounts = NULL; guint number_of_mounts; guint number_of_full_mounts; gboolean multiple_volumes = FALSE; gboolean other_usable_volumes = FALSE; /* We iterate through the static mounts in /etc/fstab first, seeing if * they're mounted by checking if the GUnixMountPoint has a corresponding GUnixMountEntry. * Iterating through the static mounts means we automatically ignore dynamically mounted media. */ mounts = g_unix_mount_points_get (time_read); for (l = mounts; l != NULL; l = l->next) { GUnixMountPoint *mount_point = l->data; GUnixMountEntry *mount; LdsmMountInfo *mount_info; const gchar *path; path = g_unix_mount_point_get_mount_path (mount_point); mount = g_unix_mount_at (path, time_read); g_unix_mount_point_free (mount_point); if (mount == NULL) { /* The GUnixMountPoint is not mounted */ continue; } mount_info = g_new0 (LdsmMountInfo, 1); mount_info->mount = mount; path = g_unix_mount_get_mount_path (mount); if (g_unix_mount_is_readonly (mount)) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_should_ignore (mount)) { ldsm_free_mount_info (mount_info); continue; } if (statvfs (path, &mount_info->buf) != 0) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_is_virtual (mount_info)) { ldsm_free_mount_info (mount_info); continue; } check_mounts = g_list_prepend (check_mounts, mount_info); } g_list_free (mounts); number_of_mounts = g_list_length (check_mounts); if (number_of_mounts > 1) multiple_volumes = TRUE; for (l = check_mounts; l != NULL; l = l->next) { LdsmMountInfo *mount_info = l->data; if (!ldsm_mount_has_space (mount_info)) { full_mounts = g_list_prepend (full_mounts, mount_info); } else { g_hash_table_remove (ldsm_notified_hash, g_unix_mount_get_mount_path (mount_info->mount)); ldsm_free_mount_info (mount_info); } } number_of_full_mounts = g_list_length (full_mounts); if (number_of_mounts > number_of_full_mounts) other_usable_volumes = TRUE; ldsm_maybe_warn_mounts (full_mounts, multiple_volumes, other_usable_volumes); g_list_free (check_mounts); g_list_free (full_mounts); return TRUE; }