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]
22 * Copyright 2016 Toomas Soome <tsoome@me.com>
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
33 #include <sys/mkdev.h>
37 static int lofi(di_minor_t minor
, di_node_t node
);
38 static int lofi_rm_all(char *link
);
41 * devfs create callback register
43 static devfsadm_create_t lofi_create_cbt
[] = {
44 { "pseudo", "ddi_pseudo", LOFI_DRIVER_NAME
,
45 TYPE_EXACT
| DRV_EXACT
, ILEVEL_0
, lofi
,
48 DEVFSADM_CREATE_INIT_V0(lofi_create_cbt
);
51 * devfs cleanup register
53 static devfsadm_remove_V1_t lofi_remove_cbt
[] = {
54 {"pseudo", "^r?lofi/[0-9]+$", RM_ALWAYS
| RM_PRE
| RM_HOT
,
55 ILEVEL_0
, lofi_rm_all
},
57 DEVFSADM_REMOVE_INIT_V1(lofi_remove_cbt
);
60 * Wrapper around devfsadm_rm_all() that allows termination of remove
64 lofi_rm_all(char *link
)
66 devfsadm_rm_all(link
);
67 return (DEVFSADM_TERMINATE
);
72 * For the master device:
73 * /dev/lofictl -> /devices/pseudo/lofi@0:ctl
74 * For each other device
75 * /dev/lofi/1 -> /devices/pseudo/lofi@1:disk
76 * /dev/rlofi/1 -> /devices/pseudo/lofi@1:disk,raw
79 lofi(di_minor_t minor
, di_node_t node
)
82 char mn
[MAXNAMELEN
+ 1];
83 char path
[PATH_MAX
+ 1];
85 (void) strcpy(mn
, di_minor_name(minor
));
87 if (strcmp(mn
, "ctl") == 0) {
88 (void) devfsadm_mklink(LOFI_CTL_NAME
, node
, minor
, 0);
90 instance
= di_instance(node
);
92 if (strcmp(mn
, LOFI_BLOCK_NODE
) == 0) {
93 (void) snprintf(path
, sizeof (path
), "%s/%d",
94 LOFI_BLOCK_NAME
, instance
);
95 } else if (strcmp(mn
, LOFI_CHAR_NODE
) == 0) {
96 (void) snprintf(path
, sizeof (path
), "%s/%d",
97 LOFI_CHAR_NAME
, instance
);
99 return (DEVFSADM_CONTINUE
);
102 (void) devfsadm_mklink(path
, node
, minor
, 0);
104 return (DEVFSADM_CONTINUE
);