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