diff options
author | Nikias Bassen | 2009-10-30 18:07:20 +0100 |
---|---|---|
committer | Matt Colyer | 2009-11-02 20:52:55 -0800 |
commit | 549f4389e3009d9f78b94d4a3570e29f428968ab (patch) | |
tree | f5de57c8a5a3e54f634287743f0b638786b674ec | |
parent | d6226d01ce5bd00a85310061fb33d0510ecd7564 (diff) | |
download | libimobiledevice-549f4389e3009d9f78b94d4a3570e29f428968ab.tar.gz libimobiledevice-549f4389e3009d9f78b94d4a3570e29f428968ab.tar.bz2 |
AFC: new function afc_set_file_time
This function allows to set the modification time of a file. The
time value needs to be specified as nanoseconds since epoch.
[#81 state:resolved]
Signed-off-by: Matt Colyer <matt@colyer.name>
-rw-r--r-- | include/libiphone/afc.h | 1 | ||||
-rw-r--r-- | src/AFC.c | 43 | ||||
-rw-r--r-- | src/AFC.h | 3 |
3 files changed, 46 insertions, 1 deletions
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index e913f91..1c714c9 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -105,6 +105,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); afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize); afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); +afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime); /* Helper functions */ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value); @@ -1213,3 +1213,46 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c return ret; } + +/** Sets the modification time of a file on the phone. + * + * @param client The client to use to set the file size. + * @param path Path of the file for which the modification time should be set. + * @param mtime The modification time to set in nanoseconds since epoch. + * + * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. + */ +afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime) +{ + char *response = NULL; + char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); + int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || !path || !client->afc_packet || !client->connection) + return AFC_E_INVALID_ARGUMENT; + + afc_lock(client); + + // Send command + memcpy(send, &mtime, 8); + 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); + free(send); + if (bytes <= 0) { + afc_unlock(client); + return AFC_E_NOT_ENOUGH_DATA; + } + // Receive response + ret = afc_receive_data(client, &response, &bytes); + if (response) + free(response); + + afc_unlock(client); + + return ret; +} + @@ -82,6 +82,7 @@ enum { AFC_OP_SET_FS_BS = 0x00000019, // SetFSBlockSize (0x800000) AFC_OP_SET_SOCKET_BS = 0x0000001A, // SetSocketBlockSize (0x800000) AFC_OP_FILE_LOCK = 0x0000001B, // FileRefLock - AFC_OP_MAKE_LINK = 0x0000001C // MakeLink + AFC_OP_MAKE_LINK = 0x0000001C, // MakeLink + AFC_OP_SET_FILE_TIME = 0x0000001E // set st_mtime }; |