/* Since the mount point is used by two separate threads, it can only be accessed securely by using a locking mechanism. Therefore we keep a copy of the mount point here. Access must only be done after locking. */ void space_set_ipod_itdb(iTunesDB *itdb) { const gchar *mp = NULL; if (itdb) { ExtraiTunesDBData *eitdb = itdb->userdata; g_return_if_fail (eitdb); if (!eitdb->ipod_ejected) { mp = itdb_get_mountpoint(itdb); } } if (space_mutex) g_mutex_lock (space_mutex); space_itdb = itdb; /* update the free space data if mount point changed */ if (!space_mp || !mp || (strcmp(space_mp, mp) != 0)) { g_free(space_mp); space_mp = g_strdup(mp); space_data_update(); } if (space_mutex) g_mutex_unlock (space_mutex); }
const char * rb_ipod_db_get_mount_path (RbIpodDb *ipod_db) { RbIpodDbPrivate *priv = IPOD_DB_GET_PRIVATE (ipod_db); return itdb_get_mountpoint (priv->itdb); }
G_GNUC_INTERNAL int ipod_write_artwork_db (Itdb_iTunesDB *itdb) { iPodBuffer *buf; int bytes_written; char *filename; int id_max; Itdb_DB db; int status; db.db_type = DB_TYPE_ITUNES; db.db.itdb = itdb; id_max = itdb_prepare_thumbnails (itdb); /* First, let's write the .ithmb files, this will create the * various thumbnails as well */ status = itdb_write_ithumb_files (&db); if (status != 0) { return -1; } filename = ipod_db_get_artwork_db_path (itdb_get_mountpoint (itdb)); if (filename == NULL) { /* FIXME: the iTunesDB will be inconsistent wrt artwork_count * it might be better to 0 out this field in all tracks * when we encounter an error */ return -1; } buf = ipod_buffer_new (filename, itdb->device->byte_order, DB_TYPE_ITUNES); if (buf == NULL) { g_print ("Couldn't create %s\n", filename); g_free (filename); return -1; } bytes_written = write_mhfd (&db, buf, id_max); /* Refcount of the shared buffer should drop to 0 and this should * sync buffered data to disk */ ipod_buffer_destroy (buf); if (bytes_written == -1) { g_print ("Failed to save %s\n", filename); /* FIXME: maybe should unlink the file we may have created */ g_free (filename); return -1; } g_free (filename); return 0; }