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 /*
235c51f124SMoriah Waterland * 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 <stdio.h>
335c51f124SMoriah Waterland #include <string.h>
345c51f124SMoriah Waterland #include <limits.h>
355c51f124SMoriah Waterland #include <sys/types.h>
365c51f124SMoriah Waterland #include "pkgstrct.h"
375c51f124SMoriah Waterland #include "pkglib.h"
385c51f124SMoriah Waterland
395c51f124SMoriah Waterland /*
405c51f124SMoriah Waterland * Name: putcfile
415c51f124SMoriah Waterland * Description: Write contents file entry to specified FILE
425c51f124SMoriah Waterland * Arguments: struct cfent a_ept - data for contents file entry
435c51f124SMoriah Waterland * FILE *a_fp - FP of file to write contents file entry to
445c51f124SMoriah Waterland * Notes: This is identical to putcvfpfile() but this function takes a
455c51f124SMoriah Waterland * stdio FILE* file to write to instead of a VFP_T file. It is
465c51f124SMoriah Waterland * MUCH slower than putcvfpfile().
475c51f124SMoriah Waterland */
485c51f124SMoriah Waterland
495c51f124SMoriah Waterland int
putcfile(struct cfent * a_ept,FILE * a_fp)505c51f124SMoriah Waterland putcfile(struct cfent *a_ept, FILE *a_fp)
515c51f124SMoriah Waterland {
525c51f124SMoriah Waterland struct pinfo *pinfo;
535c51f124SMoriah Waterland
545c51f124SMoriah Waterland if (a_ept->ftype == 'i') {
555c51f124SMoriah Waterland return (0); /* no ifiles stored in contents DB */
565c51f124SMoriah Waterland }
575c51f124SMoriah Waterland
585c51f124SMoriah Waterland if (a_ept->path == NULL) {
595c51f124SMoriah Waterland return (-1); /* no path name - no entry to write */
605c51f124SMoriah Waterland }
615c51f124SMoriah Waterland
625c51f124SMoriah Waterland if (fputs(a_ept->path, a_fp) == EOF) {
635c51f124SMoriah Waterland return (-1);
645c51f124SMoriah Waterland }
655c51f124SMoriah Waterland
665c51f124SMoriah Waterland if (a_ept->ainfo.local) {
675c51f124SMoriah Waterland if (putc('=', a_fp) == EOF) {
685c51f124SMoriah Waterland return (-1);
695c51f124SMoriah Waterland }
705c51f124SMoriah Waterland if (fputs(a_ept->ainfo.local, a_fp) == EOF)
715c51f124SMoriah Waterland return (-1);
725c51f124SMoriah Waterland }
735c51f124SMoriah Waterland
745c51f124SMoriah Waterland if (a_ept->volno) {
755c51f124SMoriah Waterland if (fprintf(a_fp, " %d", a_ept->volno) < 0) {
765c51f124SMoriah Waterland return (-1);
775c51f124SMoriah Waterland }
785c51f124SMoriah Waterland }
795c51f124SMoriah Waterland
805c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
815c51f124SMoriah Waterland return (-1);
825c51f124SMoriah Waterland }
835c51f124SMoriah Waterland
845c51f124SMoriah Waterland if (putc(a_ept->ftype, a_fp) == EOF) {
855c51f124SMoriah Waterland return (-1);
865c51f124SMoriah Waterland }
875c51f124SMoriah Waterland
885c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
895c51f124SMoriah Waterland return (-1);
905c51f124SMoriah Waterland }
915c51f124SMoriah Waterland
925c51f124SMoriah Waterland if (fputs(a_ept->pkg_class, a_fp) == EOF) {
935c51f124SMoriah Waterland return (-1);
945c51f124SMoriah Waterland }
955c51f124SMoriah Waterland
965c51f124SMoriah Waterland if ((a_ept->ftype == 'c') || (a_ept->ftype == 'b')) {
975c51f124SMoriah Waterland if (a_ept->ainfo.major == BADMAJOR) {
985c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
995c51f124SMoriah Waterland return (-1);
1005c51f124SMoriah Waterland }
1015c51f124SMoriah Waterland
1025c51f124SMoriah Waterland if (putc('?', a_fp) == EOF) {
1035c51f124SMoriah Waterland return (-1);
1045c51f124SMoriah Waterland }
1055c51f124SMoriah Waterland } else {
106*4656d474SGarrett D'Amore if (fprintf(a_fp, " %ld", a_ept->ainfo.major) < 0)
1075c51f124SMoriah Waterland return (-1);
1085c51f124SMoriah Waterland }
1095c51f124SMoriah Waterland
1105c51f124SMoriah Waterland if (a_ept->ainfo.minor == BADMINOR) {
1115c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
1125c51f124SMoriah Waterland return (-1);
1135c51f124SMoriah Waterland }
1145c51f124SMoriah Waterland
1155c51f124SMoriah Waterland if (putc('?', a_fp) == EOF) {
1165c51f124SMoriah Waterland return (-1);
1175c51f124SMoriah Waterland }
1185c51f124SMoriah Waterland } else {
119*4656d474SGarrett D'Amore if (fprintf(a_fp, " %ld", a_ept->ainfo.minor) < 0)
1205c51f124SMoriah Waterland return (-1);
1215c51f124SMoriah Waterland }
1225c51f124SMoriah Waterland }
1235c51f124SMoriah Waterland
1245c51f124SMoriah Waterland if ((a_ept->ftype == 'd') || (a_ept->ftype == 'x') ||
1255c51f124SMoriah Waterland (a_ept->ftype == 'c') || (a_ept->ftype == 'b') ||
1265c51f124SMoriah Waterland (a_ept->ftype == 'p') || (a_ept->ftype == 'f') ||
1275c51f124SMoriah Waterland (a_ept->ftype == 'v') || (a_ept->ftype == 'e')) {
1285c51f124SMoriah Waterland if (fprintf(a_fp,
1295c51f124SMoriah Waterland ((a_ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
1305c51f124SMoriah Waterland a_ept->ainfo.mode) < 0)
1315c51f124SMoriah Waterland return (-1);
1325c51f124SMoriah Waterland
1335c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
1345c51f124SMoriah Waterland return (-1);
1355c51f124SMoriah Waterland }
1365c51f124SMoriah Waterland
1375c51f124SMoriah Waterland if (fputs(a_ept->ainfo.owner, a_fp) == EOF) {
1385c51f124SMoriah Waterland return (-1);
1395c51f124SMoriah Waterland }
1405c51f124SMoriah Waterland
1415c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
1425c51f124SMoriah Waterland return (-1);
1435c51f124SMoriah Waterland }
1445c51f124SMoriah Waterland
1455c51f124SMoriah Waterland if (fputs(a_ept->ainfo.group, a_fp) == EOF) {
1465c51f124SMoriah Waterland return (-1);
1475c51f124SMoriah Waterland }
1485c51f124SMoriah Waterland }
1495c51f124SMoriah Waterland
1505c51f124SMoriah Waterland if ((a_ept->ftype == 'f') || (a_ept->ftype == 'v') ||
1515c51f124SMoriah Waterland (a_ept->ftype == 'e')) {
1525c51f124SMoriah Waterland if (fprintf(a_fp,
1535c51f124SMoriah Waterland ((a_ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
1545c51f124SMoriah Waterland a_ept->cinfo.size) < 0)
1555c51f124SMoriah Waterland return (-1);
1565c51f124SMoriah Waterland
1575c51f124SMoriah Waterland if (fprintf(a_fp,
1585c51f124SMoriah Waterland ((a_ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
1595c51f124SMoriah Waterland a_ept->cinfo.cksum) < 0)
1605c51f124SMoriah Waterland return (-1);
1615c51f124SMoriah Waterland
1625c51f124SMoriah Waterland if (fprintf(a_fp,
1635c51f124SMoriah Waterland ((a_ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
1645c51f124SMoriah Waterland a_ept->cinfo.modtime) < 0)
1655c51f124SMoriah Waterland return (-1);
1665c51f124SMoriah Waterland }
1675c51f124SMoriah Waterland
1685c51f124SMoriah Waterland pinfo = a_ept->pinfo;
1695c51f124SMoriah Waterland while (pinfo) {
1705c51f124SMoriah Waterland if (putc(' ', a_fp) == EOF) {
1715c51f124SMoriah Waterland return (-1);
1725c51f124SMoriah Waterland }
1735c51f124SMoriah Waterland
1745c51f124SMoriah Waterland if (pinfo->status) {
1755c51f124SMoriah Waterland if (fputc(pinfo->status, a_fp) == EOF) {
1765c51f124SMoriah Waterland return (-1);
1775c51f124SMoriah Waterland }
1785c51f124SMoriah Waterland }
1795c51f124SMoriah Waterland
1805c51f124SMoriah Waterland if (fputs(pinfo->pkg, a_fp) == EOF) {
1815c51f124SMoriah Waterland return (-1);
1825c51f124SMoriah Waterland }
1835c51f124SMoriah Waterland
1845c51f124SMoriah Waterland if (pinfo->editflag) {
1855c51f124SMoriah Waterland if (putc('\\', a_fp) == EOF) {
1865c51f124SMoriah Waterland return (-1);
1875c51f124SMoriah Waterland }
1885c51f124SMoriah Waterland }
1895c51f124SMoriah Waterland
1905c51f124SMoriah Waterland if (pinfo->aclass[0]) {
1915c51f124SMoriah Waterland if (putc(':', a_fp) == EOF) {
1925c51f124SMoriah Waterland return (-1);
1935c51f124SMoriah Waterland }
1945c51f124SMoriah Waterland if (fputs(pinfo->aclass, a_fp) == EOF) {
1955c51f124SMoriah Waterland return (-1);
1965c51f124SMoriah Waterland }
1975c51f124SMoriah Waterland }
1985c51f124SMoriah Waterland pinfo = pinfo->next;
1995c51f124SMoriah Waterland }
2005c51f124SMoriah Waterland
2015c51f124SMoriah Waterland if (putc('\n', a_fp) == EOF) {
2025c51f124SMoriah Waterland return (-1);
2035c51f124SMoriah Waterland }
2045c51f124SMoriah Waterland return (0);
2055c51f124SMoriah Waterland }
2065c51f124SMoriah Waterland
2075c51f124SMoriah Waterland /*
2085c51f124SMoriah Waterland * Name: putcvfpfile
2095c51f124SMoriah Waterland * Description: Write contents file entry to specified VFP
2105c51f124SMoriah Waterland * Arguments: struct cfent a_ept - data for contents file entry
2115c51f124SMoriah Waterland * VFP_T *a_vfp - VFP of file to write contents file entry to
2125c51f124SMoriah Waterland * Notes: This is identical to putcfile() but this function takes a
2135c51f124SMoriah Waterland * VFP_T file to write to instead of a stdio FILE file. It is
2145c51f124SMoriah Waterland * MUCH faster tha putcfile().
2155c51f124SMoriah Waterland */
2165c51f124SMoriah Waterland
2175c51f124SMoriah Waterland int
putcvfpfile(struct cfent * a_ept,VFP_T * a_vfp)2185c51f124SMoriah Waterland putcvfpfile(struct cfent *a_ept, VFP_T *a_vfp)
2195c51f124SMoriah Waterland {
2205c51f124SMoriah Waterland struct pinfo *pinfo;
2215c51f124SMoriah Waterland
2225c51f124SMoriah Waterland /* contents file does not maintain any 'i' file entries */
2235c51f124SMoriah Waterland
2245c51f124SMoriah Waterland if (a_ept->ftype == 'i') {
2255c51f124SMoriah Waterland return (0);
2265c51f124SMoriah Waterland }
2275c51f124SMoriah Waterland
2285c51f124SMoriah Waterland /* cannot create an entry if it has no file name */
2295c51f124SMoriah Waterland
2305c51f124SMoriah Waterland if (a_ept->path == NULL) {
2315c51f124SMoriah Waterland return (-1);
2325c51f124SMoriah Waterland }
2335c51f124SMoriah Waterland
2345c51f124SMoriah Waterland /*
2355c51f124SMoriah Waterland * Format of contents file line could be one of:
2365c51f124SMoriah Waterland * /file=./dir/file s class SUNWxxx
2375c51f124SMoriah Waterland * /file=../dir/file l class SUNWxxx
2385c51f124SMoriah Waterland * /dir d class mode owner group SUNWxxx SUNWyyy
2395c51f124SMoriah Waterland * /devices/name c class major minor mode owner group SUNWxxx
2405c51f124SMoriah Waterland * /file f class mode owner group size cksum modtime SUNWxxx
2415c51f124SMoriah Waterland * /file x class mode owner group SUNWppro
2425c51f124SMoriah Waterland * /file v class mode owner group size cksum modtime SUNWxxx
2435c51f124SMoriah Waterland * /file e class mode owner group size cksum modtime SUNWxxx
2445c51f124SMoriah Waterland * The package name could be prefixed by one of the following
2455c51f124SMoriah Waterland * status indicators: +-*!%@#~
2465c51f124SMoriah Waterland */
2475c51f124SMoriah Waterland
2485c51f124SMoriah Waterland /*
2495c51f124SMoriah Waterland * Adding an entry to the specified VFP. During normal processing the
2505c51f124SMoriah Waterland * contents file is copied to a temporary contents file and entries are
2515c51f124SMoriah Waterland * added as appropriate. When this processing is completed, a decision
2525c51f124SMoriah Waterland * is made on whether or not to overwrite the real contents file with
2535c51f124SMoriah Waterland * the contents of the temporary contents file. If the temporary
2545c51f124SMoriah Waterland * contents file is just a copy of the real contents file then there is
2555c51f124SMoriah Waterland * no need to overwrite the real contents file with the contents of the
2565c51f124SMoriah Waterland * temporary contents file. This decision is made in part on whether
2575c51f124SMoriah Waterland * or not any new or modified entries have been added to the temporary
2585c51f124SMoriah Waterland * contents file. Set the "data is modified" indication associated
2595c51f124SMoriah Waterland * with this VFP so that the real contents file is overwritten when
2605c51f124SMoriah Waterland * processing is done.
2615c51f124SMoriah Waterland */
2625c51f124SMoriah Waterland
2635c51f124SMoriah Waterland (void) vfpSetModified(a_vfp);
2645c51f124SMoriah Waterland
2655c51f124SMoriah Waterland /* write initial path [all entries] */
2665c51f124SMoriah Waterland
2675c51f124SMoriah Waterland vfpPuts(a_vfp, a_ept->path);
2685c51f124SMoriah Waterland
2695c51f124SMoriah Waterland /* if link, write out '=' portion */
2705c51f124SMoriah Waterland
2715c51f124SMoriah Waterland if (a_ept->ainfo.local) {
2725c51f124SMoriah Waterland vfpPutc(a_vfp, '=');
2735c51f124SMoriah Waterland vfpPuts(a_vfp, a_ept->ainfo.local);
2745c51f124SMoriah Waterland }
2755c51f124SMoriah Waterland
2765c51f124SMoriah Waterland /* if volume, write it out */
2775c51f124SMoriah Waterland
2785c51f124SMoriah Waterland if (a_ept->volno) {
2795c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
2805c51f124SMoriah Waterland vfpPutInteger(a_vfp, a_ept->volno);
2815c51f124SMoriah Waterland }
2825c51f124SMoriah Waterland
2835c51f124SMoriah Waterland /* write out <space><entry type><space>class> */
2845c51f124SMoriah Waterland
2855c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
2865c51f124SMoriah Waterland vfpPutc(a_vfp, a_ept->ftype);
2875c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
2885c51f124SMoriah Waterland vfpPuts(a_vfp, a_ept->pkg_class);
2895c51f124SMoriah Waterland
2905c51f124SMoriah Waterland /* if char/block device, write out major/minor numbers */
2915c51f124SMoriah Waterland
2925c51f124SMoriah Waterland if ((a_ept->ftype == 'c') || (a_ept->ftype == 'b')) {
2935c51f124SMoriah Waterland /* major device number */
2945c51f124SMoriah Waterland if (a_ept->ainfo.major == BADMAJOR) {
2955c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
2965c51f124SMoriah Waterland vfpPutc(a_vfp, '?');
2975c51f124SMoriah Waterland } else {
2985c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
2995c51f124SMoriah Waterland vfpPutInteger(a_vfp, a_ept->ainfo.major);
3005c51f124SMoriah Waterland }
3015c51f124SMoriah Waterland
3025c51f124SMoriah Waterland /* minor device number */
3035c51f124SMoriah Waterland if (a_ept->ainfo.minor == BADMINOR) {
3045c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
3055c51f124SMoriah Waterland vfpPutc(a_vfp, '?');
3065c51f124SMoriah Waterland } else {
3075c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
3085c51f124SMoriah Waterland vfpPutInteger(a_vfp, a_ept->ainfo.minor);
3095c51f124SMoriah Waterland }
3105c51f124SMoriah Waterland }
3115c51f124SMoriah Waterland
3125c51f124SMoriah Waterland /* if dxcbpfve, write out mode, owner, group */
3135c51f124SMoriah Waterland
3145c51f124SMoriah Waterland if ((a_ept->ftype == 'd') || (a_ept->ftype == 'x') ||
3155c51f124SMoriah Waterland (a_ept->ftype == 'c') || (a_ept->ftype == 'b') ||
3165c51f124SMoriah Waterland (a_ept->ftype == 'p') || (a_ept->ftype == 'f') ||
3175c51f124SMoriah Waterland (a_ept->ftype == 'v') || (a_ept->ftype == 'e')) {
3185c51f124SMoriah Waterland
3195c51f124SMoriah Waterland /* mode */
3205c51f124SMoriah Waterland vfpPutFormat(a_vfp,
3215c51f124SMoriah Waterland ((a_ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
3225c51f124SMoriah Waterland a_ept->ainfo.mode);
3235c51f124SMoriah Waterland
3245c51f124SMoriah Waterland /* owner */
3255c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
3265c51f124SMoriah Waterland vfpPuts(a_vfp, a_ept->ainfo.owner);
3275c51f124SMoriah Waterland
3285c51f124SMoriah Waterland /* group */
3295c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
3305c51f124SMoriah Waterland vfpPuts(a_vfp, a_ept->ainfo.group);
3315c51f124SMoriah Waterland }
3325c51f124SMoriah Waterland /* if f/v/e, write out size, cksum, modtime */
3335c51f124SMoriah Waterland
3345c51f124SMoriah Waterland if ((a_ept->ftype == 'f') || (a_ept->ftype == 'v') ||
3355c51f124SMoriah Waterland (a_ept->ftype == 'e')) {
3365c51f124SMoriah Waterland /* size */
3375c51f124SMoriah Waterland vfpPutFormat(a_vfp,
3385c51f124SMoriah Waterland ((a_ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
3395c51f124SMoriah Waterland a_ept->cinfo.size);
3405c51f124SMoriah Waterland
3415c51f124SMoriah Waterland /* cksum */
3425c51f124SMoriah Waterland vfpPutFormat(a_vfp,
3435c51f124SMoriah Waterland ((a_ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
3445c51f124SMoriah Waterland a_ept->cinfo.cksum);
3455c51f124SMoriah Waterland
3465c51f124SMoriah Waterland /* modtime */
3475c51f124SMoriah Waterland vfpPutFormat(a_vfp,
3485c51f124SMoriah Waterland ((a_ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
3495c51f124SMoriah Waterland a_ept->cinfo.modtime);
3505c51f124SMoriah Waterland }
3515c51f124SMoriah Waterland
3525c51f124SMoriah Waterland /* write out list of all packages referencing this entry */
3535c51f124SMoriah Waterland
3545c51f124SMoriah Waterland pinfo = a_ept->pinfo;
3555c51f124SMoriah Waterland while (pinfo) {
3565c51f124SMoriah Waterland vfpPutc(a_vfp, ' ');
3575c51f124SMoriah Waterland if (pinfo->status) {
3585c51f124SMoriah Waterland vfpPutc(a_vfp, pinfo->status);
3595c51f124SMoriah Waterland }
3605c51f124SMoriah Waterland
3615c51f124SMoriah Waterland vfpPuts(a_vfp, pinfo->pkg);
3625c51f124SMoriah Waterland
3635c51f124SMoriah Waterland if (pinfo->editflag) {
3645c51f124SMoriah Waterland vfpPutc(a_vfp, '\\');
3655c51f124SMoriah Waterland }
3665c51f124SMoriah Waterland
3675c51f124SMoriah Waterland if (pinfo->aclass[0]) {
3685c51f124SMoriah Waterland vfpPutc(a_vfp, ':');
3695c51f124SMoriah Waterland vfpPuts(a_vfp, pinfo->aclass);
3705c51f124SMoriah Waterland }
3715c51f124SMoriah Waterland pinfo = pinfo->next;
3725c51f124SMoriah Waterland }
3735c51f124SMoriah Waterland
3745c51f124SMoriah Waterland vfpPutc(a_vfp, '\n');
3755c51f124SMoriah Waterland return (0);
3765c51f124SMoriah Waterland }
377