4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
40 #include <sys/types.h>
51 #include "instzones_lib.h"
52 #include "zones_strings.h"
54 #define isdot(x) ((x[0] == '.') && (!x[1] || (x[1] == '/')))
55 #define isdotdot(x) ((x[0] == '.') && (x[1] == '.') && \
56 (!x[2] || (x[2] == '/')))
59 * *****************************************************************************
60 * global external (public) functions
61 * *****************************************************************************
65 * Name: z_make_zone_root
66 * Description: Given its zonepath, generate a string representing the
67 * mountpoint of where the root path for a nonglobal zone is
68 * mounted. The zone is mounted using 'zoneadm', which mounts
69 * the zone's filesystems wrt <zonepath>/lu/a
70 * Arguments: zone_path - non-NULL pointer to string representing zonepath
71 * Returns: char * - pointer to string representing zonepath of zone
72 * NULL - if zone_path is NULL.
73 * Notes: The string returned is in static storage and should not be
74 * free()ed by the caller.
77 z_make_zone_root(char *zone_path
)
79 static char zone_root_buf
[MAXPATHLEN
];
81 if (zone_path
== NULL
)
84 (void) snprintf(zone_root_buf
, MAXPATHLEN
, "%s%slu/a", zone_path
,
85 (zone_path
[0] != '\0' &&
86 zone_path
[strlen(zone_path
) - 1] == '/') ? "" : "/");
88 return (zone_root_buf
);
92 z_path_canonize(char *a_file
)
98 /* remove references such as "./" and "../" and "//" */
99 for (pt
= a_file
; *pt
; /* void */) {
101 (void) strcpy(pt
, pt
[1] ? pt
+2 : pt
+1);
102 } else if (isdotdot(pt
)) {
111 } while (isdotdot(last
));
112 --pt
; /* point to previous '/' */
117 while ((*--pt
!= '/') && (pt
> a_file
))
123 (void) strcpy(pt
, last
);
125 while (*pt
&& (*pt
!= '/')) {
129 while (pt
[1] == '/') {
130 (void) strcpy(pt
, pt
+1);
137 if ((--pt
> a_file
) && (*pt
== '/')) {
143 z_canoninplace(char *src
)
148 /* keep a ptr to the beginning of the src string */
162 * remove any trailing slashes, unless the whole string is just "/".
163 * If the whole string is "/" (i.e. if the last '/' cahr in dst
164 * in the beginning of the original string), just terminate it
167 if ((*(dst
- 1) == '/') && ((dst
- 1) != src_start
))