19781SMoriah.Waterland@Sun.COM /* 29781SMoriah.Waterland@Sun.COM * CDDL HEADER START 39781SMoriah.Waterland@Sun.COM * 49781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the 59781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License"). 69781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License. 79781SMoriah.Waterland@Sun.COM * 89781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 99781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing. 109781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions 119781SMoriah.Waterland@Sun.COM * and limitations under the License. 129781SMoriah.Waterland@Sun.COM * 139781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 149781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 159781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 169781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 179781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 189781SMoriah.Waterland@Sun.COM * 199781SMoriah.Waterland@Sun.COM * CDDL HEADER END 209781SMoriah.Waterland@Sun.COM */ 219781SMoriah.Waterland@Sun.COM 229781SMoriah.Waterland@Sun.COM /* 23*10619SPhaniram.Krishnamurthy@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 249781SMoriah.Waterland@Sun.COM * Use is subject to license terms. 259781SMoriah.Waterland@Sun.COM */ 269781SMoriah.Waterland@Sun.COM 279781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 289781SMoriah.Waterland@Sun.COM /* All Rights Reserved */ 299781SMoriah.Waterland@Sun.COM 309781SMoriah.Waterland@Sun.COM 319781SMoriah.Waterland@Sun.COM 329781SMoriah.Waterland@Sun.COM #include <limits.h> 339781SMoriah.Waterland@Sun.COM #include <string.h> 349781SMoriah.Waterland@Sun.COM #include <stdio.h> 359781SMoriah.Waterland@Sun.COM #include <stdlib.h> 369781SMoriah.Waterland@Sun.COM #include <unistd.h> 379781SMoriah.Waterland@Sun.COM #include <fcntl.h> 38*10619SPhaniram.Krishnamurthy@Sun.COM #include <libinst.h> 399781SMoriah.Waterland@Sun.COM 409781SMoriah.Waterland@Sun.COM char * 419781SMoriah.Waterland@Sun.COM srcpath(char *dir, char *src, int part, int nparts) 429781SMoriah.Waterland@Sun.COM { 439781SMoriah.Waterland@Sun.COM static char tmppath[PATH_MAX]; 449781SMoriah.Waterland@Sun.COM char *copy; 459781SMoriah.Waterland@Sun.COM size_t copyLen; 469781SMoriah.Waterland@Sun.COM 479781SMoriah.Waterland@Sun.COM copy = tmppath; 489781SMoriah.Waterland@Sun.COM 499781SMoriah.Waterland@Sun.COM if (dir != NULL) { 509781SMoriah.Waterland@Sun.COM size_t theLen = strlen(dir); 519781SMoriah.Waterland@Sun.COM 529781SMoriah.Waterland@Sun.COM (void) strcpy(copy, dir); 539781SMoriah.Waterland@Sun.COM copy += theLen; 549781SMoriah.Waterland@Sun.COM copyLen = (sizeof (tmppath) - theLen); 559781SMoriah.Waterland@Sun.COM } else { 569781SMoriah.Waterland@Sun.COM copy[0] = '\0'; 579781SMoriah.Waterland@Sun.COM copyLen = sizeof (tmppath); 589781SMoriah.Waterland@Sun.COM } 599781SMoriah.Waterland@Sun.COM 609781SMoriah.Waterland@Sun.COM if (nparts > 1) { 619781SMoriah.Waterland@Sun.COM (void) snprintf(copy, copyLen, 629781SMoriah.Waterland@Sun.COM ((src[0] == '/') ? "/root.%d%s" : "/reloc.%d/%s"), 639781SMoriah.Waterland@Sun.COM part, src); 649781SMoriah.Waterland@Sun.COM } else { 659781SMoriah.Waterland@Sun.COM (void) snprintf(copy, copyLen, 669781SMoriah.Waterland@Sun.COM ((src[0] == '/') ? "/root%s" : "/reloc/%s"), src); 679781SMoriah.Waterland@Sun.COM } 689781SMoriah.Waterland@Sun.COM 699781SMoriah.Waterland@Sun.COM return (tmppath); 709781SMoriah.Waterland@Sun.COM } 71*10619SPhaniram.Krishnamurthy@Sun.COM 72*10619SPhaniram.Krishnamurthy@Sun.COM /* 73*10619SPhaniram.Krishnamurthy@Sun.COM * During a partial install(Ex. Migration of a zone), if the'contchg' field of 74*10619SPhaniram.Krishnamurthy@Sun.COM * mstat structure is set i.e. there is a mismatch between the entry in pkgmap 75*10619SPhaniram.Krishnamurthy@Sun.COM * and package database and the file is of type 'f', the source path on the 76*10619SPhaniram.Krishnamurthy@Sun.COM * Global zone is to be generated(mostly for being copied again to the NGZ). 77*10619SPhaniram.Krishnamurthy@Sun.COM * Given the local source path(relocatable), this function builds the absolute 78*10619SPhaniram.Krishnamurthy@Sun.COM * source path. 79*10619SPhaniram.Krishnamurthy@Sun.COM * 80*10619SPhaniram.Krishnamurthy@Sun.COM * NOTE: This function is a private interface. Should only be called during a 81*10619SPhaniram.Krishnamurthy@Sun.COM * a partial install and for files of type 'f'. 82*10619SPhaniram.Krishnamurthy@Sun.COM * Source translation is done differently from 'e' and 'v' types. 83*10619SPhaniram.Krishnamurthy@Sun.COM */ 84*10619SPhaniram.Krishnamurthy@Sun.COM char * 85*10619SPhaniram.Krishnamurthy@Sun.COM trans_srcp_pi(char *local_path) 86*10619SPhaniram.Krishnamurthy@Sun.COM { 87*10619SPhaniram.Krishnamurthy@Sun.COM static char pi_srcPath[PATH_MAX]; 88*10619SPhaniram.Krishnamurthy@Sun.COM char *tmp_basedir, *tmp_inst_root; 89*10619SPhaniram.Krishnamurthy@Sun.COM int inst_root_len, basedir_len; 90*10619SPhaniram.Krishnamurthy@Sun.COM 91*10619SPhaniram.Krishnamurthy@Sun.COM /* Get the basedir and it's length */ 92*10619SPhaniram.Krishnamurthy@Sun.COM tmp_basedir = get_basedir(); 93*10619SPhaniram.Krishnamurthy@Sun.COM basedir_len = strlen(tmp_basedir); 94*10619SPhaniram.Krishnamurthy@Sun.COM 95*10619SPhaniram.Krishnamurthy@Sun.COM /* Get the install root and it's length */ 96*10619SPhaniram.Krishnamurthy@Sun.COM tmp_inst_root = get_inst_root(); 97*10619SPhaniram.Krishnamurthy@Sun.COM inst_root_len = strlen(tmp_inst_root); 98*10619SPhaniram.Krishnamurthy@Sun.COM 99*10619SPhaniram.Krishnamurthy@Sun.COM /* 100*10619SPhaniram.Krishnamurthy@Sun.COM * Get past install root if something exists 101*10619SPhaniram.Krishnamurthy@Sun.COM * Example: 102*10619SPhaniram.Krishnamurthy@Sun.COM * INSTROOT = /a (on scratch zone) 103*10619SPhaniram.Krishnamurthy@Sun.COM * BASEDIR = /a/usr (on scratch zone) 104*10619SPhaniram.Krishnamurthy@Sun.COM * local_path = "~bin/ls" 105*10619SPhaniram.Krishnamurthy@Sun.COM * 106*10619SPhaniram.Krishnamurthy@Sun.COM * Absolute path for source on GZ: 107*10619SPhaniram.Krishnamurthy@Sun.COM * a) If BASEDIR == INSTROOT 108*10619SPhaniram.Krishnamurthy@Sun.COM * /<local_path string starting from index 1> 109*10619SPhaniram.Krishnamurthy@Sun.COM * In the above example, absolute path is 110*10619SPhaniram.Krishnamurthy@Sun.COM * /bin/ls 111*10619SPhaniram.Krishnamurthy@Sun.COM * 112*10619SPhaniram.Krishnamurthy@Sun.COM * b) If BASEDIR > INSTROOT 113*10619SPhaniram.Krishnamurthy@Sun.COM * /usr/<local_path string starting from index 1> 114*10619SPhaniram.Krishnamurthy@Sun.COM * In the above example, absolute path is 115*10619SPhaniram.Krishnamurthy@Sun.COM * /usr/bin/ls 116*10619SPhaniram.Krishnamurthy@Sun.COM */ 117*10619SPhaniram.Krishnamurthy@Sun.COM if ((strncmp(tmp_inst_root, tmp_basedir, inst_root_len) == 0) && 118*10619SPhaniram.Krishnamurthy@Sun.COM (inst_root_len == basedir_len)) { 119*10619SPhaniram.Krishnamurthy@Sun.COM /* 120*10619SPhaniram.Krishnamurthy@Sun.COM * Prefix root to the local path. NOTE that local_path[0] 121*10619SPhaniram.Krishnamurthy@Sun.COM * has a '~' character. Move past it. 122*10619SPhaniram.Krishnamurthy@Sun.COM * 123*10619SPhaniram.Krishnamurthy@Sun.COM * NOTE: local_path array size is expected to be >= 2. 124*10619SPhaniram.Krishnamurthy@Sun.COM */ 125*10619SPhaniram.Krishnamurthy@Sun.COM (void) snprintf(pi_srcPath, PATH_MAX, "/%s", 126*10619SPhaniram.Krishnamurthy@Sun.COM &(local_path[1])); 127*10619SPhaniram.Krishnamurthy@Sun.COM } else { 128*10619SPhaniram.Krishnamurthy@Sun.COM /* 129*10619SPhaniram.Krishnamurthy@Sun.COM * NOTE: local_path array size is expected to be >= 2. 130*10619SPhaniram.Krishnamurthy@Sun.COM */ 131*10619SPhaniram.Krishnamurthy@Sun.COM (void) snprintf(pi_srcPath, PATH_MAX, "%s/%s", 132*10619SPhaniram.Krishnamurthy@Sun.COM &(tmp_basedir[inst_root_len]), &(local_path[1])); 133*10619SPhaniram.Krishnamurthy@Sun.COM } 134*10619SPhaniram.Krishnamurthy@Sun.COM 135*10619SPhaniram.Krishnamurthy@Sun.COM return (pi_srcPath); 136*10619SPhaniram.Krishnamurthy@Sun.COM } 137