147133Sobrien/*- 247133Sobrien * Copyright (C) 2006 John Birrell <jb@freebsd.org>. 347133Sobrien * All rights reserved. 447133Sobrien * 547133Sobrien * Redistribution and use in source and binary forms, with or without 647133Sobrien * modification, are permitted provided that the following conditions 747133Sobrien * are met: 847133Sobrien * 1. Redistributions of source code must retain the above copyright 947133Sobrien * notice(s), this list of conditions and the following disclaimer as 1047133Sobrien * the first lines of this file unmodified other than the possible 1147133Sobrien * addition of one or more copyright notices. 1247133Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1347133Sobrien * notice(s), this list of conditions and the following disclaimer in the 1447133Sobrien * documentation and/or other materials provided with the distribution. 1547133Sobrien * 1647133Sobrien * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 1747133Sobrien * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1847133Sobrien * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1947133Sobrien * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 2047133Sobrien * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2147133Sobrien * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2247133Sobrien * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 2347133Sobrien * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2447133Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2547133Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 2651594Speter * DAMAGE. 2750477Speter * 2847133Sobrien * $FreeBSD$ 2955723Simp * 3055723Simp */ 3147133Sobrien 3247133Sobrienstatic void 3348114Sobriendtrace_clone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev) 3448114Sobrien{ 3548114Sobrien int u = -1; 3648114Sobrien size_t len; 3748114Sobrien 3848114Sobrien if (*dev != NULL) 3948114Sobrien return; 4048114Sobrien 4148114Sobrien len = strlen(name); 4248114Sobrien 4348114Sobrien if (len != 6 && len != 13) 4448114Sobrien return; 4548114Sobrien 4648114Sobrien if (bcmp(name,"dtrace",6) != 0) 4748114Sobrien return; 4848114Sobrien 4948114Sobrien if (len == 13 && bcmp(name,"dtrace/dtrace",13) != 0) 5048114Sobrien return; 5148114Sobrien 5248114Sobrien /* Clone the device to the new minor number. */ 5348114Sobrien if (clone_create(&dtrace_clones, &dtrace_cdevsw, &u, dev, 0) != 0) 5448114Sobrien /* Create the /dev/dtrace/dtraceNN entry. */ 5548114Sobrien *dev = make_dev_cred(&dtrace_cdevsw, u, cred, 5648114Sobrien UID_ROOT, GID_WHEEL, 0600, "dtrace/dtrace%d", u); 5748114Sobrien if (*dev != NULL) { 5848114Sobrien dev_ref(*dev); 5948114Sobrien (*dev)->si_flags |= SI_CHEAPCLONE; 6048114Sobrien } 6148114Sobrien} 6248114Sobrien