diff options
| author | 2009-07-19 20:07:21 +0200 | |
|---|---|---|
| committer | 2009-07-20 11:01:59 +0200 | |
| commit | 37f8ad0f3e64c23cd32c8c58636510f7964f1891 (patch) | |
| tree | 332918af6206fb240dbb79c6ba896810174b3920 | |
| parent | 67a0fe9b8eb5c85348f282fee540e4fee6eedde9 (diff) | |
| download | libimobiledevice-37f8ad0f3e64c23cd32c8c58636510f7964f1891.tar.gz libimobiledevice-37f8ad0f3e64c23cd32c8c58636510f7964f1891.tar.bz2 | |
New type afc_lock_op_t with allowed lock operations for afc_lock_file. Only non-blocking locks are supported via AFC.
Signed-off-by: Martin Szulecki <opensuse@sukimashita.com>
| -rw-r--r-- | dev/main.c | 4 | ||||
| -rw-r--r-- | include/libiphone/afc.h | 8 | ||||
| -rw-r--r-- | src/AFC.c | 22 |
3 files changed, 19 insertions, 15 deletions
| @@ -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 | ||
| 24 | typedef 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 | |||
| 24 | struct afc_client_int; | 30 | struct afc_client_int; |
| 25 | typedef struct afc_client_int *afc_client_t; | 31 | typedef 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 *** | |||
| 36 | iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); | 42 | iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); |
| 37 | iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); | 43 | iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); |
| 38 | iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); | 44 | iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); |
| 39 | iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation); | 45 | iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, afc_lock_op_t operation); |
| 40 | iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); | 46 | iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); |
| 41 | iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); | 47 | iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); |
| 42 | iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); | 48 | iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); |
| @@ -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 | */ |
| 1003 | iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation) | 1001 | iphone_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 |
