5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *
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 *
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 *
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 *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/*
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <limits.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <string.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdio.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <stdlib.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <unistd.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#include <fcntl.h>
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India#include <libinst.h>
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandchar *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandsrcpath(char *dir, char *src, int part, int nparts)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland{
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland static char tmppath[PATH_MAX];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char *copy;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t copyLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland copy = tmppath;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dir != NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland size_t theLen = strlen(dir);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(copy, dir);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland copy += theLen;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland copyLen = (sizeof (tmppath) - theLen);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland copy[0] = '\0';
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland copyLen = sizeof (tmppath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (nparts > 1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(copy, copyLen,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ((src[0] == '/') ? "/root.%d%s" : "/reloc.%d/%s"),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland part, src);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(copy, copyLen,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ((src[0] == '/') ? "/root%s" : "/reloc/%s"), src);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland }
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (tmppath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland}
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India/*
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * During a partial install(Ex. Migration of a zone), if the'contchg' field of
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * mstat structure is set i.e. there is a mismatch between the entry in pkgmap
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * and package database and the file is of type 'f', the source path on the
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Global zone is to be generated(mostly for being copied again to the NGZ).
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Given the local source path(relocatable), this function builds the absolute
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * source path.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: This function is a private interface. Should only be called during a
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * a partial install and for files of type 'f'.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Source translation is done differently from 'e' and 'v' types.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore Indiachar *
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore Indiatrans_srcp_pi(char *local_path)
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India{
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India static char pi_srcPath[PATH_MAX];
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char *tmp_basedir, *tmp_inst_root;
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India int inst_root_len, basedir_len;
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /* Get the basedir and it's length */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India tmp_basedir = get_basedir();
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India basedir_len = strlen(tmp_basedir);
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /* Get the install root and it's length */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India tmp_inst_root = get_inst_root();
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India inst_root_len = strlen(tmp_inst_root);
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Get past install root if something exists
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Example:
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * INSTROOT = /a (on scratch zone)
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * BASEDIR = /a/usr (on scratch zone)
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * local_path = "~bin/ls"
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Absolute path for source on GZ:
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * a) If BASEDIR == INSTROOT
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /<local_path string starting from index 1>
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * In the above example, absolute path is
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /bin/ls
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * b) If BASEDIR > INSTROOT
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /usr/<local_path string starting from index 1>
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * In the above example, absolute path is
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * /usr/bin/ls
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if ((strncmp(tmp_inst_root, tmp_basedir, inst_root_len) == 0) &&
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (inst_root_len == basedir_len)) {
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Prefix root to the local path. NOTE that local_path[0]
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * has a '~' character. Move past it.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India *
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: local_path array size is expected to be >= 2.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(pi_srcPath, PATH_MAX, "/%s",
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India &(local_path[1]));
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India } else {
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * NOTE: local_path array size is expected to be >= 2.
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(pi_srcPath, PATH_MAX, "%s/%s",
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India &(tmp_basedir[inst_root_len]), &(local_path[1]));
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India return (pi_srcPath);
d676c6678e0d7d3d3a700014d359b227edba0042phaniram rampura krishnamurthy - Sun Microsystems - Bangalore India}