xref: /onnv-gate/usr/src/cmd/devfsadm/tape_link.c (revision 1676:37f4a3e2bd99)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1676Sjpk  * Common Development and Distribution License (the "License").
6*1676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <devfsadm.h>
290Sstevel@tonic-gate #include <strings.h>
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <limits.h>
32*1676Sjpk #include <bsm/devalloc.h>
330Sstevel@tonic-gate 
34*1676Sjpk extern int system_labeled;
350Sstevel@tonic-gate 
360Sstevel@tonic-gate static int tape_process(di_minor_t minor, di_node_t node);
370Sstevel@tonic-gate 
380Sstevel@tonic-gate static devfsadm_create_t tape_cbt[] = {
390Sstevel@tonic-gate 	{ "tape", "ddi_byte:tape", NULL,
400Sstevel@tonic-gate 	TYPE_EXACT, ILEVEL_0,	tape_process
410Sstevel@tonic-gate 	},
420Sstevel@tonic-gate };
430Sstevel@tonic-gate 
440Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(tape_cbt);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #define	TAPE_LINK_RE "^rmt/[0-9]+[cbhlmnu]*"
470Sstevel@tonic-gate 
480Sstevel@tonic-gate static devfsadm_remove_t tape_remove_cbt[] = {
490Sstevel@tonic-gate 	{ "tape", TAPE_LINK_RE, RM_PRE, ILEVEL_0, devfsadm_rm_all
500Sstevel@tonic-gate 	}
510Sstevel@tonic-gate };
520Sstevel@tonic-gate 
530Sstevel@tonic-gate DEVFSADM_REMOVE_INIT_V0(tape_remove_cbt);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * This function is called for every tape minor node.
580Sstevel@tonic-gate  * Calls enumerate to assign a logical tape id, and then
590Sstevel@tonic-gate  * devfsadm_mklink to make the link.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate static int
tape_process(di_minor_t minor,di_node_t node)620Sstevel@tonic-gate tape_process(di_minor_t minor, di_node_t node)
630Sstevel@tonic-gate {
64*1676Sjpk 	int flags = 0;
650Sstevel@tonic-gate 	char l_path[PATH_MAX + 1];
660Sstevel@tonic-gate 	char *buf;
670Sstevel@tonic-gate 	char *mn;
680Sstevel@tonic-gate 	char *devfspath;
690Sstevel@tonic-gate 	devfsadm_enumerate_t rules[1] = {"rmt/([0-9]+)", 1, MATCH_ADDR};
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	mn = di_minor_name(minor);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	if ((mn != NULL) && (*mn >= '0') && (*mn <= '9')) {
750Sstevel@tonic-gate 		/*
760Sstevel@tonic-gate 		 * first character cannot be a digit as it would combine
770Sstevel@tonic-gate 		 * with the tape instance number to make an ambiguous quantity.
780Sstevel@tonic-gate 		 */
790Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
800Sstevel@tonic-gate 	}
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	devfspath = di_devfs_path(node);
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	(void) strcpy(l_path, devfspath);
850Sstevel@tonic-gate 	(void) strcat(l_path, ":");
860Sstevel@tonic-gate 	(void) strcat(l_path, mn);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	di_devfs_path_free(devfspath);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	/*
910Sstevel@tonic-gate 	 *  devfsadm_enumerate finds the logical tape id from the physical path,
920Sstevel@tonic-gate 	 *  omitting minor name field. The logical tape id is returned in buf.
930Sstevel@tonic-gate 	 */
940Sstevel@tonic-gate 	if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
950Sstevel@tonic-gate 		return (DEVFSADM_CONTINUE);
960Sstevel@tonic-gate 	}
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	(void) strcpy(l_path, "rmt/");
990Sstevel@tonic-gate 	(void) strcat(l_path, buf);
1000Sstevel@tonic-gate 	(void) strcat(l_path, mn);
1010Sstevel@tonic-gate 	free(buf);
1020Sstevel@tonic-gate 
103*1676Sjpk 	if (system_labeled)
104*1676Sjpk 		flags = DA_ADD|DA_TAPE;
105*1676Sjpk 
106*1676Sjpk 	(void) devfsadm_mklink(l_path, node, minor, flags);
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	return (DEVFSADM_CONTINUE);
1090Sstevel@tonic-gate }
110