• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.statfs (statfs)
2
3The **statfs** module provides APIs for obtaining file system information, including the total number of bytes and the number of idle bytes of the file system.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.statvfs](js-apis-file-statvfs.md).
10
11## Modules to Import
12
13```js
14import statfs from '@ohos.statfs';
15```
16## statfs.getFreeBytes
17
18getFreeBytes(path:string):Promise<number>
19
20Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
21
22**System capability**: SystemCapability.FileManagement.File.FileIO
23
24**Parameters**
25
26| Name| Type  | Mandatory| Description                        |
27| ------ | ------ | ---- | ---------------------------- |
28| path   | string | Yes  | File path of the file system.|
29
30**Return value**
31
32| Type                 | Description          |
33| --------------------- | -------------- |
34| Promise<number> | Promise used to return the number of free bytes obtained.|
35
36**Example**
37
38  ```js
39  let path = "/dev";
40  statfs.getFreeBytes(path).then(function (number) {
41      console.info("getFreeBytes promise successfully:" + number);
42  }).catch(function (err) {
43      console.info("getFreeBytes failed with error:" + err);
44  });
45  ```
46
47## statfs.getFreeBytes
48
49getFreeBytes(path:string, callback:AsyncCallback<number>): void
50
51Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
52
53**System capability**: SystemCapability.FileManagement.File.FileIO
54
55**Parameters**
56
57| Name  | Type                       | Mandatory| Description                        |
58| -------- | --------------------------- | ---- | ---------------------------- |
59| path     | string                      | Yes  | File path of the file system.|
60| callback | AsyncCallback<number> | Yes  | Callback invoked to return the number of free bytes obtained.|
61
62**Example**
63
64  ```js
65  import featureAbility from '@ohos.ability.featureAbility';
66  let context = featureAbility.getContext();
67  context.getFilesDir().then(function (path) {
68      statfs.getFreeBytes(path, function (err, number) {
69          console.info("getFreeBytes callback successfully:" + number);
70      });
71  });
72  ```
73
74## statfs.getTotalBytes
75
76getTotalBytes(path: string): Promise<number>
77
78Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
79
80**System capability**: SystemCapability.FileManagement.File.FileIO
81
82**Parameters**
83
84| Name| Type  | Mandatory| Description                        |
85| ---- | ------ | ---- | ---------------------------- |
86| path | string | Yes  | File path of the file system.|
87
88**Return value**
89
90| Type                 | Description        |
91| --------------------- | ------------ |
92| Promise<number> | Promise used to return the total number of bytes obtained.|
93
94**Example**
95
96  ```js
97  let path = "/dev";
98  statfs.getTotalBytes(path).then(function (number) {
99      console.info("getTotalBytes promise successfully:" + number);
100  }).catch(function (err) {
101      console.info("getTotalBytes failed with error:" + err);
102  });
103  ```
104
105## statfs.getTotalBytes
106
107getTotalBytes(path: string, callback: AsyncCallback<number>): void
108
109Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
110
111**System capability**: SystemCapability.FileManagement.File.FileIO
112
113**Parameters**
114
115| Name  | Type                       | Mandatory| Description                        |
116| -------- | --------------------------- | ---- | ---------------------------- |
117| path     | string                      | Yes  | File path of the file system.|
118| callback | AsyncCallback<number> | Yes  | Callback invoked to return the total number of bytes obtained.  |
119
120**Example**
121
122  ```js
123  import featureAbility from '@ohos.ability.featureAbility';
124  let context = featureAbility.getContext();
125  context.getFilesDir().then(function (path) {
126      statfs.getTotalBytes(path, function(err, number) {
127          console.info("getTotalBytes callback successfully:" + number);
128      });
129  });
130  ```
131