xref: /illumos-gate/usr/src/cmd/devfsadm/misc_link.c (revision 15f90b02)
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 (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24  * Copyright (c) 2015, Joyent, Inc. All rights reserved.
25  * Copyright 2022 Garrett D'Amore <garrett@damore.org>
26  */
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", "eventfd",
94 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
95 	},
96 	{ "pseudo", "ddi_pseudo", "signalfd",
97 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
98 	},
99 	{ "pseudo", "ddi_pseudo", "rsm",
100 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
101 	},
102 	{ "pseudo", "ddi_pseudo",
103 	    "(^lockstat$)|(^SUNW,rtvc$)|(^vol$)|(^log$)|(^sy$)|"
104 	    "(^ksyms$)|(^clone$)|(^tl$)|(^tnf$)|(^kstat$)|(^mdesc$)|(^eeprom$)|"
105 	    "(^ptsl$)|(^mm$)|(^wc$)|(^dump$)|(^cn$)|(^svvslo$)|(^ptm$)|"
106 	    "(^ptc$)|(^openeepr$)|(^poll$)|(^sysmsg$)|(^random$)|(^trapstat$)|"
107 	    "(^cryptoadm$)|(^crypto$)|(^pool$)|(^poolctl$)|(^bl$)|(^kmdb$)|"
108 	    "(^sysevent$)|(^physmem$)",
109 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
110 	},
111 	{ "pseudo", "ddi_pseudo",
112 	    "(^ip$)|(^tcp$)|(^udp$)|(^icmp$)|"
113 	    "(^ip6$)|(^tcp6$)|(^udp6$)|(^icmp6$)|"
114 	    "(^rts$)|(^arp$)|(^ipsecah$)|(^ipsecesp$)|(^keysock$)|(^spdsock$)|"
115 	    "(^rds$)|(^sdp$)|(^ipnet$)|(^dlpistub$)|(^bpf$)",
116 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name
117 	},
118 	{ "pseudo", "ddi_pseudo", "ipd",
119 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
120 	},
121 	{ "pseudo", "ddi_pseudo",
122 	    "(^ipf$)|(^ipnat$)|(^ipstate$)|(^ipauth$)|"
123 	    "(^ipsync$)|(^ipscan$)|(^iplookup$)",
124 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
125 	},
126 	{ "pseudo", "ddi_pseudo", "dld",
127 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
128 	},
129 	{ "pseudo", "ddi_pseudo",
130 	    "(^kdmouse$)|(^rootprop$)",
131 	    TYPE_EXACT | DRV_RE, ILEVEL_0, node_name
132 	},
133 	{ "pseudo", "ddi_pseudo", "timerfd",
134 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
135 	},
136 	{ "pseudo", "ddi_pseudo", "tod",
137 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name
138 	},
139 	{ "pseudo", "ddi_pseudo", "envctrl(two)?",
140 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
141 	},
142 	{ "pseudo", "ddi_pseudo", "fcode",
143 	    TYPE_EXACT | DRV_RE, ILEVEL_0, minor_name,
144 	},
145 	{ "power_button", "ddi_power_button", NULL,
146 	    TYPE_EXACT, ILEVEL_0, power_button,
147 	},
148 	{ "FC port", "ddi_ctl:devctl", "fp",
149 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, fc_port
150 	},
151 	{ "printer", "ddi_printer", NULL,
152 	    TYPE_EXACT, ILEVEL_0, printer_create
153 	},
154 	{ "pseudo", "ddi_pseudo", "se",
155 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, se_hdlc_create
156 	},
157 	{ "ppm",  "ddi_ppm", NULL,
158 	    TYPE_EXACT, ILEVEL_0, ppm
159 	},
160 	{ "pseudo", "ddi_pseudo", "gpio_87317",
161 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, gpio
162 	},
163 	{ "pseudo", "ddi_pseudo", "sckmdrv",
164 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
165 	},
166 	{ "pseudo", "ddi_pseudo", "oplkmdrv",
167 	    TYPE_EXACT | DRV_RE, ILEVEL_0, kmdrv_create,
168 	},
169 	{ "av", "^ddi_av:(isoch|async)$", NULL,
170 	    TYPE_RE, ILEVEL_0, av_create,
171 	},
172 	{ "pseudo", "ddi_pseudo", "tsalarm",
173 	    TYPE_EXACT | DRV_RE, ILEVEL_0, tsalarm_create,
174 	},
175 	{ "pseudo", "ddi_pseudo", "ntwdt",
176 	    TYPE_EXACT | DRV_RE, ILEVEL_0, ntwdt_create,
177 	},
178 	{ "pseudo", "ddi_pseudo", "daplt",
179 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
180 	},
181 	{ "pseudo", "ddi_pseudo", "zcons",
182 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, zcons_create,
183 	},
184 	{ "pseudo", "ddi_pseudo", CPUID_DRIVER_NAME,
185 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, cpuid,
186 	},
187 	{ "pseudo", "ddi_pseudo", "glvc",
188 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, glvc,
189 	},
190 	{ "pseudo", "ddi_pseudo", "dm2s",
191 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name,
192 	},
193 	{ "pseudo", "ddi_pseudo", "nsmb",
194 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, minor_name,
195 	},
196 	{ "pseudo", "ddi_pseudo", "mem_cache",
197 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
198 	},
199 	{ "pseudo", "ddi_pseudo", "fm",
200 	    TYPE_EXACT | DRV_RE, ILEVEL_1, minor_name,
201 	},
202 	{ "pseudo", "ddi_pseudo", "smbsrv",
203 	    TYPE_EXACT | DRV_EXACT, ILEVEL_1, minor_name,
204 	},
205 	{ "pseudo", "ddi_pseudo", "tpm",
206 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
207 	},
208 	{ "pseudo", "ddi_pseudo", "overlay",
209 	    TYPE_EXACT | DRV_EXACT, ILEVEL_0, minor_name
210 	}
211 };
212 
213 DEVFSADM_CREATE_INIT_V0(misc_cbt);
214 
215 static devfsadm_remove_t misc_remove_cbt[] = {
216 	{ "pseudo", "^profile$",
217 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
218 	},
219 	{ "pseudo", "^rsm$",
220 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
221 	},
222 	{ "printer", "^printers/[0-9]+$",
223 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
224 	},
225 	{ "av", "^av/[0-9]+/(async|isoch)$",
226 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
227 	},
228 	{ "pseudo", "^daplt$",
229 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
230 	},
231 	{ "pseudo", "^zcons/" ZONENAME_REGEXP "/(" ZCONS_MANAGER_NAME "|"
232 		ZCONS_SUBSIDIARY_NAME ")$",
233 	    RM_PRE | RM_HOT | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
234 	},
235 	{ "pseudo", "^" CPUID_SELF_NAME "$", RM_ALWAYS | RM_PRE | RM_HOT,
236 	    ILEVEL_0, devfsadm_rm_all
237 	},
238 	{ "enclosure", "^es/ses[0-9]+$", RM_POST,
239 		ILEVEL_0, devfsadm_rm_all
240 	},
241 	{ "pseudo", "^pfil$",
242 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
243 	},
244 	{ "pseudo", "^tpm$",
245 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_all
246 	},
247 	{ "pseudo", "^sctp|sctp6$",
248 	    RM_PRE | RM_ALWAYS, ILEVEL_0, devfsadm_rm_link
249 	}
250 };
251 
252 /* Rules for gpio devices */
253 static devfsadm_enumerate_t gpio_rules[1] =
254 	{"^gpio([0-9]+)$", 1, MATCH_ALL};
255 
256 DEVFSADM_REMOVE_INIT_V0(misc_remove_cbt);
257 
258 /*
259  * Handles minor node type "ddi_display".
260  *
261  * type=ddi_display fbs/\M0 fb\N0
262  */
263 static int
display(di_minor_t minor,di_node_t node)264 display(di_minor_t minor, di_node_t node)
265 {
266 	char l_path[PATH_MAX + 1], contents[PATH_MAX + 1], *buf;
267 	devfsadm_enumerate_t rules[1] = {"^fb([0-9]+)$", 1, MATCH_ALL};
268 	char *mn = di_minor_name(minor);
269 
270 	/* create fbs/\M0 primary link */
271 	(void) strcpy(l_path, "fbs/");
272 	(void) strcat(l_path, mn);
273 	(void) devfsadm_mklink(l_path, node, minor, 0);
274 
275 	/* create fb\N0 which links to fbs/\M0 */
276 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
277 		return (DEVFSADM_CONTINUE);
278 	}
279 	(void) strcpy(contents, l_path);
280 	(void) strcpy(l_path, "fb");
281 	(void) strcat(l_path, buf);
282 	free(buf);
283 	(void) devfsadm_secondary_link(l_path, contents, 0);
284 	return (DEVFSADM_CONTINUE);
285 }
286 
287 /*
288  * Handles minor node type "ddi_parallel".
289  * type=ddi_parallel;name=mcpp     mcpp\N0
290  */
291 static int
parallel(di_minor_t minor,di_node_t node)292 parallel(di_minor_t minor, di_node_t node)
293 {
294 	char path[PATH_MAX + 1], *buf;
295 	devfsadm_enumerate_t rules[1] = {"mcpp([0-9]+)$", 1, MATCH_ALL};
296 
297 
298 	if (strcmp(di_node_name(node), "mcpp") != 0) {
299 		return (DEVFSADM_CONTINUE);
300 	}
301 
302 	if (NULL == (buf = di_devfs_path(node))) {
303 		return (DEVFSADM_CONTINUE);
304 	}
305 
306 	(void) snprintf(path, sizeof (path), "%s:%s",
307 	    buf, di_minor_name(minor));
308 
309 	di_devfs_path_free(buf);
310 
311 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
312 		return (DEVFSADM_CONTINUE);
313 	}
314 	(void) snprintf(path, sizeof (path), "mcpp%s", buf);
315 	free(buf);
316 
317 	(void) devfsadm_mklink(path, node, minor, 0);
318 	return (DEVFSADM_CONTINUE);
319 }
320 
321 static int
ses_callback(di_minor_t minor,di_node_t node)322 ses_callback(di_minor_t minor, di_node_t node)
323 {
324 	char l_path[PATH_MAX];
325 	char *buf;
326 	char *devfspath;
327 	char p_path[PATH_MAX];
328 	devfsadm_enumerate_t re[] = {"^es$/^ses([0-9]+)$", 1, MATCH_ALL};
329 
330 	/* find devices path -- need to free mem */
331 	if (NULL == (devfspath = di_devfs_path(node))) {
332 		return (DEVFSADM_CONTINUE);
333 	}
334 
335 	(void) snprintf(p_path, sizeof (p_path), "%s:%s", devfspath,
336 	    di_minor_name(minor));
337 
338 
339 	/* find next number to use; buf is an ascii number */
340 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
341 		/* free memory */
342 		di_devfs_path_free(devfspath);
343 		return (DEVFSADM_CONTINUE);
344 	}
345 
346 	(void) snprintf(l_path, sizeof (l_path), "es/ses%s", buf);
347 
348 	(void) devfsadm_mklink(l_path, node, minor, 0);
349 	/* free memory */
350 	free(buf);
351 	di_devfs_path_free(devfspath);
352 	return (DEVFSADM_CONTINUE);
353 
354 }
355 
356 static int
node_slash_minor(di_minor_t minor,di_node_t node)357 node_slash_minor(di_minor_t minor, di_node_t node)
358 {
359 
360 	char path[PATH_MAX + 1];
361 
362 	(void) strcpy(path, di_node_name(node));
363 	(void) strcat(path, "/");
364 	(void) strcat(path, di_minor_name(minor));
365 	(void) devfsadm_mklink(path, node, minor, 0);
366 	return (DEVFSADM_CONTINUE);
367 }
368 
369 static int
driver_minor(di_minor_t minor,di_node_t node)370 driver_minor(di_minor_t minor, di_node_t node)
371 {
372 	char path[PATH_MAX + 1];
373 
374 	(void) strcpy(path, di_driver_name(node));
375 	(void) strcat(path, di_minor_name(minor));
376 	(void) devfsadm_mklink(path, node, minor, 0);
377 	return (DEVFSADM_CONTINUE);
378 }
379 
380 /*
381  * Handles links of the form:
382  * type=ddi_pseudo;name=xyz  \D
383  */
384 static int
node_name(di_minor_t minor,di_node_t node)385 node_name(di_minor_t minor, di_node_t node)
386 {
387 	(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
388 	return (DEVFSADM_CONTINUE);
389 }
390 
391 /*
392  * Handles links of the form:
393  * type=ddi_pseudo;name=xyz  \M0
394  */
395 static int
minor_name(di_minor_t minor,di_node_t node)396 minor_name(di_minor_t minor, di_node_t node)
397 {
398 	char *mn = di_minor_name(minor);
399 
400 	(void) devfsadm_mklink(mn, node, minor, 0);
401 	if (strcmp(mn, "icmp") == 0) {
402 		(void) devfsadm_mklink("rawip", node, minor, 0);
403 	}
404 	if (strcmp(mn, "icmp6") == 0) {
405 		(void) devfsadm_mklink("rawip6", node, minor, 0);
406 	}
407 	if (strcmp(mn, "ipf") == 0) {
408 		(void) devfsadm_mklink("ipl", node, minor, 0);
409 	}
410 	return (DEVFSADM_CONTINUE);
411 }
412 
413 /*
414  * create links at /dev/wifi for wifi minor node
415  */
416 static int
wifi_minor_name(di_minor_t minor,di_node_t node)417 wifi_minor_name(di_minor_t minor, di_node_t node)
418 {
419 	char buf[256];
420 	char *mn = di_minor_name(minor);
421 
422 	(void) snprintf(buf, sizeof (buf), "%s%s", "wifi/", mn);
423 	(void) devfsadm_mklink(buf, node, minor, 0);
424 
425 	return (DEVFSADM_CONTINUE);
426 }
427 
428 static int
conskbd(di_minor_t minor,di_node_t node)429 conskbd(di_minor_t minor, di_node_t node)
430 {
431 	(void) devfsadm_mklink("kbd", node, minor, 0);
432 	return (DEVFSADM_CONTINUE);
433 }
434 
435 static int
consms(di_minor_t minor,di_node_t node)436 consms(di_minor_t minor, di_node_t node)
437 {
438 	(void) devfsadm_mklink("mouse", node, minor, 0);
439 	return (DEVFSADM_CONTINUE);
440 }
441 
442 static int
power_button(di_minor_t minor,di_node_t node)443 power_button(di_minor_t minor, di_node_t node)
444 {
445 	(void) devfsadm_mklink("power_button", node, minor, 0);
446 	return (DEVFSADM_CONTINUE);
447 }
448 
449 static int
fc_port(di_minor_t minor,di_node_t node)450 fc_port(di_minor_t minor, di_node_t node)
451 {
452 	devfsadm_enumerate_t rules[1] = {"fc/fp([0-9]+)$", 1, MATCH_ALL};
453 	char *buf, path[PATH_MAX + 1];
454 	char *ptr;
455 
456 	if (NULL == (ptr = di_devfs_path(node))) {
457 		return (DEVFSADM_CONTINUE);
458 	}
459 
460 	(void) strcpy(path, ptr);
461 	(void) strcat(path, ":");
462 	(void) strcat(path, di_minor_name(minor));
463 
464 	di_devfs_path_free(ptr);
465 
466 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
467 		return (DEVFSADM_CONTINUE);
468 	}
469 
470 	(void) strcpy(path, "fc/fp");
471 	(void) strcat(path, buf);
472 	free(buf);
473 
474 	(void) devfsadm_mklink(path, node, minor, 0);
475 	return (DEVFSADM_CONTINUE);
476 }
477 
478 /*
479  * Handles:
480  *	minor node type "ddi_printer".
481  *	rules of the form: type=ddi_printer;name=bpp  \M0
482  */
483 static int
printer_create(di_minor_t minor,di_node_t node)484 printer_create(di_minor_t minor, di_node_t node)
485 {
486 	char *mn;
487 	char path[PATH_MAX + 1], *buf;
488 	devfsadm_enumerate_t rules[1] = {"^printers$/^([0-9]+)$", 1, MATCH_ALL};
489 
490 	mn = di_minor_name(minor);
491 
492 	if (strcmp(di_driver_name(node), "bpp") == 0) {
493 		(void) devfsadm_mklink(mn, node, minor, 0);
494 	}
495 
496 	if (NULL == (buf = di_devfs_path(node))) {
497 		return (DEVFSADM_CONTINUE);
498 	}
499 
500 	(void) snprintf(path, sizeof (path), "%s:%s", buf, mn);
501 	di_devfs_path_free(buf);
502 
503 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
504 		return (DEVFSADM_CONTINUE);
505 	}
506 
507 	(void) snprintf(path, sizeof (path), "printers/%s", buf);
508 	free(buf);
509 
510 	(void) devfsadm_mklink(path, node, minor, 0);
511 
512 	return (DEVFSADM_CONTINUE);
513 }
514 
515 /*
516  * Handles links of the form:
517  * type=ddi_pseudo;name=se;minor2=hdlc	se_hdlc\N0
518  * type=ddi_pseudo;name=serial;minor2=hdlc	se_hdlc\N0
519  */
520 static int
se_hdlc_create(di_minor_t minor,di_node_t node)521 se_hdlc_create(di_minor_t minor, di_node_t node)
522 {
523 	devfsadm_enumerate_t rules[1] = {"^se_hdlc([0-9]+)$", 1, MATCH_ALL};
524 	char *buf, path[PATH_MAX + 1];
525 	char *ptr;
526 	char *mn;
527 
528 	mn = di_minor_name(minor);
529 
530 	/* minor node should be of the form: "?,hdlc" */
531 	if (strcmp(mn + 1, ",hdlc") != 0) {
532 		return (DEVFSADM_CONTINUE);
533 	}
534 
535 	if (NULL == (ptr = di_devfs_path(node))) {
536 		return (DEVFSADM_CONTINUE);
537 	}
538 
539 	(void) strcpy(path, ptr);
540 	(void) strcat(path, ":");
541 	(void) strcat(path, mn);
542 
543 	di_devfs_path_free(ptr);
544 
545 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1) != 0) {
546 		return (DEVFSADM_CONTINUE);
547 	}
548 
549 	(void) strcpy(path, "se_hdlc");
550 	(void) strcat(path, buf);
551 	free(buf);
552 
553 	(void) devfsadm_mklink(path, node, minor, 0);
554 
555 	return (DEVFSADM_CONTINUE);
556 }
557 
558 static int
gpio(di_minor_t minor,di_node_t node)559 gpio(di_minor_t minor, di_node_t node)
560 {
561 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
562 	char *minor_nm, *drvr_nm;
563 
564 
565 	minor_nm = di_minor_name(minor);
566 	drvr_nm = di_driver_name(node);
567 	if ((minor_nm == NULL) || (drvr_nm == NULL)) {
568 		return (DEVFSADM_CONTINUE);
569 	}
570 
571 	devfspath = di_devfs_path(node);
572 
573 	(void) strcpy(p_path, devfspath);
574 	(void) strcat(p_path, ":");
575 	(void) strcat(p_path, minor_nm);
576 	di_devfs_path_free(devfspath);
577 
578 	/* build the physical path from the components */
579 	if (devfsadm_enumerate_int(p_path, 0, &buf, gpio_rules, 1)) {
580 		return (DEVFSADM_CONTINUE);
581 	}
582 
583 	(void) snprintf(l_path, sizeof (l_path), "%s%s", "gpio", buf);
584 
585 	free(buf);
586 
587 	(void) devfsadm_mklink(l_path, node, minor, 0);
588 
589 	return (DEVFSADM_CONTINUE);
590 }
591 
592 /*
593  * Creates /dev/ppm nodes for Platform Specific PM module
594  */
595 static int
ppm(di_minor_t minor,di_node_t node)596 ppm(di_minor_t minor, di_node_t node)
597 {
598 	(void) devfsadm_mklink("ppm", node, minor, 0);
599 	return (DEVFSADM_CONTINUE);
600 }
601 
602 /*
603  * Handles:
604  *	/dev/av/[0-9]+/(async|isoch)
605  */
606 static int
av_create(di_minor_t minor,di_node_t node)607 av_create(di_minor_t minor, di_node_t node)
608 {
609 	devfsadm_enumerate_t rules[1] = {"^av$/^([0-9]+)$", 1, MATCH_ADDR};
610 	char	*minor_str;
611 	char	path[PATH_MAX + 1];
612 	char	*buf;
613 
614 	if ((buf = di_devfs_path(node)) == NULL) {
615 		return (DEVFSADM_CONTINUE);
616 	}
617 
618 	minor_str = di_minor_name(minor);
619 	(void) snprintf(path, sizeof (path), "%s:%s", buf, minor_str);
620 	di_devfs_path_free(buf);
621 
622 	if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
623 		return (DEVFSADM_CONTINUE);
624 	}
625 
626 	(void) snprintf(path, sizeof (path), "av/%s/%s", buf, minor_str);
627 	free(buf);
628 
629 	(void) devfsadm_mklink(path, node, minor, 0);
630 
631 	return (DEVFSADM_CONTINUE);
632 }
633 
634 /*
635  * Creates /dev/lom and /dev/tsalarm:ctl for tsalarm node
636  */
637 static int
tsalarm_create(di_minor_t minor,di_node_t node)638 tsalarm_create(di_minor_t minor, di_node_t node)
639 {
640 	char buf[PATH_MAX + 1];
641 	char *mn = di_minor_name(minor);
642 
643 	(void) snprintf(buf, sizeof (buf), "%s%s", di_node_name(node), ":ctl");
644 
645 	(void) devfsadm_mklink(mn, node, minor, 0);
646 	(void) devfsadm_mklink(buf, node, minor, 0);
647 
648 	return (DEVFSADM_CONTINUE);
649 }
650 
651 /*
652  * Creates /dev/ntwdt for ntwdt node
653  */
654 static int
ntwdt_create(di_minor_t minor,di_node_t node)655 ntwdt_create(di_minor_t minor, di_node_t node)
656 {
657 	(void) devfsadm_mklink("ntwdt", node, minor, 0);
658 	return (DEVFSADM_CONTINUE);
659 }
660 
661 static int
zcons_create(di_minor_t minor,di_node_t node)662 zcons_create(di_minor_t minor, di_node_t node)
663 {
664 	char	*minor_str;
665 	char	*zonename;
666 	char	path[MAXPATHLEN];
667 
668 	minor_str = di_minor_name(minor);
669 
670 	if (di_prop_lookup_strings(DDI_DEV_T_ANY, node, "zonename",
671 	    &zonename) == -1) {
672 		return (DEVFSADM_CONTINUE);
673 	}
674 
675 	(void) snprintf(path, sizeof (path), "zcons/%s/%s", zonename,
676 	    minor_str);
677 	(void) devfsadm_mklink(path, node, minor, 0);
678 
679 	return (DEVFSADM_CONTINUE);
680 }
681 
682 /*
683  *	/dev/cpu/self/cpuid	->	/devices/pseudo/cpuid@0:self
684  */
685 static int
cpuid(di_minor_t minor,di_node_t node)686 cpuid(di_minor_t minor, di_node_t node)
687 {
688 	(void) devfsadm_mklink(CPUID_SELF_NAME, node, minor, 0);
689 	return (DEVFSADM_CONTINUE);
690 }
691 
692 /*
693  * For device
694  *      /dev/spfma -> /devices/virtual-devices/fma@5:glvc
695  */
696 static int
glvc(di_minor_t minor,di_node_t node)697 glvc(di_minor_t minor, di_node_t node)
698 {
699 	char node_name[MAXNAMELEN + 1];
700 
701 	(void) strcpy(node_name, di_node_name(node));
702 
703 	if (strncmp(node_name, "fma", 3) == 0) {
704 		/* Only one fma channel */
705 		(void) devfsadm_mklink("spfma", node, minor, 0);
706 	}
707 	return (DEVFSADM_CONTINUE);
708 }
709 
710 /*
711  * Handles links of the form:
712  * type=ddi_pseudo;name=sckmdrv		kmdrv\M0
713  * type=ddi_pseudo;name=oplkmdrv	kmdrv\M0
714  */
715 static int
kmdrv_create(di_minor_t minor,di_node_t node)716 kmdrv_create(di_minor_t minor, di_node_t node)
717 {
718 
719 	(void) devfsadm_mklink("kmdrv", node, minor, 0);
720 	return (DEVFSADM_CONTINUE);
721 }
722