harmony 鸿蒙@ohos.volumeManager (Volume Management)
@ohos.volumeManager (Volume Management)
The volumeManager module provides APIs for volume and disk management, including obtaining volume information, mounting or unmounting volumes, partitioning disks, and formatting volumes.
NOTE
- The initial APIs of this module are supported since API version 9.
 - The APIs of this module are system APIs and cannot be called by third-party applications.
 
Modules to Import
import volumemanager from "@ohos.volumeManager";
volumemanager.getAllVolumes
getAllVolumes(): Promise<Array<Volume>>
Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Return value
| Type | Description | 
|---|---|
| Promise<Volume[]> | Promise used to return the execution result. | 
Example
  volumemanager.getAllVolumes().then(function(volumes){
      // Do something.
  });
volumemanager.getAllVolumes
getAllVolumes(callback: AsyncCallback<Array<Volume>>): void
Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| callback | AsyncCallback<Volume[]> | Yes | Callback invoked to return the volume information obtained. | 
Example
  let uuid = "";
  volumemanager.getAllVolumes(function(error, volumes){
      // Do something
  });
volumemanager.mount
mount(volumeId: string): Promise<boolean>
Asynchronously mounts a volume. This API uses a promise to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
Return value
| Type | Description | 
|---|---|
| Promise<boolean> | Promise used to return the execution result. | 
Example
  let volumeId = "";
  volumemanager.mount(volumeId).then(function(flag){
      // Do something
  });
volumemanager.mount
mount(volumeId: string, callback:AsyncCallback<boolean>):void
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the execution result. | 
Example
  let volumeId = "";
  volumemanager.mount(volumeId, function(error, flag){
      // Do something
  });
volumemanager.unmount
unmount(volumeId: string): Promise<boolean>
Asynchronously unmounts a volume. This API uses a promise to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
Return value
| Type | Description | 
|---|---|
| Promise<boolean> | Promise used to return the execution result. | 
Example
  let volumeId = "";
  volumemanager.unmount(volumeId).then(function(flag){
      // Do something
  });
volumemanager.unmount
unmount(volumeId: string, callback: AsyncCallback<boolean>): void
Asynchronously unmounts a volume. This API uses a callback to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the execution result. | 
Example
  let volumeId = "";
  volumemanager.unmount(volumeId, function(error, flag){
      // Do something
  });
volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string): Promise<Volume>
Asynchronously obtains volume information based on the universally unique identifier (UUID). This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| uuid | string | Yes | UUID of the volume. | 
Return value
| Type | Description | 
|---|---|
| Promise<Volume> | Promise used to return the volume information obtained. | 
Example
  let uuid = "";
  volumemanager.getVolumeByUuid(uuid).then(function(volume) {
      console.info("getVolumeByUuid successfully:" + JSON.stringify(volume));
  }).catch(function(error){
      console.info("getVolumeByUuid failed with error:"+ error);
  });
volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void
Asynchronously obtains volume information based on the UUID. This API uses a callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| uuid | string | Yes | UUID of the volume. | 
| callback | AsyncCallback<Volume> | Yes | Callback invoked to return the volume information obtained. | 
Example
  let uuid = "";
  volumemanager.getVolumeByUuid(uuid, (error, volume) => {
      // Do something.   
  });
volumemanager.getVolumeById
getVolumeById(volumeId: string): Promise<Volume>
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
Return value
| Type | Description | 
|---|---|
| Promise<Volume> | Promise used to return the volume information obtained. | 
Example
  let volumeId = "";
  volumemanager.getVolumeById(volumeId).then(function(volume) {
      console.info("getVolumeById successfully:" + JSON.stringify(volume));
  }).catch(function(error){
      console.info("getVolumeById failed with error:"+ error);
  });
volumemanager.getVolumeById
getVolumeById(volumeId: string, callback: AsyncCallback<Volume>): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
Required permissions: ohos.permission.STORAGE_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
| callback | AsyncCallback<Volume> | Yes | Callback invoked to return the volume information obtained. | 
Example
  let volumeId = "";
  volumemanager.getVolumeById(volumeId, (error, volume) => {
      // Do something.   
  });
volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string): Promise<void>
Asynchronously sets the volume description based on the UUID. This API uses a promise to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| uuid | string | Yes | UUID of the volume. | 
| description | string | Yes | Volume description. | 
Return value
| Type | Description | 
|---|---|
| Promise<void> | Promise used to return the result. | 
Example
  let uuid = "";
  let description = "";
  volumemanager.setVolumeDescription(uuid, description).then(function() {
      console.info("setVolumeDescription successfully");
  }).catch(function(error){
      console.info("setVolumeDescription failed with error:"+ error);
  });
volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string, callback: AsyncCallback<void>): void
Asynchronously sets the volume description based on the UUID. This API uses a callback to return the result.
Required permissions: ohos.permission.MOUNT_UNMOUNT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| uuid | string | Yes | UUID of the volume. | 
| description | string | Yes | Volume description. | 
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 
Example
  let uuid = "";
  let description = "";
  volumemanager.setVolumeDescription(uuid, description, (error, bool) => {
      // Do something.   
  });
volumemanager.format
format(volumeId: string, fsType: string): Promise<void>
Asynchronously formats a volume. This API uses a promise to return the result.
Required permissions: ohos.permission.MOUNT_FORMAT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
| fsType | string | Yes | File system type. | 
Return value
| Type | Description | 
|---|---|
| Promise<void> | Promise used to return the result. | 
Example
  let volumeId = "";
  let fsType = "";
  volumemanager.format(volumeId, fsType).then(function() {
      console.info("format successfully");
  }).catch(function(error){
      console.info("format failed with error:"+ error);
  });
volumemanager.format
format(volumeId: string, fsType: string, callback: AsyncCallback<void>): void
Asynchronously formats a volume. This API uses a callback to return the result.
Required permissions: ohos.permission.MOUNT_FORMAT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| volumeId | string | Yes | Volume ID. | 
| fsType | string | Yes | File system type. | 
| callback | AsyncCallback<void> | Yes | Called after the volume is formatted. | 
Example
  let volumeId = "";
  let fsType = "";
  volumemanager.format(volumeId, fsType, (error, bool) => {
      // Do something.   
  });
volumemanager.partition
partition(diskId: string, type: number): Promise<void>
Asynchronously partitions a disk. This API uses a promise to return the result.
Required permissions: ohos.permission.MOUNT_FORMAT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| diskId | string | Yes | ID of the disk to which the volume belongs. | 
| type | number | Yes | Partition type. | 
Return value
|Type |Description | |———————|———————–| |Promise<void> |Promise used to return the result. |
Example
  let diskId = "";
  let type = 0;
  volumemanager.partition(diskId, type).then(function() {
      console.info("partition successfully");
  }).catch(function(error){
      console.info("partition failed with error:"+ error);
  });
volumemanager.partition
partition(diskId: string, type: number, callback: AsyncCallback<void>): void
Asynchronously partitions a disk. This API uses a callback to return the result.
Required permissions: ohos.permission.MOUNT_FORMAT_MANAGER
System capability: SystemCapability.FileManagement.StorageService.Volume
Parameters
| Name | Type | Mandatory | Description | 
|---|---|---|---|
| diskId | string | Yes | ID of the disk to which the volume belongs. | 
| type | number | Yes | Partition type. | 
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 
Example
  let diskId = "";
  let type = 0;
  volumemanager.partition(diskId, type, (error, bool) => {
      // Do something.   
  });
Volume
System capability: SystemCapability.FileManagement.StorageService.Volume
Attributes
| Name | Type | Readable | Writable | Description | 
|---|---|---|---|---|
| id | string | Yes | No | Volume ID. | 
| uuid | string | Yes | No | UUID of the volume. | 
| diskId | string | Yes | No | ID of the disk to which the volume belongs. | 
| description | string | Yes | No | Description of the volume. | 
| removable | boolean | Yes | No | Whether the volume is a removable storage device. | 
| state | number | Yes | No | Volume state. | 
| path | string | Yes | No | Mount address of the volume. | 
你可能感兴趣的鸿蒙文章
harmony 鸿蒙System Common Events
harmony 鸿蒙System Common Events
harmony 鸿蒙API Reference Document Description
harmony 鸿蒙BundleStatusCallback
harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)
harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)
harmony 鸿蒙@ohos.bundle (Bundle)
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)
- 所属分类: 后端技术
 - 本文标签:
 
热门推荐
- 
                        2、 - 优质文章
 - 
                        3、 gate.io
 - 
                        7、 openharmony
 - 
                        9、 golang