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 2005 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 #define DCAM_RE_STRING_LEN 64 34 35 #define DCAM_STR_LINK_RE "^dcam([0-9]+)$" 36 #define DCAM_CTL_LINK_RE "^dcamctl([0-9]+)$" 37 38 static int dcam1394_process(di_minor_t minor, di_node_t node); 39 40 static devfsadm_create_t dcam1394_cbt[] = { 41 { 42 "firewire", 43 NULL, 44 "dcam", 45 DRV_RE, 46 ILEVEL_0, 47 dcam1394_process 48 } 49 }; 50 51 static char *debug_mid = "dcam1394_mid"; 52 53 DEVFSADM_CREATE_INIT_V0(dcam1394_cbt); 54 55 56 static devfsadm_remove_t dcam1394_remove_cbt[] = { 57 { 58 "firewire", 59 DCAM_STR_LINK_RE, 60 RM_PRE | RM_HOT | RM_ALWAYS, 61 ILEVEL_0, 62 devfsadm_rm_all 63 }, 64 { 65 "firewire", 66 DCAM_CTL_LINK_RE, 67 RM_PRE | RM_HOT | RM_ALWAYS, 68 ILEVEL_0, 69 devfsadm_rm_all 70 } 71 }; 72 73 DEVFSADM_REMOVE_INIT_V0(dcam1394_remove_cbt); 74 75 int 76 minor_init(void) 77 { 78 devfsadm_print(debug_mid, "dcam1394_link: minor_init\n"); 79 return (DEVFSADM_SUCCESS); 80 } 81 82 int 83 minor_fini(void) 84 { 85 devfsadm_print(debug_mid, "dcam1394_link: minor_fini\n"); 86 return (DEVFSADM_SUCCESS); 87 } 88 89 90 /* 91 * This function is called for every dcam1394 minor node. 92 * Calls enumerate to assign a logical dcam1394 id, and then 93 * devfsadm_mklink to make the link. 94 */ 95 static int 96 dcam1394_process(di_minor_t minor, di_node_t node) 97 { 98 char m_name[PATH_MAX], restring0[DCAM_RE_STRING_LEN]; 99 char l_path[PATH_MAX], p_path[PATH_MAX], *buf, *devfspath; 100 devfsadm_enumerate_t re[1]; 101 102 (void) strcpy(m_name, di_minor_name(minor)); 103 104 if (strcmp(di_driver_name(node), "dcam1394") != 0) { 105 return (DEVFSADM_CONTINUE); 106 } 107 108 if (strncmp(m_name, "dcamctl", 7) == 0) { 109 (void) snprintf(restring0, DCAM_RE_STRING_LEN, 110 DCAM_CTL_LINK_RE); 111 } else if (strncmp(m_name, "dcam", 4) == 0) { 112 (void) snprintf(restring0, DCAM_RE_STRING_LEN, 113 DCAM_STR_LINK_RE); 114 } else { 115 return (DEVFSADM_CONTINUE); 116 } 117 118 re[0].re = restring0; 119 re[0].subexp = 1; 120 re[0].flags = MATCH_ALL; 121 122 devfsadm_print(debug_mid, 123 "dcam1394_process: path %s\n", di_devfs_path(node)); 124 125 (void) strcpy(p_path, devfspath = di_devfs_path(node)); 126 (void) strcat(p_path, ":"); 127 (void) strcat(p_path, di_minor_name(minor)); 128 di_devfs_path_free(devfspath); 129 130 /* 131 * Build the physical path from the components, omitting 132 * minor name field. Find the logical dcam1394 id, and 133 * stuff it in buf. 134 */ 135 if (devfsadm_enumerate_int(p_path, 0, &buf, re, 1)) { 136 devfsadm_print(debug_mid, 137 "dcam1394_process: exit/continue\n"); 138 return (DEVFSADM_CONTINUE); 139 } 140 141 devfsadm_print(debug_mid, "dcam1394_process: p_path=%s buf=%s\n", 142 p_path, buf); 143 144 if (strncmp(di_minor_name(minor), "dcamctl", 7) == 0) 145 (void) snprintf(l_path, PATH_MAX, "dcamctl%s", buf); 146 else 147 (void) snprintf(l_path, PATH_MAX, "dcam%s", buf); 148 149 (void) devfsadm_mklink(l_path, node, minor, 0); 150 151 free(buf); 152 153 return (DEVFSADM_CONTINUE); 154 } 155