Tizen Native API

Functions

int storage_foreach_device_supported (storage_device_supported_cb callback, void *user_data)
 Retrieves all storage in a device.
int storage_get_root_directory (int storage_id, char **path)
 Gets the absolute path to the root directory of the given storage.
int storage_get_directory (int storage_id, storage_directory_e type, char **path)
 Gets the absolute path to the each directory of the given storage.
int storage_get_type (int storage_id, storage_type_e *type)
 Gets the type of the given storage.
int storage_get_state (int storage_id, storage_state_e *state)
 Gets the current state of the given storage.
int storage_set_state_changed_cb (int storage_id, storage_state_changed_cb callback, void *user_data)
 Registers a callback function to be invoked when the state of the storage changes.
int storage_unset_state_changed_cb (int storage_id, storage_state_changed_cb callback)
 Unregisters the callback function.
int storage_get_total_space (int storage_id, unsigned long long *bytes)
 Gets the total space of the given storage in bytes.
int storage_get_available_space (int storage_id, unsigned long long *bytes)
 Gets the available space size of the given storage in bytes.
int storage_get_internal_memory_size (struct statvfs *buf)
 This generic API is used to get the internal memory size.
int storage_get_external_memory_size (struct statvfs *buf)
 This generic API is used to get the external memory size.

Typedefs

typedef bool(* storage_device_supported_cb )(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
 Called to get information once for each supported storage.
typedef void(* storage_state_changed_cb )(int storage_id, storage_state_e state, void *user_data)
 Called when the state of storage changes.

The STORAGE API provides functions to get storage information.

Required Header

#include <storage.h>

Overview

The STORAGE API provides functions to get storage information.

The type of storage information includes:

  • Root directory
  • Storage type (Internal or External)
  • Storage status
  • Total and available space size

The type of directory information includes:

  • Images
  • Sounds
  • Videos
  • Camera
  • Downloads
  • Music
  • Documents
  • Others
  • System ringtones

Typedef Documentation

typedef bool(* storage_device_supported_cb)(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)

Called to get information once for each supported storage.

Since :
2.3
Parameters:
[in]storage_idThe unique storage ID
[in]typeThe type of the storage
[in]stateThe current state of the storage
[in]pathThe absolute path to the root directory of the storage
[in]user_dataThe user data passed from the foreach function
Returns:
true to continue with the next iteration of the loop,
otherwise false to break out of the loop
Precondition:
storage_foreach_device_supported() will invoke this callback function.
See also:
storage_foreach_device_supported()
typedef void(* storage_state_changed_cb)(int storage_id, storage_state_e state, void *user_data)

Called when the state of storage changes.

Since :
2.3
Parameters:
[in]storage_idThe unique storage ID
[in]stateThe current state of the storage
[in]user_dataThe user data passed from the foreach function
Precondition:
storage_set_state_changed_cb() will invoke this callback function.
See also:
storage_set_state_changed_cb()
storage_unset_state_changed_cb()

Enumeration Type Documentation

Enumeration of the storage directory types.

Since :
2.3
Enumerator:
STORAGE_DIRECTORY_IMAGES 

Image directory

STORAGE_DIRECTORY_SOUNDS 

Sounds directory

STORAGE_DIRECTORY_VIDEOS 

Videos directory

STORAGE_DIRECTORY_CAMERA 

Camera directory

STORAGE_DIRECTORY_DOWNLOADS 

Downloads directory

STORAGE_DIRECTORY_MUSIC 

Music directory

STORAGE_DIRECTORY_DOCUMENTS 

Documents directory

STORAGE_DIRECTORY_OTHERS 

Others directory

STORAGE_DIRECTORY_SYSTEM_RINGTONES 

System ringtones directory. Only available for internal storage.

Enumeration of error codes for Storage.

Since :
2.3
Enumerator:
STORAGE_ERROR_NONE 

Successful

STORAGE_ERROR_INVALID_PARAMETER 

Invalid parameter

STORAGE_ERROR_OUT_OF_MEMORY 

Out of memory

STORAGE_ERROR_NOT_SUPPORTED 

Storage not supported

STORAGE_ERROR_OPERATION_FAILED 

Operation failed

Enumeration of the state of storage devices.

Since :
2.3
Enumerator:
STORAGE_STATE_UNMOUNTABLE 

Storage is present but cannot be mounted. Typically it happens if the file system of the storage is corrupted

STORAGE_STATE_REMOVED 

Storage is not present

STORAGE_STATE_MOUNTED 

Storage is present and mounted with read/write access

STORAGE_STATE_MOUNTED_READ_ONLY 

Storage is present and mounted with read only access

Enumeration of the storage types.

Since :
2.3
Enumerator:
STORAGE_TYPE_INTERNAL 

Internal device storage (built-in storage in a device, non-removable)

STORAGE_TYPE_EXTERNAL 

External storage


Function Documentation

int storage_foreach_device_supported ( storage_device_supported_cb  callback,
void *  user_data 
)

Retrieves all storage in a device.

This function invokes the callback function once for each storage in a device.
If storage_device_supported_cb() returns false, then the iteration will be finished.

Since :
2.3
Parameters:
[in]callbackThe iteration callback function
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
Postcondition:
This function invokes storage_device_supported_cb() repeatedly for each supported device.
See also:
storage_device_supported_cb()
int storage_get_available_space ( int  storage_id,
unsigned long long *  bytes 
)

Gets the available space size of the given storage in bytes.

Since :
2.3
Parameters:
[in]storage_idThe storage device
[out]bytesThe available space size of the storage (bytes)
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
STORAGE_ERROR_OPERATION_FAILEDOperation failed
See also:
storage_get_state()
storage_get_total_space()
int storage_get_directory ( int  storage_id,
storage_directory_e  type,
char **  path 
)

Gets the absolute path to the each directory of the given storage.

Files saved on the internal/external storage are readable or writeable by all applications. When an application is uninstalled, the files written by that application are not removed from the internal/external storage.

Since :
2.3
Remarks:
The directory path may not exist, so you must make sure that it exists before using it.
If you want to access files or directories in internal storage except STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/mediastorage.
If you want to access files or directories in STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/systemsettings.
If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.
You must release path using free().
Parameters:
[in]storage_idThe storage device
[in]typeThe directory type
[out]pathThe absolute path to the directory type
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_OUT_OF_MEMORYOut of memory
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
See also:
storage_get_state()
int storage_get_external_memory_size ( struct statvfs *  buf)

This generic API is used to get the external memory size.

Since :
2.3
Parameters:
[out]bufA pointer to a statvfs structure
Returns:
0 on success, otherwise a negative error value on failure
See also:
Example:
    ...
  struct statvfs s;
    if (storage_get_external_memory_size(&s) < 0)
        dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get external memory size");
    else
        dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf",
                (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail);
    ...
int storage_get_internal_memory_size ( struct statvfs *  buf)

This generic API is used to get the internal memory size.

Since :
2.3
Parameters:
[out]bufA pointer to a statvfs structure
Returns:
0 on success, otherwise a negative error value on failure
See also:
Example:
    ...
  struct statvfs s;
    if (storage_get_internal_memory_size(&s) < 0)
        dlog_print(DLOG_DEBUG, LOG_TAG, "Fail to get internal memory size");
    else
        dlog_print(DLOG_DEBUG, LOG_TAG, "Total mem : %lf, Avail mem : %lf",
                (double)s.f_frsize*s.f_blocks, (double)s.f_bsize*s.f_bavail);
    ...
int storage_get_root_directory ( int  storage_id,
char **  path 
)

Gets the absolute path to the root directory of the given storage.

Files saved on the internal/external storage are readable or writeable by all applications. When an application is uninstalled, the files written by that application are not removed from the internal/external storage.

Since :
2.3
Remarks:
If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.
If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.
You must release path using free().
Parameters:
[in]storage_idThe storage device
[out]pathThe absolute path to the storage directory
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_OUT_OF_MEMORYOut of memory
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
See also:
storage_get_state()
int storage_get_state ( int  storage_id,
storage_state_e state 
)

Gets the current state of the given storage.

Since :
2.3
Parameters:
[in]storage_idThe storage device
[out]stateThe current state of the storage
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
See also:
storage_get_root_directory()
storage_get_total_space()
storage_get_available_space()
int storage_get_total_space ( int  storage_id,
unsigned long long *  bytes 
)

Gets the total space of the given storage in bytes.

Since :
2.3
Parameters:
[in]storage_idThe storage device
[out]bytesThe total space size of the storage (bytes)
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
STORAGE_ERROR_OPERATION_FAILEDOperation failed
See also:
storage_get_state()
storage_get_available_space()
int storage_get_type ( int  storage_id,
storage_type_e type 
)

Gets the type of the given storage.

Since :
2.3
Parameters:
[in]storage_idThe storage device
[out]typeThe type of the storage
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
int storage_set_state_changed_cb ( int  storage_id,
storage_state_changed_cb  callback,
void *  user_data 
)

Registers a callback function to be invoked when the state of the storage changes.

Since :
2.3
Parameters:
[in]storage_idThe storage device
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
STORAGE_ERROR_OPERATION_FAILEDOperation failed
Postcondition:
storage_state_changed_cb() will be invoked if the state of the registered storage changes.
See also:
storage_state_changed_cb()
storage_unset_state_changed_cb()
int storage_unset_state_changed_cb ( int  storage_id,
storage_state_changed_cb  callback 
)

Unregisters the callback function.

Since :
2.3
Parameters:
[in]storage_idThe storage device to monitor
[in]callbackThe callback function to register
Returns:
0 on success, otherwise a negative error value
Return values:
STORAGE_ERROR_NONESuccessful
STORAGE_ERROR_INVALID_PARAMETERInvalid parameter
STORAGE_ERROR_NOT_SUPPORTEDStorage not supported
STORAGE_ERROR_OPERATION_FAILEDOperation failed
See also:
storage_state_changed_cb()
storage_set_state_changed_cb()