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 2004 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 <strings.h> 31 #include <stdlib.h> 32 #include <limits.h> 33 34 35 static int tape_process(di_minor_t minor, di_node_t node); 36 37 static devfsadm_create_t tape_cbt[] = { 38 { "tape", "ddi_byte:tape", NULL, 39 TYPE_EXACT, ILEVEL_0, tape_process 40 }, 41 }; 42 43 DEVFSADM_CREATE_INIT_V0(tape_cbt); 44 45 #define TAPE_LINK_RE "^rmt/[0-9]+[cbhlmnu]*" 46 47 static devfsadm_remove_t tape_remove_cbt[] = { 48 { "tape", TAPE_LINK_RE, RM_PRE, ILEVEL_0, devfsadm_rm_all 49 } 50 }; 51 52 DEVFSADM_REMOVE_INIT_V0(tape_remove_cbt); 53 54 55 /* 56 * This function is called for every tape minor node. 57 * Calls enumerate to assign a logical tape id, and then 58 * devfsadm_mklink to make the link. 59 */ 60 static int 61 tape_process(di_minor_t minor, di_node_t node) 62 { 63 char l_path[PATH_MAX + 1]; 64 char *buf; 65 char *mn; 66 char *devfspath; 67 devfsadm_enumerate_t rules[1] = {"rmt/([0-9]+)", 1, MATCH_ADDR}; 68 69 mn = di_minor_name(minor); 70 71 72 if ((mn != NULL) && (*mn >= '0') && (*mn <= '9')) { 73 /* 74 * first character cannot be a digit as it would combine 75 * with the tape instance number to make an ambiguous quantity. 76 */ 77 return (DEVFSADM_CONTINUE); 78 } 79 80 devfspath = di_devfs_path(node); 81 82 (void) strcpy(l_path, devfspath); 83 (void) strcat(l_path, ":"); 84 (void) strcat(l_path, mn); 85 86 di_devfs_path_free(devfspath); 87 88 /* 89 * devfsadm_enumerate finds the logical tape id from the physical path, 90 * omitting minor name field. The logical tape id is returned in buf. 91 */ 92 if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) { 93 return (DEVFSADM_CONTINUE); 94 } 95 96 (void) strcpy(l_path, "rmt/"); 97 (void) strcat(l_path, buf); 98 (void) strcat(l_path, mn); 99 free(buf); 100 101 (void) devfsadm_mklink(l_path, node, minor, 0); 102 103 return (DEVFSADM_CONTINUE); 104 } 105