Index: patches/15_read_chunks.diff |
=================================================================== |
--- patches/15_read_chunks.diff (revision 0) |
+++ patches/15_read_chunks.diff (revision 0) |
@@ -0,0 +1,99 @@ |
+Index: src/libmtp.c |
+=================================================================== |
+--- src/libmtp.c (revision 167447) |
++++ src/libmtp.c (working copy) |
+@@ -4972,6 +4972,56 @@ |
+ } |
+ |
+ /** |
++ * This copies a chunk of a file off the device to memory. |
++ * @param device a pointer to the device to get the track from. |
++ * @param id the file ID of the file to retrieve. |
++ * @param offset the offset of the file to read from. |
++ * @param count the amount of data to read. |
++ * @param data a pointer to the data from the device. Must be |
++ * <coded>free()</code>:ed by the caller after use. |
++ * @param datalen the amount of data written to <code>data</code>. |
++ * @return 0 if the transfer was successful, any other value means |
++ * failure. |
++ */ |
++int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t* device, uint32_t id, |
++ uint32_t offset, uint32_t count, |
++ unsigned char** data, uint32_t* datalen) |
++{ |
++ uint16_t ret; |
++ PTPParams *params = (PTPParams *) device->params; |
++ PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; |
++ PTPObject *ob; |
++ |
++ if (!data || !datalen) { |
++ add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk(): Invalid parameter."); |
++ return -1; |
++ } |
++ |
++ ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob); |
++ if (ret != PTP_RC_OK) { |
++ add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk(): Could not get object info."); |
++ return -1; |
++ } |
++ if (ob->oi.ObjectFormat == PTP_OFC_Association) { |
++ add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk(): Bad object format."); |
++ return -1; |
++ } |
++ |
++ ret = ptp_getpartialobject(params, id, offset, count, data, datalen); |
++ |
++ if (ret == PTP_ERROR_CANCEL) { |
++ add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Get_File_Chunk(): Cancelled transfer."); |
++ return -1; |
++ } |
++ if (ret != PTP_RC_OK) { |
++ add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_File_Chunk(): Could not get file from device."); |
++ return -1; |
++ } |
++ |
++ return 0; |
++} |
++ |
++/** |
+ * This is a manual conversion from MTPDataGetFunc to PTPDataGetFunc |
+ * to isolate the internal type. |
+ */ |
+Index: src/libmtp.h |
+=================================================================== |
+--- src/libmtp.h (revision 167447) |
++++ src/libmtp.h (working copy) |
+@@ -876,6 +876,8 @@ |
+ uint32_t const, |
+ uint32_t const); |
+ LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); |
++int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, |
++ unsigned char**, uint32_t*); |
+ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, |
+ LIBMTP_progressfunc_t const, void const * const); |
+ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, |
+Index: src/libmtp.h.in |
+=================================================================== |
+--- src/libmtp.h.in (revision 167447) |
++++ src/libmtp.h.in (working copy) |
+@@ -876,6 +876,8 @@ |
+ uint32_t const, |
+ uint32_t const); |
+ LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); |
++int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, |
++ unsigned char**, uint32_t*); |
+ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, |
+ LIBMTP_progressfunc_t const, void const * const); |
+ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, |
+Index: src/libmtp.sym |
+=================================================================== |
+--- src/libmtp.sym (revision 167447) |
++++ src/libmtp.sym (working copy) |
+@@ -49,6 +49,7 @@ |
+ LIBMTP_Get_Filelisting_With_Callback |
+ LIBMTP_Get_Files_And_Folders |
+ LIBMTP_Get_Filemetadata |
++LIBMTP_Get_File_Chunk |
+ LIBMTP_Get_File_To_File |
+ LIBMTP_Get_File_To_File_Descriptor |
+ LIBMTP_Get_File_To_Handler |