2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
18 .\" Copyright (c) 1999, Sun Microsystems, Inc. All Rights Reserved
19 .\" Copyright 2017 Nexenta Systems, Inc.
27 .Nm devid_get_minor_name ,
28 .Nm devid_deviceid_to_nmlist ,
29 .Nm devid_free_nmlist ,
33 .Nm devid_str_encode ,
34 .Nm devid_str_decode ,
35 .Nm devid_str_from_path ,
37 .Nd device ID interfaces for user applications
44 .Fa "ddi_devid_t *retdevid"
48 .Fa "ddi_devid_t devid"
51 .Fo devid_get_minor_name
53 .Fa "char **retminor_name"
56 .Fo devid_deviceid_to_nmlist
57 .Fa "char *search_path"
58 .Fa "ddi_devid_t devid"
59 .Fa "char *minor_name"
60 .Fa "devid_nmlist_t **retlist"
64 .Fa "devid_nmlist_t *list"
68 .Fa "ddi_devid_t devid1"
69 .Fa "ddi_devid_t devid2"
73 .Fa "ddi_devid_t devid"
77 .Fa "ddi_devid_t devid"
81 .Fa "ddi_devid_t devid"
82 .Fa "char *minor_name"
87 .Fa "ddi_devid_t *retdevid"
88 .Fa "char **retminor_name"
91 .Fo devid_str_from_path
92 .Fa "const char *path"
99 These functions provide unique identifiers
102 Applications and device drivers use these functions to identify and locate
103 devices, independent of the device's physical connection or its logical device
110 the device ID for the device associated with the open file descriptor
112 which refers to any device.
113 It returns an error if the device does not have an associated device ID.
114 The caller must free the memory allocated for
122 function frees the space that was allocated for the returned
127 .Fn devid_str_decode .
130 .Fn devid_get_minor_name
131 function returns the minor name, in
133 for the device associated with the open file descriptor
135 This name is specific to the particular minor number, but is
138 The caller of this function must free the memory allocated for the returned
144 .Fn devid_deviceid_to_nmlist
145 function returns an array of
147 structures, where each entry matches the
154 specified is one of the special values
156 .Dv DEVID_MINOR_NAME_ALL ,
157 .Dv DEVID_MINOR_NAME_ALL_CHR ,
159 .Dv DEVID_MINOR_NAME_ALL_BLK
161 then all minor names associated with
163 which also meet the special
165 filtering requirements are returned.
168 structure contains the device name and device number.
169 The last entry of the array contains a null pointer for the
173 for the device number.
174 This function traverses the file tree, starting at
176 For each device with a matching device ID and minor name tuple, a device name
177 and device number are added to the
179 If no matches are found, an error is returned.
180 The caller of this function must free the memory allocated for the returned
182 .Fn devid_free_nmlist
184 This function may take a long time to complete if called with the device ID of
185 an unattached device.
188 .Fn devid_free_nmlist
189 function frees the memory allocated by the
190 .Fn devid_deviceid_to_nmlist
191 function and returned in the
196 function compares two device IDs and determines both equality and sort order.
197 The function returns an integer greater than 0 if the device ID pointed to by
199 is greater than the device ID pointed to by
201 It returns 0 if the device ID pointed to by
203 is equal to the device ID pointed to by
205 It returns an integer less than 0 if the device ID pointed to by
207 is less than the device ID pointed to by
209 This function is the only valid mechanism to determine the equality of two
211 This function may indicate equality for arguments which by simple inspection
216 function returns the size of
222 function validates the format of a
224 It returns 1 if the format is valid, and 0 if invalid.
225 This check may not be as complete as the corresponding kernel function
228 .Xr ddi_devid_compare 9F
237 into a null-terminated ASCII string, returning a pointer to that string.
238 To avoid shell conflicts, the
240 portion of the string is limited to uppercase and lowercase letters, digits, and
256 If there is an ASCII quote character in the binary form of a
258 the string representation will be in hex_id form, not ascii_id form.
261 character is added for
263 at the head of the string
269 are non-null, a slash
271 is used to separate the
275 in the encoded string.
283 is null then the special string
286 Note that you cannot compare the returned string against another string with
288 to determine devid equality.
289 The string returned must be freed by calling
293 .Fn devid_str_from_path
295 .Fn devid_str_encode ,
301 includes the minor name, it will be encoded as well.
302 The string returned must be freed by calling
307 function takes a string previously produced by the
310 .Fn ddi_devid_str_encode
312 .Xr ddi_devid_compare 9F
314 function and decodes the contained device ID and minor name, allocating and
315 returning pointers to the extracted parts via the
323 was specified, the returned device ID and minor name will both be null.
324 A non-null returned devid must be freed by the caller by the
327 A non-null returned minor name must be freed by calling
332 function frees the character string returned by
339 .Fn devid_get_minor_name .
341 Upon successful completion, the
343 .Fn devid_get_minor_name ,
344 .Fn devid_str_decode ,
346 .Fn devid_deviceid_to_nmlist
348 Otherwise, they return -1.
352 function returns the following values:
355 The device ID pointed to by
357 is less than the device ID pointed to by
360 The device ID pointed to by
362 is equal to the device ID pointed to by
365 The device ID pointed to by
367 is greater than the device ID pointed to by
373 function returns the size of
378 is null, the number of bytes that must be allocated and initialized to determine
379 the size of a complete device ID is returned.
383 function returns 1 if the
385 is valid and 0 if the
392 .Fn devid_str_from_path
393 functions return NULL to indicate failure.
394 Failure may be caused by attempting to encode an invalid string.
395 If the return value is non-null, the caller must free the returned string by
405 .Fn devid_get_minor_name ,
409 The following example shows the proper use of
411 .Fn devid_get_minor_name ,
414 to free the space allocated for
422 char *minor_name, *devidstr;
424 if ((fd = open("/dev/dsk/c0t3d0s0", O_RDONLY|O_NDELAY)) < 0) {
427 if (devid_get(fd, &devid) != 0) {
430 if (devid_get_minor_name(fd, &minor_name) != 0) {
433 if ((devidstr = devid_str_encode(devid, minor_name)) == 0) {
436 printf("devid %s\en", devidstr);
437 devid_str_free(devidstr);
439 devid_str_free(minor_name);
444 .Fn devid_deviceid_to_nmlist
446 .Fn devid_free_nmlist
448 The following example shows the proper use of
449 .Fn devid_deviceid_to_nmlist
451 .Fn devid_free_nmlist :
453 devid_nmlist_t *list = NULL;
456 if (devid_deviceid_to_nmlist("/dev/rdsk", devid,
459 /* loop through list and process device names and numbers */
460 devid_free_nmlist(list);
465 .Sh INTERFACE STABILITY
471 .Xr ddi_devid_compare 9F