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```ts 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 ```ts 42 import { BusinessError } from '@ohos.base'; 43 let path: string = "/dev"; 44 statvfs.getFreeSize(path).then((number: number) => { 45 console.info("getFreeSize promise successfully, Size: " + number); 46 }).catch((err: BusinessError) => { 47 console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); 48 }); 49 ``` 50 51## statvfs.getFreeSize 52 53getFreeSize(path:string, callback:AsyncCallback<number>): void 54 55Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses an asynchronous callback to return the result. 56 57**System capability**: SystemCapability.FileManagement.File.FileIO 58 59**Parameters** 60 61 | Name | Type | Mandatory| Description | 62 | -------- | --------------------------- | ---- | ---------------------------- | 63 | path | string | Yes | File path of the file system.| 64 | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of free bytes obtained.| 65 66**Error codes** 67 68For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes). 69 70**Example** 71 72 ```ts 73 import { BusinessError } from '@ohos.base'; 74 let path: string = "/dev"; 75 statvfs.getFreeSize(path, (err: BusinessError, number: number) => { 76 if (err) { 77 console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); 78 } else { 79 console.info("getFreeSize callback successfully, Size: " + number); 80 } 81 }); 82 ``` 83 84## statvfs.getFreeSizeSync<sup>10+</sup> 85 86getFreeSizeSync(path:string): number 87 88Obtains the number of free bytes of the specified file system. This API returns the result synchronously. 89 90**System capability**: SystemCapability.FileManagement.File.FileIO 91 92**Parameters** 93 94 | Name| Type | Mandatory| Description | 95 | ------ | ------ | ---- | ---------------------------- | 96 | path | string | Yes | File path of the file system.| 97 98**Return value** 99 100 | Type | Description | 101 | --------------------- | -------------- | 102 | number | Promise used to return the number of free bytes obtained.| 103 104**Error codes** 105 106For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes). 107 108**Example** 109 110 ```ts 111 let path = "/dev"; 112 let number = statvfs.getFreeSizeSync(path); 113 console.info("getFreeSize promise successfully, Size: " + number); 114 ``` 115 116## statvfs.getTotalSize 117 118getTotalSize(path: string): Promise<number> 119 120Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result. 121 122**System capability**: SystemCapability.FileManagement.File.FileIO 123 124**Parameters** 125 126 | Name| Type | Mandatory| Description | 127 | ---- | ------ | ---- | ---------------------------- | 128 | path | string | Yes | File path of the file system.| 129 130**Return value** 131 132 | Type | Description | 133 | --------------------- | ------------ | 134 | Promise<number> | Promise used to return the total number of bytes obtained.| 135 136**Error codes** 137 138For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes). 139 140**Example** 141 142 ```ts 143 import { BusinessError } from '@ohos.base'; 144 let path: string = "/dev"; 145 statvfs.getTotalSize(path).then((number: number) => { 146 console.info("getTotalSize promise successfully, Size: " + number); 147 }).catch((err: BusinessError) => { 148 console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); 149 }); 150 ``` 151 152## statvfs.getTotalSize 153 154getTotalSize(path: string, callback: AsyncCallback<number>): void 155 156Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses an asynchronous callback to return the result. 157 158**System capability**: SystemCapability.FileManagement.File.FileIO 159 160**Parameters** 161 162 | Name | Type | Mandatory| Description | 163 | -------- | --------------------------- | ---- | ---------------------------- | 164 | path | string | Yes | File path of the file system.| 165 | callback | AsyncCallback<number> | Yes | Callback invoked to return the total number of bytes obtained. | 166 167**Error codes** 168 169For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes). 170 171**Example** 172 173 ```ts 174 import { BusinessError } from '@ohos.base'; 175 let path: string = "/dev"; 176 statvfs.getTotalSize(path, (err: BusinessError, number: number) => { 177 if (err) { 178 console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); 179 } else { 180 console.info("getTotalSize promise successfully, Size: " + number); 181 } 182 }); 183 ``` 184 185## statvfs.getTotalSizeSync<sup>10+</sup> 186 187getTotalSizeSync(path: string): number 188 189Obtains the total number of bytes of the specified file system. This API returns the result synchronously. 190 191**System capability**: SystemCapability.FileManagement.File.FileIO 192 193**Parameters** 194 195 | Name| Type | Mandatory| Description | 196 | ---- | ------ | ---- | ---------------------------- | 197 | path | string | Yes | File path of the file system.| 198 199**Return value** 200 201 | Type | Description | 202 | --------------------- | ------------ | 203 | number | Promise used to return the total number of bytes obtained.| 204 205**Error codes** 206 207For details about the error codes, see [Basic File IO Error Codes](../errorcodes/errorcode-filemanagement.md#basic-file-io-error-codes). 208 209**Example** 210 211 ```ts 212 let path = "/dev"; 213 let number = statvfs.getTotalSizeSync(path); 214 console.info("getTotalSize promise successfully, Size: " + number); 215 ``` 216