summaryrefslogtreecommitdiffstats
path: root/include/libiphone/afc.h
blob: 77b6f0e51d8b54b25df01e81105590bf509539b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * @file libiphone/afc.h
 * @brief AFC Implementation
 * \internal
 *
 * Copyright (c) 2009 Nikias Bassen All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef AFC_H
#define AFC_H

#ifdef __cplusplus
extern "C" {
#endif

#include <libiphone/libiphone.h>

/* Error Codes */
#define AFC_E_SUCCESS                 0
#define AFC_E_UNKNOWN_ERROR           1
#define AFC_E_OP_HEADER_INVALID       2
#define AFC_E_NO_RESOURCES            3
#define AFC_E_READ_ERROR              4
#define AFC_E_WRITE_ERROR             5
#define AFC_E_UNKNOWN_PACKET_TYPE     6
#define AFC_E_INVALID_ARGUMENT        7
#define AFC_E_OBJECT_NOT_FOUND        8
#define AFC_E_OBJECT_IS_DIR           9
#define AFC_E_PERM_DENIED            10
#define AFC_E_SERVICE_NOT_CONNECTED  11
#define AFC_E_OP_TIMEOUT             12
#define AFC_E_TOO_MUCH_DATA          13
#define AFC_E_END_OF_DATA            14
#define AFC_E_OP_NOT_SUPPORTED       15
#define AFC_E_OBJECT_EXISTS          16
#define AFC_E_OBJECT_BUSY            17
#define AFC_E_NO_SPACE_LEFT          18
#define AFC_E_OP_WOULD_BLOCK         19
#define AFC_E_IO_ERROR               20
#define AFC_E_OP_INTERRUPTED         21
#define AFC_E_OP_IN_PROGRESS         22
#define AFC_E_INTERNAL_ERROR         23

#define AFC_E_MUX_ERROR              30
#define AFC_E_NO_MEM                 31
#define AFC_E_NOT_ENOUGH_DATA        32
#define AFC_E_DIR_NOT_EMPTY          33

typedef int16_t afc_error_t;

/* Flags */
typedef enum {
	AFC_FOPEN_RDONLY   = 0x00000001, // r   O_RDONLY
	AFC_FOPEN_RW       = 0x00000002, // r+  O_RDWR   | O_CREAT
	AFC_FOPEN_WRONLY   = 0x00000003, // w   O_WRONLY | O_CREAT  | O_TRUNC
	AFC_FOPEN_WR       = 0x00000004, // w+  O_RDWR   | O_CREAT  | O_TRUNC
	AFC_FOPEN_APPEND   = 0x00000005, // a   O_WRONLY | O_APPEND | O_CREAT
	AFC_FOPEN_RDAPPEND = 0x00000006  // a+  O_RDWR   | O_APPEND | O_CREAT
} afc_file_mode_t;

typedef enum {
	AFC_HARDLINK = 1,
	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;

/* Interface */
afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t *client);
afc_error_t afc_client_free(afc_client_t client);
afc_error_t afc_get_device_info(afc_client_t client, char ***infos);
afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list);
afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***infolist);
afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle);
afc_error_t afc_file_close(afc_client_t client, uint64_t handle);
afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation);
afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes);
afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes);
afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence);
afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position);
afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize);
afc_error_t afc_remove_path(afc_client_t client, const char *path);
afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to);
afc_error_t afc_make_directory(afc_client_t client, const char *dir);
afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize);
afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname);

/* Helper functions */
char *      afc_get_device_info_field(afc_client_t client, const char *field);

#ifdef __cplusplus
}
#endif

#endif