Home | History | Annotate | Download | only in devfsadm
      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 #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 #define	DCAM_RE_STRING_LEN	64
     36 
     37 #define	DCAM_STR_LINK_RE	"^dcam([0-9]+)$"
     38 #define	DCAM_CTL_LINK_RE	"^dcamctl([0-9]+)$"
     39 
     40 static int dcam1394_process(di_minor_t minor, di_node_t node);
     41 
     42 static devfsadm_create_t dcam1394_cbt[] = {
     43 	{
     44 		"firewire",
     45 		NULL,
     46 		"dcam",
     47 		DRV_RE,
     48 		ILEVEL_0,
     49 		dcam1394_process
     50 	}
     51 };
     52 
     53 static char *debug_mid = "dcam1394_mid";
     54 
     55 DEVFSADM_CREATE_INIT_V0(dcam1394_cbt);
     56 
     57 
     58 static devfsadm_remove_t dcam1394_remove_cbt[] = {
     59 	{
     60 		"firewire",
     61 		DCAM_STR_LINK_RE,
     62 		RM_PRE | RM_HOT | RM_ALWAYS,
     63 		ILEVEL_0,
     64 		devfsadm_rm_all
     65 	},
     66 	{
     67 		"firewire",
     68 		DCAM_CTL_LINK_RE,
     69 		RM_PRE | RM_HOT | RM_ALWAYS,
     70 		ILEVEL_0,
     71 		devfsadm_rm_all
     72 	}
     73 };
     74 
     75 DEVFSADM_REMOVE_INIT_V0(dcam1394_remove_cbt);
     76 
     77 int
     78 minor_init(void)
     79 {
     80 	devfsadm_print(debug_mid, "dcam1394_link: minor_init\n");
     81 	return (DEVFSADM_SUCCESS);
     82 }
     83 
     84 int
     85 minor_fini(void)
     86 {
     87 	devfsadm_print(debug_mid, "dcam1394_link: minor_fini\n");
     88 	return (DEVFSADM_SUCCESS);
     89 }
     90 
     91 
     92 /*
     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.
     96  */
     97 static int
     98 dcam1394_process(di_minor_t minor, di_node_t node)
     99 {
    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];
    103 
    104 	(void) strcpy(m_name, di_minor_name(minor));
    105 
    106 	if (strcmp(di_driver_name(node), "dcam1394") != 0) {
    107 	    return (DEVFSADM_CONTINUE);
    108 	}
    109 
    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);
    118 	}
    119 
    120 	re[0].re	= restring0;
    121 	re[0].subexp	= 1;
    122 	re[0].flags	= MATCH_ALL;
    123 
    124 	devfsadm_print(debug_mid,
    125 	    "dcam1394_process: path %s\n", di_devfs_path(node));
    126 
    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);
    131 
    132 	/*
    133 	 * Build the physical path from the components, omitting
    134 	 * minor name field.  Find the logical dcam1394 id, and
    135 	 * stuff it in buf.
    136 	 */
    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);
    141 	}
    142 
    143 	devfsadm_print(debug_mid, "dcam1394_process: p_path=%s buf=%s\n",
    144 	    p_path, buf);
    145 
    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);
    150 
    151 	(void) devfsadm_mklink(l_path, node, minor, 0);
    152 
    153 	free(buf);
    154 
    155 	return (DEVFSADM_CONTINUE);
    156 }
    157