1# @ohos.statfs (statfs) 2 3The **statfs** module provides APIs for obtaining file system information, including the total size and free size of a file system, in bytes. 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> - 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). 9 10## Modules to Import 11 12```ts 13import statfs from '@ohos.statfs'; 14``` 15 16## Statfs.getFreeBytes 17 18getFreeBytes(path:string):Promise<number> 19 20Obtains the free size of the specified file system, in bytes. 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 | Path of the file system.| 29 30**Return value** 31 32 | Type | Description | 33 | --------------------- | -------------- | 34 | Promise<number> | Promise used to return the free size obtained.| 35 36**Example** 37 38 ```ts 39 import { BusinessError } from '@ohos.base'; 40 let path = "/dev"; 41 statfs.getFreeBytes(path).then((number: number) => { 42 console.info("getFreeBytes promise successfully:" + number); 43 }).catch((err: BusinessError) => { 44 console.error("getFreeBytes failed with error:" + JSON.stringify(err)); 45 }); 46 ``` 47 48## Statfs.getFreeBytes 49 50getFreeBytes(path:string, callback:AsyncCallback<number>): void 51 52Obtains the free size of the specified file system, in bytes. This API uses an asynchronous callback to return the result. 53 54**System capability**: SystemCapability.FileManagement.File.FileIO 55 56**Parameters** 57 58 | Name | Type | Mandatory| Description | 59 | -------- | --------------------------- | ---- | ---------------------------- | 60 | path | string | Yes | Path of the file system.| 61 | callback | AsyncCallback<number> | Yes | Callback used to return the free size obtained.| 62 63**Example** 64 65 ```ts 66 import common from '@ohos.app.ability.common'; 67 import { BusinessError } from '@ohos.base'; 68 let context = getContext(this) as common.UIAbilityContext; 69 let path = context.filesDir; 70 statfs.getFreeBytes(path, (err: BusinessError, freeBytes:Number) => { 71 if (err) { 72 console.error('getFreeBytes callback failed'); 73 } else { 74 console.info('getFreeBytes callback success' + freeBytes); 75 } 76 }); 77 ``` 78 79## Statfs.getTotalBytes 80 81getTotalBytes(path: string): Promise<number> 82 83Obtains the total size of the specified file system, in byte. This API uses a promise to return the result. 84 85**System capability**: SystemCapability.FileManagement.File.FileIO 86 87**Parameters** 88 89 | Name| Type | Mandatory| Description | 90 | ---- | ------ | ---- | ---------------------------- | 91 | path | string | Yes | Path of the file system.| 92 93**Return value** 94 95 | Type | Description | 96 | --------------------- | ------------ | 97 | Promise<number> | Promise used to return the total size obtained.| 98 99**Example** 100 101 ```ts 102 import { BusinessError } from '@ohos.base'; 103 let path = "/dev"; 104 statfs.getTotalBytes(path).then((number: number) => { 105 console.info("getTotalBytes promise successfully:" + number); 106 }).catch((err: BusinessError) => { 107 console.error("getTotalBytes failed with error:" + JSON.stringify(err)); 108 }); 109 ``` 110 111## Statfs.getTotalBytes 112 113getTotalBytes(path: string, callback: AsyncCallback<number>): void 114 115Obtains the total size of the specified file system, in bytes. This API uses an asynchronous callback to return the result. 116 117**System capability**: SystemCapability.FileManagement.File.FileIO 118 119**Parameters** 120 121 | Name | Type | Mandatory| Description | 122 | -------- | --------------------------- | ---- | ---------------------------- | 123 | path | string | Yes | Path of the file system.| 124 | callback | AsyncCallback<number> | Yes | Callback used to return the total size obtained. | 125 126**Example** 127 128 ```ts 129 import common from '@ohos.app.ability.common'; 130 import { BusinessError } from '@ohos.base'; 131 let context = getContext(this) as common.UIAbilityContext; 132 let path = context.filesDir; 133 statfs.getTotalBytes(path, (err: BusinessError, totalBytes:Number) => { 134 if (err) { 135 console.error('getTotalBytes callback failed'); 136 } else { 137 console.info('getTotalBytes callback success' + totalBytes); 138 } 139 }); 140 ``` 141