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 5aa646b9dSvikram * Common Development and Distribution License (the "License"). 6aa646b9dSvikram * 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*a29e56d9SToomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com> 23aa646b9dSvikram * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24aa646b9dSvikram * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <regex.h> 287c478bd9Sstevel@tonic-gate #include <devfsadm.h> 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <strings.h> 317c478bd9Sstevel@tonic-gate #include <stdlib.h> 327c478bd9Sstevel@tonic-gate #include <limits.h> 337c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 347c478bd9Sstevel@tonic-gate #include <sys/lofi.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate static int lofi(di_minor_t minor, di_node_t node); 38aa646b9dSvikram static int lofi_rm_all(char *link); 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * devfs create callback register 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate static devfsadm_create_t lofi_create_cbt[] = { 447c478bd9Sstevel@tonic-gate { "pseudo", "ddi_pseudo", LOFI_DRIVER_NAME, 457c478bd9Sstevel@tonic-gate TYPE_EXACT | DRV_EXACT, ILEVEL_0, lofi, 467c478bd9Sstevel@tonic-gate }, 477c478bd9Sstevel@tonic-gate }; 487c478bd9Sstevel@tonic-gate DEVFSADM_CREATE_INIT_V0(lofi_create_cbt); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * devfs cleanup register 527c478bd9Sstevel@tonic-gate */ 53aa646b9dSvikram static devfsadm_remove_V1_t lofi_remove_cbt[] = { 547c478bd9Sstevel@tonic-gate {"pseudo", "^r?lofi/[0-9]+$", RM_ALWAYS | RM_PRE | RM_HOT, 55aa646b9dSvikram ILEVEL_0, lofi_rm_all}, 567c478bd9Sstevel@tonic-gate }; 57aa646b9dSvikram DEVFSADM_REMOVE_INIT_V1(lofi_remove_cbt); 58aa646b9dSvikram 59aa646b9dSvikram /* 60aa646b9dSvikram * Wrapper around devfsadm_rm_all() that allows termination of remove 61aa646b9dSvikram * process 62aa646b9dSvikram */ 63aa646b9dSvikram static int 64aa646b9dSvikram lofi_rm_all(char *link) 65aa646b9dSvikram { 66aa646b9dSvikram devfsadm_rm_all(link); 67aa646b9dSvikram return (DEVFSADM_TERMINATE); 68aa646b9dSvikram } 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * For the master device: 737c478bd9Sstevel@tonic-gate * /dev/lofictl -> /devices/pseudo/lofi@0:ctl 747c478bd9Sstevel@tonic-gate * For each other device 75*a29e56d9SToomas Soome * /dev/lofi/1 -> /devices/pseudo/lofi@1:disk 76*a29e56d9SToomas Soome * /dev/rlofi/1 -> /devices/pseudo/lofi@1:disk,raw 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate static int 797c478bd9Sstevel@tonic-gate lofi(di_minor_t minor, di_node_t node) 807c478bd9Sstevel@tonic-gate { 81*a29e56d9SToomas Soome int instance; 827c478bd9Sstevel@tonic-gate char mn[MAXNAMELEN + 1]; 837c478bd9Sstevel@tonic-gate char path[PATH_MAX + 1]; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate (void) strcpy(mn, di_minor_name(minor)); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate if (strcmp(mn, "ctl") == 0) { 887c478bd9Sstevel@tonic-gate (void) devfsadm_mklink(LOFI_CTL_NAME, node, minor, 0); 897c478bd9Sstevel@tonic-gate } else { 90*a29e56d9SToomas Soome instance = di_instance(node); 917c478bd9Sstevel@tonic-gate 92*a29e56d9SToomas Soome if (strcmp(mn, LOFI_BLOCK_NODE) == 0) { 93*a29e56d9SToomas Soome (void) snprintf(path, sizeof (path), "%s/%d", 94*a29e56d9SToomas Soome LOFI_BLOCK_NAME, instance); 95*a29e56d9SToomas Soome } else if (strcmp(mn, LOFI_CHAR_NODE) == 0) { 96*a29e56d9SToomas Soome (void) snprintf(path, sizeof (path), "%s/%d", 97*a29e56d9SToomas Soome LOFI_CHAR_NAME, instance); 987c478bd9Sstevel@tonic-gate } else { 997c478bd9Sstevel@tonic-gate return (DEVFSADM_CONTINUE); 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate (void) devfsadm_mklink(path, node, minor, 0); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate return (DEVFSADM_CONTINUE); 1057c478bd9Sstevel@tonic-gate } 106