xref: /titanic_44/usr/src/cmd/devfsadm/misc_link.c (revision 98157a7002f4f2cf7978f3084ca5577f0a1d72b2)
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 };
182 
183 DEVFSADM_CREATE_INIT_V0(misc_cbt);
184 
185 static devfsadm_remove_t misc_remove_cbt[] = {
186 	{ "pseudo", "^profile$",
187 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
188 	},
189 	{ "pseudo", "^rsm$",
190 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
191 	},
192 	{ "printer", "^printers/[0-9]+$",
193 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
194 	},
195 	{ "av", "^av/[0-9]+/(async|isoch)$",
196 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
197 	},
198 	{ "pseudo", "^daplt$",
199 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
200 	},
201 	{ "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MASTER_NAME "|"
202 		ZCONS_SLAVE_NAME ")$",
203 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
204 	},
205 	{ "pseudo", "^" CPUID_SELF_NAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
206 	    ILEVEL_0, devfsadm_rm_all
207 	},
208 	{ "enclosure", "^es/ses[0-9]+$", RM_POST,
209 		ILEVEL_0, devfsadm_rm_all
210 	},
211 	{ "pseudo", "^pfil$",
212 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
213 	}
214 };
215 
216 /* Rules for gpio devices */
217 static devfsadm_enumerate_t gpio_rules[1] =
218 	{"^gpio([0-9]+)$", 1, MATCH_ALL};
219 
220 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
221 
222 /*
223  * Handles minor node type "ddi_display".
224  *
225  * type=ddi_display fbs/\M0 fb\N0
226  */
227 static int
228 display(di_minor_t minor, di_node_t node)
229 {
230 	char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf;
231 	devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL};
232 	char *mn = di_minor_name(minor);
233 
234 	/* create fbs/\M0 primary link */
235 	(void) strcpy(l_path, "fbs/");
236 	(void) strcat(l_path, mn);
237 	(void) devfsadm_mklink(l_path, node, minor, 0);
238 
239 	/* create fb\N0 which links to fbs/\M0 */
240 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
241 		return (DEVFSADM_CONTINUE);
242 	}
243 	(void) strcpy(contents, l_path);
244 	(void) strcpy(l_path, "fb");
245 	(void) strcat(l_path, buf);
246 	free(buf);
247 	(void) devfsadm_secondary_link(l_path, contents, 0);
248 	return (DEVFSADM_CONTINUE);
249 }
250 
251 /*
252  * Handles minor node type "ddi_parallel".
253  * type=ddi_parallel;name=mcpp     mcpp\N0
254  */
255 static int
256 parallel(di_minor_t minor, di_node_t node)
257 {
258 	char path[PATH_MAX + 1], *buf;
259 	devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL};
260 
261 
262 	if (strcmp(di_node_name(node), "mcpp") != 0) {
263 		return (DEVFSADM_CONTINUE);
264 	}
265 
266 	if (NULL == (buf = di_devfs_path(node))) {
267 		return (DEVFSADM_CONTINUE);
268 	}
269 
270 	(void) snprintf(path, sizeof (path), "%s:%s",
271 	    buf, di_minor_name(minor));
272 
273 	di_devfs_path_free(buf);
274 
275 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
276 		return (DEVFSADM_CONTINUE);
277 	}
278 	(void) snprintf(path, sizeof (path), "mcpp%s", buf);
279 	free(buf);
280 
281 	(void) devfsadm_mklink(path, node, minor, 0);
282 	return (DEVFSADM_CONTINUE);
283 }
284 
285 static int
286 ses_callback(di_minor_t minor, di_node_t node)
287 {
288 	char l_path[PATH_MAX];
289 	char *buf;
290 	char *devfspath;
291 	char p_path[PATH_MAX];
292 	devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL};
293 
294 	/* find devices path -- need to free mem */
295 	if (NULL == (devfspath = di_devfs_path(node))) {
296 		return (DEVFSADM_CONTINUE);
297 	}
298 
299 	(void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath,
300 	    di_minor_name(minor));
301 
302 
303 	/* find next number to use; buf is an ascii number */
304 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
305 		/* free memory */
306 		di_devfs_path_free(devfspath);
307 		return (DEVFSADM_CONTINUE);
308 	}
309 
310 	(void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf);
311 
312 	(void) devfsadm_mklink(l_path, node, minor, 0);
313 	/* free memory */
314 	free(buf);
315 	di_devfs_path_free(devfspath);
316 	return (DEVFSADM_CONTINUE);
317 
318 }
319 
320 static int
321 node_slash_minor(di_minor_t minor, di_node_t node)
322 {
323 
324 	char path[PATH_MAX + 1];
325 
326 	(void) strcpy(path, di_node_name(node));
327 	(void) strcat(path, "/");
328 	(void) strcat(path, di_minor_name(minor));
329 	(void) devfsadm_mklink(path, node, minor, 0);
330 	return (DEVFSADM_CONTINUE);
331 }
332 
333 static int
334 driver_minor(di_minor_t minor, di_node_t node)
335 {
336 	char path[PATH_MAX + 1];
337 
338 	(void) strcpy(path, di_driver_name(node));
339 	(void) strcat(path, di_minor_name(minor));
340 	(void) devfsadm_mklink(path, node, minor, 0);
341 	return (DEVFSADM_CONTINUE);
342 }
343 
344 /*
345  * Handles links of the form:
346  * type=ddi_pseudo;name=xyz  \D
347  */
348 static int
349 node_name(di_minor_t minor, di_node_t node)
350 {
351 	(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
352 	return (DEVFSADM_CONTINUE);
353 }
354 
355 /*
356  * Handles links of the form:
357  * type=ddi_pseudo;name=xyz  \M0
358  */
359 static int
360 minor_name(di_minor_t minor, di_node_t node)
361 {
362 	char *mn = di_minor_name(minor);
363 
364 	(void) devfsadm_mklink(mn, node, minor, 0);
365 	if (strcmp(mn, "icmp") == 0) {
366 		(void) devfsadm_mklink("rawip", node, minor, 0);
367 	}
368 	if (strcmp(mn, "icmp6") == 0) {
369 		(void) devfsadm_mklink("rawip6", node, minor, 0);
370 	}
371 	if (strcmp(mn, "ipf") == 0) {
372 		(void) devfsadm_mklink("ipl", node, minor, 0);
373 	}
374 	return (DEVFSADM_CONTINUE);
375 }
376 
377 /*
378  * create links at /dev/wifi for wifi minor node
379  */
380 static int
381 wifi_minor_name(di_minor_t minor, di_node_t node)
382 {
383 	char buf[256];
384 	char *mn = di_minor_name(minor);
385 
386 	(void) snprintf(buf, sizeof (buf), "%s%s", "wifi/", mn);
387 	(void) devfsadm_mklink(buf, node, minor, 0);
388 
389 	return (DEVFSADM_CONTINUE);
390 }
391 
392 static int
393 conskbd(di_minor_t minor, di_node_t node)
394 {
395 	(void) devfsadm_mklink("kbd", node, minor, 0);
396 	return (DEVFSADM_CONTINUE);
397 }
398 
399 static int
400 consms(di_minor_t minor, di_node_t node)
401 {
402 	(void) devfsadm_mklink("mouse", node, minor, 0);
403 	return (DEVFSADM_CONTINUE);
404 }
405 
406 static int
407 power_button(di_minor_t minor, di_node_t node)
408 {
409 	(void) devfsadm_mklink("power_button", node, minor, 0);
410 	return (DEVFSADM_CONTINUE);
411 }
412 
413 static int
414 fc_port(di_minor_t minor, di_node_t node)
415 {
416 	devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL};
417 	char *buf, path[PATH_MAX + 1];
418 	char *ptr;
419 
420 	if (NULL == (ptr = di_devfs_path(node))) {
421 		return (DEVFSADM_CONTINUE);
422 	}
423 
424 	(void) strcpy(path, ptr);
425 	(void) strcat(path, ":");
426 	(void) strcat(path, di_minor_name(minor));
427 
428 	di_devfs_path_free(ptr);
429 
430 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
431 		return (DEVFSADM_CONTINUE);
432 	}
433 
434 	(void) strcpy(path, "fc/fp");
435 	(void) strcat(path, buf);
436 	free(buf);
437 
438 	(void) devfsadm_mklink(path, node, minor, 0);
439 	return (DEVFSADM_CONTINUE);
440 }
441 
442 /*
443  * Handles:
444  *	minor node type "ddi_printer".
445  * 	rules of the form: type=ddi_printer;name=bpp  \M0
446  */
447 static int
448 printer_create(di_minor_t minor, di_node_t node)
449 {
450 	char *mn;
451 	char path[PATH_MAX + 1], *buf;
452 	devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL};
453 
454 	mn = di_minor_name(minor);
455 
456 	if (strcmp(di_driver_name(node), "bpp") == 0) {
457 		(void) devfsadm_mklink(mn, node, minor, 0);
458 	}
459 
460 	if (NULL == (buf = di_devfs_path(node))) {
461 		return (DEVFSADM_CONTINUE);
462 	}
463 
464 	(void) snprintf(path, sizeof (path), "%s:%s", buf, mn);
465 	di_devfs_path_free(buf);
466 
467 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
468 		return (DEVFSADM_CONTINUE);
469 	}
470 
471 	(void) snprintf(path, sizeof (path), "printers/%s", buf);
472 	free(buf);
473 
474 	(void) devfsadm_mklink(path, node, minor, 0);
475 
476 	return (DEVFSADM_CONTINUE);
477 }
478 
479 /*
480  * Handles links of the form:
481  * type=ddi_pseudo;name=se;minor2=hdlc	se_hdlc\N0
482  * type=ddi_pseudo;name=serial;minor2=hdlc	se_hdlc\N0
483  */
484 static int
485 se_hdlc_create(di_minor_t minor, di_node_t node)
486 {
487 	devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL};
488 	char *buf, path[PATH_MAX + 1];
489 	char *ptr;
490 	char *mn;
491 
492 	mn = di_minor_name(minor);
493 
494 	/* minor node should be of the form: "?,hdlc" */
495 	if (strcmp(mn + 1, ",hdlc") != 0) {
496 		return (DEVFSADM_CONTINUE);
497 	}
498 
499 	if (NULL == (ptr = di_devfs_path(node))) {
500 		return (DEVFSADM_CONTINUE);
501 	}
502 
503 	(void) strcpy(path, ptr);
504 	(void) strcat(path, ":");
505 	(void) strcat(path, mn);
506 
507 	di_devfs_path_free(ptr);
508 
509 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
510 		return (DEVFSADM_CONTINUE);
511 	}
512 
513 	(void) strcpy(path, "se_hdlc");
514 	(void) strcat(path, buf);
515 	free(buf);
516 
517 	(void) devfsadm_mklink(path, node, minor, 0);
518 
519 	return (DEVFSADM_CONTINUE);
520 }
521 
522 static int
523 gpio(di_minor_t minor, di_node_t node)
524 {
525 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
526 	char *minor_nm, *drvr_nm;
527 
528 
529 	minor_nm = di_minor_name(minor);
530 	drvr_nm = di_driver_name(node);
531 	if ((minor_nm == NULL) || (drvr_nm == NULL)) {
532 		return (DEVFSADM_CONTINUE);
533 	}
534 
535 	devfspath = di_devfs_path(node);
536 
537 	(void) strcpy(p_path, devfspath);
538 	(void) strcat(p_path, ":");
539 	(void) strcat(p_path, minor_nm);
540 	di_devfs_path_free(devfspath);
541 
542 	/* build the physical path from the components */
543 	if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) {
544 		return (DEVFSADM_CONTINUE);
545 	}
546 
547 	(void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf);
548 
549 	free(buf);
550 
551 	(void) devfsadm_mklink(l_path, node, minor, 0);
552 
553 	return (DEVFSADM_CONTINUE);
554 }
555 
556 /*
557  * Creates /dev/ppm nodes for Platform Specific PM module
558  */
559 static int
560 ppm(di_minor_t minor, di_node_t node)
561 {
562 	(void) devfsadm_mklink("ppm", node, minor, 0);
563 	return (DEVFSADM_CONTINUE);
564 }
565 
566 /*
567  * Handles:
568  *	/dev/av/[0-9]+/(async|isoch)
569  */
570 static int
571 av_create(di_minor_t minor, di_node_t node)
572 {
573 	devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR};
574 	char	*minor_str;
575 	char	path[PATH_MAX + 1];
576 	char	*buf;
577 
578 	if ((buf = di_devfs_path(node)) == NULL) {
579 		return (DEVFSADM_CONTINUE);
580 	}
581 
582 	minor_str = di_minor_name(minor);
583 	(void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str);
584 	di_devfs_path_free(buf);
585 
586 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
587 		return (DEVFSADM_CONTINUE);
588 	}
589 
590 	(void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str);
591 	free(buf);
592 
593 	(void) devfsadm_mklink(path, node, minor, 0);
594 
595 	return (DEVFSADM_CONTINUE);
596 }
597 
598 /*
599  * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node
600  */
601 static int
602 tsalarm_create(di_minor_t minor, di_node_t node)
603 {
604 	char buf[PATH_MAX + 1];
605 	char *mn = di_minor_name(minor);
606 
607 	(void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl");
608 
609 	(void) devfsadm_mklink(mn, node, minor, 0);
610 	(void) devfsadm_mklink(buf, node, minor, 0);
611 
612 	return (DEVFSADM_CONTINUE);
613 }
614 
615 /*
616  * Creates /dev/ntwdt for ntwdt node
617  */
618 static int
619 ntwdt_create(di_minor_t minor, di_node_t node)
620 {
621 	(void) devfsadm_mklink("ntwdt", node, minor, 0);
622 	return (DEVFSADM_CONTINUE);
623 }
624 
625 static int
626 zcons_create(di_minor_t minor, di_node_t node)
627 {
628 	char	*minor_str;
629 	char	*zonename;
630 	char	path[MAXPATHLEN];
631 
632 	minor_str = di_minor_name(minor);
633 
634 	if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename",
635 	    &zonename) == -1) {
636 		return (DEVFSADM_CONTINUE);
637 	}
638 
639 	(void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename,
640 	    minor_str);
641 	(void) devfsadm_mklink(path, node, minor, 0);
642 
643 	return (DEVFSADM_CONTINUE);
644 }
645 
646 /*
647  *	/dev/cpu/self/cpuid 	->	/devices/pseudo/cpuid@0:self
648  */
649 static int
650 cpuid(di_minor_t minor, di_node_t node)
651 {
652 	(void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0);
653 	return (DEVFSADM_CONTINUE);
654 }
655 
656 /*
657  * For device
658  *      /dev/spfma -> /devices/virtual-devices/fma@5:glvc
659  */
660 static int
661 glvc(di_minor_t minor, di_node_t node)
662 {
663 	char node_name[MAXNAMELEN + 1];
664 
665 	(void) strcpy(node_name, di_node_name(node));
666 
667 	if (strncmp(node_name, "fma", 3) == 0) {
668 		/* Only one fma channel */
669 		(void) devfsadm_mklink("spfma", node, minor, 0);
670 	}
671 	return (DEVFSADM_CONTINUE);
672 }
673 
674 /*
675  * Handles links of the form:
676  * type=ddi_pseudo;name=sckmdrv		kmdrv\M0
677  * type=ddi_pseudo;name=oplkmdrv	kmdrv\M0
678  */
679 static int
680 kmdrv_create(di_minor_t minor, di_node_t node)
681 {
682 
683 	(void) devfsadm_mklink("kmdrv", node, minor, 0);
684 	return (DEVFSADM_CONTINUE);
685 }
686