summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/main.c4
-rw-r--r--include/libiphone/afc.h8
-rw-r--r--src/AFC.c22
3 files changed, 19 insertions, 15 deletions
diff --git a/dev/main.c b/dev/main.c
index cf7dbaa..33ebc2d 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
128 afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); 128 afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
129 if (lockfile) { 129 if (lockfile) {
130 printf("locking file\n"); 130 printf("locking file\n");
131 afc_lock_file(afc, lockfile, 2 | 4); 131 afc_lock_file(afc, lockfile, AFC_LOCK_EX);
132 132
133 perform_notification(phone, client, NP_SYNC_DID_START); 133 perform_notification(phone, client, NP_SYNC_DID_START);
134 } 134 }
@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
227 //perform_notification(phone, control, NP_SYNC_DID_FINISH); 227 //perform_notification(phone, control, NP_SYNC_DID_FINISH);
228 228
229 printf("XXX unlocking file\n"); 229 printf("XXX unlocking file\n");
230 afc_lock_file(afc, lockfile, 8 | 4); 230 afc_lock_file(afc, lockfile, AFC_LOCK_UN);
231 231
232 printf("XXX closing file\n"); 232 printf("XXX closing file\n");
233 afc_close_file(afc, lockfile); 233 afc_close_file(afc, lockfile);
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h
index 2a0bbad..b64510b 100644
--- a/include/libiphone/afc.h
+++ b/include/libiphone/afc.h
@@ -21,6 +21,12 @@ typedef enum {
21 AFC_SYMLINK = 2 21 AFC_SYMLINK = 2
22} afc_link_type_t; 22} afc_link_type_t;
23 23
24typedef enum {
25 AFC_LOCK_SH = 1 | 4, // shared lock
26 AFC_LOCK_EX = 2 | 4, // exclusive lock
27 AFC_LOCK_UN = 8 | 4 // unlock
28} afc_lock_op_t;
29
24struct afc_client_int; 30struct afc_client_int;
25typedef struct afc_client_int *afc_client_t; 31typedef struct afc_client_int *afc_client_t;
26 32
@@ -36,7 +42,7 @@ iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char ***
36iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); 42iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist );
37iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); 43iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle );
38iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); 44iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle);
39iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation); 45iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, afc_lock_op_t operation);
40iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); 46iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes);
41iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); 47iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes);
42iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); 48iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence);
diff --git a/src/AFC.c b/src/AFC.c
index e666c45..cd120fc 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -174,6 +174,9 @@ static int afcerror_to_errno(int afcerror)
174 case 10: // occurs if you try to open a file without permission 174 case 10: // occurs if you try to open a file without permission
175 res = EPERM; 175 res = EPERM;
176 break; 176 break;
177 case 19: // occurs if you try to lock an already locked file
178 res = EWOULDBLOCK;
179 break;
177 default: // we'll assume it's an errno value, but report it 180 default: // we'll assume it's an errno value, but report it
178 log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror)); 181 log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror));
179 res = afcerror; 182 res = afcerror;
@@ -986,21 +989,16 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
986 989
987/** Locks or unlocks a file on the phone. 990/** Locks or unlocks a file on the phone.
988 * 991 *
989 * makes use of flock, see 992 * makes use of flock on the device, see
990 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html 993 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
991 * 994 *
992 * operation (same as in sys/file.h on linux): 995 * @param client The client to lock the file with.
993 *
994 * LOCK_SH 1 // shared lock
995 * LOCK_EX 2 // exclusive lock
996 * LOCK_NB 4 // don't block when locking
997 * LOCK_UN 8 // unlock
998 *
999 * @param client The client to close the file with.
1000 * @param handle File handle of a previously opened file. 996 * @param handle File handle of a previously opened file.
1001 * @operation the lock or unlock operation to perform. 997 * @param operation the lock or unlock operation to perform, this is one of
998 * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock),
999 * or AFC_LOCK_UN (unlock).
1002 */ 1000 */
1003iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation) 1001iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t operation)
1004{ 1002{
1005 if (!client || (handle == 0)) 1003 if (!client || (handle == 0))
1006 return IPHONE_E_INVALID_ARG; 1004 return IPHONE_E_INVALID_ARG;
@@ -1024,7 +1022,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation
1024 1022
1025 if (bytes <= 0) { 1023 if (bytes <= 0) {
1026 afc_unlock(client); 1024 afc_unlock(client);
1027 log_debug_msg("fuck\n"); 1025 log_debug_msg("Could not send lock command\n");
1028 return IPHONE_E_UNKNOWN_ERROR; 1026 return IPHONE_E_UNKNOWN_ERROR;
1029 } 1027 }
1030 // Receive the response 1028 // Receive the response