1# @ohos.file.volumeManager (卷管理)(系统接口) 2<!--Kit: Core File Kit--> 3<!--Subsystem: FileManagement--> 4<!--Owner: @wang_zhangjun; @zhuangzhuang--> 5<!--Designer: @wang_zhangjun; @zhuangzhuang; @renguang1116--> 6<!--Tester: @liuhonggang123; @yue-ye2; @juxiaopang--> 7<!--Adviser: @foryourself--> 8 9该模块提供卷设备、磁盘设备查询和管理的相关功能:包括查询卷设备信息,对卷设备的挂载卸载、对磁盘设备分区以及卷设备的格式化等功能。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> - 本模块为系统接口。 15 16## 导入模块 17 18```ts 19import volumemanager from "@ohos.file.volumeManager"; 20``` 21 22## volumemanager.getAllVolumes 23 24getAllVolumes(): Promise<Array<Volume>> 25 26异步获取当前外置存储中所有卷设备信息,以promise方式返回。 27 28**需要权限**:ohos.permission.STORAGE_MANAGER 29 30**系统能力**:SystemCapability.FileManagement.StorageService.Volume 31 32**返回值:** 33 34 | 类型 | 说明 | 35 | ---------------------------------- | -------------------------- | 36 | Promise<[Volume](#volume)[]> | Promise对象,返回当前所有可获得的卷设备信息。 | 37 38**错误码:** 39 40以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 41 42| 错误码ID | 错误信息 | 43| -------- | -------- | 44| 201 | Permission verification failed. | 45| 202 | The caller is not a system application. | 46| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 47| 13600001 | IPC error. | 48| 13900042 | Unknown error. | 49 50**示例:** 51 52 ```ts 53 import { BusinessError } from '@ohos.base'; 54 volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => { 55 // do something with volumes, which is an array 56 }).catch((error: BusinessError) => { 57 console.error("getAllVolumes failed"); 58 }); 59 ``` 60 61## volumemanager.getAllVolumes 62 63getAllVolumes(callback: AsyncCallback<Array<Volume>>): void 64 65异步获取当前外置存储中所有卷设备信息,以callback方式返回。 66 67**需要权限**:ohos.permission.STORAGE_MANAGER 68 69**系统能力**:SystemCapability.FileManagement.StorageService.Volume 70 71**参数:** 72 73 | 参数名 | 类型 | 必填 | 说明 | 74 | -------- | ------------------------------------------------- | ---- | ------------------------------------ | 75 | callback | AsyncCallback<[Volume](#volume)[]> | 是 | 获取当前所有可获得的卷设备信息之后的回调。 | 76 77**错误码:** 78 79以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 80 81| 错误码ID | 错误信息 | 82| -------- | -------- | 83| 201 | Permission verification failed. | 84| 202 | The caller is not a system application. | 85| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. | 86| 13600001 | IPC error. | 87| 13900042 | Unknown error. | 88 89**示例:** 90 91 ```ts 92 import { BusinessError } from '@ohos.base'; 93 volumemanager.getAllVolumes((error: BusinessError, volumes: Array<volumemanager.Volume>) => { 94 // do something 95 }); 96 ``` 97 98## volumemanager.mount 99 100mount(volumeId: string): Promise<void> 101 102异步挂载指定卷设备,以promise方式返回。当前仅支持vfat、exfat以及ntfs三种文件系统的卷设备挂载。 103 104**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 105 106**系统能力**:SystemCapability.FileManagement.StorageService.Volume 107 108**参数:** 109 110 | 参数名 | 类型 | 必填 | 说明 | 111 | -------- | ------ | ---- | ---- | 112 | volumeId | string | 是 | 卷设备id。 | 113 114**返回值:** 115 116 | 类型 | 说明 | 117 | ---------------------- | ---------- | 118 | Promise<void> | 无返回结果的Promise对象。 | 119 120**错误码:** 121 122以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 123 124| 错误码ID | 错误信息 | 125| -------- | -------- | 126| 201 | Permission verification failed. | 127| 202 | The caller is not a system application. | 128| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 129| 13600001 | IPC error. | 130| 13600002 | Not supported filesystem. | 131| 13600003 | Failed to mount. | 132| 13600005 | Incorrect volume state. | 133| 13600008 | No such object. | 134| 13900042 | Unknown error. | 135 136**示例:** 137 138 ```ts 139 import { BusinessError } from '@ohos.base'; 140 let volumeId: string = ""; 141 volumemanager.mount(volumeId).then(() => { 142 // do something 143 }).catch((error: BusinessError) => { 144 console.error("mount failed"); 145 }); 146 ``` 147 148## volumemanager.mount 149 150mount(volumeId: string, callback:AsyncCallback<void>):void 151 152异步挂载指定卷设备,以callback方式返回。当前仅支持vfat、exfat以及ntfs三种文件系统的卷设备挂载。 153 154**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 155 156**系统能力**:SystemCapability.FileManagement.StorageService.Volume 157 158**参数:** 159 160 | 参数名 | 类型 | 必填 | 说明 | 161 | -------- | ------------------------------------- | ---- | -------------------- | 162 | volumeId | string | 是 | 卷设备id。 | 163 | callback | AsyncCallback<void> | 是 | 挂载指定卷设备之后的回调。 | 164 165**错误码:** 166 167以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 168 169| 错误码ID | 错误信息 | 170| -------- | -------- | 171| 201 | Permission verification failed. | 172| 202 | The caller is not a system application. | 173| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 174| 13600001 | IPC error. | 175| 13600002 | Not supported filesystem. | 176| 13600003 | Failed to mount. | 177| 13600005 | Incorrect volume state. | 178| 13600008 | No such object. | 179| 13900042 | Unknown error. | 180 181**示例:** 182 183 ```ts 184 import { BusinessError } from '@ohos.base'; 185 let volumeId: string = ""; 186 volumemanager.mount(volumeId, (error: BusinessError) => { 187 // do something 188 }); 189 ``` 190 191## volumemanager.unmount 192 193unmount(volumeId: string): Promise<void> 194 195异步卸载指定卷设备,以promise方式返回。 196 197**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 198 199**系统能力**:SystemCapability.FileManagement.StorageService.Volume 200 201**参数:** 202 203 | 参数名 | 类型 | 必填 | 说明 | 204 | -------- | ------ | ---- | ---- | 205 | volumeId | string | 是 | 卷设备id。 | 206 207**返回值:** 208 209 | 类型 | 说明 | 210 | ---------------------- | ---------- | 211 | Promise<void> | 无返回结果的Promise对象。 | 212 213**错误码:** 214 215以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 216 217| 错误码ID | 错误信息 | 218| -------- | -------- | 219| 201 | Permission verification failed. | 220| 202 | The caller is not a system application. | 221| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 222| 13600001 | IPC error. | 223| 13600002 | Not supported filesystem. | 224| 13600004 | Failed to unmount. | 225| 13600005 | Incorrect volume state. | 226| 13600008 | No such object. | 227| 13900042 | Unknown error. | 228 229**示例:** 230 231 ```ts 232 import { BusinessError } from '@ohos.base'; 233 let volumeId: string = ""; 234 volumemanager.unmount(volumeId).then(() => { 235 // do something 236 }).catch((error: BusinessError) => { 237 console.error("mount failed"); 238 }); 239 ``` 240 241## volumemanager.unmount 242 243unmount(volumeId: string, callback: AsyncCallback<void>): void 244 245异步卸载指定卷设备,以callback方式返回。 246 247**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 248 249**系统能力**:SystemCapability.FileManagement.StorageService.Volume 250 251**参数:** 252 253 | 参数名 | 类型 | 必填 | 说明 | 254 | -------- | ------------------------------------- | ---- | -------------------- | 255 | volumeId | string | 是 | 卷设备id。 | 256 | callback | AsyncCallback<void> | 是 | 卸载指定卷设备之后的回调。 | 257 258**错误码:** 259 260以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 261 262| 错误码ID | 错误信息 | 263| -------- | -------- | 264| 201 | Permission verification failed. | 265| 202 | The caller is not a system application. | 266| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 267| 13600001 | IPC error. | 268| 13600002 | Not supported filesystem. | 269| 13600004 | Failed to unmount. | 270| 13600005 | Incorrect volume state. | 271| 13600008 | No such object. | 272| 13900042 | Unknown error. | 273 274**示例:** 275 276 ```ts 277 import { BusinessError } from '@ohos.base'; 278 let volumeId: string = ""; 279 volumemanager.unmount(volumeId, (error: BusinessError) => { 280 // do something 281 }); 282 ``` 283 284## volumemanager.getVolumeByUuid 285 286getVolumeByUuid(uuid: string): Promise<Volume> 287 288异步通过卷设备uuid获得指定卷设备信息,以promise方式返回。 289 290**需要权限**:ohos.permission.STORAGE_MANAGER 291 292**系统能力**:SystemCapability.FileManagement.StorageService.Volume 293 294**参数:** 295 296 | 参数名 | 类型 | 必填 | 说明 | 297 | -------- | ------ | ---- | ---- | 298 | uuid | string | 是 | 卷设备uuid。 | 299 300**返回值:** 301 302 | 类型 | 说明 | 303 | ---------------------------------- | -------------------------- | 304 | Promise<[Volume](#volume)> | Promise对象,返回当前所有可获得的卷设备信息。 | 305 306**错误码:** 307 308以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 309 310| 错误码ID | 错误信息 | 311| -------- | -------- | 312| 201 | Permission verification failed. | 313| 202 | The caller is not a system application. | 314| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 315| 13600001 | IPC error. | 316| 13600008 | No such object. | 317| 13900042 | Unknown error. | 318 319**示例:** 320 321 ```ts 322 import { BusinessError } from '@ohos.base'; 323 let uuid: string = ""; 324 volumemanager.getVolumeByUuid(uuid).then((volume: volumemanager.Volume) => { 325 console.info("getVolumeByUuid successfully:" + JSON.stringify(volume)); 326 }).catch((error: BusinessError) => { 327 console.error("getVolumeByUuid failed with error:" + JSON.stringify(error)); 328 }); 329 ``` 330 331## volumemanager.getVolumeByUuid 332 333getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void 334 335异步通过卷设备uuid获得指定卷设备信息,以callback方式返回。 336 337**需要权限**:ohos.permission.STORAGE_MANAGER 338 339**系统能力**:SystemCapability.FileManagement.StorageService.Volume 340 341**参数:** 342 343 | 参数名 | 类型 | 必填 | 说明 | 344 | -------- | ------------------------------------------------ | ---- | -------------------- | 345 | uuid | string | 是 | 卷设备uuid。 | 346 | callback | AsyncCallback<[Volume](#volume)> | 是 | 获取卷设备信息之后的回调。 | 347 348**错误码:** 349 350以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 351 352| 错误码ID | 错误信息 | 353| -------- | -------- | 354| 201 | Permission verification failed. | 355| 202 | The caller is not a system application. | 356| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 357| 13600001 | IPC error. | 358| 13600008 | No such object. | 359| 13900042 | Unknown error. | 360 361**示例:** 362 363 ```ts 364 import { BusinessError } from '@ohos.base'; 365 let uuid: string = ""; 366 volumemanager.getVolumeByUuid(uuid, (error: BusinessError, volume: volumemanager.Volume) => { 367 // do something 368 }); 369 ``` 370 371## volumemanager.getVolumeById 372 373getVolumeById(volumeId: string): Promise<Volume> 374 375异步通过卷设备id获得指定卷设备信息,以promise方式返回。 376 377**需要权限**:ohos.permission.STORAGE_MANAGER 378 379**系统能力**:SystemCapability.FileManagement.StorageService.Volume 380 381**参数:** 382 383 | 参数名 | 类型 | 必填 | 说明 | 384 | -------- | ------ | ---- | ---- | 385 | volumeId | string | 是 | 卷设备id。 | 386 387**返回值:** 388 389 | 类型 | 说明 | 390 | ---------------------------------- | -------------------------- | 391 | Promise<[Volume](#volume)> | Promise对象,返回当前所有可获得的卷设备信息。 | 392 393**错误码:** 394 395以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 396 397| 错误码ID | 错误信息 | 398| -------- | -------- | 399| 201 | Permission verification failed. | 400| 202 | The caller is not a system application. | 401| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 402| 13600001 | IPC error. | 403| 13600008 | No such object. | 404| 13900042 | Unknown error. | 405 406**示例:** 407 408 ```ts 409 import { BusinessError } from '@ohos.base'; 410 let volumeId: string = ""; 411 volumemanager.getVolumeById(volumeId).then((volume: volumemanager.Volume) => { 412 console.info("getVolumeById successfully:" + JSON.stringify(volume)); 413 }).catch((error: BusinessError) => { 414 console.error("getVolumeById failed with error:" + JSON.stringify(error)); 415 }); 416 ``` 417 418## volumemanager.getVolumeById 419 420getVolumeById(volumeId: string, callback: AsyncCallback<Volume>): void 421 422异步通过指定卷设备id获得卷设备信息,以callback方式返回。 423 424**需要权限**:ohos.permission.STORAGE_MANAGER 425 426**系统能力**:SystemCapability.FileManagement.StorageService.Volume 427 428**参数:** 429 430 | 参数名 | 类型 | 必填 | 说明 | 431 | -------- | ------------------------- | ---- | ----------------------------- | 432 | volumeId | string | 是 | 卷设备id。 | 433 | callback | AsyncCallback<[Volume](#volume)> | 是 | 获取卷设备信息之后的回调。 | 434 435**错误码:** 436 437以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 438 439| 错误码ID | 错误信息 | 440| -------- | -------- | 441| 201 | Permission verification failed. | 442| 202 | The caller is not a system application. | 443| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 444| 13600001 | IPC error. | 445| 13600008 | No such object. | 446| 13900042 | Unknown error. | 447 448**示例:** 449 450 ```ts 451 import { BusinessError } from '@ohos.base'; 452 let volumeId: string = ""; 453 volumemanager.getVolumeById(volumeId, (error: BusinessError, volume: volumemanager.Volume) => { 454 // do something 455 }); 456 ``` 457 458## volumemanager.setVolumeDescription 459 460setVolumeDescription(uuid: string, description: string): Promise<void> 461 462异步修改指定卷设备描述,以promise方式返回。 463 464**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 465 466**系统能力**:SystemCapability.FileManagement.StorageService.Volume 467 468**参数:** 469 470 | 参数名 | 类型 | 必填 | 说明 | 471 | --------- | ------ | ---- | ---- | 472 | uuid | string | 是 | 卷设备uuid。 | 473 | description | string | 是 | 卷设备描述。 | 474 475**返回值:** 476 477 | 类型 | 说明 | 478 | ---------------------- | -------------------------- | 479 | Promise<void> | 无返回结果的Promise对象。 | 480 481**错误码:** 482 483以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 484 485| 错误码ID | 错误信息 | 486| -------- | -------- | 487| 201 | Permission verification failed. | 488| 202 | The caller is not a system application. | 489| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 490| 13600001 | IPC error. | 491| 13600002 | Not supported filesystem. | 492| 13600005 | Incorrect volume state. | 493| 13600008 | No such object. | 494| 13900042 | Unknown error. | 495 496**示例:** 497 498 ```ts 499 import { BusinessError } from '@ohos.base'; 500 let uuid: string = ""; 501 let description: string = ""; 502 volumemanager.setVolumeDescription(uuid, description).then(() => { 503 console.info("setVolumeDescription successfully"); 504 }).catch((error: BusinessError) => { 505 console.error("setVolumeDescription failed with error:" + JSON.stringify(error)); 506 }); 507 ``` 508 509## volumemanager.setVolumeDescription 510 511setVolumeDescription(uuid: string, description: string, callback: AsyncCallback<void>): void 512 513异步修改指定卷设备描述,以callback方式返回。 514 515**需要权限**:ohos.permission.MOUNT_UNMOUNT_MANAGER 516 517**系统能力**:SystemCapability.FileManagement.StorageService.Volume 518 519**参数:** 520 521 | 参数名 | 类型 | 必填 | 说明 | 522 | ---------- | --------------------------------------- | ---- | ---------------- | 523 | uuid | string | 是 | 卷设备uuid。 | 524 | description | string | 是 | 卷设备描述。 | 525 | callback | AsyncCallback<void> | 是 | 设置卷描述之后的回调。 | 526 527**错误码:** 528 529以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 530 531| 错误码ID | 错误信息 | 532| -------- | -------- | 533| 201 | Permission verification failed. | 534| 202 | The caller is not a system application. | 535| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 536| 13600001 | IPC error. | 537| 13600002 | Not supported filesystem. | 538| 13600005 | Incorrect volume state. | 539| 13600008 | No such object. | 540| 13900042 | Unknown error. | 541 542**示例:** 543 544 ```ts 545 import { BusinessError } from '@ohos.base'; 546 let uuid: string = ""; 547 let description: string = ""; 548 volumemanager.setVolumeDescription(uuid, description, (error: BusinessError) => { 549 // do something 550 }); 551 ``` 552 553## volumemanager.format 554 555format(volumeId: string, fsType: string): Promise<void> 556 557异步对指定卷设备进行格式化,以promise方式返回。当前仅支持vfat和exfat两种文件系统类型的格式化,只有处于卸载状态的卷设备可以进行格式化,格式化后卷设备的uuid、挂载路径和卷设备描述均会发生变化。 558 559**需要权限**:ohos.permission.MOUNT_FORMAT_MANAGER 560 561**系统能力**:SystemCapability.FileManagement.StorageService.Volume 562 563**参数:** 564 565 | 参数名 | 类型 | 必填 | 说明 | 566 | ----------- | ------ | ---- | ---- | 567 | volumeId | string | 是 | 卷设备id。 | 568 | fsType | string | 是 | 文件系统类型(vfat或者exfat)。 | 569 570**返回值:** 571 572 | 类型 | 说明 | 573 | ---------------------- | ---------- | 574 | Promise<void> | 无返回结果的Promise对象。 | 575 576**错误码:** 577 578以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 579 580| 错误码ID | 错误信息 | 581| -------- | -------- | 582| 201 | Permission verification failed. | 583| 202 | The caller is not a system application. | 584| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 585| 13600001 | IPC error. | 586| 13600002 | Not supported filesystem. | 587| 13600005 | Incorrect volume state. | 588| 13600008 | No such object. | 589| 13900042 | Unknown error. | 590 591**示例:** 592 593 ```ts 594 import { BusinessError } from '@ohos.base'; 595 let volumeId: string = ""; 596 let fsType: string = ""; 597 volumemanager.format(volumeId, fsType).then(() => { 598 console.info("format successfully"); 599 }).catch((error: BusinessError) => { 600 console.error("format failed with error:" + JSON.stringify(error)); 601 }); 602 ``` 603 604## volumemanager.format 605 606format(volumeId: string, fsType: string, callback: AsyncCallback<void>): void 607 608异步对指定卷设备进行格式化,以callback方式返回。当前仅支持vfat和exfat两种文件系统类型的格式化,只有处于卸载状态的卷设备可以进行格式化,格式化后卷设备的uuid、挂载路径和卷设备描述均会发生变化。 609 610**需要权限**:ohos.permission.MOUNT_FORMAT_MANAGER 611 612**系统能力**:SystemCapability.FileManagement.StorageService.Volume 613 614**参数:** 615 616 | 参数名 | 类型 | 必填 | 说明 | 617 | -------- | ------------------------- | ---- | ----------------------------- | 618 | volumeId | string | 是 | 卷设备id。 | 619 | fsType | string | 是 | 文件系统类型(vfat或者exfat)。 | 620 | callback | AsyncCallback<void> | 是 | 对指定卷设备格式化后的回调。 | 621 622**错误码:** 623 624以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 625 626| 错误码ID | 错误信息 | 627| -------- | -------- | 628| 201 | Permission verification failed. | 629| 202 | The caller is not a system application. | 630| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 631| 13600001 | IPC error. | 632| 13600002 | Not supported filesystem. | 633| 13600005 | Incorrect volume state. | 634| 13600008 | No such object. | 635| 13900042 | Unknown error. | 636 637**示例:** 638 639 ```ts 640 import { BusinessError } from '@ohos.base'; 641 let volumeId: string = ""; 642 let fsType: string = ""; 643 volumemanager.format(volumeId, fsType, (error: BusinessError) => { 644 // do something 645 }); 646 ``` 647 648## volumemanager.partition 649 650partition(diskId: string, type: number): Promise<void> 651 652异步对磁盘设备进行分区,以promise方式返回。当前仅支持将磁盘设备重新分区为一个分区,系统是支持读取多分区的磁盘设备。 653 654**需要权限**:ohos.permission.MOUNT_FORMAT_MANAGER 655 656**系统能力**:SystemCapability.FileManagement.StorageService.Volume 657 658**参数:** 659 660 | 参数名 | 类型 | 必填 | 说明 | 661 | ----------- | ------ | ---- | ---- | 662 | diskId | string | 是 | 卷设备所属的磁盘设备id。 | 663 | type | number | 是 | 分区类型。 | 664 665**返回值:** 666 667 | 类型 | 说明 | 668 | --------------------- | ----------------------- | 669 | Promise<void> | 无返回结果的Promise对象。 | 670 671**错误码:** 672 673以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 674 675| 错误码ID | 错误信息 | 676| -------- | -------- | 677| 201 | Permission verification failed. | 678| 202 | The caller is not a system application. | 679| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 680| 13600001 | IPC error. | 681| 13600008 | No such object. | 682| 13900042 | Unknown error. | 683 684**示例:** 685 686 ```ts 687 import { BusinessError } from '@ohos.base'; 688 let diskId: string = ""; 689 let type: number = 0; 690 volumemanager.partition(diskId, type).then(() => { 691 console.info("partition successfully"); 692 }).catch((error: BusinessError) => { 693 console.error("partition failed with error:" + JSON.stringify(error)); 694 }); 695 ``` 696 697## volumemanager.partition 698 699partition(diskId: string, type: number, callback: AsyncCallback<void>): void 700 701异步对磁盘进行分区,以callback方式返回。当前仅支持将磁盘设备重新分区为一个分区,系统是支持读取多分区的磁盘设备。 702 703**需要权限**:ohos.permission.MOUNT_FORMAT_MANAGER 704 705**系统能力**:SystemCapability.FileManagement.StorageService.Volume 706 707**参数:** 708 709 | 参数名 | 类型 | 必填 | 说明 | 710 | -------- | --------------------------------------- | ---- | ---------------- | 711 | diskId | string | 是 | 卷设备所属的磁盘id。 | 712 | type | number | 是 | 分区类型。 | 713 | callback | AsyncCallback<void> | 是 | 对磁盘设备进行分区。 | 714 715**错误码:** 716 717以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。 718 719| 错误码ID | 错误信息 | 720| -------- | -------- | 721| 201 | Permission verification failed. | 722| 202 | The caller is not a system application. | 723| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 724| 13600001 | IPC error. | 725| 13600008 | No such object. | 726| 13900042 | Unknown error. | 727 728**示例:** 729 730 ```ts 731 import { BusinessError } from '@ohos.base'; 732 let diskId: string = ""; 733 let type: number = 0; 734 volumemanager.partition(diskId, type, (error: BusinessError) => { 735 // do something 736 }); 737 ``` 738 739## Volume 740 741**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.Volume。 742 743### 属性 744 745| 名称 | 类型 | 只读 | 可选 | 说明 | 746| ----------- | ------- | ------- | ----- | -------------------- | 747| id | string | 否 | 否 | 卷设备ID的格式为vol-{主设备号}-{次设备号},主设备号用来区分不同种类的设备,次设备号用来区分同一类型的多个设备,卷设备ID会随着插卡顺序不同而变化。 | 748| uuid | string | 否 | 否 | 卷设备uuid是卷设备的通用唯一识别码,不会随着插卡顺序变化而变化,但是卷设备的格式化会改变卷设备的uuid。 | 749| diskId | string | 否 | 否 | 卷设备所属的磁盘ID,一个磁盘可以有一个或者多个卷设备。磁盘设备ID的格式为disk-{主设备号}-{次设备号},与卷设备ID相似。 | 750| description | string | 否 | 否 | 卷设备描述。 | 751| removable | boolean | 否 | 否 | 表示卷设备是否可移除,当前仅支持可移除存储设备。true为可移除;false为不可移除。 | 752| state | number | 否 | 否 | 卷设备状态标识:<br>0:卸载状态 UNMOUNTED。<br> 1:检查状态 CHECKING。<br> 2:挂载状态 MOUNTED。<br> 3:正在弹出状态 EJECTING。 | 753| path | string | 否 | 否 | 卷设备的挂载地址,一般为/mnt/data/external/{uuid}。 | 754| fsType<sup>12+</sup> | string | 否 | 否 | 文件系统的类型,常见有ext2、vfat、NTFS等。 |