diff options
| author | 2009-07-25 03:46:54 +0200 | |
|---|---|---|
| committer | 2009-07-25 03:46:54 +0200 | |
| commit | 0e255cfe381caedf0375e6834021333d971f8050 (patch) | |
| tree | a9c5bcffb2a7cea2e037dad1513a502ffab7df28 | |
| parent | 8415e1f13dfc8c31fe4d1ff695af26189297795b (diff) | |
| download | libimobiledevice-0e255cfe381caedf0375e6834021333d971f8050.tar.gz libimobiledevice-0e255cfe381caedf0375e6834021333d971f8050.tar.bz2 | |
Implement afc_file_tell() and adjust afc_receive_data() to handle it
| -rw-r--r-- | dev/afccheck.c | 9 | ||||
| -rw-r--r-- | include/libiphone/afc.h | 1 | ||||
| -rw-r--r-- | src/AFC.c | 45 | 
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)  	int *buf = (int *) malloc(buffersize);  	int *buf2 = (int *) malloc(buffersize);  	unsigned int bytes = 0; +	uint64_t position = 0; +	  	//fill buffer  	int i = 0;  	for (i = 0; i < BUFFER_SIZE; i++) { @@ -65,9 +67,12 @@ void check_afc(gpointer data)  	//now read it  	bytes = 0;  	afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); -	afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); +	afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes); +	afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes); +	if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position)) +		printf("Tell operation failed\n");  	afc_file_close(((param *) data)->afc, file); -	if (bytes != buffersize) +	if (position != buffersize)  		printf("Read operation failed\n");  	//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  afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes);  afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes);  afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position);  afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize);  afc_error_t afc_remove_path(afc_client_t client, const char *path);  afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); @@ -329,6 +329,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *  	} else if (header.operation == AFC_OP_FILE_OPEN_RES) {  		/* file handle response */  		log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); +	} else if (header.operation == AFC_OP_FILE_TELL_RES) { +		/* tell response */ +		log_debug_msg("%s: got a tell response, position=%lld\n", __func__, param1);  	} else {  		/* unknown operation code received */  		free(*dump_here); @@ -986,8 +989,46 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,  	afc_unlock(client); -	if (bytes < 0) { -		return IPHONE_E_AFC_ERROR; +	return ret; +} + +/** Returns current position in a pre-opened file on the phone. + *  + * @param client The client to use. + * @param handle File handle of a previously opened file. + * @param position Position in bytes of indicator + *  + * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. + */ +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) +{ +	char *buffer = (char *) malloc(sizeof(char) * 8); +	int bytes = 0; +	afc_error_t ret = AFC_E_UNKNOWN_ERROR; + +	if (!client || (handle == 0)) +		return AFC_E_INVALID_ARGUMENT; + +	afc_lock(client); + +	// Send the command +	memcpy(buffer, &handle, sizeof(uint64_t));	// handle +	client->afc_packet->operation = AFC_OP_FILE_TELL; +	client->afc_packet->this_length = client->afc_packet->entire_length = 0; +	bytes = afc_dispatch_packet(client, buffer, 8); +	free(buffer); +	buffer = NULL; + +	if (bytes <= 0) { +		afc_unlock(client); +		return AFC_E_NOT_ENOUGH_DATA; +	} + +	// Receive the data +	ret = afc_receive_data(client, &buffer, &bytes); +	if (bytes > 0 && buffer) { +		/* Get the position */ +		memcpy(position, buffer, sizeof(uint64_t));  	}  	if (buffer)  		free(buffer); | 
