xref: /titanic_44/usr/src/cmd/devfsadm/ieee1394_link.c (revision 24db46411fd54f70c35b94bb952eb7ba040e43b4)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <devfsadm.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <limits.h>
33 #include <string.h>
34 
35 static int ieee1394_process(di_minor_t minor, di_node_t node);
36 
37 static devfsadm_create_t ieee1394_cbt[] = {
38 	{ "ieee1394", "ddi_ctl:devctl", "hci1394",
39 		TYPE_EXACT | DRV_EXACT, ILEVEL_0, ieee1394_process
40 	},
41 };
42 
43 static char *debug_mid = "ieee1394_mid";
44 
45 DEVFSADM_CREATE_INIT_V0(ieee1394_cbt);
46 
47 #define	IEEE1394_LINK_RE "^1394/hba[0-9]+$"
48 
49 static devfsadm_remove_t ieee1394_remove_cbt[] = {
50 	{ "ieee1394", IEEE1394_LINK_RE, RM_HOT | RM_POST,
51 		ILEVEL_0, devfsadm_rm_all
52 	},
53 };
54 
55 DEVFSADM_REMOVE_INIT_V0(ieee1394_remove_cbt);
56 
57 int
58 minor_init(void)
59 {
60 	devfsadm_print(debug_mid, "ieee1394_link: minor_init\n");
61 	return (DEVFSADM_SUCCESS);
62 }
63 
64 int
65 minor_fini(void)
66 {
67 	devfsadm_print(debug_mid, "ieee1394_link: minor_fini\n");
68 	return (DEVFSADM_SUCCESS);
69 }
70 
71 /*
72  * This function is called for every ieee1394 minor node.
73  * Calls enumerate to assign a logical ieee1394 id, and then
74  * devfsadm_mklink to make the link.
75  */
76 static int
77 ieee1394_process(di_minor_t minor, di_node_t node)
78 {
79 	char *buf, *devfspath;
80 	char l_path[PATH_MAX], p_path[PATH_MAX];
81 	devfsadm_enumerate_t re[] = {"^1394/hba([0-9]+)$", 1, MATCH_ALL};
82 
83 	devfspath = di_devfs_path(node);
84 
85 	devfsadm_print(debug_mid,
86 		"ieee1394_process: path %s\n", devfspath);
87 
88 	(void) snprintf(p_path, sizeof (p_path), "%s:%s",
89 		devfspath, di_minor_name(minor));
90 	di_devfs_path_free(devfspath);
91 
92 	/*
93 	 *  Build the physical path from the components. Find the logical
94 	 *  ieee1394 HBA id, and stuff it in buf
95 	 */
96 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
97 		devfsadm_print(debug_mid, "ieee1394_process: exit/continue\n");
98 		return (DEVFSADM_CONTINUE);
99 	}
100 	devfsadm_print(debug_mid, "ieee1394_process: p_path=%s buf=%s\n",
101 					p_path, buf);
102 
103 	(void) snprintf(l_path, sizeof (l_path), "1394/hba%s", buf);
104 
105 	free(buf);
106 
107 	devfsadm_print(debug_mid, "mklink %s %s\n", l_path, p_path);
108 
109 	(void) devfsadm_mklink(l_path, node, minor, 0);
110 
111 	return (DEVFSADM_CONTINUE);
112 }
113