pkgobjmap.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <pkgstrct.h>
#include <locale.h>
#include <libintl.h>
#include <pkglib.h>
#include <install.h>
#include <libinst.h>
#define WRN_NOPKGOBJ "WARNING: no package objects found"
#define ERR_MEMORY "memory allocation failure"
#define ERR_DUPPATH "duplicate pathname <%s>"
extern int getmapmode(void);
#define EPTMALLOC 512
int eptnum;
static int array_preloaded = 0;
static int errflg;
static int nparts;
static int xspace = -1;
void pkgobjinit(void);
char **client_local, char **server_path,
int nc);
void
pkgobjinit(void)
{
if (array_preloaded) /* Already done. */
return;
if (xspace != -1) {
xspace = -1;
}
/*
* initialize dynamic memory used to store
* path information which is read in
*/
(void) pathdup((char *)0);
}
/*
* This function assigns appropriate values based upon the pkgmap entry
* in the cfent structure.
*/
static int
int nc)
{
int path_duped = 0;
int local_duped = 0;
return (1);
nparts++;
/*
* Generate local (delivered source) paths for files
* which need them so that the install routine will know
* where to get the file from the package. Note that we
* do not resolve path environment variables here since
* they won't be resolved in the reloc directory.
*/
source[0] = '~';
sizeof (source)-1);
local_duped = 1;
}
}
/*
* Evaluate the destination path based upon available
* environment, then produce a client-relative and
* server-relative canonized path.
*/
(void) eval_path(server_path,
}
/*
* Deal with source for hard and soft links.
*/
if (mapflag) {
/* check for hard link */
(void) eval_path(
NULL,
local_duped = 1;
/* Default to server. */
}
}
}
}
/*
* For the paths (both source and target) that were too mundane to
* have been copied into dup space yet, do that.
*/
if (!path_duped) {
*client_path = *server_path;
path_duped = 1;
}
if (!local_duped) {
local_duped = 1;
}
return (0);
}
/* This initializes the package object array. */
int
init_pkgobjspace(void)
{
if (array_preloaded) /* Already done. */
return (1);
if (xspace == -1) {
"package object");
if (xspace == -1) {
return (0);
}
}
return (1);
}
int
{
/* offsets for the various path images. */
int client_path_os;
int server_path_os;
int map_path_os;
int client_local_os;
int server_local_os;
return (NULL);
}
/* Figure out all of the offsets. */
/* Allocate and store the path name. */
/* Assign the path substring pointers. */
/* If there's a local entry, allocate and store it as well. */
if (local) {
} else {
}
eptnum++;
array_preloaded = 1;
return (0);
}
/*
* This function reads the pkgmap (or any file similarly formatted) and
* returns a pointer to a list of struct cfextra (each of which
* contains a struct cfent) representing the contents of that file.
*/
/* ARGSUSED ir in pkgobjmap */
struct cfextra **
{
int i;
int n;
int nc;
pkgobjinit();
if (!init_pkgobjspace())
quit(99);
for (;;) {
/* Clear the buffer. */
/*
* Fill in a cfent structure in a very preliminary fashion.
* ept->path and ept->ainfo.local point to static memory
* areas of size PATH_MAX. These are manipulated and
* then provided their own allocations later in this function.
*/
if (n == 0)
break; /* no more entries in pkgmap */
else if (n < 0) {
return (NULL);
}
/*
* A valid entry was found in the map, so allocate an
* official record.
*/
return (NULL);
}
/* Transfer what we just read in. */
/* And process it into the cfextra structure. */
if (pkgobjassign(ept,
&(ext->server_local),
&(ext->client_local),
&(ext->server_path),
&(ext->client_path),
/* It didn't take. */
continue;
}
eptnum++;
}
if (eptnum == 0) {
return (NULL);
}
/* setup a pointer array to point to malloc'd entries space */
return (NULL);
}
(void) sortentry(-1);
for (i = 0; i < eptnum; /* void */) {
if (!sortentry(i))
i++;
}
}
/*
* This function sorts the final list of cfextra entries. If index = -1, the
* function is initialized. index = 0 doesn't get us anywhere because this
* sorts against index-1. Positive natural index values are compared and
* sorted into the array appropriately. Yes, it does seem we should use a
* quicksort on the whole array or something. The apparent reason for taking
* this approach is that there are enough special considerations to be
* applied to each package object that inserting them one-by-one doesn't cost
* that much.
*/
static int
{
static int last = 0;
int i, n, j;
if (index == 0)
return (0);
else if (index < 0) {
last = 0;
return (0);
}
/*
* Based on the index, this is the package object we're going to
* review. It may stay where it is or it may be repositioned in the
* array.
*/
/* quick comparison optimization for pre-sorted arrays */
/* do nothing */
return (0);
}
lower = 0; /* lower bound of the unsorted elements */
i = last;
do {
/*
* NOTE: This does a binary sort on path. There are lots of
* other worthy items in the array, but path is the key into
* the package database.
*/
if (n == 0) {
/*
* If the array was seeded then there are
* bound to be occasional duplicates.
* Otherwise, duplicates are definitely a
* sign of major damage.
*/
if (array_preloaded) {
errflg++;
}
} else {
errflg++;
}
}
/* remove the entry at index */
eptnum--;
return (1); /* Use this index again. */
} else if (n < 0) {
/*
* The path of interest is smaller than the path
* under test. Move down array using the method of
* division
*/
upper = i;
} else {
/* Move up array */
lower = i+1;
}
/* expand to insert at i */
for (j = index; j > i; j--)
return (0);
}
/* Return the number of blocks required by the package object provided. */
static fsblkcnt_t
{
blk =
else
blk = 0;
return (blk);
}
/* Remove ext1 from the filesystem size calculations and add ext2. */
static void
{
short fsys_entry;
/*
* Since these are on the same filesystem, either one will yield the
* correct block and fragment size.
*/
/* First, lose the old size, then add the new size. */
}
}
/*
* This function merges duplicate non-directory entries resulting from a
* dryrun or other procedure which preloads the extlist. It uses an odd
* heuristic to determine which package object is newest: only package
* objects from the dryrun file will have pinfo pointers. Therefore, the
* object with a pinfo pointer is from the dryrun file and it will be
* overwritten by the object being installed by this package.
*
* Assumptions:
* 1. The newer object will be overwriting the older object.
* 2. The two objects are close enough to the same size that
* the sizing is still OK.
*
* The calling routine will overwrite ept1, so this must return ept2 with
* the correct data to keep. There being only one logical outcome of a
* failure, this returns 1 for OK and 0 for FAIL.
*/
static int
{
return (0);
return (0);
/* First, which is the eldest? */
/*
* While ept2 has the correct pinfo list (it was preloaded into
* the array before the pkgmap was read), ept1 has everything
* else. Here we copy the guts of ept1 into ept2.
*
* Start by grabbing the pointers to the ext2 items that we
* need to either restore or free.
*/
/* to free() */
/* to preserve */
/* Copy everything from the new entry to the old */
/* Now restore the original stuff.. */
/*
* ept2 is already the one we will keep. All we have to do is
* copy over the pinfo pointer.
*/
} else
return (0);
return (1);
}
/*
* Check duplicate entries in the package object list. If it's a directory,
* this just merges them, if not, it returns a 0 to force further processing.
*/
static int
{
/* ept2 will be modified to contain "merged" entries */
return (0);
return (0);
return (0);
return (0);
return (0);
}
return (1);
}
/*
* Replace the old package database entry with the new one preserving the
* data which remains constant across the replacement.
* copied directly:
* ftype, pkg_class
*
* preserved from old:
* path, npkgs, pinfo
*/
void
{
/* Copy everything from the new entry over */
}
/*
* Copy critical portions of cf_ent (from the package database) and el_ent
* (constructed from the pkgmap) into a merged cfent structure, tp. Then copy
* that to the el_ent structure. The approach we take here is to copy over
* everything from the package database entry, condition the paths based upon
* the currently installed path and then insert the following entries from
* the new structure :
* cfent.volno
* pkg_class
* pkg_class_idx
*
* The pinfo list is then copied from the cfent list. While
* fsys_value is also copied over, it hasn't been set yet. This function
* copies over whatever the default value is from the new structure.
*
* The copied entry is returned in the el_ent argument and the function
* value is 1 on success, 0 on failure. There is no recovery plan for
* failure.
*/
int
{
/* Allocate space for cfent copy */
return (0);
}
/* Copy everything from the package database over */
/* Now overlay new items from the pkgmap */
/*
* The paths are identical, so we get them from the new entry. These
* are pointing to a malloc'd section of memory containing a string
* that we aren't moving in this operation, so everybody points to
* the same thing during these transfers.
*/
/*
* Since instvol() expects to work with the *original* mstat data,
* mstat is just copied here. NOTE: mstat looks like a structure, but
* it's really a short bit array.
*/
/* Copy everything from the temporary structure to the new entry */
return (1);
}