17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*aa646b9dSvikram * Common Development and Distribution License (the "License"). 6*aa646b9dSvikram * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*aa646b9dSvikram * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*aa646b9dSvikram * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <regex.h> 297c478bd9Sstevel@tonic-gate #include <devfsadm.h> 307c478bd9Sstevel@tonic-gate #include <stdio.h> 317c478bd9Sstevel@tonic-gate #include <strings.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate #include <limits.h> 347c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 357c478bd9Sstevel@tonic-gate #include <sys/lofi.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate static int lofi(di_minor_t minor, di_node_t node); 39*aa646b9dSvikram static int lofi_rm_all(char *link); 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * devfs create callback register 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate static devfsadm_create_t lofi_create_cbt[] = { 457c478bd9Sstevel@tonic-gate { "pseudo", "ddi_pseudo", LOFI_DRIVER_NAME, 467c478bd9Sstevel@tonic-gate TYPE_EXACT | DRV_EXACT, ILEVEL_0, lofi, 477c478bd9Sstevel@tonic-gate }, 487c478bd9Sstevel@tonic-gate }; 497c478bd9Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(lofi_create_cbt); 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * devfs cleanup register 537c478bd9Sstevel@tonic-gate */ 54*aa646b9dSvikram static devfsadm_remove_V1_t lofi_remove_cbt[] = { 557c478bd9Sstevel@tonic-gate {"pseudo", "^r?lofi/[0-9]+$", RM_ALWAYS | RM_PRE | RM_HOT, 56*aa646b9dSvikram ILEVEL_0, lofi_rm_all}, 577c478bd9Sstevel@tonic-gate }; 58*aa646b9dSvikram DEVFSADM_REMOVE_INIT_V1(lofi_remove_cbt); 59*aa646b9dSvikram 60*aa646b9dSvikram /* 61*aa646b9dSvikram * Wrapper around devfsadm_rm_all() that allows termination of remove 62*aa646b9dSvikram * process 63*aa646b9dSvikram */ 64*aa646b9dSvikram static int 65*aa646b9dSvikram lofi_rm_all(char *link) 66*aa646b9dSvikram { 67*aa646b9dSvikram devfsadm_rm_all(link); 68*aa646b9dSvikram return (DEVFSADM_TERMINATE); 69*aa646b9dSvikram } 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * For the master device: 747c478bd9Sstevel@tonic-gate * /dev/lofictl -> /devices/pseudo/lofi@0:ctl 757c478bd9Sstevel@tonic-gate * For each other device 767c478bd9Sstevel@tonic-gate * /dev/lofi/1 -> /devices/pseudo/lofi@0:1 777c478bd9Sstevel@tonic-gate * /dev/rlofi/1 -> /devices/pseudo/lofi@0:1,raw 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate static int 807c478bd9Sstevel@tonic-gate lofi(di_minor_t minor, di_node_t node) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate dev_t dev; 837c478bd9Sstevel@tonic-gate char mn[MAXNAMELEN + 1]; 847c478bd9Sstevel@tonic-gate char blkname[MAXNAMELEN + 1]; 857c478bd9Sstevel@tonic-gate char rawname[MAXNAMELEN + 1]; 867c478bd9Sstevel@tonic-gate char path[PATH_MAX + 1]; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate (void) strcpy(mn, di_minor_name(minor)); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate if (strcmp(mn, "ctl") == 0) { 917c478bd9Sstevel@tonic-gate (void) devfsadm_mklink(LOFI_CTL_NAME, node, minor, 0); 927c478bd9Sstevel@tonic-gate } else { 937c478bd9Sstevel@tonic-gate dev = di_minor_devt(minor); 947c478bd9Sstevel@tonic-gate (void) snprintf(blkname, sizeof (blkname), "%d", 957c478bd9Sstevel@tonic-gate (int)minor(dev)); 967c478bd9Sstevel@tonic-gate (void) snprintf(rawname, sizeof (rawname), "%d,raw", 977c478bd9Sstevel@tonic-gate (int)minor(dev)); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate if (strcmp(mn, blkname) == 0) { 1007c478bd9Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s", 1017c478bd9Sstevel@tonic-gate LOFI_BLOCK_NAME, blkname); 1027c478bd9Sstevel@tonic-gate } else if (strcmp(mn, rawname) == 0) { 1037c478bd9Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s", 1047c478bd9Sstevel@tonic-gate LOFI_CHAR_NAME, blkname); 1057c478bd9Sstevel@tonic-gate } else { 1067c478bd9Sstevel@tonic-gate return (DEVFSADM_CONTINUE); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate (void) devfsadm_mklink(path, node, minor, 0); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate return (DEVFSADM_CONTINUE); 1127c478bd9Sstevel@tonic-gate } 113