harmony 鸿蒙@ohos.volumeManager (卷管理)

  • 2022-08-09
  • 浏览 (496)

@ohos.volumeManager (卷管理)

该模块提供卷、磁盘查询和管理的相关功能:包括查询卷信息,对卷的挂载卸载、对磁盘分区以及卷的格式化等功能。

说明:

  • 本模块首批接口从API version 9开始支持。
  • 本模块接口为系统接口,三方应用不支持调用。

导入模块

import volumemanager from "@ohos.volumeManager";

volumemanager.getAllVolumes

getAllVolumes(): Promise<Array<Volume>>

异步获取当前所有可获得的卷信息,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

返回值:

类型 说明
Promise<Volume[]> 返回当前所有可获得的卷信息

示例:

  volumemanager.getAllVolumes().then(function(volumes){
      // do something
  });

volumemanager.getAllVolumes

getAllVolumes(callback: AsyncCallback<Array<Volume>>): void

异步获取当前所有可获得的卷信息,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
callback AsyncCallback<Volume[]> 获取当前所有可获得的卷信息之后的回调

示例:

  let uuid = "";
  volumemanager.getAllVolumes(function(error, volumes){
      // do something
  });

volumemanager.mount

mount(volumeId: string): Promise<boolean>

异步挂载指定卷,以promise方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id

返回值:

类型 说明
Promise<boolean> 挂载指定卷

示例:

  let volumeId = "";
  volumemanager.mount(volumeId).then(function(flag){
      // do something
  });

volumemanager.mount

mount(volumeId: string, callback:AsyncCallback<boolean>):void

异步获取指定卷的可用空间大小,以callback方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id
callback AsyncCallback<boolean> 挂载指定卷之后的回调

示例:

  let volumeId = "";
  volumemanager.mount(volumeId, function(error, flag){
      // do something
  });

volumemanager.unmount

unmount(volumeId: string): Promise<boolean>

异步卸载指定卷,以promise方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id

返回值:

类型 说明
Promise<boolean> 卸载指定卷

示例:

  let volumeId = "";
  volumemanager.unmount(volumeId).then(function(flag){
      // do something
  });

volumemanager.unmount

unmount(volumeId: string, callback: AsyncCallback<boolean>): void

异步卸载指定卷,以callback方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id
callback AsyncCallback<boolean> 卸载指定卷之后的回调

示例:

  let volumeId = "";
  volumemanager.unmount(volumeId, function(error, flag){
      // do something
  });

volumemanager.getVolumeByUuid

getVolumeByUuid(uuid: string): Promise<Volume>

异步通过uuid获得卷信息,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
uuid string 卷uuid

返回值:

类型 说明
Promise<Volume> 返回当前所有可获得的卷信息

示例:

  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

异步通过uuid获得卷信息,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
uuid string 卷uuid
callback AsyncCallback<Volume> 获取卷信息之后的回调

示例:

  let uuid = "";
  volumemanager.getVolumeByUuid(uuid, (error, volume) => {
      // do something    
  });

volumemanager.getVolumeById

getVolumeById(volumeId: string): Promise<Volume>

异步通过卷id获得卷信息,以promise方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id

返回值:

类型 说明
Promise<Volume> 返回当前所有可获得的卷信息

示例:

  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

异步通过卷id获得卷信息,以callback方式返回。

需要权限:ohos.permission.STORAGE_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id
callback AsyncCallback<Volume> 获取卷信息之后的回调

示例:

  let volumeId = "";
  volumemanager.getVolumeById(volumeId, (error, volume) => {
      // do something    
  });

volumemanager.setVolumeDescription

setVolumeDescription(uuid: string, description: string): Promise<void>

异步通过uuid设置卷描述,以promise方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
uuid string 卷uuid
description string 卷描述

返回值:

类型 说明
Promise<void> 设置卷信息

示例:

  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

异步通过uuid设置卷描述,以callback方式返回。

需要权限:ohos.permission.MOUNT_UNMOUNT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
uuid string 卷uuid
description string 卷描述
callback AsyncCallback<void> 设置卷描述之后的回调

示例:

  let uuid = "";
  let description = "";
  volumemanager.setVolumeDescription(uuid, description, (error, bool) => {
      // do something    
  });

volumemanager.format

format(volumeId: string, fsType: string): Promise<void>

异步对指定卷进行格式化,以promise方式返回。

需要权限:ohos.permission.MOUNT_FORMAT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id
fsType string 文件系统类型

返回值:

类型 说明
Promise<void> 对指定卷进行格式化

示例:

  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

异步对指定卷进行格式化,以callback方式返回。

需要权限:ohos.permission.MOUNT_FORMAT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
volumeId string 卷id
fsType string 文件系统类型
callback AsyncCallback<void> 对指定卷格式化后的回调

示例:

  let volumeId = "";
  let fsType = "";
  volumemanager.format(volumeId, fsType, (error, bool) => {
      // do something    
  });

volumemanager.partition

partition(diskId: string, type: number): Promise<void>

异步对磁盘进行分区,以promise方式返回。

需要权限:ohos.permission.MOUNT_FORMAT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
diskId string 卷所属的磁盘id
type number 分区类型

返回值:

|类型 |说明 | |———————|———————–| |Promise<void> |对磁盘进行分区 |

示例:

  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

异步对磁盘进行分区,以callback方式返回。

需要权限:ohos.permission.MOUNT_FORMAT_MANAGER

系统能力:SystemCapability.FileManagement.StorageService.Volume

参数:

参数名 类型 必填 说明
diskId string 卷所属的磁盘id
type number 分区类型
callback AsyncCallback<void> 对磁盘进行分区

示例:

  let diskId = "";
  let type = 0;
  volumemanager.partition(diskId, type, (error, bool) => {
      // do something    
  });

Volume

系统能力:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.Volume。

属性

名称 类型 可读 可写 说明
id string 卷id
uuid string 卷uuid
diskId string 卷所属的磁盘id
description string 卷相关描述
removable boolean 是否为可移动存储设备
state number 当前卷状态
path string 卷的挂载地址

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)

0  赞