5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
6e1ae2a33c618c4c2b14aec7d2f21743ddea5837Gary Pennington * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * System includes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * local includes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define isdot(x) ((x[0] == '.') && (!x[1] || (x[1] == '/')))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define isdotdot(x) ((x[0] == '.') && (x[1] == '.') && \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * global external (public) functions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * *****************************************************************************
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: z_make_zone_root
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Given its zonepath, generate a string representing the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mountpoint of where the root path for a nonglobal zone is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mounted. The zone is mounted using 'zoneadm', which mounts
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the zone's filesystems wrt <zonepath>/lu/a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: zone_path - non-NULL pointer to string representing zonepath
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns: char * - pointer to string representing zonepath of zone
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * NULL - if zone_path is NULL.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Notes: The string returned is in static storage and should not be
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * free()ed by the caller.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(zone_root_buf, MAXPATHLEN, "%s%slu/a", zone_path,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland zone_path[strlen(zone_path) - 1] == '/') ? "" : "/");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remove references such as "./" and "../" and "//" */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* keep a ptr to the beginning of the src string */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remove any trailing slashes, unless the whole string is just "/".
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the whole string is "/" (i.e. if the last '/' cahr in dst
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * in the beginning of the original string), just terminate it
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and return "/".
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((*(dst - 1) == '/') && ((dst - 1) != src_start))