1*eda14cbcSMatt Macy /* 2*eda14cbcSMatt Macy * CDDL HEADER START 3*eda14cbcSMatt Macy * 4*eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5*eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6*eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7*eda14cbcSMatt Macy * 8*eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*eda14cbcSMatt Macy * or http://www.opensolaris.org/os/licensing. 10*eda14cbcSMatt Macy * See the License for the specific language governing permissions 11*eda14cbcSMatt Macy * and limitations under the License. 12*eda14cbcSMatt Macy * 13*eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14*eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16*eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17*eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18*eda14cbcSMatt Macy * 19*eda14cbcSMatt Macy * CDDL HEADER END 20*eda14cbcSMatt Macy */ 21*eda14cbcSMatt Macy /* 22*eda14cbcSMatt Macy * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23*eda14cbcSMatt Macy * Use is subject to license terms. 24*eda14cbcSMatt Macy */ 25*eda14cbcSMatt Macy 26*eda14cbcSMatt Macy /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27*eda14cbcSMatt Macy /* All Rights Reserved */ 28*eda14cbcSMatt Macy 29*eda14cbcSMatt Macy /* 30*eda14cbcSMatt Macy * University Copyright- Copyright (c) 1982, 1986, 1988 31*eda14cbcSMatt Macy * The Regents of the University of California 32*eda14cbcSMatt Macy * All Rights Reserved 33*eda14cbcSMatt Macy * 34*eda14cbcSMatt Macy * University Acknowledgment- Portions of this document are derived from 35*eda14cbcSMatt Macy * software developed by the University of California, Berkeley, and its 36*eda14cbcSMatt Macy * contributors. 37*eda14cbcSMatt Macy */ 38*eda14cbcSMatt Macy 39*eda14cbcSMatt Macy 40*eda14cbcSMatt Macy #include <sys/types.h> 41*eda14cbcSMatt Macy #include <sys/pathname.h> 42*eda14cbcSMatt Macy #include <sys/kmem.h> 43*eda14cbcSMatt Macy #include <sys/sysmacros.h> 44*eda14cbcSMatt Macy 45*eda14cbcSMatt Macy /* 46*eda14cbcSMatt Macy * Pathname utilities. 47*eda14cbcSMatt Macy * 48*eda14cbcSMatt Macy * In translating file names we copy each argument file 49*eda14cbcSMatt Macy * name into a pathname structure where we operate on it. 50*eda14cbcSMatt Macy * Each pathname structure can hold "pn_bufsize" characters 51*eda14cbcSMatt Macy * including a terminating null, and operations here support 52*eda14cbcSMatt Macy * allocating and freeing pathname structures, fetching 53*eda14cbcSMatt Macy * strings from user space, getting the next character from 54*eda14cbcSMatt Macy * a pathname, combining two pathnames (used in symbolic 55*eda14cbcSMatt Macy * link processing), and peeling off the first component 56*eda14cbcSMatt Macy * of a pathname. 57*eda14cbcSMatt Macy */ 58*eda14cbcSMatt Macy 59*eda14cbcSMatt Macy /* 60*eda14cbcSMatt Macy * Allocate contents of pathname structure. Structure is typically 61*eda14cbcSMatt Macy * an automatic variable in calling routine for convenience. 62*eda14cbcSMatt Macy * 63*eda14cbcSMatt Macy * May sleep in the call to kmem_alloc() and so must not be called 64*eda14cbcSMatt Macy * from interrupt level. 65*eda14cbcSMatt Macy */ 66*eda14cbcSMatt Macy void 67*eda14cbcSMatt Macy pn_alloc(struct pathname *pnp) 68*eda14cbcSMatt Macy { 69*eda14cbcSMatt Macy pn_alloc_sz(pnp, MAXPATHLEN); 70*eda14cbcSMatt Macy } 71*eda14cbcSMatt Macy void 72*eda14cbcSMatt Macy pn_alloc_sz(struct pathname *pnp, size_t sz) 73*eda14cbcSMatt Macy { 74*eda14cbcSMatt Macy pnp->pn_buf = kmem_alloc(sz, KM_SLEEP); 75*eda14cbcSMatt Macy pnp->pn_bufsize = sz; 76*eda14cbcSMatt Macy #if 0 /* unused in ZoL */ 77*eda14cbcSMatt Macy pnp->pn_path = pnp->pn_buf; 78*eda14cbcSMatt Macy pnp->pn_pathlen = 0; 79*eda14cbcSMatt Macy #endif 80*eda14cbcSMatt Macy } 81*eda14cbcSMatt Macy 82*eda14cbcSMatt Macy /* 83*eda14cbcSMatt Macy * Free pathname resources. 84*eda14cbcSMatt Macy */ 85*eda14cbcSMatt Macy void 86*eda14cbcSMatt Macy pn_free(struct pathname *pnp) 87*eda14cbcSMatt Macy { 88*eda14cbcSMatt Macy /* pn_bufsize is usually MAXPATHLEN, but may not be */ 89*eda14cbcSMatt Macy kmem_free(pnp->pn_buf, pnp->pn_bufsize); 90*eda14cbcSMatt Macy pnp->pn_buf = NULL; 91*eda14cbcSMatt Macy pnp->pn_bufsize = 0; 92*eda14cbcSMatt Macy #if 0 /* unused in ZoL */ 93*eda14cbcSMatt Macy pnp->pn_path = NULL; 94*eda14cbcSMatt Macy pnp->pn_pathlen = 0; 95*eda14cbcSMatt Macy #endif 96*eda14cbcSMatt Macy } 97