diff options
author | Nikias Bassen | 2009-11-28 04:33:24 +0100 |
---|---|---|
committer | Matt Colyer | 2009-11-30 21:02:41 -0800 |
commit | 7adc81dddd764b0ef76fefd73852b835d3211b9b (patch) | |
tree | 7125966103693842686ff71922dce4459e7c6251 | |
parent | 12a44afce569c2cdf31018c259745e09b13bffc3 (diff) | |
download | libimobiledevice-7adc81dddd764b0ef76fefd73852b835d3211b9b.tar.gz libimobiledevice-7adc81dddd764b0ef76fefd73852b835d3211b9b.tar.bz2 |
uint32_t type fixes for afc_file_read/afc_file_write
This patch also adapts all corresponding internal functions.
The buffer lengths are now consistently handled as uint32_t.
-rw-r--r-- | include/libiphone/afc.h | 4 | ||||
-rw-r--r-- | src/AFC.c | 230 |
2 files changed, 124 insertions, 110 deletions
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 1c714c9..94eb02e 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -95,8 +95,8 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ** afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle); afc_error_t afc_file_close(afc_client_t client, uint64_t handle); afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation); -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_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read); +afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written); 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); @@ -119,21 +119,24 @@ afc_error_t afc_client_free(afc_client_t client) * @param client The client to send data through. * @param data The data to send. * @param length The length to send. - * - * @return The number of bytes actually sent, or -1 on error. + * @param bytes_sent The number of bytes actually sent. + * + * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. * * @warning set client->afc_packet->this_length and * client->afc_packet->entire_length to 0 before calling this. The * reason is that if you set them to different values, it indicates * you want to send the data as two packets. */ -static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) +static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, uint32_t length, uint32_t *bytes_sent) { - int bytes = 0, offset = 0; + uint32_t offset = 0; uint32_t sent = 0; if (!client || !client->connection || !client->afc_packet) - return 0; + return AFC_E_INVALID_ARGUMENT; + + *bytes_sent = 0; if (!data || !length) length = 0; @@ -158,21 +161,26 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l log_debug_msg("to based on the packet.\n"); log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); - return -1; + return AFC_E_INTERNAL_ERROR; } + /* send AFC packet header */ AFCPacket_to_LE(client->afc_packet); + sent = 0; iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); if (sent == 0) { - return bytes; + /* FIXME: should this be handled as success?! */ + return AFC_E_SUCCESS; } - bytes += sent; + *bytes_sent += sent; + /* send AFC packet data */ + sent = 0; iphone_device_send(client->connection, data, offset, &sent); if (sent == 0) { - return bytes; + return AFC_E_SUCCESS; } - bytes += sent; + *bytes_sent += sent; log_debug_msg("%s: sent the first now go with the second\n", __func__); log_debug_msg("%s: Length: %i\n", __func__, length - offset); @@ -182,8 +190,8 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l sent = 0; iphone_device_send(client->connection, data + offset, length - offset, &sent); - bytes = sent; - return bytes; + *bytes_sent = sent; + return AFC_E_SUCCESS; } else { log_debug_msg("%s: doin things the old way\n", __func__); log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); @@ -191,36 +199,38 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l log_debug_buffer((char*)client->afc_packet, sizeof(AFCPacket)); log_debug_msg("\n"); + /* send AFC packet header */ AFCPacket_to_LE(client->afc_packet); + sent = 0; iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); if (sent == 0) { - return bytes; + return AFC_E_SUCCESS; } - bytes += sent; + *bytes_sent += sent; + /* send AFC packet data (if there's data to send) */ if (length > 0) { log_debug_msg("%s: packet data follows\n", __func__); log_debug_buffer(data, length); log_debug_msg("\n"); iphone_device_send(client->connection, data, length, &sent); - bytes += sent; + *bytes_sent += sent; } - return bytes; + return AFC_E_SUCCESS; } - return -1; + return AFC_E_INTERNAL_ERROR; } /** Receives data through an AFC client and sets a variable to the received data. * * @param client The client to receive data on. * @param dump_here The char* to point to the newly-received data. + * @param bytes_recv How much data was received. * - * @return How much data was received, 0 on successful receive with no errors, - * -1 if there was an error involved with receiving or if the packet - * received raised a non-trivial error condition (i.e. non-zero with - * AFC_ERROR operation) + * @return AFC_E_SUCCESS when data has been received, or an AFC_E_* error value + * when an error occured. */ -static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *bytes) +static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv) { AFCPacket header; uint32_t entire_len = 0; @@ -228,16 +238,16 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * uint32_t current_count = 0; uint64_t param1 = -1; - *bytes = 0; + *bytes_recv = 0; /* first, read the AFC header */ - iphone_device_recv(client->connection, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes); + iphone_device_recv(client->connection, (char*)&header, sizeof(AFCPacket), bytes_recv); AFCPacket_from_LE(&header); - if (*bytes <= 0) { + if (*bytes_recv == 0) { log_debug_msg("%s: Just didn't get enough.\n", __func__); *dump_here = NULL; return AFC_E_MUX_ERROR; - } else if ((uint32_t)*bytes < sizeof(AFCPacket)) { + } else if (*bytes_recv < sizeof(AFCPacket)) { log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__); *dump_here = NULL; return AFC_E_MUX_ERROR; @@ -265,7 +275,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * && header.entire_length == sizeof(AFCPacket)) { log_debug_msg("%s: Empty AFCPacket received!\n", __func__); *dump_here = NULL; - *bytes = 0; + *bytes_recv = 0; if (header.operation == AFC_OP_DATA) { return AFC_E_SUCCESS; } else { @@ -285,13 +295,13 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * *dump_here = (char*)malloc(entire_len); if (this_len > 0) { - iphone_device_recv(client->connection, *dump_here, this_len, (uint32_t*)bytes); - if (*bytes <= 0) { + iphone_device_recv(client->connection, *dump_here, this_len, bytes_recv); + if (*bytes_recv <= 0) { free(*dump_here); *dump_here = NULL; log_debug_msg("%s: Did not get packet contents!\n", __func__); return AFC_E_NOT_ENOUGH_DATA; - } else if ((uint32_t)*bytes < this_len) { + } else if (*bytes_recv < this_len) { free(*dump_here); *dump_here = NULL; log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len); @@ -303,12 +313,12 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * if (entire_len > this_len) { while (current_count < entire_len) { - iphone_device_recv(client->connection, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes); - if (*bytes <= 0) { - log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes); + iphone_device_recv(client->connection, (*dump_here)+current_count, entire_len - current_count, bytes_recv); + if (*bytes_recv <= 0) { + log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes_recv); break; } - current_count += *bytes; + current_count += *bytes_recv; } if (current_count < entire_len) { log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len); @@ -348,7 +358,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * /* unknown operation code received */ free(*dump_here); *dump_here = NULL; - *bytes = 0; + *bytes_recv = 0; log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, (long long)header.operation, (long long)param1); @@ -356,13 +366,13 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * return AFC_E_OP_NOT_SUPPORTED; } - *bytes = current_count; + *bytes_recv = current_count; return AFC_E_SUCCESS; } -static int count_nullspaces(char *string, int number) +static uint32_t count_nullspaces(char *string, uint32_t number) { - int i = 0, nulls = 0; + uint32_t i = 0, nulls = 0; for (i = 0; i < number; i++) { if (string[i] == '\0') @@ -372,9 +382,9 @@ static int count_nullspaces(char *string, int number) return nulls; } -static char **make_strings_list(char *tokens, int true_length) +static char **make_strings_list(char *tokens, uint32_t true_length) { - int nulls = 0, i = 0, j = 0; + uint32_t nulls = 0, i = 0, j = 0; char **list = NULL; if (!tokens || !true_length) @@ -401,7 +411,7 @@ static char **make_strings_list(char *tokens, int true_length) */ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) { - int bytes = 0; + uint32_t bytes = 0; char *data = NULL, **list_loc = NULL; afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -414,8 +424,8 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis client->afc_packet->operation = AFC_OP_READ_DIR; client->afc_packet->entire_length = 0; client->afc_packet->this_length = 0; - bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); - if (bytes <= 0) { + ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -445,7 +455,7 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis */ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) { - int bytes = 0; + uint32_t bytes = 0; char *data = NULL, **list = NULL; afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -457,8 +467,8 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) // Send the command client->afc_packet->operation = AFC_OP_GET_DEVINFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = afc_dispatch_packet(client, NULL, 0); - if (bytes < 0) { + ret = afc_dispatch_packet(client, NULL, 0, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -526,7 +536,7 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char * afc_error_t afc_remove_path(afc_client_t client, const char *path) { char *response = NULL; - int bytes; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !path || !client->afc_packet || !client->connection) @@ -537,8 +547,8 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) // Send command client->afc_packet->this_length = client->afc_packet->entire_length = 0; client->afc_packet->operation = AFC_OP_REMOVE_PATH; - bytes = afc_dispatch_packet(client, path, strlen(path)+1); - if (bytes <= 0) { + ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -569,7 +579,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); - int bytes = 0; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !from || !to || !client->afc_packet || !client->connection) @@ -582,9 +592,9 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t memcpy(send + strlen(from) + 1, to, strlen(to) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_RENAME_PATH; - bytes = afc_dispatch_packet(client, send, strlen(to)+1 + strlen(from)+1); + ret = afc_dispatch_packet(client, send, strlen(to)+1 + strlen(from)+1, &bytes); free(send); - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -609,7 +619,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t */ afc_error_t afc_make_directory(afc_client_t client, const char *dir) { - int bytes = 0; + uint32_t bytes = 0; char *response = NULL; afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -621,8 +631,8 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) // Send command client->afc_packet->operation = AFC_OP_MAKE_DIR; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); - if (bytes <= 0) { + ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -650,7 +660,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) { char *received = NULL; - int bytes; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !path || !infolist) @@ -661,7 +671,11 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf // Send command client->afc_packet->operation = AFC_OP_GET_FILE_INFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - afc_dispatch_packet(client, path, strlen(path)+1); + ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); + if (ret != AFC_E_SUCCESS) { + afc_unlock(client); + return AFC_E_NOT_ENOUGH_DATA; + } // Receive data ret = afc_receive_data(client, &received, &bytes); @@ -692,7 +706,7 @@ afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle) { uint64_t file_mode_loc = GUINT64_TO_LE(file_mode); - int bytes = 0; + uint32_t bytes = 0; char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -710,10 +724,10 @@ afc_file_open(afc_client_t client, const char *filename, data[8 + strlen(filename)] = '\0'; client->afc_packet->operation = AFC_OP_FILE_OPEN; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = afc_dispatch_packet(client, data, 8 + strlen(filename) + 1); + ret = afc_dispatch_packet(client, data, 8 + strlen(filename) + 1, &bytes); free(data); - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { log_debug_msg("%s: Didn't receive a response to the command\n", __func__); afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; @@ -742,18 +756,19 @@ afc_file_open(afc_client_t client, const char *filename, * @param handle File handle of a previously opened file * @param data The pointer to the memory region to store the read data * @param length The number of bytes to read + * @param bytes_read The number of bytes actually read. * - * @return The number of bytes read if successful. If there was an error -1. + * @return AFC_E_SUCCESS on success or an AFC_E_* error value on error. */ iphone_error_t -afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) +afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) { char *input = NULL; - int current_count = 0, bytes_loc = 0; - const int MAXIMUM_READ_SIZE = 1 << 16; + 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->connection || handle == 0 || (length < 0)) + if (!client || !client->afc_packet || !client->connection || handle == 0) return AFC_E_INVALID_ARGUMENT; log_debug_msg("%s: called for length %i\n", __func__, length); @@ -770,10 +785,10 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); client->afc_packet->operation = AFC_OP_READ; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes_loc = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket)); + ret = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket), &bytes_loc); free(packet); - if (bytes_loc <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -788,7 +803,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint if (input) free(input); afc_unlock(client); - *bytes = current_count; + *bytes_read = current_count; /* FIXME: check that's actually a success */ return ret; } else { @@ -804,7 +819,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint log_debug_msg("%s: returning current_count as %i\n", __func__, current_count); afc_unlock(client); - *bytes = current_count; + *bytes_read = current_count; return ret; } @@ -814,23 +829,22 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint * @param handle File handle of previously opened file. * @param data The data to write to the file. * @param length How much data to write. + * @param bytes_written The number of bytes actually written to the file. * - * @return The number of bytes written to the file, or a value less than 0 if - * none were written... + * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. */ iphone_error_t -afc_file_write(afc_client_t client, uint64_t handle, - const char *data, int length, uint32_t * bytes) +afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written) { char *acknowledgement = NULL; - const int MAXIMUM_WRITE_SIZE = 1 << 15; + const uint32_t MAXIMUM_WRITE_SIZE = 1 << 15; uint32_t current_count = 0, i = 0; uint32_t segments = (length / MAXIMUM_WRITE_SIZE); - int bytes_loc = 0; + uint32_t bytes_loc = 0; char *out_buffer = NULL; afc_error_t ret = AFC_E_SUCCESS; - if (!client || !client->afc_packet || !client->connection || !bytes || (handle == 0) || (length < 0)) + if (!client || !client->afc_packet || !client->connection || !bytes_written || (handle == 0)) return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -846,8 +860,8 @@ afc_file_write(afc_client_t client, uint64_t handle, out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *)&handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); - bytes_loc = afc_dispatch_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); - if (bytes_loc < 0) { + ret = afc_dispatch_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8, &bytes_loc); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -868,9 +882,9 @@ afc_file_write(afc_client_t client, uint64_t handle, // didn't get sent in the for loop // this length is fine because it's always sizeof(AFCPacket) + 8, but // to be sure we do it again - if (current_count == (uint32_t)length) { + if (current_count == length) { afc_unlock(client); - *bytes = current_count; + *bytes_written = current_count; return ret; } @@ -880,15 +894,15 @@ afc_file_write(afc_client_t client, uint64_t handle, out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *) &handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, (length - current_count)); - bytes_loc = afc_dispatch_packet(client, out_buffer, (length - current_count) + 8); + ret = afc_dispatch_packet(client, out_buffer, (length - current_count) + 8, &bytes_loc); free(out_buffer); out_buffer = NULL; current_count += bytes_loc; - if (bytes_loc <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); - *bytes = current_count; + *bytes_written = current_count; return AFC_E_SUCCESS; } @@ -899,7 +913,7 @@ afc_file_write(afc_client_t client, uint64_t handle, } else { free(acknowledgement); } - *bytes = current_count; + *bytes_written = current_count; return ret; } @@ -911,7 +925,7 @@ afc_file_write(afc_client_t client, uint64_t handle, afc_error_t afc_file_close(afc_client_t client, uint64_t handle) { char *buffer = malloc(sizeof(char) * 8); - int bytes = 0; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || (handle == 0)) @@ -925,11 +939,11 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) memcpy(buffer, &handle, sizeof(uint64_t)); client->afc_packet->operation = AFC_OP_FILE_CLOSE; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = afc_dispatch_packet(client, buffer, 8); + ret = afc_dispatch_packet(client, buffer, 8, &bytes); free(buffer); buffer = NULL; - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_UNKNOWN_ERROR; } @@ -958,7 +972,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) { char *buffer = malloc(16); - int bytes = 0; + uint32_t bytes = 0; uint64_t op = GUINT64_TO_LE(operation); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -975,11 +989,11 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op client->afc_packet->operation = AFC_OP_FILE_LOCK; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = afc_dispatch_packet(client, buffer, 16); + ret = afc_dispatch_packet(client, buffer, 16, &bytes); free(buffer); buffer = NULL; - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); log_debug_msg("%s: could not send lock command\n", __func__); return AFC_E_UNKNOWN_ERROR; @@ -1009,7 +1023,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, char *buffer = (char *) malloc(sizeof(char) * 24); int64_t offset_loc = (int64_t)GUINT64_TO_LE(offset); uint64_t whence_loc = GUINT64_TO_LE(whence); - int bytes = 0; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || (handle == 0)) @@ -1023,11 +1037,11 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); // offset client->afc_packet->operation = AFC_OP_FILE_SEEK; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = afc_dispatch_packet(client, buffer, 24); + ret = afc_dispatch_packet(client, buffer, 24, &bytes); free(buffer); buffer = NULL; - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -1052,7 +1066,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, 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; + uint32_t bytes = 0; afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || (handle == 0)) @@ -1064,11 +1078,11 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi 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); + ret = afc_dispatch_packet(client, buffer, 8, &bytes); free(buffer); buffer = NULL; - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -1102,7 +1116,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) { char *buffer = (char *) malloc(sizeof(char) * 16); - int bytes = 0; + uint32_t bytes = 0; uint64_t newsize_loc = GUINT64_TO_LE(newsize); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -1116,11 +1130,11 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); // newsize client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = afc_dispatch_packet(client, buffer, 16); + ret = afc_dispatch_packet(client, buffer, 16, &bytes); free(buffer); buffer = NULL; - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -1147,7 +1161,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); - int bytes = 0; + uint32_t bytes = 0; uint64_t size_requested = GUINT64_TO_LE(newsize); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -1161,9 +1175,9 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) memcpy(send + 8, path, strlen(path) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_TRUNCATE; - bytes = afc_dispatch_packet(client, send, 8 + strlen(path) + 1); + ret = afc_dispatch_packet(client, send, 8 + strlen(path) + 1, &bytes); free(send); - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -1191,7 +1205,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); - int bytes = 0; + uint32_t bytes = 0; uint64_t type = GUINT64_TO_LE(linktype); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -1210,9 +1224,9 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_MAKE_LINK; - bytes = afc_dispatch_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); + ret = afc_dispatch_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1, &bytes); free(send); - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } @@ -1239,7 +1253,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); - int bytes = 0; + uint32_t bytes = 0; uint64_t mtime_loc = GUINT64_TO_LE(mtime); afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -1253,9 +1267,9 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt memcpy(send + 8, path, strlen(path) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_SET_FILE_TIME; - bytes = afc_dispatch_packet(client, send, 8 + strlen(path) + 1); + ret = afc_dispatch_packet(client, send, 8 + strlen(path) + 1, &bytes); free(send); - if (bytes <= 0) { + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return AFC_E_NOT_ENOUGH_DATA; } |