summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-07-19 20:07:21 +0200
committerGravatar Martin Szulecki2009-07-20 11:01:59 +0200
commit37f8ad0f3e64c23cd32c8c58636510f7964f1891 (patch)
tree332918af6206fb240dbb79c6ba896810174b3920
parent67a0fe9b8eb5c85348f282fee540e4fee6eedde9 (diff)
downloadlibimobiledevice-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.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[])
afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
if (lockfile) {
printf("locking file\n");
- afc_lock_file(afc, lockfile, 2 | 4);
+ afc_lock_file(afc, lockfile, AFC_LOCK_EX);
perform_notification(phone, client, NP_SYNC_DID_START);
}
@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
//perform_notification(phone, control, NP_SYNC_DID_FINISH);
printf("XXX unlocking file\n");
- afc_lock_file(afc, lockfile, 8 | 4);
+ afc_lock_file(afc, lockfile, AFC_LOCK_UN);
printf("XXX closing file\n");
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 {
AFC_SYMLINK = 2
} afc_link_type_t;
+typedef enum {
+ AFC_LOCK_SH = 1 | 4, // shared lock
+ AFC_LOCK_EX = 2 | 4, // exclusive lock
+ AFC_LOCK_UN = 8 | 4 // unlock
+} afc_lock_op_t;
+
struct afc_client_int;
typedef struct afc_client_int *afc_client_t;
@@ -36,7 +42,7 @@ iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char ***
iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist );
iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle );
iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle);
-iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation);
+iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, afc_lock_op_t operation);
iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes);
iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes);
iphone_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)
case 10: // occurs if you try to open a file without permission
res = EPERM;
break;
+ case 19: // occurs if you try to lock an already locked file
+ res = EWOULDBLOCK;
+ break;
default: // we'll assume it's an errno value, but report it
log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror));
res = afcerror;
@@ -986,21 +989,16 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
/** Locks or unlocks a file on the phone.
*
- * makes use of flock, see
+ * makes use of flock on the device, see
* http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
*
- * operation (same as in sys/file.h on linux):
- *
- * LOCK_SH 1 // shared lock
- * LOCK_EX 2 // exclusive lock
- * LOCK_NB 4 // don't block when locking
- * LOCK_UN 8 // unlock
- *
- * @param client The client to close the file with.
+ * @param client The client to lock the file with.
* @param handle File handle of a previously opened file.
- * @operation the lock or unlock operation to perform.
+ * @param operation the lock or unlock operation to perform, this is one of
+ * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock),
+ * or AFC_LOCK_UN (unlock).
*/
-iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation)
+iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t operation)
{
if (!client || (handle == 0))
return IPHONE_E_INVALID_ARG;
@@ -1024,7 +1022,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation
if (bytes <= 0) {
afc_unlock(client);
- log_debug_msg("fuck\n");
+ log_debug_msg("Could not send lock command\n");
return IPHONE_E_UNKNOWN_ERROR;
}
// Receive the response