Proofread header file
[platform/core/system/libstorage.git] / include / storage-expand.h
1 /*
2  * storage
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19 #ifndef __STORAGE_EXPAND_H__
20 #define __STORAGE_EXPAND_H__
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26
27  /**
28  * @addtogroup CAPI_SYSTEM_STORAGE_MODULE
29  * @{
30  */
31
32 #include <tizen.h>
33
34
35 /**
36  * @brief Enumeration for Storage of error codes.
37  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
38  */
39 typedef enum {
40         STORAGE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
41         STORAGE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
42         STORAGE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
43         STORAGE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NO_SUCH_DEVICE, /**< Storage not supported */
44         STORAGE_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */
45 } storage_error_e;
46
47
48 /**
49  * @brief Enumeration for the storage types.
50  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
51  */
52 typedef enum {
53         STORAGE_TYPE_INTERNAL, /**< Internal device storage (built-in storage in a device, non-removable) */
54         STORAGE_TYPE_EXTERNAL, /**< External storage */
55 } storage_type_e;
56
57
58 /**
59  * @brief Enumeration for storage devices state.
60  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
61  */
62 typedef enum {
63         STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted */
64         STORAGE_STATE_REMOVED = -1, /**< Storage is not present */
65         STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access */
66         STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access */
67 } storage_state_e;
68
69
70 /**
71  * @brief Called to get information once for each supported storage.
72  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
73  * @param[in] storage_id The unique storage ID
74  * @param[in] type The type of the storage
75  * @param[in] state The current state of the storage
76  * @param[in] path The absolute path to the root directory of the storage
77  * @param[in] user_data The user data passed from the foreach function
78  * @return @c true to continue with the next iteration of the loop, \n
79  *         otherwise @c false to break out of the loop
80  * @pre storage_foreach_device_supported() will invoke this callback function.
81  * @see storage_foreach_device_supported()
82  */
83 typedef bool (*storage_device_supported_cb)(int storage_id, storage_type_e type,
84                 storage_state_e state, const char *path, void *user_data);
85
86
87 /**
88  * @brief Retrieves all the storage in a device.
89  * @details This function invokes the callback function once for each storage in a device. \n
90  *          If storage_device_supported_cb() returns @c false, then the iteration will be finished.
91  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
92  * @param[in] callback The iteration callback function
93  * @param[in] user_data The user data to be passed to the callback function
94  * @return @c 0 on success,
95  *         otherwise a negative error value
96  * @retval #STORAGE_ERROR_NONE Successful
97  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
98  * @post This function invokes storage_device_supported_cb() repeatedly for each supported device.
99  * @see storage_device_supported_cb()
100  */
101 int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data);
102
103
104 /**
105  * @brief Gets the absolute path to the root directory of the given storage.
106  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
107  * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n
108  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n
109  *          If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n
110  *          If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
111  *          You must release @a path using free().
112  * @param[in] storage_id The storage device
113  * @param[out] path The absolute path to the storage directory
114  * @return @c 0 on success,
115  *         otherwise a negative error value
116  * @retval #STORAGE_ERROR_NONE Successful
117  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
118  * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
119  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
120  * @see storage_get_state()
121  */
122 int storage_get_root_directory(int storage_id, char **path);
123
124
125 /**
126  * @brief Enumeration for the storage directory types.
127  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
128  */
129 typedef enum {
130         STORAGE_DIRECTORY_IMAGES, /**< Image directory */
131         STORAGE_DIRECTORY_SOUNDS, /**< Sounds directory */
132         STORAGE_DIRECTORY_VIDEOS, /**< Videos directory */
133         STORAGE_DIRECTORY_CAMERA, /**< Camera directory */
134         STORAGE_DIRECTORY_DOWNLOADS, /**< Downloads directory */
135         STORAGE_DIRECTORY_MUSIC, /**< Music directory */
136         STORAGE_DIRECTORY_DOCUMENTS, /**< Documents directory */
137         STORAGE_DIRECTORY_OTHERS, /**< Others directory */
138         STORAGE_DIRECTORY_SYSTEM_RINGTONES, /**< System ringtones directory. Only available for internal storage. */
139         STORAGE_DIRECTORY_MAX
140 } storage_directory_e;
141
142
143 /**
144  * @brief Gets the absolute path to the each directory of the given storage.
145  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
146  * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n
147  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n
148  *          The directory path may not exist, so you must make sure that it exists before using it.\n
149  *          If you want to access files or directories in internal storage except #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/mediastorage.\n
150  *          If you want to access files or directories in #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare %http://tizen.org/privilege/systemsettings.\n
151  *          If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
152  *          You must release @a path using free().
153  * @param[in] storage_id The storage device
154  * @param[in] type The directory type
155  * @param[out] path The absolute path to the directory type
156  * @return @c 0 on success,
157  *         otherwise a negative error value
158  * @retval #STORAGE_ERROR_NONE Successful
159  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
160  * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
161  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
162  * @see storage_get_state()
163  */
164 int storage_get_directory(int storage_id, storage_directory_e type, char **path);
165
166
167 /**
168  * @brief Gets the type of the given storage.
169  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
170  * @param[in] storage_id The storage device
171  * @param[out] type The type of the storage
172  * @return @c 0 on success,
173  *         otherwise a negative error value
174  * @retval #STORAGE_ERROR_NONE Successful
175  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
176  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
177  */
178 int storage_get_type(int storage_id, storage_type_e *type);
179
180
181 /**
182  * @brief Gets the current state of the given storage.
183  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
184  * @param[in] storage_id The storage device
185  * @param[out] state The current state of the storage
186  * @return @c 0 on success,
187  *         otherwise a negative error value
188  * @retval #STORAGE_ERROR_NONE Successful
189  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
190  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
191  * @see storage_get_root_directory()
192  * @see storage_get_total_space()
193  * @see storage_get_available_space()
194  */
195 int storage_get_state(int storage_id, storage_state_e *state);
196
197
198 /**
199  * @brief Called when the state of storage changes.
200  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
201  * @param[in] storage_id The unique storage ID
202  * @param[in] state The current state of the storage
203  * @param[in] user_data The user data passed from the foreach function
204  * @pre storage_set_state_changed_cb() will invoke this callback function.
205  * @see storage_set_state_changed_cb()
206  * @see storage_unset_state_changed_cb()
207  */
208 typedef void (*storage_state_changed_cb)(int storage_id, storage_state_e state, void *user_data);
209
210
211 /**
212  * @brief Registers a callback function to be invoked when the state of the storage changes.
213  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
214  * @param[in] storage_id The storage device
215  * @param[in] callback The callback function to register
216  * @param[in] user_data The user data to be passed to the callback function
217  * @return @c 0 on success,
218  *         otherwise a negative error value
219  * @retval #STORAGE_ERROR_NONE Successful
220  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
221  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
222  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
223  * @post storage_state_changed_cb() will be invoked if the state of the registered storage changes.
224  * @see storage_state_changed_cb()
225  * @see storage_unset_state_changed_cb()
226  */
227 int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data);
228
229
230 /**
231  * @brief Unregisters the callback function.
232  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
233  * @param[in] storage_id The storage device to monitor
234  * @param[in] callback The callback function to register
235  * @return @c 0 on success,
236  *         otherwise a negative error value
237  * @retval #STORAGE_ERROR_NONE Successful
238  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
239  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
240  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
241  * @see storage_state_changed_cb()
242  * @see storage_set_state_changed_cb()
243  */
244 int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback);
245
246
247 /**
248  * @brief Enumeration for storage device types.
249  * @since_tizen 3.0
250  */
251 typedef enum {
252         STORAGE_DEV_EXT_SDCARD = 1001, /**< sdcard device (external storage) */
253         STORAGE_DEV_EXT_USB_MASS_STORAGE, /**< USB storage device (external storage) */
254 } storage_dev_e;
255
256
257 /**
258  * @brief Called when the state of a storage type changes.
259  * @since_tizen 3.0
260  * @param[in] storage_id The unique storage ID
261  * @param[in] type The type of the storage device
262  * @param[in] state The state of the storage
263  * @param[in] fstype The type of the file system
264  * @param[in] fsuuid The uuid of the file system
265  * @param[in] mountpath The mount path of the file system
266  * @param[in] primary The primary partition
267  * @param[in] flags The flags for the storage status
268  * @param[in] user_data The user data
269  * @pre storage_set_changed_cb() will invoke this callback function.
270  * @see storage_set_changed_cb()
271  * @see storage_unset_changed_cb()
272  */
273 typedef void (*storage_changed_cb)(int storage_id,
274                 storage_dev_e dev, storage_state_e state,
275                 const char *fstype, const char *fsuuid, const char *mountpath,
276                 bool primary, int flags, void *user_data);
277
278
279 /**
280  * @brief Registers a callback function to be invoked when the state of the specified storage device type changes.
281  * @since_tizen 3.0
282  * @param[in] type The type of the storage device
283  * @param[in] callback The callback function to register
284  * @param[in] user_data The user data to be passed to the callback function
285  * @return @c 0 on success,
286  *         otherwise a negative error value
287  * @retval #STORAGE_ERROR_NONE Successful
288  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
289  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
290  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
291  * @post storage_changed_cb() will be invoked if the state of the registered storage type changes.
292  * @see storage_changed_cb()
293  * @see storage_unset_changed_cb()
294  */
295 int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data);
296
297
298 /**
299  * @brief Unregisters the callback function for storage type state changes.
300  * @since_tizen 3.0
301  * @param[in] type The type of the the storage device
302  * @param[in] callback The callback function to unregister
303  * @return @c 0 on success,
304  *         otherwise a negative error value
305  * @retval #STORAGE_ERROR_NONE Successful
306  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
307  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
308  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
309  * @see storage_changed_cb()
310  * @see storage_set_changed_cb()
311  */
312 int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback);
313
314
315 /**
316  * @brief Gets the total space of the given storage in bytes.
317  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
318  * @param[in] storage_id The storage device
319  * @param[out] bytes The total space size of the storage (bytes)
320  * @return @c 0 on success,
321  *         otherwise a negative error value
322  * @retval #STORAGE_ERROR_NONE Successful
323  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
324  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
325  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
326  * @see storage_get_state()
327  * @see storage_get_available_space()
328  */
329 int storage_get_total_space(int storage_id, unsigned long long *bytes);
330
331
332 /**
333  * @brief Gets the available space size of the given storage in bytes.
334  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
335  * @param[in] storage_id The storage device
336  * @param[out] bytes The available space size of the storage (bytes)
337  * @return @c 0 on success,
338  *         otherwise a negative error value
339  * @retval #STORAGE_ERROR_NONE Successful
340  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
341  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
342  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
343  * @see storage_get_state()
344  * @see storage_get_total_space()
345  */
346 int storage_get_available_space(int storage_id, unsigned long long *bytes);
347
348
349 /**
350  * @}
351  */
352
353 #ifdef __cplusplus
354 }
355 #endif
356 #endif