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