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*2846Svikram * Common Development and Distribution License (the "License").
6*2846Svikram * 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*2846Svikram * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*2846Svikram * 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 <regex.h>
290Sstevel@tonic-gate #include <devfsadm.h>
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <strings.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <limits.h>
340Sstevel@tonic-gate #include <sys/mkdev.h>
350Sstevel@tonic-gate #include <sys/lofi.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate
380Sstevel@tonic-gate static int lofi(di_minor_t minor, di_node_t node);
39*2846Svikram static int lofi_rm_all(char *link);
400Sstevel@tonic-gate
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate * devfs create callback register
430Sstevel@tonic-gate */
440Sstevel@tonic-gate static devfsadm_create_t lofi_create_cbt[] = {
450Sstevel@tonic-gate { "pseudo", "ddi_pseudo", LOFI_DRIVER_NAME,
460Sstevel@tonic-gate TYPE_EXACT | DRV_EXACT, ILEVEL_0, lofi,
470Sstevel@tonic-gate },
480Sstevel@tonic-gate };
490Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(lofi_create_cbt);
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * devfs cleanup register
530Sstevel@tonic-gate */
54*2846Svikram static devfsadm_remove_V1_t lofi_remove_cbt[] = {
550Sstevel@tonic-gate {"pseudo", "^r?lofi/[0-9]+$", RM_ALWAYS | RM_PRE | RM_HOT,
56*2846Svikram ILEVEL_0, lofi_rm_all},
570Sstevel@tonic-gate };
58*2846Svikram DEVFSADM_REMOVE_INIT_V1(lofi_remove_cbt);
59*2846Svikram
60*2846Svikram /*
61*2846Svikram * Wrapper around devfsadm_rm_all() that allows termination of remove
62*2846Svikram * process
63*2846Svikram */
64*2846Svikram static int
lofi_rm_all(char * link)65*2846Svikram lofi_rm_all(char *link)
66*2846Svikram {
67*2846Svikram devfsadm_rm_all(link);
68*2846Svikram return (DEVFSADM_TERMINATE);
69*2846Svikram }
700Sstevel@tonic-gate
710Sstevel@tonic-gate
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * For the master device:
740Sstevel@tonic-gate * /dev/lofictl -> /devices/pseudo/lofi@0:ctl
750Sstevel@tonic-gate * For each other device
760Sstevel@tonic-gate * /dev/lofi/1 -> /devices/pseudo/lofi@0:1
770Sstevel@tonic-gate * /dev/rlofi/1 -> /devices/pseudo/lofi@0:1,raw
780Sstevel@tonic-gate */
790Sstevel@tonic-gate static int
lofi(di_minor_t minor,di_node_t node)800Sstevel@tonic-gate lofi(di_minor_t minor, di_node_t node)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate dev_t dev;
830Sstevel@tonic-gate char mn[MAXNAMELEN + 1];
840Sstevel@tonic-gate char blkname[MAXNAMELEN + 1];
850Sstevel@tonic-gate char rawname[MAXNAMELEN + 1];
860Sstevel@tonic-gate char path[PATH_MAX + 1];
870Sstevel@tonic-gate
880Sstevel@tonic-gate (void) strcpy(mn, di_minor_name(minor));
890Sstevel@tonic-gate
900Sstevel@tonic-gate if (strcmp(mn, "ctl") == 0) {
910Sstevel@tonic-gate (void) devfsadm_mklink(LOFI_CTL_NAME, node, minor, 0);
920Sstevel@tonic-gate } else {
930Sstevel@tonic-gate dev = di_minor_devt(minor);
940Sstevel@tonic-gate (void) snprintf(blkname, sizeof (blkname), "%d",
950Sstevel@tonic-gate (int)minor(dev));
960Sstevel@tonic-gate (void) snprintf(rawname, sizeof (rawname), "%d,raw",
970Sstevel@tonic-gate (int)minor(dev));
980Sstevel@tonic-gate
990Sstevel@tonic-gate if (strcmp(mn, blkname) == 0) {
1000Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s",
1010Sstevel@tonic-gate LOFI_BLOCK_NAME, blkname);
1020Sstevel@tonic-gate } else if (strcmp(mn, rawname) == 0) {
1030Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s",
1040Sstevel@tonic-gate LOFI_CHAR_NAME, blkname);
1050Sstevel@tonic-gate } else {
1060Sstevel@tonic-gate return (DEVFSADM_CONTINUE);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate (void) devfsadm_mklink(path, node, minor, 0);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate return (DEVFSADM_CONTINUE);
1120Sstevel@tonic-gate }
113