目录

Obtaining Application and File System Space Statistics

In the system, there may be insufficient system space or directories such as cacheDir may be subject to system quota restrictions. Application developers need to pay attention to the remaining system space and control the space occupied by their applications.

Available APIs

For details about APIs, see ohos.file.statvfs and ohos.file.storageStatistics.

Table 1 APIs for application and file system space statistics

Module API Description
@ohos.file.storageStatistics getCurrentBundleStats Obtains the storage space of the current application, in bytes.
@ohos.file.storageStatistics getFreeSize

Obtains the available space of the built-in storage, in bytes. This API returns the result asynchronously.

Note: This API is supported since API version 15.

@ohos.file.storageStatistics getFreeSizeSync

Obtains the available space of the built-in storage, in bytes. This API returns the result synchronously.

Note: This API is supported since API version 15.

@ohos.file.storageStatistics getTotalSize

Obtains the total space of the built-in storage, in bytes. This API returns the result asynchronously.

Note: This API is supported since API version 15.

@ohos.file.storageStatistics getTotalSizeSync

Obtains the total space of the built-in storage, in bytes. This API returns the result synchronously.

Note: This API is supported since API version 15.

@ohos.file.statvfs getFreeSize

Obtains the free space of a file system, in bytes.

Note: This API is supported since API version 9.

@ohos.file.statvfs getTotalSize

Obtains the total space of a file system, in bytes.

Note: This API is supported since API version 9.

Table 2 Attributes for application space statistics

The directories involved in the statistics path column in the table refer to the sandbox paths of applications. Before viewing the paths, you need to access the corresponding sandbox space by running the following commands:

  1. hdc shell
  2. nsenter -t {pid} -m sh
BundleStats Attribute Description Directory for Statistics
appSize Size of the application installation files, in bytes.

Application installation file directory:

/data/storage/el1/bundle

cacheSize Size of the application cache files, in bytes.

Application cache file directories:

/data/storage/${el1-el5}/base/cache

/data/storage/${el1-el5}/base/haps/${moduleName}/cache

Note: ${el1-el5} denotes the directories el1, el2, el3, el4, el5. ${moduleName} indicates the module name.

dataSize Size of application files (excluding application installation files), in bytes.

The files include local files, distributed files, and database files of the application.

- Local file directories (parent directories of the cache directories):

/data/storage/${el1-el5}/base

- Distributed application directory:

/data/storage/el2/distributedfiles

- Database directories:

/data/storage/${el1-el5}/database

Note: ${el1-el5} denotes the directories el1, el2, el3, el4, el5.

How to Develop