1# 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**<br> 6> 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. 7 8## Modules to Import 9 10```js 11import statfs from '@ohos.statfs'; 12``` 13## statfs.getFreeBytes 14 15getFreeBytes(path:string):Promise<number> 16 17Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result. 18 19**System capability**: SystemCapability.FileManagement.File.FileIO 20 21- **Parameters** 22 23 | Name| Type | Mandatory| Description | 24 | ------ | ------ | ---- | ---------------------------- | 25 | path | string | Yes | File path of the file system.| 26 27- Return value 28 29 | Type | Description | 30 | --------------------- | -------------- | 31 | Promise<number> | Promise used to return the number of free bytes obtained.| 32 33- Example 34 35 ```js 36 let path = "/dev"; 37 statfs.getFreeBytes(path).then(function (number){ 38 console.info("getFreeBytes promise successfully:"+ number); 39 }).catch(function(err){ 40 console.info("getFreeBytes failed with error:"+ err); 41 }); 42 ``` 43 44## statfs.getFreeBytes 45 46getFreeBytes(path:string, callback:AsyncCallback<number>): void 47 48Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result. 49 50**System capability**: SystemCapability.FileManagement.File.FileIO 51 52- **Parameters** 53 54 | Name | Type | Mandatory| Description | 55 | -------- | --------------------------- | ---- | ---------------------------- | 56 | path | string | Yes | File path of the file system.| 57 | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of free bytes obtained.| 58 59- Example 60 61 ```js 62 import featureAbility from '@ohos.ability.featureAbility'; 63 let context = featureAbility.getContext(); 64 context.getFilesDir().then(function (path) { 65 statfs.getFreeBytes(path, function(err, number){ 66 console.info("Got free bytes successfully:"+ number); 67 }); 68 }); 69 ``` 70 71## statfs.getTotalBytes 72 73getTotalBytes(path: string): Promise<number> 74 75Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result. 76 77**System capability**: SystemCapability.FileManagement.File.FileIO 78 79- **Parameters** 80 81 | Name| Type | Mandatory| Description | 82 | ---- | ------ | ---- | ---------------------------- | 83 | path | string | Yes | File path of the file system.| 84 85- Return value 86 87 | Type | Description | 88 | --------------------- | ------------ | 89 | Promise<number> | Promise used to return the total number of bytes obtained.| 90 91- Example 92 93 ```js 94 let path = "/dev"; 95 statfs.getTotalBytes(path).then(function (number){ 96 console.info("getTotalBytes promise successfully:"+ number); 97 }).catch(function(err){ 98 console.info("getTotalBytes failed with error:"+ err); 99 }); 100 ``` 101 102## statfs.getTotalBytes 103 104getTotalBytes(path: string, callback: AsyncCallback<number>): void 105 106Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result. 107 108**System capability**: SystemCapability.FileManagement.File.FileIO 109 110- **Parameters** 111 112 | Name | Type | Mandatory| Description | 113 | -------- | --------------------------- | ---- | ---------------------------- | 114 | path | string | Yes | File path of the file system.| 115 | callback | AsyncCallback<number> | Yes | Callback invoked to return the total number of bytes obtained. | 116 117- Example 118 119 ```js 120 import featureAbility from '@ohos.ability.featureAbility'; 121 let context = featureAbility.getContext(); 122 context.getFilesDir().then(function (path) { 123 statfs.getTotalBytes(path, function(err, number){ 124 console.info("Got total bytes successfully:"+ number); 125 }); 126 }); 127 ``` 128