harmony 鸿蒙@ohos.volumeManager (Volume Management)

2022-08-09 浏览 (851)

@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

TypeDescription
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

NameTypeMandatoryDescription
callbackAsyncCallback<Volume[]>YesCallback 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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.

Return value

TypeDescription
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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.
callbackAsyncCallback<boolean>YesCallback 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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.

Return value

TypeDescription
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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.
callbackAsyncCallback<boolean>YesCallback 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

NameTypeMandatoryDescription
uuidstringYesUUID of the volume.

Return value

TypeDescription
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

NameTypeMandatoryDescription
uuidstringYesUUID of the volume.
callbackAsyncCallback<Volume>YesCallback 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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.

Return value

TypeDescription
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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.
callbackAsyncCallback<Volume>YesCallback 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

NameTypeMandatoryDescription
uuidstringYesUUID of the volume.
descriptionstringYesVolume description.

Return value

TypeDescription
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

NameTypeMandatoryDescription
uuidstringYesUUID of the volume.
descriptionstringYesVolume description.
callbackAsyncCallback<void>YesCallback 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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.
fsTypestringYesFile system type.

Return value

TypeDescription
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

NameTypeMandatoryDescription
volumeIdstringYesVolume ID.
fsTypestringYesFile system type.
callbackAsyncCallback<void>YesCalled 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

NameTypeMandatoryDescription
diskIdstringYesID of the disk to which the volume belongs.
typenumberYesPartition type.

Return value

TypeDescription
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

NameTypeMandatoryDescription
diskIdstringYesID of the disk to which the volume belongs.
typenumberYesPartition type.
callbackAsyncCallback<void>YesCallback 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

NameTypeReadableWritableDescription
idstringYesNoVolume ID.
uuidstringYesNoUUID of the volume.
diskIdstringYesNoID of the disk to which the volume belongs.
descriptionstringYesNoDescription of the volume.
removablebooleanYesNoWhether the volume is a removable storage device.
statenumberYesNoVolume state.
pathstringYesNoMount address of the volume.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

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)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/03d0ad1972ce4ff5810c315e267f8134