#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "pkgstrct.h"
#include "pkglib.h"
#include "pkglibmsgs.h"
#include "pkglocale.h"
#define PKGMAP "pkgmap"
#define PKGINFO "pkginfo"
int
ckvolseq(char *dir, int part, int nparts)
{
static struct cinfo cinfo;
char ftype, path[PATH_MAX];
if (part > 0) {
ftype = 'f';
if (part == 1) {
cinfo.cksum = cinfo.size = cinfo.modtime = (-1L);
(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
if (cverify(0, &ftype, path, &cinfo, 1)) {
logerr(pkg_gt(ERR_BADPKGINFO), path);
logerr(getErrbufAddr());
return (1);
}
(void) snprintf(path, sizeof (path), "%s/pkgmap", dir);
if (access(path, 0)) {
logerr(pkg_gt(ERR_NOPKGMAP), path);
return (2);
}
} else {
cinfo.modtime = (-1);
(void) snprintf(path, sizeof (path), "%s/pkginfo", dir);
if (cverify(0, &ftype, path, &cinfo, 1)) {
logerr(pkg_gt(MSG_CORRUPT));
logerr(getErrbufAddr());
return (1);
}
}
} else
part = (-part);
if (nparts != 1) {
(void) snprintf(path, sizeof (path), "%s/root.%d", dir, part);
if (access(path, 0) == 0)
return (0);
(void) snprintf(path, sizeof (path), "%s/reloc.%d", dir, part);
if (access(path, 0) == 0)
return (0);
if (part == 1) {
(void) snprintf(path, sizeof (path), "%s/install",
dir, part);
if (access(path, 0) == 0)
return (0);
}
if (nparts) {
logerr(pkg_gt(MSG_SEQ));
return (2);
}
}
return (0);
}