summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/AFC.c43
-rw-r--r--src/AFC.h57
2 files changed, 51 insertions, 49 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 8cc88f1..1151f23 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -341,7 +341,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
&& header.entire_length == sizeof(AFCPacket)) {
log_debug_msg("%s: Empty AFCPacket received!\n", __func__);
*dump_here = NULL;
- if (header.operation == AFC_SUCCESS_RESPONSE) {
+ if (header.operation == AFC_OP_DATA) {
return 0;
} else {
client->afcerror = EIO;
@@ -396,13 +396,13 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
}
// check for errors
- if (header.operation == AFC_SUCCESS_RESPONSE) {
+ if (header.operation == AFC_OP_DATA) {
// we got a positive response!
log_debug_msg("%s: got a success response\n", __func__);
- } else if (header.operation == AFC_FILE_HANDLE) {
+ } else if (header.operation == AFC_OP_FILE_OPEN_RES) {
// we got a file handle response
log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1);
- } else if (header.operation == AFC_ERROR) {
+ } else if (header.operation == AFC_OP_STATUS) {
// error message received
if (param1 == 0) {
// ERROR_SUCCESS, this is not an error!
@@ -418,7 +418,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
return -1;
}
} else {
- // unknown operation code received!
+ /* unknown operation code received */
free(*dump_here);
*dump_here = NULL;
@@ -481,7 +481,7 @@ iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***li
afc_lock(client);
// Send the command
- client->afc_packet->operation = AFC_LIST_DIR;
+ client->afc_packet->operation = AFC_OP_READ_DIR;
client->afc_packet->entire_length = 0;
client->afc_packet->this_length = 0;
bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1);
@@ -526,7 +526,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos)
afc_lock(client);
// Send the command
- client->afc_packet->operation = AFC_GET_DEVINFO;
+ client->afc_packet->operation = AFC_OP_GET_DEVINFO;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
bytes = dispatch_AFC_packet(client, NULL, 0);
if (bytes < 0) {
@@ -545,6 +545,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos)
free(data);
afc_unlock(client);
+
*infos = list;
return IPHONE_E_SUCCESS;
}
@@ -569,7 +570,7 @@ iphone_error_t afc_delete_file(afc_client_t client, const char *path)
// Send command
client->afc_packet->this_length = client->afc_packet->entire_length = 0;
- client->afc_packet->operation = AFC_DELETE;
+ client->afc_packet->operation = AFC_OP_REMOVE_PATH;
bytes = dispatch_AFC_packet(client, path, strlen(path)+1);
if (bytes <= 0) {
afc_unlock(client);
@@ -612,7 +613,7 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char
memcpy(send, from, strlen(from) + 1);
memcpy(send + strlen(from) + 1, to, strlen(to) + 1);
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
- client->afc_packet->operation = AFC_RENAME;
+ client->afc_packet->operation = AFC_OP_RENAME_PATH;
bytes = dispatch_AFC_packet(client, send, strlen(to)+1 + strlen(from)+1);
free(send);
if (bytes <= 0) {
@@ -652,7 +653,7 @@ iphone_error_t afc_mkdir(afc_client_t client, const char *dir)
afc_lock(client);
// Send command
- client->afc_packet->operation = AFC_MAKE_DIR;
+ client->afc_packet->operation = AFC_OP_MAKE_DIR;
client->afc_packet->this_length = client->afc_packet->entire_length = 0;
bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1);
if (bytes <= 0) {
@@ -695,7 +696,7 @@ iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***
afc_lock(client);
// Send command
- client->afc_packet->operation = AFC_GET_INFO;
+ client->afc_packet->operation = AFC_OP_GET_FILE_INFO;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
dispatch_AFC_packet(client, path, strlen(path)+1);
@@ -747,7 +748,7 @@ afc_open_file(afc_client_t client, const char *filename,
memcpy(data + 4, &ag, 4);
memcpy(data + 8, filename, strlen(filename));
data[8 + strlen(filename)] = '\0';
- client->afc_packet->operation = AFC_FILE_OPEN;
+ client->afc_packet->operation = AFC_OP_FILE_OPEN;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
bytes = dispatch_AFC_packet(client, data, 8 + strlen(filename) + 1);
free(data);
@@ -808,7 +809,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket));
packet->filehandle = handle;
packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE;
- client->afc_packet->operation = AFC_READ;
+ client->afc_packet->operation = AFC_OP_READ;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
bytes_loc = dispatch_AFC_packet(client, (char *) packet, sizeof(AFCFilePacket));
free(packet);
@@ -880,7 +881,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
// Send the segment
client->afc_packet->this_length = sizeof(AFCPacket) + 8;
client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE;
- client->afc_packet->operation = AFC_WRITE;
+ client->afc_packet->operation = AFC_OP_WRITE;
out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
memcpy(out_buffer, (char *)&handle, sizeof(uint64_t));
memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE);
@@ -914,7 +915,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
client->afc_packet->this_length = sizeof(AFCPacket) + 8;
client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count);
- client->afc_packet->operation = AFC_WRITE;
+ client->afc_packet->operation = AFC_OP_WRITE;
out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
memcpy(out_buffer, (char *) &handle, sizeof(uint64_t));
memcpy(out_buffer + 8, data + current_count, (length - current_count));
@@ -960,7 +961,7 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
// Send command
memcpy(buffer, &handle, sizeof(uint64_t));
- client->afc_packet->operation = AFC_FILE_CLOSE;
+ client->afc_packet->operation = AFC_OP_FILE_CLOSE;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
bytes = dispatch_AFC_packet(client, buffer, 8);
free(buffer);
@@ -1007,7 +1008,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t
memcpy(buffer, &handle, sizeof(uint64_t));
memcpy(buffer + 8, &op, 8);
- client->afc_packet->operation = AFC_FILE_LOCK;
+ client->afc_packet->operation = AFC_OP_FILE_LOCK;
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
bytes = dispatch_AFC_packet(client, buffer, 16);
free(buffer);
@@ -1053,7 +1054,7 @@ iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offse
memcpy(buffer + 8, &whence, sizeof(int32_t)); // fromwhere
memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad
memcpy(buffer + 16, &offset, sizeof(uint64_t)); // offset
- client->afc_packet->operation = AFC_FILE_SEEK;
+ client->afc_packet->operation = AFC_OP_FILE_SEEK;
client->afc_packet->this_length = client->afc_packet->entire_length = 0;
bytes = dispatch_AFC_packet(client, buffer, 24);
free(buffer);
@@ -1097,7 +1098,7 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t
// Send command
memcpy(buffer, &handle, sizeof(uint64_t)); // handle
memcpy(buffer + 8, &newsize, sizeof(uint64_t)); // newsize
- client->afc_packet->operation = AFC_FILE_TRUNCATE;
+ client->afc_packet->operation = AFC_OP_FILE_SET_SIZE;
client->afc_packet->this_length = client->afc_packet->entire_length = 0;
bytes = dispatch_AFC_packet(client, buffer, 16);
free(buffer);
@@ -1145,7 +1146,7 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize
memcpy(send, &size_requested, 8);
memcpy(send + 8, path, strlen(path) + 1);
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
- client->afc_packet->operation = AFC_TRUNCATE;
+ client->afc_packet->operation = AFC_OP_TRUNCATE;
bytes = dispatch_AFC_packet(client, send, 8 + strlen(path) + 1);
free(send);
if (bytes <= 0) {
@@ -1196,7 +1197,7 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons
memcpy(send + 8, target, strlen(target) + 1);
memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1);
client->afc_packet->entire_length = client->afc_packet->this_length = 0;
- client->afc_packet->operation = AFC_MAKE_LINK;
+ client->afc_packet->operation = AFC_OP_MAKE_LINK;
bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1);
free(send);
if (bytes <= 0) {
diff --git a/src/AFC.h b/src/AFC.h
index 5d337e5..a0ce0ef 100644
--- a/src/AFC.h
+++ b/src/AFC.h
@@ -52,35 +52,36 @@ struct afc_client_int {
GMutex *mutex;
};
+/* AFC Operations */
enum {
- AFC_ERROR = 0x00000001,
- AFC_SUCCESS_RESPONSE = 0x00000002,
- AFC_LIST_DIR = 0x00000003, // ReadDir
- // 0x00000004 // ReadFile
- // 0x00000005 // WriteFile
- // 0x00000006 // WritePart
- AFC_TRUNCATE = 0x00000007, // Truncate
- AFC_DELETE = 0x00000008, // RemovePath
- AFC_MAKE_DIR = 0x00000009, // MakeDir
- AFC_GET_INFO = 0x0000000a, // GetFileInfo
- AFC_GET_DEVINFO = 0x0000000b, // GetDeviceInfo
- // 0x0000000c // same as 5, but writes to temp file, then renames it.
- AFC_FILE_OPEN = 0x0000000d, // FileRefOpen
- AFC_FILE_HANDLE = 0x0000000e, // _unknownPacket
- AFC_READ = 0x0000000f, // FileRefRead
- AFC_WRITE = 0x00000010, // FileRefWrite
- AFC_FILE_SEEK = 0x00000011, // FileRefSeek
- AFC_FILE_TELL = 0x00000012, // FileRefTell
- // 0x00000013 // _unknownPacket
- AFC_FILE_CLOSE = 0x00000014, // FileRefClose
- AFC_FILE_TRUNCATE = 0x00000015, // FileRefSetFileSize (ftruncate)
- // 0x00000016 // SetFatalError
- // 0x00000017 // SetConnectionOptions
- AFC_RENAME = 0x00000018, // RenamePath
- // 0x00000019 // SetFSBlockSize (0x800000)
- // 0x0000001A // SetBlockSize (0x800000)
- AFC_FILE_LOCK = 0x0000001B, // FileRefLock
- AFC_MAKE_LINK = 0x0000001C // MakeLink
+ AFC_OP_STATUS = 0x00000001, // Status
+ AFC_OP_DATA = 0x00000002, // Data
+ AFC_OP_READ_DIR = 0x00000003, // ReadDir
+ AFC_OP_READ_FILE = 0x00000004, // ReadFile
+ AFC_OP_WRITE_FILE = 0x00000005, // WriteFile
+ AFC_OP_WRITE_PART = 0x00000006, // WritePart
+ AFC_OP_TRUNCATE = 0x00000007, // TruncateFile
+ AFC_OP_REMOVE_PATH = 0x00000008, // RemovePath
+ AFC_OP_MAKE_DIR = 0x00000009, // MakeDir
+ AFC_OP_GET_FILE_INFO = 0x0000000a, // GetFileInfo
+ AFC_OP_GET_DEVINFO = 0x0000000b, // GetDeviceInfo
+ AFC_OP_WRITE_FILE_ATOM = 0x0000000c, // WriteFileAtomic (tmp file+rename)
+ AFC_OP_FILE_OPEN = 0x0000000d, // FileRefOpen
+ AFC_OP_FILE_OPEN_RES = 0x0000000e, // FileRefOpenResult
+ AFC_OP_READ = 0x0000000f, // FileRefRead
+ AFC_OP_WRITE = 0x00000010, // FileRefWrite
+ AFC_OP_FILE_SEEK = 0x00000011, // FileRefSeek
+ AFC_OP_FILE_TELL = 0x00000012, // FileRefTell
+ AFC_OP_FILE_TELL_RES = 0x00000013, // FileRefTellResult
+ AFC_OP_FILE_CLOSE = 0x00000014, // FileRefClose
+ AFC_OP_FILE_SET_SIZE = 0x00000015, // FileRefSetFileSize (ftruncate)
+ AFC_OP_GET_CON_INFO = 0x00000016, // GetConnectionInfo
+ AFC_OP_SET_CON_OPTIONS = 0x00000017, // SetConnectionOptions
+ AFC_OP_RENAME_PATH = 0x00000018, // RenamePath
+ 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
};
static int afcerror_to_errno(int afcerror);