xref: /titanic_52/usr/src/cmd/svr4pkg/pkginstall/pkgvolume.c (revision 23a1ccea6aac035f084a7a4cdc968687d1b02daf)
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 2006 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 #include <stdio.h>
32 #include <limits.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <sys/mount.h>
37 #include <pkgdev.h>
38 #include <locale.h>
39 #include <libintl.h>
40 #include <pkglib.h>
41 #include <libadm.h>
42 #include <libinst.h>
43 
44 extern char	instdir[], pkgbin[];
45 
46 void
47 pkgvolume(struct pkgdev *devp, char *pkg, int part, int nparts)
48 {
49 	static int	cpart = 0;
50 	char	path[PATH_MAX];
51 	int	n;
52 
53 	if (devp->cdevice)
54 		return;
55 	if (cpart == part)
56 		return;
57 	cpart = part;
58 
59 	if (part == 1) {
60 		if (ckvolseq(instdir, 1, nparts)) {
61 			progerr(gettext("corrupt directory structure"));
62 			quit(99);
63 		}
64 		cpart = 1;
65 		return;
66 	}
67 
68 	if (devp->mount == NULL) {
69 		if (ckvolseq(instdir, part, nparts)) {
70 			progerr(gettext("corrupt directory structure"));
71 			quit(99);
72 		}
73 		return;
74 	}
75 
76 	for (;;) {
77 		(void) chdir("/");
78 		if (n = pkgumount(devp)) {
79 			progerr(gettext("attempt to unmount <%s> failed (%d)"),
80 				devp->bdevice, n);
81 			quit(99);
82 		}
83 		if (n = pkgmount(devp, pkg, part, nparts, 1))
84 			quit(n);
85 		(void) sprintf(path, "%s/%s", devp->dirname, pkg);
86 		if (ckvolseq(path, part, nparts) == 0)
87 			break;
88 	}
89 }
90