xref: /onnv-gate/usr/src/cmd/devfsadm/dcam1394_link.c (revision 21:9318364fb703)
1*21Sap25164 /*
2*21Sap25164  * CDDL HEADER START
3*21Sap25164  *
4*21Sap25164  * The contents of this file are subject to the terms of the
5*21Sap25164  * Common Development and Distribution License, Version 1.0 only
6*21Sap25164  * (the "License").  You may not use this file except in compliance
7*21Sap25164  * with the License.
8*21Sap25164  *
9*21Sap25164  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*21Sap25164  * or http://www.opensolaris.org/os/licensing.
11*21Sap25164  * See the License for the specific language governing permissions
12*21Sap25164  * and limitations under the License.
13*21Sap25164  *
14*21Sap25164  * When distributing Covered Code, include this CDDL HEADER in each
15*21Sap25164  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*21Sap25164  * If applicable, add the following below this CDDL HEADER, with the
17*21Sap25164  * fields enclosed by brackets "[]" replaced with your own identifying
18*21Sap25164  * information: Portions Copyright [yyyy] [name of copyright owner]
19*21Sap25164  *
20*21Sap25164  * CDDL HEADER END
21*21Sap25164  */
22*21Sap25164 /*
23*21Sap25164  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*21Sap25164  * Use is subject to license terms.
25*21Sap25164  */
26*21Sap25164 
27*21Sap25164 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*21Sap25164 
29*21Sap25164 #include "devfsadm.h"
30*21Sap25164 #include <stdio.h>
31*21Sap25164 #include <stdlib.h>
32*21Sap25164 #include <limits.h>
33*21Sap25164 #include <string.h>
34*21Sap25164 
35*21Sap25164 #define	DCAM_RE_STRING_LEN	64
36*21Sap25164 
37*21Sap25164 #define	DCAM_STR_LINK_RE	"^dcam([0-9]+)$"
38*21Sap25164 #define	DCAM_CTL_LINK_RE	"^dcamctl([0-9]+)$"
39*21Sap25164 
40*21Sap25164 static int dcam1394_process(di_minor_t minor, di_node_t node);
41*21Sap25164 
42*21Sap25164 static devfsadm_create_t dcam1394_cbt[] = {
43*21Sap25164 	{
44*21Sap25164 		"firewire",
45*21Sap25164 		NULL,
46*21Sap25164 		"dcam",
47*21Sap25164 		DRV_RE,
48*21Sap25164 		ILEVEL_0,
49*21Sap25164 		dcam1394_process
50*21Sap25164 	}
51*21Sap25164 };
52*21Sap25164 
53*21Sap25164 static char *debug_mid = "dcam1394_mid";
54*21Sap25164 
55*21Sap25164 DEVFSADM_CREATE_INIT_V0(dcam1394_cbt);
56*21Sap25164 
57*21Sap25164 
58*21Sap25164 static devfsadm_remove_t dcam1394_remove_cbt[] = {
59*21Sap25164 	{
60*21Sap25164 		"firewire",
61*21Sap25164 		DCAM_STR_LINK_RE,
62*21Sap25164 		RM_PRE | RM_HOT | RM_ALWAYS,
63*21Sap25164 		ILEVEL_0,
64*21Sap25164 		devfsadm_rm_all
65*21Sap25164 	},
66*21Sap25164 	{
67*21Sap25164 		"firewire",
68*21Sap25164 		DCAM_CTL_LINK_RE,
69*21Sap25164 		RM_PRE | RM_HOT | RM_ALWAYS,
70*21Sap25164 		ILEVEL_0,
71*21Sap25164 		devfsadm_rm_all
72*21Sap25164 	}
73*21Sap25164 };
74*21Sap25164 
75*21Sap25164 DEVFSADM_REMOVE_INIT_V0(dcam1394_remove_cbt);
76*21Sap25164 
77*21Sap25164 int
minor_init(void)78*21Sap25164 minor_init(void)
79*21Sap25164 {
80*21Sap25164 	devfsadm_print(debug_mid, "dcam1394_link: minor_init\n");
81*21Sap25164 	return (DEVFSADM_SUCCESS);
82*21Sap25164 }
83*21Sap25164 
84*21Sap25164 int
minor_fini(void)85*21Sap25164 minor_fini(void)
86*21Sap25164 {
87*21Sap25164 	devfsadm_print(debug_mid, "dcam1394_link: minor_fini\n");
88*21Sap25164 	return (DEVFSADM_SUCCESS);
89*21Sap25164 }
90*21Sap25164 
91*21Sap25164 
92*21Sap25164 /*
93*21Sap25164  * This function is called for every dcam1394 minor node.
94*21Sap25164  * Calls enumerate to assign a logical dcam1394 id, and then
95*21Sap25164  * devfsadm_mklink to make the link.
96*21Sap25164  */
97*21Sap25164 static int
dcam1394_process(di_minor_t minor,di_node_t node)98*21Sap25164 dcam1394_process(di_minor_t minor, di_node_t node)
99*21Sap25164 {
100*21Sap25164 	char m_name[PATH_MAX], restring0[DCAM_RE_STRING_LEN];
101*21Sap25164 	char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
102*21Sap25164 	devfsadm_enumerate_t re[1];
103*21Sap25164 
104*21Sap25164 	(void) strcpy(m_name, di_minor_name(minor));
105*21Sap25164 
106*21Sap25164 	if (strcmp(di_driver_name(node), "dcam1394") != 0) {
107*21Sap25164 	    return (DEVFSADM_CONTINUE);
108*21Sap25164 	}
109*21Sap25164 
110*21Sap25164 	if (strncmp(m_name, "dcamctl", 7) == 0) {
111*21Sap25164 		(void) snprintf(restring0, DCAM_RE_STRING_LEN,
112*21Sap25164 				DCAM_CTL_LINK_RE);
113*21Sap25164 	} else if (strncmp(m_name, "dcam", 4) == 0) {
114*21Sap25164 		(void) snprintf(restring0, DCAM_RE_STRING_LEN,
115*21Sap25164 				DCAM_STR_LINK_RE);
116*21Sap25164 	} else {
117*21Sap25164 		return (DEVFSADM_CONTINUE);
118*21Sap25164 	}
119*21Sap25164 
120*21Sap25164 	re[0].re	= restring0;
121*21Sap25164 	re[0].subexp	= 1;
122*21Sap25164 	re[0].flags	= MATCH_ALL;
123*21Sap25164 
124*21Sap25164 	devfsadm_print(debug_mid,
125*21Sap25164 	    "dcam1394_process: path %s\n", di_devfs_path(node));
126*21Sap25164 
127*21Sap25164 	(void) strcpy(p_path, devfspath = di_devfs_path(node));
128*21Sap25164 	(void) strcat(p_path, ":");
129*21Sap25164 	(void) strcat(p_path, di_minor_name(minor));
130*21Sap25164 	di_devfs_path_free(devfspath);
131*21Sap25164 
132*21Sap25164 	/*
133*21Sap25164 	 * Build the physical path from the components, omitting
134*21Sap25164 	 * minor name field.  Find the logical dcam1394 id, and
135*21Sap25164 	 * stuff it in buf.
136*21Sap25164 	 */
137*21Sap25164 	if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
138*21Sap25164 		devfsadm_print(debug_mid,
139*21Sap25164 		    "dcam1394_process: exit/continue\n");
140*21Sap25164 		return (DEVFSADM_CONTINUE);
141*21Sap25164 	}
142*21Sap25164 
143*21Sap25164 	devfsadm_print(debug_mid, "dcam1394_process: p_path=%s buf=%s\n",
144*21Sap25164 	    p_path, buf);
145*21Sap25164 
146*21Sap25164 	if (strncmp(di_minor_name(minor), "dcamctl", 7) == 0)
147*21Sap25164 		(void) snprintf(l_path, PATH_MAX, "dcamctl%s", buf);
148*21Sap25164 	else
149*21Sap25164 		(void) snprintf(l_path, PATH_MAX, "dcam%s", buf);
150*21Sap25164 
151*21Sap25164 	(void) devfsadm_mklink(l_path, node, minor, 0);
152*21Sap25164 
153*21Sap25164 	free(buf);
154*21Sap25164 
155*21Sap25164 	return (DEVFSADM_CONTINUE);
156*21Sap25164 }
157