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> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 9 10## Modules to Import 11 12```js 13import statvfs from '@ohos.file.statvfs'; 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**Example** 36 37 ```js 38 let path = "/dev"; 39 statvfs.getFreeSize(path).then((number) => { 40 console.info("getFreeSize promise successfully, Size: " + number); 41 }).catch((err) => { 42 console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); 43 }); 44 ``` 45 46## statvfs.getFreeSize 47 48getFreeSize(path:string, callback:AsyncCallback<number>): void 49 50Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses an asynchronous callback to return the result. 51 52**System capability**: SystemCapability.FileManagement.File.FileIO 53 54**Parameters** 55 56| Name | Type | Mandatory| Description | 57| -------- | --------------------------- | ---- | ---------------------------- | 58| path | string | Yes | File path of the file system.| 59| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of free bytes obtained.| 60 61**Example** 62 63 ```js 64 let path = "/dev"; 65 statvfs.getFreeSize(path, (err, number) => { 66 if (err) { 67 console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); 68 } else { 69 console.info("getFreeSize callback successfully, Size: " + number); 70 } 71 }); 72 ``` 73 74## statvfs.getTotalSize 75 76getTotalSize(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 statvfs.getTotalSize(path).then((number) => { 99 console.info("getTotalSize promise successfully, Size: " + number); 100 }).catch((err) => { 101 console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); 102 }); 103 ``` 104 105## statvfs.getTotalSize 106 107getTotalSize(path: string, callback: AsyncCallback<number>): void 108 109Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses an asynchronous 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 let path = "/dev"; 124 statvfs.getTotalSize(path, (err, number) => { 125 if (err) { 126 console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); 127 } else { 128 console.info("getTotalSize promise successfully, Size: " + number); 129 } 130 }); 131 ``` 132