summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/AFC.c b/src/AFC.c
index dc8fe20..af07b56 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -917,6 +917,63 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file
917 return IPHONE_E_SUCCESS; 917 return IPHONE_E_SUCCESS;
918} 918}
919 919
920/** Locks or unlocks a file on the phone.
921 *
922 * makes use of flock, see
923 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
924 *
925 * operation (same as in sys/file.h on linux):
926 *
927 * LOCK_SH 1 // shared lock
928 * LOCK_EX 2 // exclusive lock
929 * LOCK_NB 4 // don't block when locking
930 * LOCK_UN 8 // unlock
931 *
932 * @param client The client to close the file with.
933 * @param file A pointer to an AFCFile struct containing the file handle of the
934 * file to close.
935 * @operation the lock or unlock operation to perform.
936 */
937iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_t file, int operation)
938{
939 if (!client || !file)
940 return IPHONE_E_INVALID_ARG;
941 char *buffer = malloc(16);
942 uint32 zero = 0;
943 int bytes = 0;
944 uint64_t op = operation;
945
946 afc_lock(client);
947
948 log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle);
949
950 // Send command
951 memcpy(buffer, &file->filehandle, sizeof(uint32));
952 memcpy(buffer + sizeof(uint32), &zero, sizeof(zero));
953 memcpy(buffer + 8, &op, 8);
954
955 client->afc_packet->operation = AFC_FILE_LOCK;
956 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
957 bytes = dispatch_AFC_packet(client, buffer, 15);
958 free(buffer);
959 buffer = NULL;
960
961 if (bytes <= 0) {
962 afc_unlock(client);
963 log_debug_msg("fuck\n");
964 return IPHONE_E_UNKNOWN_ERROR;
965 }
966 // Receive the response
967 bytes = receive_AFC_data(client, &buffer);
968 log_debug_msg("%s: receiving response (%d bytes)\n", __func__, bytes);
969 if (buffer) {
970 log_debug_buffer(buffer, bytes);
971 free(buffer);
972 }
973 afc_unlock(client);
974 return IPHONE_E_SUCCESS;
975}
976
920/** Seeks to a given position of a pre-opened file on the phone. 977/** Seeks to a given position of a pre-opened file on the phone.
921 * 978 *
922 * @param client The client to use to seek to the position. 979 * @param client The client to use to seek to the position.