Add storage_is_mounted api
[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_EXTENDED_INTERNAL, /**< Extended internal storage (External storage used as internal storage) (Since 4.0) */
56 } storage_type_e;
57
58
59 /**
60  * @brief Enumeration for storage devices state.
61  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
62  */
63 typedef enum {
64         STORAGE_STATE_UNMOUNTABLE = -2, /**< Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted */
65         STORAGE_STATE_REMOVED = -1, /**< Storage is not present */
66         STORAGE_STATE_MOUNTED = 0, /**< Storage is present and mounted with read/write access */
67         STORAGE_STATE_MOUNTED_READ_ONLY = 1, /**< Storage is present and mounted with read only access */
68 } storage_state_e;
69
70
71 /**
72  * @brief Called to get information once for each supported storage.
73  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
74  * @param[in] storage_id The unique storage ID
75  * @param[in] type The type of the storage
76  * @param[in] state The current state of the storage
77  * @param[in] path The absolute path to the root directory of the storage
78  * @param[in] user_data The user data passed from the foreach function
79  * @return @c true to continue with the next iteration of the loop, \n
80  *         otherwise @c false to break out of the loop
81  * @pre storage_foreach_device_supported() will invoke this callback function.
82  * @see storage_foreach_device_supported()
83  */
84 typedef bool (*storage_device_supported_cb)(int storage_id, storage_type_e type,
85                 storage_state_e state, const char *path, void *user_data);
86
87
88 /**
89  * @brief Retrieves all the storage in a device.
90  * @details This function invokes the callback function once for each storage in a device. \n
91  *          If storage_device_supported_cb() returns @c false, then the iteration will be finished.
92  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
93  * @param[in] callback The iteration callback function
94  * @param[in] user_data The user data to be passed to the callback function
95  * @return @c 0 on success,
96  *         otherwise a negative error value
97  * @retval #STORAGE_ERROR_NONE Successful
98  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
99  * @post This function invokes storage_device_supported_cb() repeatedly for each supported device.
100  * @see storage_device_supported_cb()
101  */
102 int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data);
103
104
105 /**
106  * @brief Gets the absolute path to the root directory of the given storage.
107  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
108  * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n
109  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n
110  *          If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n
111  *          If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
112  *          You must release @a path using free().
113  * @param[in] storage_id The storage device
114  * @param[out] path The absolute path to the storage directory
115  * @return @c 0 on success,
116  *         otherwise a negative error value
117  * @retval #STORAGE_ERROR_NONE Successful
118  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
119  * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
120  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
121  * @see storage_get_state()
122  */
123 int storage_get_root_directory(int storage_id, char **path);
124
125
126 /**
127  * @brief Enumeration for the storage directory types.
128  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
129  */
130 typedef enum {
131         STORAGE_DIRECTORY_IMAGES, /**< Image directory */
132         STORAGE_DIRECTORY_SOUNDS, /**< Sounds directory */
133         STORAGE_DIRECTORY_VIDEOS, /**< Videos directory */
134         STORAGE_DIRECTORY_CAMERA, /**< Camera directory */
135         STORAGE_DIRECTORY_DOWNLOADS, /**< Downloads directory */
136         STORAGE_DIRECTORY_MUSIC, /**< Music directory */
137         STORAGE_DIRECTORY_DOCUMENTS, /**< Documents directory */
138         STORAGE_DIRECTORY_OTHERS, /**< Others directory */
139         STORAGE_DIRECTORY_SYSTEM_RINGTONES, /**< System ringtones directory. Only available for internal storage. */
140         STORAGE_DIRECTORY_MAX
141 } storage_directory_e;
142
143
144 /**
145  * @brief Gets the absolute path to the each directory of the given storage.
146  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
147  * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n
148  *          When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n
149  *          The directory path may not exist, so you must make sure that it exists before using it.\n
150  *          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
151  *          If you want to access files or directories in #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare %http://tizen.org/privilege/systemsettings.\n
152  *          If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n
153  *          You must release @a path using free().
154  * @param[in] storage_id The storage device
155  * @param[in] type The directory type
156  * @param[out] path The absolute path to the directory type
157  * @return @c 0 on success,
158  *         otherwise a negative error value
159  * @retval #STORAGE_ERROR_NONE Successful
160  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
161  * @retval #STORAGE_ERROR_OUT_OF_MEMORY Out of memory
162  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
163  * @see storage_get_state()
164  */
165 int storage_get_directory(int storage_id, storage_directory_e type, char **path);
166
167
168 /**
169  * @brief Gets the type of the given storage.
170  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
171  * @param[in] storage_id The storage device
172  * @param[out] type The type of the storage
173  * @return @c 0 on success,
174  *         otherwise a negative error value
175  * @retval #STORAGE_ERROR_NONE Successful
176  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
177  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
178  */
179 int storage_get_type(int storage_id, storage_type_e *type);
180
181
182 /**
183  * @brief Gets the current state of the given storage.
184  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
185  * @param[in] storage_id The storage device
186  * @param[out] state The current state of the storage
187  * @return @c 0 on success,
188  *         otherwise a negative error value
189  * @retval #STORAGE_ERROR_NONE Successful
190  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
191  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
192  * @see storage_get_root_directory()
193  * @see storage_get_total_space()
194  * @see storage_get_available_space()
195  */
196 int storage_get_state(int storage_id, storage_state_e *state);
197
198
199 /**
200  * @brief Called when the state of storage changes.
201  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
202  * @param[in] storage_id The unique storage ID
203  * @param[in] state The current state of the storage
204  * @param[in] user_data The user data passed from the foreach function
205  * @pre storage_set_state_changed_cb() will invoke this callback function.
206  * @see storage_set_state_changed_cb()
207  * @see storage_unset_state_changed_cb()
208  */
209 typedef void (*storage_state_changed_cb)(int storage_id, storage_state_e state, void *user_data);
210
211
212 /**
213  * @brief Registers a callback function to be invoked when the state of the storage changes.
214  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
215  * @param[in] storage_id The storage device
216  * @param[in] callback The callback function to register
217  * @param[in] user_data The user data to be passed to the callback function
218  * @return @c 0 on success,
219  *         otherwise a negative error value
220  * @retval #STORAGE_ERROR_NONE Successful
221  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
222  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
223  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
224  * @post storage_state_changed_cb() will be invoked if the state of the registered storage changes.
225  * @see storage_state_changed_cb()
226  * @see storage_unset_state_changed_cb()
227  */
228 int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb callback, void *user_data);
229
230
231 /**
232  * @brief Unregisters the callback function.
233  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
234  * @param[in] storage_id The storage device to monitor
235  * @param[in] callback The callback function to register
236  * @return @c 0 on success,
237  *         otherwise a negative error value
238  * @retval #STORAGE_ERROR_NONE Successful
239  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
240  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
241  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
242  * @see storage_state_changed_cb()
243  * @see storage_set_state_changed_cb()
244  */
245 int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb callback);
246
247
248 /**
249  * @brief Enumeration for storage device types.
250  * @since_tizen 3.0
251  */
252 typedef enum {
253         STORAGE_DEV_EXT_SDCARD = 1001,     /**< SD card device (external storage) */
254         STORAGE_DEV_EXT_USB_MASS_STORAGE,  /**< USB storage device (external storage) */
255         STORAGE_DEV_EXTENDED_INTERNAL,     /**< Extended internal storage device (External storage used as internal storage) (Since 4.0) */
256 } storage_dev_e;
257
258
259 /**
260  * @brief Called when the state of a storage type changes.
261  * @since_tizen 3.0
262  * @param[in] storage_id The unique storage ID
263  * @param[in] dev The type of the external storage device
264  * @param[in] state The state of the storage
265  * @param[in] fstype The type of the file system
266  * @param[in] fsuuid The uuid of the file system
267  * @param[in] mountpath The mount path of the file system
268  * @param[in] primary The primary partition
269  * @param[in] flags The flags for the storage status
270  * @param[in] user_data The user data
271  * @pre storage_set_changed_cb() will invoke this callback function.
272  * @see storage_set_changed_cb()
273  * @see storage_unset_changed_cb()
274  */
275 typedef void (*storage_changed_cb)(int storage_id,
276                 storage_dev_e dev, storage_state_e state,
277                 const char *fstype, const char *fsuuid, const char *mountpath,
278                 bool primary, int flags, void *user_data);
279
280
281 /**
282  * @brief Registers a callback function to be invoked when the state of the specified storage device type changes.
283  * @since_tizen 3.0
284  * @param[in] type The type of the storage device
285  * @param[in] callback The callback function to register
286  * @param[in] user_data The user data to be passed to the callback function
287  * @return @c 0 on success,
288  *         otherwise a negative error value
289  * @retval #STORAGE_ERROR_NONE Successful
290  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
291  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
292  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
293  * @post storage_changed_cb() will be invoked if the state of the registered storage type changes.
294  * @see storage_changed_cb()
295  * @see storage_unset_changed_cb()
296  */
297 int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data);
298
299
300 /**
301  * @brief Unregisters the callback function for storage type state changes.
302  * @since_tizen 3.0
303  * @param[in] type The type of the the storage device
304  * @param[in] callback The callback function to unregister
305  * @return @c 0 on success,
306  *         otherwise a negative error value
307  * @retval #STORAGE_ERROR_NONE Successful
308  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
309  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
310  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
311  * @see storage_changed_cb()
312  * @see storage_set_changed_cb()
313  */
314 int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback);
315
316
317 /**
318  * @brief Gets the total space of the given storage in bytes.
319  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
320  * @param[in] storage_id The storage device
321  * @param[out] bytes The total space size of the storage (bytes)
322  * @return @c 0 on success,
323  *         otherwise a negative error value
324  * @retval #STORAGE_ERROR_NONE Successful
325  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
326  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
327  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
328  * @see storage_get_state()
329  * @see storage_get_available_space()
330  */
331 int storage_get_total_space(int storage_id, unsigned long long *bytes);
332
333
334 /**
335  * @brief Gets the available space size of the given storage in bytes.
336  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
337  * @param[in] storage_id The storage device
338  * @param[out] bytes The available space size of the storage (bytes)
339  * @return @c 0 on success,
340  *         otherwise a negative error value
341  * @retval #STORAGE_ERROR_NONE Successful
342  * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter
343  * @retval #STORAGE_ERROR_NOT_SUPPORTED Storage not supported
344  * @retval #STORAGE_ERROR_OPERATION_FAILED Operation failed
345  * @see storage_get_state()
346  * @see storage_get_total_space()
347  */
348 int storage_get_available_space(int storage_id, unsigned long long *bytes);
349
350
351 /**
352  * @brief Gets the type and the kind of external device for the given storage id.
353  *
354  * @since_tizen 5.0
355  *
356  * @remarks This function works only for external storages.
357  * If @a type is #STORAGE_TYPE_INTERNAL, this function returns #STORAGE_ERROR_INVALID_PARAMETER and @a dev is unchanged.
358  *
359  * @param[in] storage_id The storage id
360  * @param[out] type The storage @a type (internal or external). If @a type is #STORAGE_TYPE_INTERNAL, this function returns #STORAGE_ERROR_INVALID_PARAMETER and @a dev is unchanged.
361  * @param[out] dev The storage device for external storage.
362  *
363  * @return @c 0 on success,
364  *         otherwise a negative error value
365  *
366  * @retval #STORAGE_ERROR_NONE               Successful
367  * @retval #STORAGE_ERROR_INVALID_PARAMETER  Invalid parameter
368  * @retval #STORAGE_ERROR_OUT_OF_MEMORY      Out of memory
369  * @retval #STORAGE_ERROR_NOT_SUPPORTED      Storage not supported
370  * @retval #STORAGE_ERROR_OPERATION_FAILED   Operation failed
371  */
372 int storage_get_type_dev(int storage_id, storage_type_e *type, storage_dev_e *dev);
373
374
375 /**
376  * @}
377  */
378
379 #ifdef __cplusplus
380 }
381 #endif
382 #endif