Merge branch 'cleanups'
[unleashed.git] / usr / src / cmd / devfsadm / dcam1394_link.c
bloba4eb254dd5fb956e0637fd30389243d65a282ddb
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "devfsadm.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <limits.h>
33 #include <string.h>
35 #define DCAM_RE_STRING_LEN 64
37 #define DCAM_STR_LINK_RE "^dcam([0-9]+)$"
38 #define DCAM_CTL_LINK_RE "^dcamctl([0-9]+)$"
40 static int dcam1394_process(di_minor_t minor, di_node_t node);
42 static devfsadm_create_t dcam1394_cbt[] = {
44 "firewire",
45 NULL,
46 "dcam",
47 DRV_RE,
48 ILEVEL_0,
49 dcam1394_process
53 static char *debug_mid = "dcam1394_mid";
55 DEVFSADM_CREATE_INIT_V0(dcam1394_cbt);
58 static devfsadm_remove_t dcam1394_remove_cbt[] = {
60 "firewire",
61 DCAM_STR_LINK_RE,
62 RM_PRE | RM_HOT | RM_ALWAYS,
63 ILEVEL_0,
64 devfsadm_rm_all
67 "firewire",
68 DCAM_CTL_LINK_RE,
69 RM_PRE | RM_HOT | RM_ALWAYS,
70 ILEVEL_0,
71 devfsadm_rm_all
75 DEVFSADM_REMOVE_INIT_V0(dcam1394_remove_cbt);
77 int
78 minor_init(void)
80 devfsadm_print(debug_mid, "dcam1394_link: minor_init\n");
81 return (DEVFSADM_SUCCESS);
84 int
85 minor_fini(void)
87 devfsadm_print(debug_mid, "dcam1394_link: minor_fini\n");
88 return (DEVFSADM_SUCCESS);
93 * This function is called for every dcam1394 minor node.
94 * Calls enumerate to assign a logical dcam1394 id, and then
95 * devfsadm_mklink to make the link.
97 static int
98 dcam1394_process(di_minor_t minor, di_node_t node)
100 char m_name[PATH_MAX], restring0[DCAM_RE_STRING_LEN];
101 char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath;
102 devfsadm_enumerate_t re[1];
104 (void) strcpy(m_name, di_minor_name(minor));
106 if (strcmp(di_driver_name(node), "dcam1394") != 0) {
107 return (DEVFSADM_CONTINUE);
110 if (strncmp(m_name, "dcamctl", 7) == 0) {
111 (void) snprintf(restring0, DCAM_RE_STRING_LEN,
112 DCAM_CTL_LINK_RE);
113 } else if (strncmp(m_name, "dcam", 4) == 0) {
114 (void) snprintf(restring0, DCAM_RE_STRING_LEN,
115 DCAM_STR_LINK_RE);
116 } else {
117 return (DEVFSADM_CONTINUE);
120 re[0].re = restring0;
121 re[0].subexp = 1;
122 re[0].flags = MATCH_ALL;
124 devfsadm_print(debug_mid,
125 "dcam1394_process: path %s\n", di_devfs_path(node));
127 (void) strcpy(p_path, devfspath = di_devfs_path(node));
128 (void) strcat(p_path, ":");
129 (void) strcat(p_path, di_minor_name(minor));
130 di_devfs_path_free(devfspath);
133 * Build the physical path from the components, omitting
134 * minor name field. Find the logical dcam1394 id, and
135 * stuff it in buf.
137 if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) {
138 devfsadm_print(debug_mid,
139 "dcam1394_process: exit/continue\n");
140 return (DEVFSADM_CONTINUE);
143 devfsadm_print(debug_mid, "dcam1394_process: p_path=%s buf=%s\n",
144 p_path, buf);
146 if (strncmp(di_minor_name(minor), "dcamctl", 7) == 0)
147 (void) snprintf(l_path, PATH_MAX, "dcamctl%s", buf);
148 else
149 (void) snprintf(l_path, PATH_MAX, "dcam%s", buf);
151 (void) devfsadm_mklink(l_path, node, minor, 0);
153 free(buf);
155 return (DEVFSADM_CONTINUE);