8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / svr4pkg / pkginstall / sortmap.c
blob3901d4bfbd7c40e172098598f727b3315452539f
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
32 * This module constructs a list of entries from the pkgmap associated
33 * with this package. When finished, this list is sorted in alphabetical
34 * order and an accompanying structure list, mergstat, provides
35 * information about how these new files merge with existing files
36 * already on the system.
39 #include <stdio.h>
40 #include <string.h>
41 #include <limits.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <sys/types.h>
45 #include <pkgstrct.h>
46 #include <pkglocs.h>
47 #include <locale.h>
48 #include <libintl.h>
49 #include <install.h>
50 #include <pkglib.h>
51 #include <libadm.h>
52 #include <libinst.h>
54 /* libinst/ocfile.c */
55 extern int dbchg;
57 static int client_refer(struct cfextra **ext);
58 static int server_refer(struct cfextra **ext);
60 int
61 sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
62 PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
64 int i, n, nparts;
65 char *db_mrg = "unable to merge package and system information";
67 if (a_zoneName == (char *)NULL) {
68 echo(gettext("## Processing package information."));
69 } else {
70 echo(gettext("## Processing package information in zone <%s>."),
71 a_zoneName);
75 * The following instruction puts the client-relative basedir
76 * into the environment iff it's a relocatable package and
77 * we're installing to a client. Otherwise, it uses the regular
78 * basedir. The only reason for this is so that mappath() upon
79 * finding $BASEDIR in a path will properly resolve it to the
80 * client-relative path. This way eval_path() can properly
81 * construct the server-relative path.
83 if (is_relocatable() && is_an_inst_root())
84 putparam("BASEDIR", get_info_basedir());
87 * read the pkgmap provided by this package into
88 * memory; map parameters specified in the pathname
89 * and sort in memory by pathname
92 vfpRewind(pkgmapVfp); /* rewind input file */
94 *extlist = pkgobjmap(pkgmapVfp, 2, NULL);
96 if (*extlist == NULL) {
97 progerr(gettext("unable to process pkgmap"));
98 quit(99);
101 /* Make all paths client-relative if necessary. */
102 if (is_an_inst_root()) {
103 (void) client_refer(*extlist);
106 if (a_zoneName == (char *)NULL) {
107 echo(gettext("## Processing system information."));
108 } else {
109 echo(gettext("## Processing system information in zone <%s>."),
110 a_zoneName);
114 * calculate the number of parts in this package
115 * by locating the entry with the largest "volno"
116 * associated with it
118 nparts = 0;
119 if (is_depend_pkginfo_DB() == B_FALSE) {
120 for (i = 0; (*extlist)[i]; i++) {
121 n = (*extlist)[i]->cf_ent.volno;
122 if (n > nparts)
123 nparts = n;
126 vfpTruncate(tmpvfp);
128 dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
129 if (dbchg < 0) {
130 progerr(gettext(db_mrg));
131 quit(99);
135 /* Restore the original BASEDIR. */
136 if (is_relocatable() && is_an_inst_root())
137 putparam("BASEDIR", get_basedir());
139 if (is_an_inst_root()) {
140 (void) server_refer(*extlist);
143 return (nparts);
146 static int
147 client_refer(struct cfextra **ext)
149 int count;
151 for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
152 ext[count]->cf_ent.path = ext[count]->client_path;
153 ext[count]->cf_ent.ainfo.local = ext[count]->client_local;
156 return (1);
159 static int
160 server_refer(struct cfextra **ext)
162 int count;
164 for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
165 ext[count]->cf_ent.path = ext[count]->server_path;
166 ext[count]->cf_ent.ainfo.local = ext[count]->server_local;
169 return (1);