7857 zfs/zpool commands print scary errors after 7741
[unleashed.git] / usr / src / cmd / devfsadm / tape_link.c
blobcd532d22e9c7e2c29339e2d62db84a1913715f7c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <devfsadm.h>
29 #include <strings.h>
30 #include <stdlib.h>
31 #include <limits.h>
32 #include <bsm/devalloc.h>
34 extern int system_labeled;
36 static int tape_process(di_minor_t minor, di_node_t node);
38 static devfsadm_create_t tape_cbt[] = {
39 { "tape", "ddi_byte:tape", NULL,
40 TYPE_EXACT, ILEVEL_0, tape_process
44 DEVFSADM_CREATE_INIT_V0(tape_cbt);
46 #define TAPE_LINK_RE "^rmt/[0-9]+[cbhlmnu]*"
48 static devfsadm_remove_t tape_remove_cbt[] = {
49 { "tape", TAPE_LINK_RE, RM_PRE, ILEVEL_0, devfsadm_rm_all
53 DEVFSADM_REMOVE_INIT_V0(tape_remove_cbt);
57 * This function is called for every tape minor node.
58 * Calls enumerate to assign a logical tape id, and then
59 * devfsadm_mklink to make the link.
61 static int
62 tape_process(di_minor_t minor, di_node_t node)
64 int flags = 0;
65 char l_path[PATH_MAX + 1];
66 char *buf;
67 char *mn;
68 char *devfspath;
69 devfsadm_enumerate_t rules[1] = {"rmt/([0-9]+)", 1, MATCH_ADDR};
71 mn = di_minor_name(minor);
74 if ((mn != NULL) && (*mn >= '0') && (*mn <= '9')) {
76 * first character cannot be a digit as it would combine
77 * with the tape instance number to make an ambiguous quantity.
79 return (DEVFSADM_CONTINUE);
82 devfspath = di_devfs_path(node);
84 (void) strcpy(l_path, devfspath);
85 (void) strcat(l_path, ":");
86 (void) strcat(l_path, mn);
88 di_devfs_path_free(devfspath);
91 * devfsadm_enumerate finds the logical tape id from the physical path,
92 * omitting minor name field. The logical tape id is returned in buf.
94 if (devfsadm_enumerate_int(l_path, 0, &buf, rules, 1)) {
95 return (DEVFSADM_CONTINUE);
98 (void) strcpy(l_path, "rmt/");
99 (void) strcat(l_path, buf);
100 (void) strcat(l_path, mn);
101 free(buf);
103 if (system_labeled)
104 flags = DA_ADD|DA_TAPE;
106 (void) devfsadm_mklink(l_path, node, minor, flags);
108 return (DEVFSADM_CONTINUE);