xref: /illumos-gate/usr/src/cmd/devfsadm/ieee1394_link.c (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <devfsadm.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <limits.h>
31 #include <string.h>
32 
33 static int ieee1394_process(di_minor_t minor, di_node_t node);
34 
35 static devfsadm_create_t ieee1394_cbt[] = {
36 	{ "ieee1394", "ddi_ctl:devctl", "hci1394",
37 		TYPE_EXACT | DRV_EXACT, ILEVEL_0, ieee1394_process
38 	},
39 };
40 
41 static char *debug_mid = "ieee1394_mid";
42 
43 DEVFSADM_CREATE_INIT_V0(ieee1394_cbt);
44 
45 #define	IEEE1394_LINK_RE "^1394/hba[0-9]+$"
46 
47 static devfsadm_remove_t ieee1394_remove_cbt[] = {
48 	{ "ieee1394", IEEE1394_LINK_RE, RM_HOT | RM_POST,
49 		ILEVEL_0, devfsadm_rm_all
50 	},
51 };
52 
53 DEVFSADM_REMOVE_INIT_V0(ieee1394_remove_cbt);
54 
55 int
56 minor_init(void)
57 {
58 	devfsadm_print(debug_mid, "ieee1394_link: minor_init\n");
59 	return (DEVFSADM_SUCCESS);
60 }
61 
62 int
63 minor_fini(void)
64 {
65 	devfsadm_print(debug_mid, "ieee1394_link: minor_fini\n");
66 	return (DEVFSADM_SUCCESS);
67 }
68 
69 /*
70  * This function is called for every ieee1394 minor node.
71  * Calls enumerate to assign a logical ieee1394 id, and then
72  * devfsadm_mklink to make the link.
73  */
74 static int
75 ieee1394_process(di_minor_t minor, di_node_t node)
76 {
77 	char *buf, *devfspath;
78 	char l_path[PATH_MAX], p_path[PATH_MAX];
79 	devfsadm_enumerate_t re[] = {"^1394/hba([0-9]+)$", 1, MATCH_ALL};
80 
81 	devfspath = di_devfs_path(node);
82 
83 	devfsadm_print(debug_mid,
84 		"ieee1394_process: path %s\n", devfspath);
85 
86 	(void) snprintf(p_path, sizeof (p_path), "%s:%s",
87 		devfspath, di_minor_name(minor));
88 	di_devfs_path_free(devfspath);
89 
90 	/*
91 	 *  Build the physical path from the components. Find the logical
92 	 *  ieee1394 HBA id, and stuff it in buf
93 	 */
94 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
95 		devfsadm_print(debug_mid, "ieee1394_process: exit/continue\n");
96 		return (DEVFSADM_CONTINUE);
97 	}
98 	devfsadm_print(debug_mid, "ieee1394_process: p_path=%s buf=%s\n",
99 					p_path, buf);
100 
101 	(void) snprintf(l_path, sizeof (l_path), "1394/hba%s", buf);
102 
103 	free(buf);
104 
105 	devfsadm_print(debug_mid, "mklink %s %s\n", l_path, p_path);
106 
107 	(void) devfsadm_mklink(l_path, node, minor, 0);
108 
109 	return (DEVFSADM_CONTINUE);
110 }
111