15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland * CDDL HEADER START
35c51f124SMoriah Waterland *
45c51f124SMoriah Waterland * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland *
85c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland * See the License for the specific language governing permissions
115c51f124SMoriah Waterland * and limitations under the License.
125c51f124SMoriah Waterland *
135c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland *
195c51f124SMoriah Waterland * CDDL HEADER END
205c51f124SMoriah Waterland */
215c51f124SMoriah Waterland
225c51f124SMoriah Waterland /*
23*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
245c51f124SMoriah Waterland * Use is subject to license terms.
255c51f124SMoriah Waterland */
265c51f124SMoriah Waterland
275c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
285c51f124SMoriah Waterland /* All Rights Reserved */
295c51f124SMoriah Waterland
305c51f124SMoriah Waterland
315c51f124SMoriah Waterland
325c51f124SMoriah Waterland #include <limits.h>
335c51f124SMoriah Waterland #include <string.h>
345c51f124SMoriah Waterland #include <stdio.h>
355c51f124SMoriah Waterland #include <stdlib.h>
365c51f124SMoriah Waterland #include <unistd.h>
375c51f124SMoriah Waterland #include <fcntl.h>
38*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India #include <libinst.h>
395c51f124SMoriah Waterland
405c51f124SMoriah Waterland char *
srcpath(char * dir,char * src,int part,int nparts)415c51f124SMoriah Waterland srcpath(char *dir, char *src, int part, int nparts)
425c51f124SMoriah Waterland {
435c51f124SMoriah Waterland static char tmppath[PATH_MAX];
445c51f124SMoriah Waterland char *copy;
455c51f124SMoriah Waterland size_t copyLen;
465c51f124SMoriah Waterland
475c51f124SMoriah Waterland copy = tmppath;
485c51f124SMoriah Waterland
495c51f124SMoriah Waterland if (dir != NULL) {
505c51f124SMoriah Waterland size_t theLen = strlen(dir);
515c51f124SMoriah Waterland
525c51f124SMoriah Waterland (void) strcpy(copy, dir);
535c51f124SMoriah Waterland copy += theLen;
545c51f124SMoriah Waterland copyLen = (sizeof (tmppath) - theLen);
555c51f124SMoriah Waterland } else {
565c51f124SMoriah Waterland copy[0] = '\0';
575c51f124SMoriah Waterland copyLen = sizeof (tmppath);
585c51f124SMoriah Waterland }
595c51f124SMoriah Waterland
605c51f124SMoriah Waterland if (nparts > 1) {
615c51f124SMoriah Waterland (void) snprintf(copy, copyLen,
625c51f124SMoriah Waterland ((src[0] == '/') ? "/root.%d%s" : "/reloc.%d/%s"),
635c51f124SMoriah Waterland part, src);
645c51f124SMoriah Waterland } else {
655c51f124SMoriah Waterland (void) snprintf(copy, copyLen,
665c51f124SMoriah Waterland ((src[0] == '/') ? "/root%s" : "/reloc/%s"), src);
675c51f124SMoriah Waterland }
685c51f124SMoriah Waterland
695c51f124SMoriah Waterland return (tmppath);
705c51f124SMoriah Waterland }
71*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
72*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
73*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * During a partial install(Ex. Migration of a zone), if the'contchg' field of
74*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * mstat structure is set i.e. there is a mismatch between the entry in pkgmap
75*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * and package database and the file is of type 'f', the source path on the
76*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Global zone is to be generated(mostly for being copied again to the NGZ).
77*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Given the local source path(relocatable), this function builds the absolute
78*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * source path.
79*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
80*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: This function is a private interface. Should only be called during a
81*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * a partial install and for files of type 'f'.
82*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Source translation is done differently from 'e' and 'v' types.
83*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
84*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char *
trans_srcp_pi(char * local_path)85*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India trans_srcp_pi(char *local_path)
86*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India {
87*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India static char pi_srcPath[PATH_MAX];
88*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char *tmp_basedir, *tmp_inst_root;
89*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India int inst_root_len, basedir_len;
90*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
91*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /* Get the basedir and it's length */
92*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India tmp_basedir = get_basedir();
93*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India basedir_len = strlen(tmp_basedir);
94*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
95*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /* Get the install root and it's length */
96*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India tmp_inst_root = get_inst_root();
97*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India inst_root_len = strlen(tmp_inst_root);
98*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
99*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
100*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Get past install root if something exists
101*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Example:
102*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * INSTROOT = /a (on scratch zone)
103*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * BASEDIR = /a/usr (on scratch zone)
104*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * local_path = "~bin/ls"
105*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
106*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Absolute path for source on GZ:
107*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * a) If BASEDIR == INSTROOT
108*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /<local_path string starting from index 1>
109*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * In the above example, absolute path is
110*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /bin/ls
111*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
112*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * b) If BASEDIR > INSTROOT
113*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /usr/<local_path string starting from index 1>
114*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * In the above example, absolute path is
115*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /usr/bin/ls
116*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
117*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if ((strncmp(tmp_inst_root, tmp_basedir, inst_root_len) == 0) &&
118*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (inst_root_len == basedir_len)) {
119*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
120*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Prefix root to the local path. NOTE that local_path[0]
121*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * has a '~' character. Move past it.
122*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
123*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: local_path array size is expected to be >= 2.
124*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
125*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(pi_srcPath, PATH_MAX, "/%s",
126*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India &(local_path[1]));
127*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India } else {
128*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
129*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: local_path array size is expected to be >= 2.
130*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
131*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(pi_srcPath, PATH_MAX, "%s/%s",
132*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India &(tmp_basedir[inst_root_len]), &(local_path[1]));
133*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
134*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
135*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India return (pi_srcPath);
136*d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
137