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