xref: /illumos-gate/usr/src/lib/libpkg/common/ckvolseq.c (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 
30 
31 
32 #include <stdio.h>
33 #include <limits.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <sys/types.h>
37 #include "pkgstrct.h"
38 #include "pkglib.h"
39 #include "pkglibmsgs.h"
40 #include "pkglocale.h"
41 
42 #define	PKGMAP	"pkgmap"
43 #define	PKGINFO	"pkginfo"
44 
45 int
46 ckvolseq(char *dir, int part, int nparts)
47 {
48 	static struct cinfo cinfo;
49 	char	ftype, path[PATH_MAX];
50 
51 	if (part > 0) {
52 		ftype = 'f';
53 		if (part == 1) {
54 			/*
55 			 * save stats about content information of pkginfo
56 			 * file in order to verify multi-volume packages
57 			 */
58 			cinfo.cksum = cinfo.size = cinfo.modtime = (-1L);
59 			(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
60 			if (cverify(0, &ftype, path, &cinfo, 1)) {
61 				logerr(pkg_gt(ERR_BADPKGINFO), path);
62 				logerr(getErrbufAddr());
63 				return (1);
64 			}
65 			(void) snprintf(path, sizeof (path), "%s/pkgmap", dir);
66 			if (access(path, 0)) {
67 				logerr(pkg_gt(ERR_NOPKGMAP), path);
68 				return (2);
69 			}
70 		} else {
71 			/* temp fix due to summit problem */
72 			cinfo.modtime = (-1);
73 
74 			/* pkginfo file doesn't match first floppy */
75 			(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
76 			if (cverify(0, &ftype, path, &cinfo, 1)) {
77 				logerr(pkg_gt(MSG_CORRUPT));
78 				logerr(getErrbufAddr());
79 				return (1);
80 			}
81 		}
82 	} else
83 		part = (-part);
84 
85 	/*
86 	 * each volume in a multi-volume package must
87 	 * contain either the root.n or reloc.n directories
88 	 */
89 	if (nparts != 1) {
90 		/* look for multi-volume specification */
91 		(void) snprintf(path, sizeof (path), "%s/root.%d", dir, part);
92 		if (access(path, 0) == 0)
93 			return (0);
94 		(void) snprintf(path, sizeof (path), "%s/reloc.%d", dir, part);
95 		if (access(path, 0) == 0)
96 			return (0);
97 		if (part == 1) {
98 			(void) snprintf(path, sizeof (path), "%s/install",
99 								dir, part);
100 			if (access(path, 0) == 0)
101 				return (0);
102 		}
103 		if (nparts) {
104 			logerr(pkg_gt(MSG_SEQ));
105 			return (2);
106 		}
107 	}
108 	return (0);
109 }
110