summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-03-21 22:54:08 +0100
committerGravatar Nikias Bassen2014-03-21 22:54:08 +0100
commit7320497d00fde338f795e8caa8ebdb24cff2ee7d (patch)
tree1b8a43405a304c263bcd4f6cbe2d6ff4f091c65e /src
parent6274a11918e5c327f46d02756869de9701b6c598 (diff)
downloadlibimobiledevice-7320497d00fde338f795e8caa8ebdb24cff2ee7d.tar.gz
libimobiledevice-7320497d00fde338f795e8caa8ebdb24cff2ee7d.tar.bz2
afc: Remove segmentation code from afc_file_read()
Diffstat (limited to 'src')
-rw-r--r--src/afc.c85
1 files changed, 34 insertions, 51 deletions
diff --git a/src/afc.c b/src/afc.c
index 41a4e62..5b61ba7 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -32,9 +32,6 @@
#include "common/debug.h"
#include "endianness.h"
-/** The maximum size an AFC data packet can be */
-static const int MAXIMUM_PACKET_SIZE = (2 << 15);
-
/**
* Locks an AFC client, done for thread safety stuff
*
@@ -309,11 +306,6 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t
entire_len = (uint32_t)header.entire_length - sizeof(AFCPacket);
this_len = (uint32_t)header.this_length - sizeof(AFCPacket);
- /* this is here as a check (perhaps a different upper limit is good?) */
- if (entire_len > (uint32_t)MAXIMUM_PACKET_SIZE) {
- fprintf(stderr, "%s: entire_len is larger than MAXIMUM_PACKET_SIZE, (%d > %d)!", __func__, entire_len, MAXIMUM_PACKET_SIZE);
- }
-
dump_here = (char*)malloc(entire_len);
if (this_len > 0) {
service_receive(client->parent, dump_here, this_len, bytes_recv);
@@ -795,7 +787,6 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
{
char *input = NULL;
uint32_t current_count = 0, bytes_loc = 0;
- const uint32_t MAXIMUM_READ_SIZE = 1 << 16;
afc_error_t ret = AFC_E_SUCCESS;
if (!client || !client->afc_packet || !client->parent || handle == 0)
@@ -804,50 +795,42 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
afc_lock(client);
- /* Looping here to get around the maximum amount of data that
- afc_receive_data can handle */
- while (current_count < length) {
- debug_info("current count is %i but length is %i", current_count, length);
-
- /* Send the read command */
- struct {
- uint64_t handle;
- uint64_t size;
- } readinfo;
- readinfo.handle = handle;
- readinfo.size = htole64(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE);
- ret = afc_dispatch_packet(client, AFC_OP_READ, (const char*)&readinfo, sizeof(readinfo), NULL, 0, &bytes_loc);
-
- if (ret != AFC_E_SUCCESS) {
- afc_unlock(client);
- return AFC_E_NOT_ENOUGH_DATA;
- }
- /* Receive the data */
- ret = afc_receive_data(client, &input, &bytes_loc);
- debug_info("afc_receive_data returned error: %d", ret);
- debug_info("bytes returned: %i", bytes_loc);
- if (ret != AFC_E_SUCCESS) {
- afc_unlock(client);
- return ret;
- } else if (bytes_loc == 0) {
- if (input)
- free(input);
- afc_unlock(client);
- *bytes_read = current_count;
- /* FIXME: check that's actually a success */
- return ret;
- } else {
- if (input) {
- debug_info("%d", bytes_loc);
- memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
- free(input);
- input = NULL;
- current_count += (bytes_loc > length) ? length : bytes_loc;
- }
+ /* Send the read command */
+ struct {
+ uint64_t handle;
+ uint64_t size;
+ } readinfo;
+ readinfo.handle = handle;
+ readinfo.size = htole64(length);
+ ret = afc_dispatch_packet(client, AFC_OP_READ, (const char*)&readinfo, sizeof(readinfo), NULL, 0, &bytes_loc);
+
+ if (ret != AFC_E_SUCCESS) {
+ afc_unlock(client);
+ return AFC_E_NOT_ENOUGH_DATA;
+ }
+ /* Receive the data */
+ ret = afc_receive_data(client, &input, &bytes_loc);
+ debug_info("afc_receive_data returned error: %d", ret);
+ debug_info("bytes returned: %i", bytes_loc);
+ if (ret != AFC_E_SUCCESS) {
+ afc_unlock(client);
+ return ret;
+ } else if (bytes_loc == 0) {
+ if (input)
+ free(input);
+ afc_unlock(client);
+ *bytes_read = current_count;
+ /* FIXME: check that's actually a success */
+ return ret;
+ } else {
+ if (input) {
+ debug_info("%d", bytes_loc);
+ memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
+ free(input);
+ input = NULL;
+ current_count += (bytes_loc > length) ? length : bytes_loc;
}
}
- debug_info("returning current_count as %i", current_count);
-
afc_unlock(client);
*bytes_read = current_count;
return ret;