diff options
author | Nikias Bassen | 2009-07-03 22:20:19 +0200 |
---|---|---|
committer | Matt Colyer | 2009-07-07 08:31:25 -0700 |
commit | 6de08b1e12946b85a595f82c1c04391d70d8b828 (patch) | |
tree | 82466625784125b98a88baf0017b9cd50bc20fd0 | |
parent | 9990d53ba2ff4e92b1844beb001dcc9c47d30f3e (diff) | |
download | libimobiledevice-6de08b1e12946b85a595f82c1c04391d70d8b828.tar.gz libimobiledevice-6de08b1e12946b85a595f82c1c04391d70d8b828.tar.bz2 |
Support for creating hard- and symlinks
-rw-r--r-- | include/libiphone/libiphone.h | 7 | ||||
-rw-r--r-- | src/AFC.c | 52 |
2 files changed, 58 insertions, 1 deletions
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index fc24d35..463efa7 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -63,6 +63,11 @@ typedef enum { AFC_FOPEN_RDAPPEND = 0x00000006 // a+ O_RDWR | O_APPEND | O_CREAT } iphone_afc_file_mode_t; +typedef enum { + IPHONE_AFC_HARDLINK = 1, + IPHONE_AFC_SYMLINK = 2 +} iphone_afc_link_type_t; + struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; @@ -127,7 +132,7 @@ iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char * iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize); - +iphone_error_t iphone_afc_make_link ( iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname); iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, @@ -1170,3 +1170,55 @@ iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, } return IPHONE_E_SUCCESS; } + +/** Creates a hard link or symbolic link on the device. + * + * @param client The client to use for making a link + * @param type 1 = hard link, 2 = symlink + * @param target The file to be linked. + * @param linkname The name of link. + * + * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG + * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + */ +iphone_error_t iphone_afc_make_link(iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname) +{ + char *response = NULL; + char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); + int bytes = 0; + uint64_t type = linktype; + + if (!client || !target || !linkname || !client->afc_packet || client->sfd < 0) + return IPHONE_E_INVALID_ARG; + + afc_lock(client); + + log_debug_msg("link type: %lld\n", type); + log_debug_msg("target: %s, length:%d\n", target, strlen(target)); + log_debug_msg("linkname: %s, length:%d\n", linkname, strlen(linkname)); + + // Send command + memcpy(send, &type, 8); + memcpy(send + 8, target, strlen(target) + 1); + 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_MAKE_LINK; + bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); + free(send); + if (bytes <= 0) { + afc_unlock(client); + return IPHONE_E_NOT_ENOUGH_DATA; + } + // Receive response + bytes = receive_AFC_data(client, &response); + if (response) + free(response); + + afc_unlock(client); + + if (bytes < 0) { + return IPHONE_E_NOT_ENOUGH_DATA; + } else { + return IPHONE_E_SUCCESS; + } +} |