summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/afccheck.c9
-rw-r--r--include/libiphone/afc.h1
-rw-r--r--src/AFC.c45
3 files changed, 51 insertions, 4 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c
index d06a147..a9b666e 100644
--- a/dev/afccheck.c
+++ b/dev/afccheck.c
@@ -45,6 +45,8 @@ void check_afc(gpointer data)
45 int *buf = (int *) malloc(buffersize); 45 int *buf = (int *) malloc(buffersize);
46 int *buf2 = (int *) malloc(buffersize); 46 int *buf2 = (int *) malloc(buffersize);
47 unsigned int bytes = 0; 47 unsigned int bytes = 0;
48 uint64_t position = 0;
49
48 //fill buffer 50 //fill buffer
49 int i = 0; 51 int i = 0;
50 for (i = 0; i < BUFFER_SIZE; i++) { 52 for (i = 0; i < BUFFER_SIZE; i++) {
@@ -65,9 +67,12 @@ void check_afc(gpointer data)
65 //now read it 67 //now read it
66 bytes = 0; 68 bytes = 0;
67 afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); 69 afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file);
68 afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); 70 afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes);
71 afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes);
72 if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position))
73 printf("Tell operation failed\n");
69 afc_file_close(((param *) data)->afc, file); 74 afc_file_close(((param *) data)->afc, file);
70 if (bytes != buffersize) 75 if (position != buffersize)
71 printf("Read operation failed\n"); 76 printf("Read operation failed\n");
72 77
73 //compare buffers 78 //compare buffers
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h
index 18bf32d..08122a1 100644
--- a/include/libiphone/afc.h
+++ b/include/libiphone/afc.h
@@ -96,6 +96,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
96afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); 96afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes);
97afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); 97afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes);
98afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); 98afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence);
99afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position);
99afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); 100afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize);
100afc_error_t afc_remove_path(afc_client_t client, const char *path); 101afc_error_t afc_remove_path(afc_client_t client, const char *path);
101afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); 102afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to);
diff --git a/src/AFC.c b/src/AFC.c
index 87ce78e..6a6d3f2 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -329,6 +329,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
329 } else if (header.operation == AFC_OP_FILE_OPEN_RES) { 329 } else if (header.operation == AFC_OP_FILE_OPEN_RES) {
330 /* file handle response */ 330 /* file handle response */
331 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); 331 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1);
332 } else if (header.operation == AFC_OP_FILE_TELL_RES) {
333 /* tell response */
334 log_debug_msg("%s: got a tell response, position=%lld\n", __func__, param1);
332 } else { 335 } else {
333 /* unknown operation code received */ 336 /* unknown operation code received */
334 free(*dump_here); 337 free(*dump_here);
@@ -986,8 +989,46 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
986 989
987 afc_unlock(client); 990 afc_unlock(client);
988 991
989 if (bytes < 0) { 992 return ret;
990 return IPHONE_E_AFC_ERROR; 993}
994
995/** Returns current position in a pre-opened file on the phone.
996 *
997 * @param client The client to use.
998 * @param handle File handle of a previously opened file.
999 * @param position Position in bytes of indicator
1000 *
1001 * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure.
1002 */
1003afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)
1004{
1005 char *buffer = (char *) malloc(sizeof(char) * 8);
1006 int bytes = 0;
1007 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1008
1009 if (!client || (handle == 0))
1010 return AFC_E_INVALID_ARGUMENT;
1011
1012 afc_lock(client);
1013
1014 // Send the command
1015 memcpy(buffer, &handle, sizeof(uint64_t)); // handle
1016 client->afc_packet->operation = AFC_OP_FILE_TELL;
1017 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1018 bytes = afc_dispatch_packet(client, buffer, 8);
1019 free(buffer);
1020 buffer = NULL;
1021
1022 if (bytes <= 0) {
1023 afc_unlock(client);
1024 return AFC_E_NOT_ENOUGH_DATA;
1025 }
1026
1027 // Receive the data
1028 ret = afc_receive_data(client, &buffer, &bytes);
1029 if (bytes > 0 && buffer) {
1030 /* Get the position */
1031 memcpy(position, buffer, sizeof(uint64_t));
991 } 1032 }
992 if (buffer) 1033 if (buffer)
993 free(buffer); 1034 free(buffer);