summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/afc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/afc.h')
-rw-r--r--include/libimobiledevice/afc.h233
1 files changed, 233 insertions, 0 deletions
diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h
index 289c749..2f272e0 100644
--- a/include/libimobiledevice/afc.h
+++ b/include/libimobiledevice/afc.h
@@ -95,30 +95,263 @@ typedef struct afc_client_private afc_client_private;
95typedef afc_client_private *afc_client_t; /**< The client handle. */ 95typedef afc_client_private *afc_client_t; /**< The client handle. */
96 96
97/* Interface */ 97/* Interface */
98
99/**
100 * Makes a connection to the AFC service on the device.
101 *
102 * @param device The device to connect to.
103 * @param service The service descriptor returned by lockdownd_start_service.
104 * @param client Pointer that will be set to a newly allocated afc_client_t
105 * upon successful return.
106 *
107 * @return AFC_E_SUCCESS on success, AFC_E_INVALID_ARG if device or service is
108 * invalid, AFC_E_MUX_ERROR if the connection cannot be established,
109 * or AFC_E_NO_MEM if there is a memory allocation problem.
110 */
98afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t *client); 111afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t *client);
112
113/**
114 * Starts a new AFC service on the specified device and connects to it.
115 *
116 * @param device The device to connect to.
117 * @param client Pointer that will point to a newly allocated
118 * afc_client_t upon successful return. Must be freed using
119 * afc_client_free() after use.
120 * @param label The label to use for communication. Usually the program name.
121 * Pass NULL to disable sending the label in requests to lockdownd.
122 *
123 * @return AFC_E_SUCCESS on success, or an AFC_E_* error
124 * code otherwise.
125 */
99afc_error_t afc_client_start_service(idevice_t device, afc_client_t* client, const char* label); 126afc_error_t afc_client_start_service(idevice_t device, afc_client_t* client, const char* label);
127
128/**
129 * Frees up an AFC client. If the connection was created by the
130 * client itself, the connection will be closed.
131 *
132 * @param client The client to free.
133 */
100afc_error_t afc_client_free(afc_client_t client); 134afc_error_t afc_client_free(afc_client_t client);
101 135
136/**
137 * Get device information for a connected client. The device information
138 * returned is the device model as well as the free space, the total capacity
139 * and blocksize on the accessed disk partition.
140 *
141 * @param client The client to get device info for.
142 * @param infos A char ** list of parameters as given by AFC or NULL if there
143 * was an error.
144 *
145 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
146 */
102afc_error_t afc_get_device_info(afc_client_t client, char ***infos); 147afc_error_t afc_get_device_info(afc_client_t client, char ***infos);
148
149/**
150 * Gets a directory listing of the directory requested.
151 *
152 * @param client The client to get a directory listing from.
153 * @param dir The directory to list. (must be a fully-qualified path)
154 * @param list A char list of files in that directory, terminated by an empty
155 * string or NULL if there was an error.
156 *
157 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
158 */
103afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list); 159afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list);
160
161/**
162 * Gets information about a specific file.
163 *
164 * @param client The client to use to get the information of the file.
165 * @param path The fully-qualified path to the file.
166 * @param infolist Pointer to a buffer that will be filled with a NULL-terminated
167 * list of strings with the file information.
168 * Set to NULL before calling this function.
169 *
170 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
171 */
104afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***infolist); 172afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***infolist);
173
174/**
175 * Opens a file on the device.
176 *
177 * @param client The client to use to open the file.
178 * @param filename The file to open. (must be a fully-qualified path)
179 * @param file_mode The mode to use to open the file. Can be AFC_FILE_READ or
180 * AFC_FILE_WRITE; the former lets you read and write,
181 * however, and the second one will *create* the file,
182 * destroying anything previously there.
183 * @param handle Pointer to a uint64_t that will hold the handle of the file
184 *
185 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
186 */
105afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle); 187afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle);
188
189/**
190 * Closes a file on the device.
191 *
192 * @param client The client to close the file with.
193 * @param handle File handle of a previously opened file.
194 */
106afc_error_t afc_file_close(afc_client_t client, uint64_t handle); 195afc_error_t afc_file_close(afc_client_t client, uint64_t handle);
196
197/**
198 * Locks or unlocks a file on the device.
199 *
200 * makes use of flock on the device, see
201 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
202 *
203 * @param client The client to lock the file with.
204 * @param handle File handle of a previously opened file.
205 * @param operation the lock or unlock operation to perform, this is one of
206 * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock),
207 * or AFC_LOCK_UN (unlock).
208 */
107afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation); 209afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation);
210
211/**
212 * Attempts to the read the given number of bytes from the given file.
213 *
214 * @param client The relevant AFC client
215 * @param handle File handle of a previously opened file
216 * @param data The pointer to the memory region to store the read data
217 * @param length The number of bytes to read
218 * @param bytes_read The number of bytes actually read.
219 *
220 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
221 */
108afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read); 222afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read);
223
224/**
225 * Writes a given number of bytes to a file.
226 *
227 * @param client The client to use to write to the file.
228 * @param handle File handle of previously opened file.
229 * @param data The data to write to the file.
230 * @param length How much data to write.
231 * @param bytes_written The number of bytes actually written to the file.
232 *
233 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
234 */
109afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written); 235afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written);
236
237/**
238 * Seeks to a given position of a pre-opened file on the device.
239 *
240 * @param client The client to use to seek to the position.
241 * @param handle File handle of a previously opened.
242 * @param offset Seek offset.
243 * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END.
244 *
245 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
246 */
110afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); 247afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence);
248
249/**
250 * Returns current position in a pre-opened file on the device.
251 *
252 * @param client The client to use.
253 * @param handle File handle of a previously opened file.
254 * @param position Position in bytes of indicator
255 *
256 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
257 */
111afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position); 258afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position);
259
260/**
261 * Sets the size of a file on the device.
262 *
263 * @param client The client to use to set the file size.
264 * @param handle File handle of a previously opened file.
265 * @param newsize The size to set the file to.
266 *
267 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
268 *
269 * @note This function is more akin to ftruncate than truncate, and truncate
270 * calls would have to open the file before calling this, sadly.
271 */
112afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); 272afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize);
273
274/**
275 * Deletes a file or directory.
276 *
277 * @param client The client to use.
278 * @param path The path to delete. (must be a fully-qualified path)
279 *
280 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
281 */
113afc_error_t afc_remove_path(afc_client_t client, const char *path); 282afc_error_t afc_remove_path(afc_client_t client, const char *path);
283
284/**
285 * Renames a file or directory on the device.
286 *
287 * @param client The client to have rename.
288 * @param from The name to rename from. (must be a fully-qualified path)
289 * @param to The new name. (must also be a fully-qualified path)
290 *
291 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
292 */
114afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); 293afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to);
294
295/**
296 * Creates a directory on the device.
297 *
298 * @param client The client to use to make a directory.
299 * @param dir The directory's path. (must be a fully-qualified path, I assume
300 * all other mkdir restrictions apply as well)
301 *
302 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
303 */
115afc_error_t afc_make_directory(afc_client_t client, const char *dir); 304afc_error_t afc_make_directory(afc_client_t client, const char *dir);
305
306/**
307 * Sets the size of a file on the device without prior opening it.
308 *
309 * @param client The client to use to set the file size.
310 * @param path The path of the file to be truncated.
311 * @param newsize The size to set the file to.
312 *
313 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
314 */
116afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize); 315afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize);
316
317/**
318 * Creates a hard link or symbolic link on the device.
319 *
320 * @param client The client to use for making a link
321 * @param linktype 1 = hard link, 2 = symlink
322 * @param target The file to be linked.
323 * @param linkname The name of link.
324 *
325 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
326 */
117afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); 327afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname);
328
329/**
330 * Sets the modification time of a file on the device.
331 *
332 * @param client The client to use to set the file size.
333 * @param path Path of the file for which the modification time should be set.
334 * @param mtime The modification time to set in nanoseconds since epoch.
335 *
336 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
337 */
118afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime); 338afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime);
119 339
120/* Helper functions */ 340/* Helper functions */
341
342/**
343 * Get a specific key of the device info list for a client connection.
344 * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize.
345 * This is a helper function for afc_get_device_info().
346 *
347 * @param client The client to get device info for.
348 * @param key The key to get the value of.
349 * @param value The value for the key if successful or NULL otherwise.
350 *
351 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
352 */
121afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value); 353afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value);
354
122afc_error_t afc_dictionary_free(char **dictionary); 355afc_error_t afc_dictionary_free(char **dictionary);
123 356
124#ifdef __cplusplus 357#ifdef __cplusplus