1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland  * CDDL HEADER START
3*5c51f124SMoriah Waterland  *
4*5c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland  *
8*5c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland  * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland  * and limitations under the License.
12*5c51f124SMoriah Waterland  *
13*5c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland  *
19*5c51f124SMoriah Waterland  * CDDL HEADER END
20*5c51f124SMoriah Waterland  */
21*5c51f124SMoriah Waterland 
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*5c51f124SMoriah Waterland  * Use is subject to license terms.
25*5c51f124SMoriah Waterland  */
26*5c51f124SMoriah Waterland 
27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*5c51f124SMoriah Waterland /* All Rights Reserved */
29*5c51f124SMoriah Waterland 
30*5c51f124SMoriah Waterland 
31*5c51f124SMoriah Waterland 
32*5c51f124SMoriah Waterland #include <stdio.h>
33*5c51f124SMoriah Waterland #include <limits.h>
34*5c51f124SMoriah Waterland #include <stdlib.h>
35*5c51f124SMoriah Waterland #include <unistd.h>
36*5c51f124SMoriah Waterland #include <sys/types.h>
37*5c51f124SMoriah Waterland #include "pkgstrct.h"
38*5c51f124SMoriah Waterland #include "pkglib.h"
39*5c51f124SMoriah Waterland #include "pkglibmsgs.h"
40*5c51f124SMoriah Waterland #include "pkglocale.h"
41*5c51f124SMoriah Waterland 
42*5c51f124SMoriah Waterland #define	PKGMAP	"pkgmap"
43*5c51f124SMoriah Waterland #define	PKGINFO	"pkginfo"
44*5c51f124SMoriah Waterland 
45*5c51f124SMoriah Waterland int
ckvolseq(char * dir,int part,int nparts)46*5c51f124SMoriah Waterland ckvolseq(char *dir, int part, int nparts)
47*5c51f124SMoriah Waterland {
48*5c51f124SMoriah Waterland 	static struct cinfo cinfo;
49*5c51f124SMoriah Waterland 	char	ftype, path[PATH_MAX];
50*5c51f124SMoriah Waterland 
51*5c51f124SMoriah Waterland 	if (part > 0) {
52*5c51f124SMoriah Waterland 		ftype = 'f';
53*5c51f124SMoriah Waterland 		if (part == 1) {
54*5c51f124SMoriah Waterland 			/*
55*5c51f124SMoriah Waterland 			 * save stats about content information of pkginfo
56*5c51f124SMoriah Waterland 			 * file in order to verify multi-volume packages
57*5c51f124SMoriah Waterland 			 */
58*5c51f124SMoriah Waterland 			cinfo.cksum = cinfo.size = cinfo.modtime = (-1L);
59*5c51f124SMoriah Waterland 			(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
60*5c51f124SMoriah Waterland 			if (cverify(0, &ftype, path, &cinfo, 1)) {
61*5c51f124SMoriah Waterland 				logerr(pkg_gt(ERR_BADPKGINFO), path);
62*5c51f124SMoriah Waterland 				logerr(getErrbufAddr());
63*5c51f124SMoriah Waterland 				return (1);
64*5c51f124SMoriah Waterland 			}
65*5c51f124SMoriah Waterland 			(void) snprintf(path, sizeof (path), "%s/pkgmap", dir);
66*5c51f124SMoriah Waterland 			if (access(path, 0)) {
67*5c51f124SMoriah Waterland 				logerr(pkg_gt(ERR_NOPKGMAP), path);
68*5c51f124SMoriah Waterland 				return (2);
69*5c51f124SMoriah Waterland 			}
70*5c51f124SMoriah Waterland 		} else {
71*5c51f124SMoriah Waterland 			/* temp fix due to summit problem */
72*5c51f124SMoriah Waterland 			cinfo.modtime = (-1);
73*5c51f124SMoriah Waterland 
74*5c51f124SMoriah Waterland 			/* pkginfo file doesn't match first floppy */
75*5c51f124SMoriah Waterland 			(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
76*5c51f124SMoriah Waterland 			if (cverify(0, &ftype, path, &cinfo, 1)) {
77*5c51f124SMoriah Waterland 				logerr(pkg_gt(MSG_CORRUPT));
78*5c51f124SMoriah Waterland 				logerr(getErrbufAddr());
79*5c51f124SMoriah Waterland 				return (1);
80*5c51f124SMoriah Waterland 			}
81*5c51f124SMoriah Waterland 		}
82*5c51f124SMoriah Waterland 	} else
83*5c51f124SMoriah Waterland 		part = (-part);
84*5c51f124SMoriah Waterland 
85*5c51f124SMoriah Waterland 	/*
86*5c51f124SMoriah Waterland 	 * each volume in a multi-volume package must
87*5c51f124SMoriah Waterland 	 * contain either the root.n or reloc.n directories
88*5c51f124SMoriah Waterland 	 */
89*5c51f124SMoriah Waterland 	if (nparts != 1) {
90*5c51f124SMoriah Waterland 		/* look for multi-volume specification */
91*5c51f124SMoriah Waterland 		(void) snprintf(path, sizeof (path), "%s/root.%d", dir, part);
92*5c51f124SMoriah Waterland 		if (access(path, 0) == 0)
93*5c51f124SMoriah Waterland 			return (0);
94*5c51f124SMoriah Waterland 		(void) snprintf(path, sizeof (path), "%s/reloc.%d", dir, part);
95*5c51f124SMoriah Waterland 		if (access(path, 0) == 0)
96*5c51f124SMoriah Waterland 			return (0);
97*5c51f124SMoriah Waterland 		if (part == 1) {
98*5c51f124SMoriah Waterland 			(void) snprintf(path, sizeof (path), "%s/install",
99*5c51f124SMoriah Waterland 								dir, part);
100*5c51f124SMoriah Waterland 			if (access(path, 0) == 0)
101*5c51f124SMoriah Waterland 				return (0);
102*5c51f124SMoriah Waterland 		}
103*5c51f124SMoriah Waterland 		if (nparts) {
104*5c51f124SMoriah Waterland 			logerr(pkg_gt(MSG_SEQ));
105*5c51f124SMoriah Waterland 			return (2);
106*5c51f124SMoriah Waterland 		}
107*5c51f124SMoriah Waterland 	}
108*5c51f124SMoriah Waterland 	return (0);
109*5c51f124SMoriah Waterland }
110