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