xref: /titanic_44/usr/src/cmd/devfsadm/misc_link.c (revision b26a64ae582e72d0b4c710cd8eba9c4afd4a9fdd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <regex.h>
29 #include <devfsadm.h>
30 #include <stdio.h>
31 #include <strings.h>
32 #include <stdlib.h>
33 #include <limits.h>
34 #include <sys/zone.h>
35 #include <sys/zcons.h>
36 #include <sys/cpuid_drv.h>
37 
38 static int display(di_minor_t minor, di_node_t node);
39 static int parallel(di_minor_t minor, di_node_t node);
40 static int node_slash_minor(di_minor_t minor, di_node_t node);
41 static int driver_minor(di_minor_t minor, di_node_t node);
42 static int node_name(di_minor_t minor, di_node_t node);
43 static int minor_name(di_minor_t minor, di_node_t node);
44 static int wifi_minor_name(di_minor_t minor, di_node_t node);
45 static int conskbd(di_minor_t minor, di_node_t node);
46 static int consms(di_minor_t minor, di_node_t node);
47 static int power_button(di_minor_t minor, di_node_t node);
48 static int fc_port(di_minor_t minor, di_node_t node);
49 static int printer_create(di_minor_t minor, di_node_t node);
50 static int se_hdlc_create(di_minor_t minor, di_node_t node);
51 static int ppm(di_minor_t minor, di_node_t node);
52 static int gpio(di_minor_t minor, di_node_t node);
53 static int av_create(di_minor_t minor, di_node_t node);
54 static int tsalarm_create(di_minor_t minor, di_node_t node);
55 static int ntwdt_create(di_minor_t minor, di_node_t node);
56 static int zcons_create(di_minor_t minor, di_node_t node);
57 static int cpuid(di_minor_t minor, di_node_t node);
58 static int glvc(di_minor_t minor, di_node_t node);
59 static int ses_callback(di_minor_t minor, di_node_t node);
60 static int kmdrv_create(di_minor_t minor, di_node_t node);
61 
62 static devfsadm_create_t misc_cbt[] = {
63 	{ "pseudo", "ddi_pseudo", "(^sad$)",
64 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_slash_minor
65 	},
66 	{ "pseudo", "ddi_pseudo", "zsh",
67 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, driver_minor
68 	},
69 	{ "network", "ddi_network", NULL,
70 	    TYPE_EXACT, ILEVEL_0, minor_name
71 	},
72 	{ "wifi", "ddi_network:wifi", NULL,
73 	    TYPE_EXACT, ILEVEL_0, wifi_minor_name
74 	},
75 	{ "display", "ddi_display", NULL,
76 	    TYPE_EXACT, ILEVEL_0, display
77 	},
78 	{ "parallel", "ddi_parallel", NULL,
79 	    TYPE_EXACT, ILEVEL_0, parallel
80 	},
81 	{ "enclosure", DDI_NT_SCSI_ENCLOSURE, NULL,
82 	    TYPE_EXACT, ILEVEL_0, ses_callback
83 	},
84 	{ "pseudo", "ddi_pseudo", "(^winlock$)|(^pm$)",
85 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
86 	},
87 	{ "pseudo", "ddi_pseudo", "conskbd",
88 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, conskbd
89 	},
90 	{ "pseudo", "ddi_pseudo", "consms",
91 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, consms
92 	},
93 	{ "pseudo", "ddi_pseudo", "rsm",
94 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
95 	},
96 	{ "pseudo", "ddi_pseudo",
97 	    "(^lockstat$)|(^SUNW,rtvc$)|(^vol$)|(^log$)|(^sy$)|"
98 	    "(^ksyms$)|(^clone$)|(^tl$)|(^tnf$)|(^kstat$)|(^mdesc$)|"
99 	    "(^eeprom$)|(^ptsl$)|(^mm$)|(^wc$)|(^dump$)|(^cn$)|(^lo$)|(^ptm$)|"
100 	    "(^ptc$)|(^openeepr$)|(^poll$)|(^sysmsg$)|(^random$)|(^trapstat$)|"
101 	    "(^cryptoadm$)|(^crypto$)|(^pool$)|(^poolctl$)|(^bl$)|(^kmdb$)|"
102 	    "(^sysevent$)|(^kssl$)|(^physmem$)",
103 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
104 	},
105 	{ "pseudo", "ddi_pseudo",
106 	    "(^ip$)|(^tcp$)|(^udp$)|(^icmp$)|(^sctp$)|"
107 	    "(^ip6$)|(^tcp6$)|(^udp6$)|(^icmp6$)|(^sctp6$)|"
108 	    "(^rts$)|(^arp$)|(^ipsecah$)|(^ipsecesp$)|(^keysock$)|(^spdsock$)|"
109 	    "(^nca$)|(^rds$)|(^sdp$)",
110 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
111 	},
112 	{ "pseudo", "ddi_pseudo",
113 	    "(^ipf$)|(^ipnat$)|(^ipstate$)|(^ipauth$)|"
114 	    "(^ipsync$)|(^ipscan$)|(^iplookup$)",
115 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
116 	},
117 	{ "pseudo", "ddi_pseudo",
118 	    "(^kdmouse$)|(^logi$)|(^rootprop$)|(^msm$)",
119 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
120 	},
121 	{ "pseudo", "ddi_pseudo", "tod",
122 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
123 	},
124 	{ "pseudo", "ddi_pseudo", "envctrl(two)?",
125 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
126 	},
127 	{ "pseudo", "ddi_pseudo", "fcode",
128 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
129 	},
130 	{ "power_button", "ddi_power_button", NULL,
131 	    TYPE_EXACT, ILEVEL_0, power_button,
132 	},
133 	{ "FC port", "ddi_ctl:devctl", "fp",
134 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, fc_port
135 	},
136 	{ "printer", "ddi_printer", NULL,
137 	    TYPE_EXACT, ILEVEL_0, printer_create
138 	},
139 	{ "pseudo", "ddi_pseudo", "se",
140 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, se_hdlc_create
141 	},
142 	{ "ppm",  "ddi_ppm", NULL,
143 	    TYPE_EXACT, ILEVEL_0, ppm
144 	},
145 	{ "pseudo", "ddi_pseudo", "gpio_87317",
146 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, gpio
147 	},
148 	{ "pseudo", "ddi_pseudo", "sckmdrv",
149 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
150 	},
151 	{ "pseudo", "ddi_pseudo", "oplkmdrv",
152 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
153 	},
154 	{ "av", "^ddi_av:(isoch|async)$", NULL,
155 	    TYPE_RE, ILEVEL_0, av_create,
156 	},
157 	{ "pseudo", "ddi_pseudo", "tsalarm",
158 	    TYPE_EXACT | DRV_RE, ILEVEL_0, tsalarm_create,
159 	},
160 	{ "pseudo", "ddi_pseudo", "ntwdt",
161 	    TYPE_EXACT | DRV_RE, ILEVEL_0, ntwdt_create,
162 	},
163 	{ "pseudo", "ddi_pseudo", "daplt",
164 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
165 	},
166 	{ "pseudo", "ddi_pseudo", "zcons",
167 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, zcons_create,
168 	},
169 	{ "pseudo", "ddi_pseudo", CPUID_DRIVER_NAME,
170 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, cpuid,
171 	},
172 	{ "pseudo", "ddi_pseudo", "glvc",
173 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, glvc,
174 	},
175 	{ "pseudo", "ddi_pseudo", "dm2s",
176 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name,
177 	},
178 	{ "pseudo", "ddi_pseudo", "nsmb",
179 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
180 	},
181 	{ "pseudo", "ddi_pseudo", "mem_cache",
182 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
183 	},
184 };
185 
186 DEVFSADM_CREATE_INIT_V0(misc_cbt);
187 
188 static devfsadm_remove_t misc_remove_cbt[] = {
189 	{ "pseudo", "^profile$",
190 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
191 	},
192 	{ "pseudo", "^rsm$",
193 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
194 	},
195 	{ "printer", "^printers/[0-9]+$",
196 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
197 	},
198 	{ "av", "^av/[0-9]+/(async|isoch)$",
199 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
200 	},
201 	{ "pseudo", "^daplt$",
202 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
203 	},
204 	{ "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MASTER_NAME "|"
205 		ZCONS_SLAVE_NAME ")$",
206 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
207 	},
208 	{ "pseudo", "^" CPUID_SELF_NAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
209 	    ILEVEL_0, devfsadm_rm_all
210 	},
211 	{ "enclosure", "^es/ses[0-9]+$", RM_POST,
212 		ILEVEL_0, devfsadm_rm_all
213 	},
214 	{ "pseudo", "^pfil$",
215 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
216 	}
217 };
218 
219 /* Rules for gpio devices */
220 static devfsadm_enumerate_t gpio_rules[1] =
221 	{"^gpio([0-9]+)$", 1, MATCH_ALL};
222 
223 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
224 
225 /*
226  * Handles minor node type "ddi_display".
227  *
228  * type=ddi_display fbs/\M0 fb\N0
229  */
230 static int
231 display(di_minor_t minor, di_node_t node)
232 {
233 	char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf;
234 	devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL};
235 	char *mn = di_minor_name(minor);
236 
237 	/* create fbs/\M0 primary link */
238 	(void) strcpy(l_path, "fbs/");
239 	(void) strcat(l_path, mn);
240 	(void) devfsadm_mklink(l_path, node, minor, 0);
241 
242 	/* create fb\N0 which links to fbs/\M0 */
243 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
244 		return (DEVFSADM_CONTINUE);
245 	}
246 	(void) strcpy(contents, l_path);
247 	(void) strcpy(l_path, "fb");
248 	(void) strcat(l_path, buf);
249 	free(buf);
250 	(void) devfsadm_secondary_link(l_path, contents, 0);
251 	return (DEVFSADM_CONTINUE);
252 }
253 
254 /*
255  * Handles minor node type "ddi_parallel".
256  * type=ddi_parallel;name=mcpp     mcpp\N0
257  */
258 static int
259 parallel(di_minor_t minor, di_node_t node)
260 {
261 	char path[PATH_MAX + 1], *buf;
262 	devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL};
263 
264 
265 	if (strcmp(di_node_name(node), "mcpp") != 0) {
266 		return (DEVFSADM_CONTINUE);
267 	}
268 
269 	if (NULL == (buf = di_devfs_path(node))) {
270 		return (DEVFSADM_CONTINUE);
271 	}
272 
273 	(void) snprintf(path, sizeof (path), "%s:%s",
274 	    buf, di_minor_name(minor));
275 
276 	di_devfs_path_free(buf);
277 
278 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
279 		return (DEVFSADM_CONTINUE);
280 	}
281 	(void) snprintf(path, sizeof (path), "mcpp%s", buf);
282 	free(buf);
283 
284 	(void) devfsadm_mklink(path, node, minor, 0);
285 	return (DEVFSADM_CONTINUE);
286 }
287 
288 static int
289 ses_callback(di_minor_t minor, di_node_t node)
290 {
291 	char l_path[PATH_MAX];
292 	char *buf;
293 	char *devfspath;
294 	char p_path[PATH_MAX];
295 	devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL};
296 
297 	/* find devices path -- need to free mem */
298 	if (NULL == (devfspath = di_devfs_path(node))) {
299 		return (DEVFSADM_CONTINUE);
300 	}
301 
302 	(void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath,
303 	    di_minor_name(minor));
304 
305 
306 	/* find next number to use; buf is an ascii number */
307 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
308 		/* free memory */
309 		di_devfs_path_free(devfspath);
310 		return (DEVFSADM_CONTINUE);
311 	}
312 
313 	(void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf);
314 
315 	(void) devfsadm_mklink(l_path, node, minor, 0);
316 	/* free memory */
317 	free(buf);
318 	di_devfs_path_free(devfspath);
319 	return (DEVFSADM_CONTINUE);
320 
321 }
322 
323 static int
324 node_slash_minor(di_minor_t minor, di_node_t node)
325 {
326 
327 	char path[PATH_MAX + 1];
328 
329 	(void) strcpy(path, di_node_name(node));
330 	(void) strcat(path, "/");
331 	(void) strcat(path, di_minor_name(minor));
332 	(void) devfsadm_mklink(path, node, minor, 0);
333 	return (DEVFSADM_CONTINUE);
334 }
335 
336 static int
337 driver_minor(di_minor_t minor, di_node_t node)
338 {
339 	char path[PATH_MAX + 1];
340 
341 	(void) strcpy(path, di_driver_name(node));
342 	(void) strcat(path, di_minor_name(minor));
343 	(void) devfsadm_mklink(path, node, minor, 0);
344 	return (DEVFSADM_CONTINUE);
345 }
346 
347 /*
348  * Handles links of the form:
349  * type=ddi_pseudo;name=xyz  \D
350  */
351 static int
352 node_name(di_minor_t minor, di_node_t node)
353 {
354 	(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
355 	return (DEVFSADM_CONTINUE);
356 }
357 
358 /*
359  * Handles links of the form:
360  * type=ddi_pseudo;name=xyz  \M0
361  */
362 static int
363 minor_name(di_minor_t minor, di_node_t node)
364 {
365 	char *mn = di_minor_name(minor);
366 
367 	(void) devfsadm_mklink(mn, node, minor, 0);
368 	if (strcmp(mn, "icmp") == 0) {
369 		(void) devfsadm_mklink("rawip", node, minor, 0);
370 	}
371 	if (strcmp(mn, "icmp6") == 0) {
372 		(void) devfsadm_mklink("rawip6", node, minor, 0);
373 	}
374 	if (strcmp(mn, "ipf") == 0) {
375 		(void) devfsadm_mklink("ipl", node, minor, 0);
376 	}
377 	return (DEVFSADM_CONTINUE);
378 }
379 
380 /*
381  * create links at /dev/wifi for wifi minor node
382  */
383 static int
384 wifi_minor_name(di_minor_t minor, di_node_t node)
385 {
386 	char buf[256];
387 	char *mn = di_minor_name(minor);
388 
389 	(void) snprintf(buf, sizeof (buf), "%s%s", "wifi/", mn);
390 	(void) devfsadm_mklink(buf, node, minor, 0);
391 
392 	return (DEVFSADM_CONTINUE);
393 }
394 
395 static int
396 conskbd(di_minor_t minor, di_node_t node)
397 {
398 	(void) devfsadm_mklink("kbd", node, minor, 0);
399 	return (DEVFSADM_CONTINUE);
400 }
401 
402 static int
403 consms(di_minor_t minor, di_node_t node)
404 {
405 	(void) devfsadm_mklink("mouse", node, minor, 0);
406 	return (DEVFSADM_CONTINUE);
407 }
408 
409 static int
410 power_button(di_minor_t minor, di_node_t node)
411 {
412 	(void) devfsadm_mklink("power_button", node, minor, 0);
413 	return (DEVFSADM_CONTINUE);
414 }
415 
416 static int
417 fc_port(di_minor_t minor, di_node_t node)
418 {
419 	devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL};
420 	char *buf, path[PATH_MAX + 1];
421 	char *ptr;
422 
423 	if (NULL == (ptr = di_devfs_path(node))) {
424 		return (DEVFSADM_CONTINUE);
425 	}
426 
427 	(void) strcpy(path, ptr);
428 	(void) strcat(path, ":");
429 	(void) strcat(path, di_minor_name(minor));
430 
431 	di_devfs_path_free(ptr);
432 
433 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
434 		return (DEVFSADM_CONTINUE);
435 	}
436 
437 	(void) strcpy(path, "fc/fp");
438 	(void) strcat(path, buf);
439 	free(buf);
440 
441 	(void) devfsadm_mklink(path, node, minor, 0);
442 	return (DEVFSADM_CONTINUE);
443 }
444 
445 /*
446  * Handles:
447  *	minor node type "ddi_printer".
448  * 	rules of the form: type=ddi_printer;name=bpp  \M0
449  */
450 static int
451 printer_create(di_minor_t minor, di_node_t node)
452 {
453 	char *mn;
454 	char path[PATH_MAX + 1], *buf;
455 	devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL};
456 
457 	mn = di_minor_name(minor);
458 
459 	if (strcmp(di_driver_name(node), "bpp") == 0) {
460 		(void) devfsadm_mklink(mn, node, minor, 0);
461 	}
462 
463 	if (NULL == (buf = di_devfs_path(node))) {
464 		return (DEVFSADM_CONTINUE);
465 	}
466 
467 	(void) snprintf(path, sizeof (path), "%s:%s", buf, mn);
468 	di_devfs_path_free(buf);
469 
470 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
471 		return (DEVFSADM_CONTINUE);
472 	}
473 
474 	(void) snprintf(path, sizeof (path), "printers/%s", buf);
475 	free(buf);
476 
477 	(void) devfsadm_mklink(path, node, minor, 0);
478 
479 	return (DEVFSADM_CONTINUE);
480 }
481 
482 /*
483  * Handles links of the form:
484  * type=ddi_pseudo;name=se;minor2=hdlc	se_hdlc\N0
485  * type=ddi_pseudo;name=serial;minor2=hdlc	se_hdlc\N0
486  */
487 static int
488 se_hdlc_create(di_minor_t minor, di_node_t node)
489 {
490 	devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL};
491 	char *buf, path[PATH_MAX + 1];
492 	char *ptr;
493 	char *mn;
494 
495 	mn = di_minor_name(minor);
496 
497 	/* minor node should be of the form: "?,hdlc" */
498 	if (strcmp(mn + 1, ",hdlc") != 0) {
499 		return (DEVFSADM_CONTINUE);
500 	}
501 
502 	if (NULL == (ptr = di_devfs_path(node))) {
503 		return (DEVFSADM_CONTINUE);
504 	}
505 
506 	(void) strcpy(path, ptr);
507 	(void) strcat(path, ":");
508 	(void) strcat(path, mn);
509 
510 	di_devfs_path_free(ptr);
511 
512 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
513 		return (DEVFSADM_CONTINUE);
514 	}
515 
516 	(void) strcpy(path, "se_hdlc");
517 	(void) strcat(path, buf);
518 	free(buf);
519 
520 	(void) devfsadm_mklink(path, node, minor, 0);
521 
522 	return (DEVFSADM_CONTINUE);
523 }
524 
525 static int
526 gpio(di_minor_t minor, di_node_t node)
527 {
528 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
529 	char *minor_nm, *drvr_nm;
530 
531 
532 	minor_nm = di_minor_name(minor);
533 	drvr_nm = di_driver_name(node);
534 	if ((minor_nm == NULL) || (drvr_nm == NULL)) {
535 		return (DEVFSADM_CONTINUE);
536 	}
537 
538 	devfspath = di_devfs_path(node);
539 
540 	(void) strcpy(p_path, devfspath);
541 	(void) strcat(p_path, ":");
542 	(void) strcat(p_path, minor_nm);
543 	di_devfs_path_free(devfspath);
544 
545 	/* build the physical path from the components */
546 	if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) {
547 		return (DEVFSADM_CONTINUE);
548 	}
549 
550 	(void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf);
551 
552 	free(buf);
553 
554 	(void) devfsadm_mklink(l_path, node, minor, 0);
555 
556 	return (DEVFSADM_CONTINUE);
557 }
558 
559 /*
560  * Creates /dev/ppm nodes for Platform Specific PM module
561  */
562 static int
563 ppm(di_minor_t minor, di_node_t node)
564 {
565 	(void) devfsadm_mklink("ppm", node, minor, 0);
566 	return (DEVFSADM_CONTINUE);
567 }
568 
569 /*
570  * Handles:
571  *	/dev/av/[0-9]+/(async|isoch)
572  */
573 static int
574 av_create(di_minor_t minor, di_node_t node)
575 {
576 	devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR};
577 	char	*minor_str;
578 	char	path[PATH_MAX + 1];
579 	char	*buf;
580 
581 	if ((buf = di_devfs_path(node)) == NULL) {
582 		return (DEVFSADM_CONTINUE);
583 	}
584 
585 	minor_str = di_minor_name(minor);
586 	(void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str);
587 	di_devfs_path_free(buf);
588 
589 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
590 		return (DEVFSADM_CONTINUE);
591 	}
592 
593 	(void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str);
594 	free(buf);
595 
596 	(void) devfsadm_mklink(path, node, minor, 0);
597 
598 	return (DEVFSADM_CONTINUE);
599 }
600 
601 /*
602  * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node
603  */
604 static int
605 tsalarm_create(di_minor_t minor, di_node_t node)
606 {
607 	char buf[PATH_MAX + 1];
608 	char *mn = di_minor_name(minor);
609 
610 	(void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl");
611 
612 	(void) devfsadm_mklink(mn, node, minor, 0);
613 	(void) devfsadm_mklink(buf, node, minor, 0);
614 
615 	return (DEVFSADM_CONTINUE);
616 }
617 
618 /*
619  * Creates /dev/ntwdt for ntwdt node
620  */
621 static int
622 ntwdt_create(di_minor_t minor, di_node_t node)
623 {
624 	(void) devfsadm_mklink("ntwdt", node, minor, 0);
625 	return (DEVFSADM_CONTINUE);
626 }
627 
628 static int
629 zcons_create(di_minor_t minor, di_node_t node)
630 {
631 	char	*minor_str;
632 	char	*zonename;
633 	char	path[MAXPATHLEN];
634 
635 	minor_str = di_minor_name(minor);
636 
637 	if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename",
638 	    &zonename) == -1) {
639 		return (DEVFSADM_CONTINUE);
640 	}
641 
642 	(void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename,
643 	    minor_str);
644 	(void) devfsadm_mklink(path, node, minor, 0);
645 
646 	return (DEVFSADM_CONTINUE);
647 }
648 
649 /*
650  *	/dev/cpu/self/cpuid 	->	/devices/pseudo/cpuid@0:self
651  */
652 static int
653 cpuid(di_minor_t minor, di_node_t node)
654 {
655 	(void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0);
656 	return (DEVFSADM_CONTINUE);
657 }
658 
659 /*
660  * For device
661  *      /dev/spfma -> /devices/virtual-devices/fma@5:glvc
662  */
663 static int
664 glvc(di_minor_t minor, di_node_t node)
665 {
666 	char node_name[MAXNAMELEN + 1];
667 
668 	(void) strcpy(node_name, di_node_name(node));
669 
670 	if (strncmp(node_name, "fma", 3) == 0) {
671 		/* Only one fma channel */
672 		(void) devfsadm_mklink("spfma", node, minor, 0);
673 	}
674 	return (DEVFSADM_CONTINUE);
675 }
676 
677 /*
678  * Handles links of the form:
679  * type=ddi_pseudo;name=sckmdrv		kmdrv\M0
680  * type=ddi_pseudo;name=oplkmdrv	kmdrv\M0
681  */
682 static int
683 kmdrv_create(di_minor_t minor, di_node_t node)
684 {
685 
686 	(void) devfsadm_mklink("kmdrv", node, minor, 0);
687 	return (DEVFSADM_CONTINUE);
688 }
689