Add a new interface for getting the folder list for a certain
storage, useful in file handling:
LIBMTP_Get_Folder_List_For_Storage()
diff --git a/examples/filetree.c b/examples/filetree.c
index 880369f..dcfea7e 100644
--- a/examples/filetree.c
+++ b/examples/filetree.c
@@ -140,7 +140,7 @@
/* Loop over storages */
for (storage = device->storage; storage != 0; storage = storage->next) {
- fprintf(stdout, " Storage: %s\n", storage->StorageDescription);
+ fprintf(stdout, "Storage: %s\n", storage->StorageDescription);
recursive_file_tree(device, storage, 0, 0);
}
diff --git a/examples/folders.c b/examples/folders.c
index 5aeaee0..14c285d 100644
--- a/examples/folders.c
+++ b/examples/folders.c
@@ -42,7 +42,6 @@
int main (int argc, char **argv)
{
LIBMTP_mtpdevice_t *device, *iter;
- LIBMTP_folder_t *folders;
LIBMTP_Init();
printf("Attempting to connect device(s)\n");
@@ -50,7 +49,7 @@
switch(LIBMTP_Get_Connected_Devices(&device))
{
case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
- printf("mtp-folders: No Devices have been found\n");
+ printf("mtp-folders: no devices found\n");
return 0;
case LIBMTP_ERROR_CONNECTING:
fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n");
@@ -74,7 +73,9 @@
/* iterate through connected MTP devices */
for(iter = device; iter != NULL; iter = iter->next)
{
+ LIBMTP_devicestorage_t *storage;
char *friendlyname;
+ int ret;
/* Echo the friendly name so we know which device we are working with */
friendlyname = LIBMTP_Get_Friendlyname(iter);
@@ -86,19 +87,33 @@
}
LIBMTP_Dump_Errorstack(iter);
- LIBMTP_Clear_Errorstack(iter); /* Get folder listing */
+ LIBMTP_Clear_Errorstack(iter);
- folders = LIBMTP_Get_Folder_List(iter);
-
- if (folders == NULL) {
- fprintf(stdout, "No folders found\n");
+ /* Get all storages for this device */
+ ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
+ if (ret != 0) {
+ perror("LIBMTP_Get_Storage()\n");
LIBMTP_Dump_Errorstack(iter);
LIBMTP_Clear_Errorstack(iter);
- } else {
- dump_folder_list(folders,0);
+ continue;
}
- LIBMTP_destroy_folder_t(folders);
+ /* Loop over storages, dump folder for each one */
+ for (storage = device->storage; storage != 0; storage = storage->next) {
+ LIBMTP_folder_t *folders;
+
+ printf("Storage: %s\n", storage->StorageDescription);
+ folders = LIBMTP_Get_Folder_List_For_Storage(iter, storage->id);
+
+ if (folders == NULL) {
+ fprintf(stdout, "No folders found\n");
+ LIBMTP_Dump_Errorstack(iter);
+ LIBMTP_Clear_Errorstack(iter);
+ } else {
+ dump_folder_list(folders,0);
+ }
+ LIBMTP_destroy_folder_t(folders);
+ }
}
LIBMTP_Release_Device_List(device);
diff --git a/src/libmtp.c b/src/libmtp.c
index 7f30025..49d7df0 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -4055,7 +4055,7 @@
* NOTE: the request will always perform I/O with the device.
* @param device a pointer to the MTP device to report info from.
* @param storage a storage on the device to report info from. If
- * NULL is passed in, the files for the given parent will be
+ * 0 is passed in, the files for the given parent will be
* searched across all available storages.
* @param parent the parent folder id.
*/
@@ -4079,7 +4079,7 @@
return NULL;
}
- if (storage == NULL)
+ if (storage == 0)
storageid = PTP_GOH_ALL_STORAGE;
else
storageid = storage;
@@ -6760,9 +6760,11 @@
* on the current MTP device.
*
* @param device a pointer to the device to get the folder listing for.
+ * @param storage a storage ID to get the folder list from
* @return a list of folders
*/
-LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t *device)
+ LIBMTP_folder_t *LIBMTP_Get_Folder_List_For_Storage(LIBMTP_mtpdevice_t *device,
+ uint32_t const storage)
{
PTPParams *params = (PTPParams *) device->params;
LIBMTP_folder_t head, *rv;
@@ -6795,6 +6797,11 @@
if (ob->oi.ObjectFormat != PTP_OFC_Association) {
continue;
}
+
+ if (storage != PTP_GOH_ALL_STORAGE && storage != ob->oi.StorageID) {
+ continue;
+ }
+
/*
* Do we know how to handle these? They are part
* of the MTP 1.0 specification paragraph 3.6.4.
@@ -6825,7 +6832,7 @@
head.sibling = folder;
}
- // We begin at the root folder and get them all recursively
+ // We begin at the given root folder and get them all recursively
rv = get_subfolders_for_folder(&head, 0x00000000U);
// Some buggy devices may have some files in the "root folder"
@@ -6856,6 +6863,18 @@
}
/**
+ * This returns a list of all folders available
+ * on the current MTP device.
+ *
+ * @param device a pointer to the device to get the folder listing for.
+ * @return a list of folders
+ */
+LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t *device)
+{
+ return LIBMTP_Get_Folder_List_For_Storage(device, PTP_GOH_ALL_STORAGE);
+}
+
+/**
* This create a folder on the current MTP device. The PTP name
* for a folder is "association". The PTP/MTP devices does not
* have an internal "folder" concept really, it contains a flat
diff --git a/src/libmtp.h.in b/src/libmtp.h.in
index 5520ab7..293ff9c 100644
--- a/src/libmtp.h.in
+++ b/src/libmtp.h.in
@@ -952,6 +952,8 @@
LIBMTP_folder_t *LIBMTP_new_folder_t(void);
void LIBMTP_destroy_folder_t(LIBMTP_folder_t*);
LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t*);
+LIBMTP_folder_t *LIBMTP_Get_Folder_List_For_Storage(LIBMTP_mtpdevice_t*,
+ uint32_t const);
LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t*, uint32_t const);
uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t*, char *, uint32_t, uint32_t);
int LIBMTP_Set_Folder_Name(LIBMTP_mtpdevice_t *, LIBMTP_folder_t *, const char *);
diff --git a/src/libmtp.sym b/src/libmtp.sym
index 55d5a00..9b37b3a 100644
--- a/src/libmtp.sym
+++ b/src/libmtp.sym
@@ -73,6 +73,7 @@
LIBMTP_new_folder_t
LIBMTP_destroy_folder_t
LIBMTP_Get_Folder_List
+LIBMTP_Get_Folder_List_For_Storage
LIBMTP_Find_Folder
LIBMTP_Create_Folder
LIBMTP_new_playlist_t