summaryrefslogtreecommitdiffstats
path: root/src/afc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/afc.h')
-rw-r--r--src/afc.h122
1 files changed, 70 insertions, 52 deletions
diff --git a/src/afc.h b/src/afc.h
index 9c9f12d..6bfdf56 100644
--- a/src/afc.h
+++ b/src/afc.h
@@ -1,28 +1,34 @@
1/* 1/*
2 * afc.h 2 * afc.h
3 * Defines and structs and the like for the built-in AFC client 3 * Defines and structs and the like for the built-in AFC client
4 * 4 *
5 * Copyright (c) 2014 Martin Szulecki All Rights Reserved.
5 * Copyright (c) 2008 Zach C. All Rights Reserved. 6 * Copyright (c) 2008 Zach C. All Rights Reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 11 * version 2.1 of the License, or (at your option) any later version.
11 * 12 *
12 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details. 16 * Lesser General Public License for more details.
16 * 17 *
17 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software 19 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 21 */
21 22
22#include <glib.h> 23#ifndef __AFC_H
24#define __AFC_H
25
23#include <stdint.h> 26#include <stdint.h>
24 27
25#include "libimobiledevice/afc.h" 28#include "libimobiledevice/afc.h"
29#include "service.h"
30#include "endianness.h"
31#include <libimobiledevice-glue/thread.h>
26 32
27#define AFC_MAGIC "CFA6LPAA" 33#define AFC_MAGIC "CFA6LPAA"
28#define AFC_MAGIC_LEN (8) 34#define AFC_MAGIC_LEN (8)
@@ -33,60 +39,72 @@ typedef struct {
33} AFCPacket; 39} AFCPacket;
34 40
35#define AFCPacket_to_LE(x) \ 41#define AFCPacket_to_LE(x) \
36 (x)->entire_length = GUINT64_TO_LE((x)->entire_length); \ 42 (x)->entire_length = htole64((x)->entire_length); \
37 (x)->this_length = GUINT64_TO_LE((x)->this_length); \ 43 (x)->this_length = htole64((x)->this_length); \
38 (x)->packet_num = GUINT64_TO_LE((x)->packet_num); \ 44 (x)->packet_num = htole64((x)->packet_num); \
39 (x)->operation = GUINT64_TO_LE((x)->operation); 45 (x)->operation = htole64((x)->operation);
40 46
41#define AFCPacket_from_LE(x) \ 47#define AFCPacket_from_LE(x) \
42 (x)->entire_length = GUINT64_FROM_LE((x)->entire_length); \ 48 (x)->entire_length = le64toh((x)->entire_length); \
43 (x)->this_length = GUINT64_FROM_LE((x)->this_length); \ 49 (x)->this_length = le64toh((x)->this_length); \
44 (x)->packet_num = GUINT64_FROM_LE((x)->packet_num); \ 50 (x)->packet_num = le64toh((x)->packet_num); \
45 (x)->operation = GUINT64_FROM_LE((x)->operation); 51 (x)->operation = le64toh((x)->operation);
46
47typedef struct {
48 uint64_t filehandle, size;
49} AFCFilePacket;
50 52
51struct afc_client_private { 53struct afc_client_private {
52 idevice_connection_t connection; 54 service_client_t parent;
53 AFCPacket *afc_packet; 55 AFCPacket *afc_packet;
54 int file_handle; 56 uint32_t packet_extra;
55 int lock; 57 mutex_t mutex;
56 GMutex *mutex; 58 int free_parent;
57 int own_connection;
58}; 59};
59 60
60/* AFC Operations */ 61/* AFC Operations */
61enum { 62enum {
62 AFC_OP_STATUS = 0x00000001, /* Status */ 63 AFC_OP_INVALID = 0x00000000, /* Invalid */
63 AFC_OP_DATA = 0x00000002, /* Data */ 64 AFC_OP_STATUS = 0x00000001, /* Status */
64 AFC_OP_READ_DIR = 0x00000003, /* ReadDir */ 65 AFC_OP_DATA = 0x00000002, /* Data */
65 AFC_OP_READ_FILE = 0x00000004, /* ReadFile */ 66 AFC_OP_READ_DIR = 0x00000003, /* ReadDir */
66 AFC_OP_WRITE_FILE = 0x00000005, /* WriteFile */ 67 AFC_OP_READ_FILE = 0x00000004, /* ReadFile */
67 AFC_OP_WRITE_PART = 0x00000006, /* WritePart */ 68 AFC_OP_WRITE_FILE = 0x00000005, /* WriteFile */
68 AFC_OP_TRUNCATE = 0x00000007, /* TruncateFile */ 69 AFC_OP_WRITE_PART = 0x00000006, /* WritePart */
69 AFC_OP_REMOVE_PATH = 0x00000008, /* RemovePath */ 70 AFC_OP_TRUNCATE = 0x00000007, /* TruncateFile */
70 AFC_OP_MAKE_DIR = 0x00000009, /* MakeDir */ 71 AFC_OP_REMOVE_PATH = 0x00000008, /* RemovePath */
71 AFC_OP_GET_FILE_INFO = 0x0000000a, /* GetFileInfo */ 72 AFC_OP_MAKE_DIR = 0x00000009, /* MakeDir */
72 AFC_OP_GET_DEVINFO = 0x0000000b, /* GetDeviceInfo */ 73 AFC_OP_GET_FILE_INFO = 0x0000000A, /* GetFileInfo */
73 AFC_OP_WRITE_FILE_ATOM = 0x0000000c, /* WriteFileAtomic (tmp file+rename) */ 74 AFC_OP_GET_DEVINFO = 0x0000000B, /* GetDeviceInfo */
74 AFC_OP_FILE_OPEN = 0x0000000d, /* FileRefOpen */ 75 AFC_OP_WRITE_FILE_ATOM = 0x0000000C, /* WriteFileAtomic (tmp file+rename) */
75 AFC_OP_FILE_OPEN_RES = 0x0000000e, /* FileRefOpenResult */ 76 AFC_OP_FILE_OPEN = 0x0000000D, /* FileRefOpen */
76 AFC_OP_READ = 0x0000000f, /* FileRefRead */ 77 AFC_OP_FILE_OPEN_RES = 0x0000000E, /* FileRefOpenResult */
77 AFC_OP_WRITE = 0x00000010, /* FileRefWrite */ 78 AFC_OP_FILE_READ = 0x0000000F, /* FileRefRead */
78 AFC_OP_FILE_SEEK = 0x00000011, /* FileRefSeek */ 79 AFC_OP_FILE_WRITE = 0x00000010, /* FileRefWrite */
79 AFC_OP_FILE_TELL = 0x00000012, /* FileRefTell */ 80 AFC_OP_FILE_SEEK = 0x00000011, /* FileRefSeek */
80 AFC_OP_FILE_TELL_RES = 0x00000013, /* FileRefTellResult */ 81 AFC_OP_FILE_TELL = 0x00000012, /* FileRefTell */
81 AFC_OP_FILE_CLOSE = 0x00000014, /* FileRefClose */ 82 AFC_OP_FILE_TELL_RES = 0x00000013, /* FileRefTellResult */
82 AFC_OP_FILE_SET_SIZE = 0x00000015, /* FileRefSetFileSize (ftruncate) */ 83 AFC_OP_FILE_CLOSE = 0x00000014, /* FileRefClose */
83 AFC_OP_GET_CON_INFO = 0x00000016, /* GetConnectionInfo */ 84 AFC_OP_FILE_SET_SIZE = 0x00000015, /* FileRefSetFileSize (ftruncate) */
84 AFC_OP_SET_CON_OPTIONS = 0x00000017, /* SetConnectionOptions */ 85 AFC_OP_GET_CON_INFO = 0x00000016, /* GetConnectionInfo */
85 AFC_OP_RENAME_PATH = 0x00000018, /* RenamePath */ 86 AFC_OP_SET_CON_OPTIONS = 0x00000017, /* SetConnectionOptions */
86 AFC_OP_SET_FS_BS = 0x00000019, /* SetFSBlockSize (0x800000) */ 87 AFC_OP_RENAME_PATH = 0x00000018, /* RenamePath */
87 AFC_OP_SET_SOCKET_BS = 0x0000001A, /* SetSocketBlockSize (0x800000) */ 88 AFC_OP_SET_FS_BS = 0x00000019, /* SetFSBlockSize (0x800000) */
88 AFC_OP_FILE_LOCK = 0x0000001B, /* FileRefLock */ 89 AFC_OP_SET_SOCKET_BS = 0x0000001A, /* SetSocketBlockSize (0x800000) */
89 AFC_OP_MAKE_LINK = 0x0000001C, /* MakeLink */ 90 AFC_OP_FILE_LOCK = 0x0000001B, /* FileRefLock */
90 AFC_OP_SET_FILE_TIME = 0x0000001E /* set st_mtime */ 91 AFC_OP_MAKE_LINK = 0x0000001C, /* MakeLink */
92 AFC_OP_GET_FILE_HASH = 0x0000001D, /* GetFileHash */
93 AFC_OP_SET_FILE_MOD_TIME = 0x0000001E, /* SetModTime */
94 AFC_OP_GET_FILE_HASH_RANGE = 0x0000001F, /* GetFileHashWithRange */
95 /* iOS 6+ */
96 AFC_OP_FILE_SET_IMMUTABLE_HINT = 0x00000020, /* FileRefSetImmutableHint */
97 AFC_OP_GET_SIZE_OF_PATH_CONTENTS = 0x00000021, /* GetSizeOfPathContents */
98 AFC_OP_REMOVE_PATH_AND_CONTENTS = 0x00000022, /* RemovePathAndContents */
99 AFC_OP_DIR_OPEN = 0x00000023, /* DirectoryEnumeratorRefOpen */
100 AFC_OP_DIR_OPEN_RESULT = 0x00000024, /* DirectoryEnumeratorRefOpenResult */
101 AFC_OP_DIR_READ = 0x00000025, /* DirectoryEnumeratorRefRead */
102 AFC_OP_DIR_CLOSE = 0x00000026, /* DirectoryEnumeratorRefClose */
103 /* iOS 7+ */
104 AFC_OP_FILE_READ_OFFSET = 0x00000027, /* FileRefReadWithOffset */
105 AFC_OP_FILE_WRITE_OFFSET = 0x00000028 /* FileRefWriteWithOffset */
91}; 106};
92 107
108afc_error_t afc_client_new_with_service_client(service_client_t service_client, afc_client_t *client);
109
110#endif