• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.statvfs (File System Space Statistics)
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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import statvfs from '@ohos.file.statvfs';
13```
14
15## statvfs.getFreeSize
16
17getFreeSize(path:string):Promise<number>
18
19Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
20
21**System capability**: SystemCapability.FileManagement.File.FileIO
22
23**Parameters**
24
25  | Name| Type  | Mandatory| Description                        |
26  | ------ | ------ | ---- | ---------------------------- |
27  | path   | string | Yes  | File path of the file system.|
28
29**Return value**
30
31  | Type                 | Description          |
32  | --------------------- | -------------- |
33  | Promise<number> | Promise used to return the number of free bytes obtained.|
34
35**Error codes**
36
37For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
38
39**Example**
40
41  ```js
42  let path = "/dev";
43  statvfs.getFreeSize(path).then((number) => {
44    console.info("getFreeSize promise successfully, Size: " + number);
45  }).catch((err) => {
46    console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
47  });
48  ```
49
50## statvfs.getFreeSize
51
52getFreeSize(path:string, callback:AsyncCallback<number>): void
53
54Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses an asynchronous callback to return the result.
55
56**System capability**: SystemCapability.FileManagement.File.FileIO
57
58**Parameters**
59
60  | Name  | Type                       | Mandatory| Description                        |
61  | -------- | --------------------------- | ---- | ---------------------------- |
62  | path     | string                      | Yes  | File path of the file system.|
63  | callback | AsyncCallback<number> | Yes  | Callback invoked to return the number of free bytes obtained.|
64
65**Error codes**
66
67For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
68
69**Example**
70
71  ```js
72  let path = "/dev";
73  statvfs.getFreeSize(path, (err, number) => {
74    if (err) {
75      console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
76    } else {
77      console.info("getFreeSize callback successfully, Size: " + number);
78    }
79  });
80  ```
81
82## statvfs.getTotalSize
83
84getTotalSize(path: string): Promise<number>
85
86Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
87
88**System capability**: SystemCapability.FileManagement.File.FileIO
89
90**Parameters**
91
92  | Name| Type  | Mandatory| Description                        |
93  | ---- | ------ | ---- | ---------------------------- |
94  | path | string | Yes  | File path of the file system.|
95
96**Return value**
97
98  | Type                 | Description        |
99  | --------------------- | ------------ |
100  | Promise<number> | Promise used to return the total number of bytes obtained.|
101
102**Error codes**
103
104For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
105
106**Example**
107
108  ```js
109  let path = "/dev";
110  statvfs.getTotalSize(path).then((number) => {
111    console.info("getTotalSize promise successfully, Size: " + number);
112  }).catch((err) => {
113    console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
114  });
115  ```
116
117## statvfs.getTotalSize
118
119getTotalSize(path: string, callback: AsyncCallback<number>): void
120
121Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses an asynchronous callback to return the result.
122
123**System capability**: SystemCapability.FileManagement.File.FileIO
124
125**Parameters**
126
127  | Name  | Type                       | Mandatory| Description                        |
128  | -------- | --------------------------- | ---- | ---------------------------- |
129  | path     | string                      | Yes  | File path of the file system.|
130  | callback | AsyncCallback<number> | Yes  | Callback invoked to return the total number of bytes obtained.  |
131
132**Error codes**
133
134For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes).
135
136**Example**
137
138  ```js
139  let path = "/dev";
140  statvfs.getTotalSize(path, (err, number) => {
141    if (err) {
142      console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
143    } else {
144      console.info("getTotalSize promise successfully, Size: " + number);
145    }
146  });
147  ```
148