OLD | NEW |
(Empty) | |
| 1 diff --git src/libmtp.c src/libmtp.c |
| 2 index b91f246..bbe2642 100644 |
| 3 --- src/libmtp.c |
| 4 +++ src/libmtp.c |
| 5 @@ -4415,6 +4415,78 @@ LIBMTP_file_t * LIBMTP_Get_Files_And_Folders(LIBMTP_mtpde
vice_t *device, |
| 6 return retfiles; |
| 7 } |
| 8 |
| 9 +/** |
| 10 + * This function retrieves the list of ids of files and folders in a certain |
| 11 + * folder with id parent on a certain storage on a certain device. |
| 12 + * The device used with this operations must have been opened with |
| 13 + * LIBMTP_Open_Raw_Device_Uncached() or it will fail. |
| 14 + * |
| 15 + * NOTE: the request will always perform I/O with the device. |
| 16 + * @param device a pointer to the MTP device to report info from. |
| 17 + * @param storage a storage on the device to report info from. If |
| 18 + * 0 is passed in, the files for the given parent will be |
| 19 + * searched across all available storages. |
| 20 + * @param parent the parent folder id. |
| 21 + * @param out the pointer where the array of ids is returned. It is |
| 22 + * set only when the returned value > 0. The caller takes the |
| 23 + * ownership of the array and has to free() it. |
| 24 + * @return the length of the returned array or -1 in case of failure. |
| 25 + */ |
| 26 + |
| 27 +int LIBMTP_Get_Children(LIBMTP_mtpdevice_t *device, |
| 28 + uint32_t const storage, |
| 29 + uint32_t const parent, |
| 30 + uint32_t **out) |
| 31 +{ |
| 32 + PTPParams *params = (PTPParams *) device->params; |
| 33 + PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; |
| 34 + LIBMTP_file_t *retfiles = NULL; |
| 35 + LIBMTP_file_t *curfile = NULL; |
| 36 + PTPObjectHandles currentHandles; |
| 37 + uint32_t storageid; |
| 38 + uint16_t ret; |
| 39 + int i = 0; |
| 40 + |
| 41 + if (device->cached) { |
| 42 + // This function is only supposed to be used by devices |
| 43 + // opened as uncached! |
| 44 + LIBMTP_ERROR("tried to use %s on a cached device!\n", __func__); |
| 45 + return -1; |
| 46 + } |
| 47 + |
| 48 + if (FLAG_BROKEN_GET_OBJECT_PROPVAL(ptp_usb)) { |
| 49 + // These devices cannot handle the commands needed for |
| 50 + // Uncached access! |
| 51 + LIBMTP_ERROR("tried to use %s on an unsupported device, " |
| 52 + "this command does not work on all devices " |
| 53 + "due to missing low-level support to read " |
| 54 + "information on individual tracks\n", |
| 55 + __func__); |
| 56 + return -1; |
| 57 + } |
| 58 + |
| 59 + if (storage == 0) |
| 60 + storageid = PTP_GOH_ALL_STORAGE; |
| 61 + else |
| 62 + storageid = storage; |
| 63 + |
| 64 + ret = ptp_getobjecthandles(params, |
| 65 + storageid, |
| 66 + PTP_GOH_ALL_FORMATS, |
| 67 + parent, |
| 68 + ¤tHandles); |
| 69 + |
| 70 + if (ret != PTP_RC_OK) { |
| 71 + add_ptp_error_to_errorstack(device, ret, |
| 72 + "LIBMTP_Get_Children(): could not get object handles."); |
| 73 + return -1; |
| 74 + } |
| 75 + |
| 76 + if (currentHandles.Handler == NULL || currentHandles.n == 0) |
| 77 + return 0; |
| 78 + *out = currentHandles.Handler; |
| 79 + return currentHandles.n; |
| 80 +} |
| 81 |
| 82 /** |
| 83 * This creates a new track metadata structure and allocates memory |
| 84 diff --git src/libmtp.h src/libmtp.h |
| 85 index 33fac41..f923cc1 100644 |
| 86 --- src/libmtp.h |
| 87 +++ src/libmtp.h |
| 88 @@ -875,6 +875,10 @@ LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_
mtpdevice_t *, |
| 89 LIBMTP_file_t * LIBMTP_Get_Files_And_Folders(LIBMTP_mtpdevice_t *, |
| 90 uint32_t const, |
| 91 uint32_t const); |
| 92 +int LIBMTP_Get_Children(LIBMTP_mtpdevice_t *, |
| 93 + uint32_t const, |
| 94 + uint32_t const, |
| 95 + uint32_t **); |
| 96 LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); |
| 97 int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, |
| 98 unsigned char**, uint32_t*); |
| 99 diff --git src/libmtp.h.in src/libmtp.h.in |
| 100 index b49d449..2b2f0bb 100644 |
| 101 --- src/libmtp.h.in |
| 102 +++ src/libmtp.h.in |
| 103 @@ -875,6 +875,10 @@ LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_
mtpdevice_t *, |
| 104 LIBMTP_file_t * LIBMTP_Get_Files_And_Folders(LIBMTP_mtpdevice_t *, |
| 105 uint32_t const, |
| 106 uint32_t const); |
| 107 +int LIBMTP_Get_Children(LIBMTP_mtpdevice_t *, |
| 108 + uint32_t const, |
| 109 + uint32_t const, |
| 110 + uint32_t**); |
| 111 LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); |
| 112 int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, |
| 113 unsigned char**, uint32_t*); |
| 114 diff --git src/libmtp.sym src/libmtp.sym |
| 115 index b6951b2..4130fe8 100644 |
| 116 --- src/libmtp.sym |
| 117 +++ src/libmtp.sym |
| 118 @@ -48,6 +48,7 @@ LIBMTP_Get_Filetype_Description |
| 119 LIBMTP_Get_Filelisting |
| 120 LIBMTP_Get_Filelisting_With_Callback |
| 121 LIBMTP_Get_Files_And_Folders |
| 122 +LIBMTP_Get_Children |
| 123 LIBMTP_Get_Filemetadata |
| 124 LIBMTP_Get_File_Chunk |
| 125 LIBMTP_Get_File_To_File |
OLD | NEW |