xref: /illumos-gate/usr/src/lib/libpkg/common/pkglib.h (revision 32991bed)
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 
22*32991bedSPeter Tribble /*
23*32991bedSPeter Tribble  * Copyright (c) 2017 Peter Tribble.
24*32991bedSPeter Tribble  */
25*32991bedSPeter Tribble 
265c51f124SMoriah Waterland /*
275c51f124SMoriah Waterland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
285c51f124SMoriah Waterland  * Use is subject to license terms.
295c51f124SMoriah Waterland  */
305c51f124SMoriah Waterland 
315c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
325c51f124SMoriah Waterland /* All Rights Reserved */
335c51f124SMoriah Waterland 
345c51f124SMoriah Waterland #ifndef	_PKGLIB_H
355c51f124SMoriah Waterland #define	_PKGLIB_H
365c51f124SMoriah Waterland 
375c51f124SMoriah Waterland 
385c51f124SMoriah Waterland #ifdef	__cplusplus
395c51f124SMoriah Waterland extern "C" {
405c51f124SMoriah Waterland #endif
415c51f124SMoriah Waterland 
425c51f124SMoriah Waterland #include <sys/types.h>
435c51f124SMoriah Waterland #include <limits.h>
445c51f124SMoriah Waterland #include <stdio.h>
455c51f124SMoriah Waterland #include <pkgdev.h>
465c51f124SMoriah Waterland #include <pkgstrct.h>
475c51f124SMoriah Waterland #include "cfext.h"
485c51f124SMoriah Waterland 
4962224350SCasper H.S. Dik /*
5062224350SCasper H.S. Dik  * The contents database file interface.
5162224350SCasper H.S. Dik  */
5262224350SCasper H.S. Dik 
5362224350SCasper H.S. Dik typedef struct pkg_server *PKGserver;
5462224350SCasper H.S. Dik 
5562224350SCasper H.S. Dik /* Some commands modify the internal database: add them here */
5662224350SCasper H.S. Dik #define	PKG_WRITE_COMMAND(cmd)	((cmd) == PKG_ADDLINES)
5762224350SCasper H.S. Dik 
5862224350SCasper H.S. Dik #define	PKG_EXIT		0x0
5962224350SCasper H.S. Dik #define	PKG_FINDFILE		0x1
6062224350SCasper H.S. Dik #define	PKG_DUMP		0x2
6162224350SCasper H.S. Dik #define	PKG_PKGSYNC		0x3
6262224350SCasper H.S. Dik #define	PKG_FILTER		0x4
6362224350SCasper H.S. Dik #define	PKG_ADDLINES		0x5
6462224350SCasper H.S. Dik #define	PKG_NOP			0x6
6562224350SCasper H.S. Dik 
6662224350SCasper H.S. Dik #define	SUNW_PKG_SERVERMODE	"SUNW_PKG_SERVERMODE"
6762224350SCasper H.S. Dik 
6862224350SCasper H.S. Dik #define	PKGSERV_MODE		"pkg-server-mode="
6962224350SCasper H.S. Dik #define	PKGSERV_MODE_LEN	(sizeof (PKGSERV_MODE) - 1)
7062224350SCasper H.S. Dik 
7162224350SCasper H.S. Dik #define	MODE_PERMANENT		"permanent"
7262224350SCasper H.S. Dik #define	MODE_RUN_ONCE		"run_once"
7362224350SCasper H.S. Dik #define	MODE_TIMEOUT		"timeout"
7462224350SCasper H.S. Dik 
7562224350SCasper H.S. Dik #define	MAXLOGFILESIZE		(20 * 1024 * 1024)
7662224350SCasper H.S. Dik 
7762224350SCasper H.S. Dik #define	PKGLOG			"pkglog"
7862224350SCasper H.S. Dik #define	PKGDOOR			".door"
7962224350SCasper H.S. Dik 
8062224350SCasper H.S. Dik typedef enum {
8162224350SCasper H.S. Dik 	INVALID,		/* Not initialized */
8262224350SCasper H.S. Dik 	NEVER,			/* Don't start, does check if it is running. */
8362224350SCasper H.S. Dik 	FLUSH_LOG,		/* Run it once to incorporate the log. */
8462224350SCasper H.S. Dik 	RUN_ONCE,		/* Run until the current client stops. */
8562224350SCasper H.S. Dik 	TIMEOUT,		/* Run until a timeout occurs. */
8662224350SCasper H.S. Dik 	PERMANENT,		/* Run until it is externally terminated. */
8762224350SCasper H.S. Dik 	DEFAULTMODE = TIMEOUT	/* The default mode, must come last */
8862224350SCasper H.S. Dik } start_mode_t;
8962224350SCasper H.S. Dik 
9062224350SCasper H.S. Dik typedef struct pkgcmd {
9162224350SCasper H.S. Dik 	int cmd;
9262224350SCasper H.S. Dik 	char buf[1];
9362224350SCasper H.S. Dik } pkgcmd_t;
9462224350SCasper H.S. Dik 
9562224350SCasper H.S. Dik typedef struct pkgfilter {
9662224350SCasper H.S. Dik 	int cmd;
9762224350SCasper H.S. Dik 	int len;
9862224350SCasper H.S. Dik 	char buf[1];
9962224350SCasper H.S. Dik } pkgfilter_t;
10062224350SCasper H.S. Dik 
1015c51f124SMoriah Waterland /*
1025c51f124SMoriah Waterland  * Virtual File Protocol definitions
1035c51f124SMoriah Waterland  */
1045c51f124SMoriah Waterland 
1055c51f124SMoriah Waterland /*
1065c51f124SMoriah Waterland  * flags associated with virtual file protocol operations; note that these flags
1075c51f124SMoriah Waterland  * may only occupy the low order 16 bits of the 32-bit unsigned flag.
1085c51f124SMoriah Waterland  */
1095c51f124SMoriah Waterland 
1105c51f124SMoriah Waterland typedef unsigned long VFPFLAGS_T;
1115c51f124SMoriah Waterland 
1125c51f124SMoriah Waterland #define	VFP_NONE	0x00000000	/* no special flags */
1135c51f124SMoriah Waterland #define	VFP_NEEDNOW	0x00000001	/* need memory now */
1145c51f124SMoriah Waterland #define	VFP_SEQUENTIAL	0x00000002	/* sequential access */
1155c51f124SMoriah Waterland #define	VFP_RANDOM	0x00000004	/* random access */
1165c51f124SMoriah Waterland #define	VFP_NOMMAP	0x00000008	/* do not use mmap to access file */
1175c51f124SMoriah Waterland #define	VFP_NOMALLOC	0x00000010	/* do not use malloc to buffer file */
1185c51f124SMoriah Waterland 
1195c51f124SMoriah Waterland /* virtual file protocol object */
1205c51f124SMoriah Waterland 
1215c51f124SMoriah Waterland typedef struct _vfp VFP_T;
1225c51f124SMoriah Waterland 
1235c51f124SMoriah Waterland /* structure behind the virtual file protocol object */
1245c51f124SMoriah Waterland 
1255c51f124SMoriah Waterland struct _vfp {
1265c51f124SMoriah Waterland 	FILE		*_vfpFile;	/* -> opened FILE */
1275c51f124SMoriah Waterland 	char		*_vfpCurr;	/* -> current byte to read/write */
1285c51f124SMoriah Waterland 	char		*_vfpHighWater;	/* -> last byte modified */
1295c51f124SMoriah Waterland 	char		*_vfpEnd;	/* -> last data byte */
1305c51f124SMoriah Waterland 	char		*_vfpPath;	/* -> path associated with FILE */
1315c51f124SMoriah Waterland 	char		*_vfpStart;	/* -> first data byte */
1325c51f124SMoriah Waterland 	void		*_vfpExtra;	/* undefined */
1335c51f124SMoriah Waterland 	size_t		_vfpSize;	/* size of mapped/allocated area */
1345c51f124SMoriah Waterland 	size_t		_vfpMapSize;	/* # mapped bytes */
1355c51f124SMoriah Waterland 	VFPFLAGS_T	_vfpFlags;	/* flags associated with vfp/data */
1365c51f124SMoriah Waterland 	int		_vfpOverflow;	/* non-zero if buffer write overflow */
1375c51f124SMoriah Waterland 	blkcnt_t	_vfpCkStBlocks;	/* checkpoint # blocks */
1385c51f124SMoriah Waterland 	dev_t		_vfpCkDev;	/* checkpoint device i.d. */
1395c51f124SMoriah Waterland 	ino_t		_vfpCkIno;	/* checkpoint inode # */
1405c51f124SMoriah Waterland 	off_t		_vfpCkSize;	/* checkpoint size */
1415c51f124SMoriah Waterland 	time_t		_vfpCkMtime;	/* checkpoint modification time */
1425c51f124SMoriah Waterland };
1435c51f124SMoriah Waterland 
1445c51f124SMoriah Waterland /*
1455c51f124SMoriah Waterland  * get highest modified byte (length) contained in vfp
1465c51f124SMoriah Waterland  *
1475c51f124SMoriah Waterland  * determine number of bytes to write - it will be the highest of:
1485c51f124SMoriah Waterland  *  -- the current pointer into the file - this is updated whenever
1495c51f124SMoriah Waterland  *	the location of the file is changed by a single byte
1505c51f124SMoriah Waterland  *  -- the last "high water mark" - the last known location that
1515c51f124SMoriah Waterland  *	was written to the file - updated only when the location
1525c51f124SMoriah Waterland  *	of the file is directly changed - e.g. vfpSetCurrCharPtr,
1535c51f124SMoriah Waterland  *	vfpTruncate, vfpRewind.
1545c51f124SMoriah Waterland  * this reduces the "bookkeeping" that needs to be done to know
1555c51f124SMoriah Waterland  * how many bytes to write out to the file - typically a file is
1565c51f124SMoriah Waterland  * written sequentially so the current file pointer is sufficient
1575c51f124SMoriah Waterland  * to determine how many bytes to write out.
1585c51f124SMoriah Waterland  */
1595c51f124SMoriah Waterland 
1605c51f124SMoriah Waterland #define	vfpGetModifiedLen(VFP)						\
1615c51f124SMoriah Waterland 	(size_t)(((VFP)->_vfpHighWater > (VFP)->_vfpCurr) ?		\
1625c51f124SMoriah Waterland 		(((ptrdiff_t)(VFP)->_vfpHighWater -			\
1635c51f124SMoriah Waterland 				(ptrdiff_t)(VFP)->_vfpStart)) :		\
1645c51f124SMoriah Waterland 		(((ptrdiff_t)(VFP)->_vfpCurr -				\
1655c51f124SMoriah Waterland 				(ptrdiff_t)(VFP)->_vfpStart)))
1665c51f124SMoriah Waterland 
1675c51f124SMoriah Waterland /*
1685c51f124SMoriah Waterland  * increment current pointer by specified delta
1695c51f124SMoriah Waterland  * if the delta exceeds the buffer size, set pointer to buffer end
1705c51f124SMoriah Waterland  */
1715c51f124SMoriah Waterland #define	vfpIncCurrPtrBy(VFP, INC)					\
1725c51f124SMoriah Waterland 	{								\
1735c51f124SMoriah Waterland 		((VFP)->_vfpCurr) += (INC);				\
1745c51f124SMoriah Waterland 		if (((VFP)->_vfpCurr) > ((VFP)->_vfpEnd)) {		\
1755c51f124SMoriah Waterland 			(VFP)->_vfpCurr = (VFP)->_vfpEnd;		\
1765c51f124SMoriah Waterland 			(VFP)->_vfpOverflow = 1;			\
1775c51f124SMoriah Waterland 		}							\
1785c51f124SMoriah Waterland 		if ((VFP)->_vfpHighWater < (VFP)->_vfpCurr) {		\
1795c51f124SMoriah Waterland 			(VFP)->_vfpHighWater = (VFP)->_vfpCurr;		\
1805c51f124SMoriah Waterland 		}							\
1815c51f124SMoriah Waterland 	}
1825c51f124SMoriah Waterland 
1835c51f124SMoriah Waterland /* get the path associated with the vfp */
1845c51f124SMoriah Waterland #define	vfpGetPath(VFP)		((VFP)->_vfpPath)
1855c51f124SMoriah Waterland 
1865c51f124SMoriah Waterland /* get a string from the vfp into a fixed size buffer */
1875c51f124SMoriah Waterland #define	vfpGets(VFP, PTR, LEN)						\
1885c51f124SMoriah Waterland 	{								\
1895c51f124SMoriah Waterland 		char	*XXpXX = (PTR);					\
1905c51f124SMoriah Waterland 		size_t	XXlXX = (LEN);					\
1915c51f124SMoriah Waterland 		while ((*(VFP)->_vfpCurr != '\0') &&			\
1925c51f124SMoriah Waterland 				(*(VFP)->_vfpCurr != '\n')) {		\
1935c51f124SMoriah Waterland 			if (XXlXX > 1) {				\
1945c51f124SMoriah Waterland 				*XXpXX++ = *(VFP)->_vfpCurr;		\
1955c51f124SMoriah Waterland 				XXlXX--;				\
1965c51f124SMoriah Waterland 			}						\
1975c51f124SMoriah Waterland 			(VFP)->_vfpCurr++;				\
1985c51f124SMoriah Waterland 		}							\
1995c51f124SMoriah Waterland 		*XXpXX++ = '\0';					\
2005c51f124SMoriah Waterland 		if (*(VFP)->_vfpCurr != '\0') {				\
2015c51f124SMoriah Waterland 			(VFP)->_vfpCurr++;				\
2025c51f124SMoriah Waterland 		}							\
2035c51f124SMoriah Waterland 	}
2045c51f124SMoriah Waterland 
2055c51f124SMoriah Waterland /* get number of bytes remaining to read */
2065c51f124SMoriah Waterland #define	vfpGetBytesRemaining(VFP)	\
2075c51f124SMoriah Waterland 	(((((VFP)->_vfpHighWater) <= ((VFP)->_vfpCurr))) ? 0 : 		\
2085c51f124SMoriah Waterland 	((((ptrdiff_t)(VFP)->_vfpHighWater)-((ptrdiff_t)(VFP)->_vfpCurr))))
2095c51f124SMoriah Waterland 
2105c51f124SMoriah Waterland /* get number of bytes remaining to write */
2115c51f124SMoriah Waterland #define	vfpGetBytesAvailable(VFP)	\
2125c51f124SMoriah Waterland 	(((((VFP)->_vfpEnd) <= ((VFP)->_vfpCurr))) ? 0 : 		\
2135c51f124SMoriah Waterland 	((((ptrdiff_t)(VFP)->_vfpEnd)-((ptrdiff_t)(VFP)->_vfpCurr))))
2145c51f124SMoriah Waterland 
2155c51f124SMoriah Waterland /* put current character and increment to next */
2165c51f124SMoriah Waterland #define	vfpPutc(VFP, C)							\
2175c51f124SMoriah Waterland 	{								\
2185c51f124SMoriah Waterland 		(*(VFP)->_vfpCurr) = ((char)(C));			\
2195c51f124SMoriah Waterland 		vfpIncCurrPtrBy((VFP), 1);				\
2205c51f124SMoriah Waterland 	}
2215c51f124SMoriah Waterland 
2225c51f124SMoriah Waterland /* put integer to current character and increment */
2235c51f124SMoriah Waterland #define	vfpPutInteger(VFP, NUMBER)	vfpPutFormat((VFP), "%d", (NUMBER))
2245c51f124SMoriah Waterland 
2255c51f124SMoriah Waterland /* put long to current character and increment */
2265c51f124SMoriah Waterland #define	vfpPutLong(VFP, NUMBER)	vfpPutFormat((VFP), "%ld", (NUMBER))
2275c51f124SMoriah Waterland 
2285c51f124SMoriah Waterland /* get current character and increment to next */
2295c51f124SMoriah Waterland #define	vfpGetc(VFP)		(*(VFP)->_vfpCurr++)
2305c51f124SMoriah Waterland 
2315c51f124SMoriah Waterland /* get current character - do not increment */
2325c51f124SMoriah Waterland #define	vfpGetcNoInc(VFP)	(*(VFP)->_vfpCurr)
2335c51f124SMoriah Waterland 
2345c51f124SMoriah Waterland /* get pointer to current character */
2355c51f124SMoriah Waterland #define	vfpGetCurrCharPtr(VFP)	((VFP)->_vfpCurr)
2365c51f124SMoriah Waterland 
2375c51f124SMoriah Waterland /* increment current character pointer */
2385c51f124SMoriah Waterland #define	vfpIncCurrPtr(VFP)	vfpIncCurrPtrBy((VFP), 1)
2395c51f124SMoriah Waterland 
2405c51f124SMoriah Waterland /* decrement current character pointer */
2415c51f124SMoriah Waterland #define	vfpDecCurrPtr(VFP)	((VFP)->_vfpCurr--)
2425c51f124SMoriah Waterland 
2435c51f124SMoriah Waterland /* get pointer to first data byte in buffer */
2445c51f124SMoriah Waterland #define	vfpGetFirstCharPtr(VFP)	((VFP)->_vfpStart)
2455c51f124SMoriah Waterland 
2465c51f124SMoriah Waterland /* get pointer to last data byte in buffer */
2475c51f124SMoriah Waterland #define	vfpGetLastCharPtr(VFP)	((VFP)->_vfpHighWater)
2485c51f124SMoriah Waterland 
2495c51f124SMoriah Waterland /* set pointer to current character */
2505c51f124SMoriah Waterland #define	vfpSetCurrCharPtr(VFP, PTR)					\
2515c51f124SMoriah Waterland 	if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) {			\
2525c51f124SMoriah Waterland 		(VFP)->_vfpHighWater = (VFP)->_vfpCurr;			\
2535c51f124SMoriah Waterland 	}								\
2545c51f124SMoriah Waterland 	((VFP)->_vfpCurr = (PTR))
2555c51f124SMoriah Waterland 
2565c51f124SMoriah Waterland /* set pointer to last data byte in buffer */
2575c51f124SMoriah Waterland #define	vfpSetLastCharPtr(VFP, PTR)					\
2585c51f124SMoriah Waterland 	if ((PTR) >= (VFP)->_vfpStart) {				\
2595c51f124SMoriah Waterland 		(VFP)->_vfpHighWater = (PTR);				\
2605c51f124SMoriah Waterland 		if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) {		\
2615c51f124SMoriah Waterland 			(VFP)->_vfpCurr = (VFP)->_vfpHighWater;		\
2625c51f124SMoriah Waterland 		}							\
2635c51f124SMoriah Waterland 	}
2645c51f124SMoriah Waterland 
2655c51f124SMoriah Waterland /* seek to end of file - one past last data byte in file */
2665c51f124SMoriah Waterland #define	vfpSeekToEnd(VFP)	((VFP)->_vfpCurr = ((VFP)->_vfpHighWater)+1)
2675c51f124SMoriah Waterland 
2685c51f124SMoriah Waterland /* get number of bytes between current char and specified char */
2695c51f124SMoriah Waterland #define	vfpGetCurrPtrDelta(VFP, P)	\
2705c51f124SMoriah Waterland 	(((ptrdiff_t)(P))-((ptrdiff_t)(VFP)->_vfpCurr))
2715c51f124SMoriah Waterland 
2725c51f124SMoriah Waterland /* put string to current character and increment */
2735c51f124SMoriah Waterland #define	vfpPuts(VFP, S)							\
2745c51f124SMoriah Waterland 	{								\
2755c51f124SMoriah Waterland 		size_t	xxLen;						\
2765c51f124SMoriah Waterland 		size_t	xxResult;					\
2775c51f124SMoriah Waterland 		xxLen = vfpGetBytesAvailable((VFP));			\
2785c51f124SMoriah Waterland 		xxResult = strlcpy(((VFP)->_vfpCurr), (S), xxLen);	\
2795c51f124SMoriah Waterland 		vfpIncCurrPtrBy((VFP), xxResult);			\
2805c51f124SMoriah Waterland 	}
2815c51f124SMoriah Waterland 
2825c51f124SMoriah Waterland /* put fixed number of bytes to current character and increment */
2835c51f124SMoriah Waterland #define	vfpPutBytes(VFP, PTR, LEN)					\
2845c51f124SMoriah Waterland 	{								\
2855c51f124SMoriah Waterland 		size_t	xxLen;						\
2865c51f124SMoriah Waterland 		xxLen = vfpGetBytesAvailable((VFP));			\
2875c51f124SMoriah Waterland 		if (xxLen > (LEN)) {					\
2885c51f124SMoriah Waterland 			xxLen = (LEN);					\
2895c51f124SMoriah Waterland 		} else {						\
2905c51f124SMoriah Waterland 			(VFP)->_vfpOverflow = 1;			\
2915c51f124SMoriah Waterland 		}							\
2925c51f124SMoriah Waterland 		memcpy((VFP)->_vfpCurr, (PTR), (xxLen));		\
2935c51f124SMoriah Waterland 		vfpIncCurrPtrBy((VFP), (xxLen));			\
2945c51f124SMoriah Waterland 	}
2955c51f124SMoriah Waterland 
2965c51f124SMoriah Waterland /* put format one arg to current character and increment */
2975c51f124SMoriah Waterland #define	vfpPutFormat(VFP, FORMAT, ARG)					\
2985c51f124SMoriah Waterland 	{								\
2995c51f124SMoriah Waterland 	char	xxTeMpXX[256];						\
3005c51f124SMoriah Waterland 	(void) snprintf(xxTeMpXX, sizeof (xxTeMpXX), (FORMAT), (ARG));	\
3015c51f124SMoriah Waterland 	vfpPuts((VFP), xxTeMpXX);					\
3025c51f124SMoriah Waterland 	}
3035c51f124SMoriah Waterland 
3045c51f124SMoriah Waterland struct dm_buf {
3055c51f124SMoriah Waterland 	char *text_buffer;	/* start of allocated buffer */
3065c51f124SMoriah Waterland 	int offset;		/* number of bytes into the text_buffer */
3075c51f124SMoriah Waterland 	int allocation;		/* size of buffer in bytes */
3085c51f124SMoriah Waterland };
3095c51f124SMoriah Waterland 
3105c51f124SMoriah Waterland /* This structure is used to hold a dynamically growing string */
3115c51f124SMoriah Waterland 
3125c51f124SMoriah Waterland struct dstr {
3135c51f124SMoriah Waterland 	char *pc;
3145c51f124SMoriah Waterland 	int   len;
3155c51f124SMoriah Waterland 	int   max;
3165c51f124SMoriah Waterland };
3175c51f124SMoriah Waterland 
3185c51f124SMoriah Waterland /* setmapmode() defines */
3195c51f124SMoriah Waterland #define	MAPALL		0	/* resolve all variables */
3205c51f124SMoriah Waterland #define	MAPBUILD	1	/* map only build variables */
3215c51f124SMoriah Waterland #define	MAPINSTALL	2	/* map only install variables */
3225c51f124SMoriah Waterland #define	MAPNONE		3	/* map no variables */
3235c51f124SMoriah Waterland 
3245c51f124SMoriah Waterland #define	NON_ABI_NAMELNGTH	33	/* 32 chars for name + 1 for NULL */
3255c51f124SMoriah Waterland 
3265c51f124SMoriah Waterland #define	BLK_SIZE	512	/* size of logical block */
3275c51f124SMoriah Waterland 
3285c51f124SMoriah Waterland /* max length for printed attributes */
3295c51f124SMoriah Waterland #define	ATTR_MAX	80
3305c51f124SMoriah Waterland 
3315c51f124SMoriah Waterland /*
3325c51f124SMoriah Waterland  * These three defines indicate that the prototype file contains a '?'
3335c51f124SMoriah Waterland  * meaning do not specify this data in the pkgmap entry.
3345c51f124SMoriah Waterland  */
3355c51f124SMoriah Waterland #define	CURMODE		BADMODE		/* current mode has been specified */
3365c51f124SMoriah Waterland #define	CUROWNER	BADOWNER	/* ... same for owner ... */
3375c51f124SMoriah Waterland #define	CURGROUP	BADGROUP	/* ... and group. */
3385c51f124SMoriah Waterland 
3395c51f124SMoriah Waterland #define	WILDCARD		BADMODE >> 1
3405c51f124SMoriah Waterland #define	DB_UNDEFINED_ENTRY	"?"
3415c51f124SMoriah Waterland 
3425c51f124SMoriah Waterland #define	DEFAULT_MODE		0755
3435c51f124SMoriah Waterland #define	DEFAULT_MODE_FILE	0644
3445c51f124SMoriah Waterland #define	DEFAULT_OWNER	"root"
3455c51f124SMoriah Waterland #define	DEFAULT_GROUP	"other"
3465c51f124SMoriah Waterland 
3475c51f124SMoriah Waterland #define	INST_RELEASE "var/sadm/system/admin/INST_RELEASE"
3485c51f124SMoriah Waterland 
3495c51f124SMoriah Waterland #define	RANDOM			"/dev/urandom"
3505c51f124SMoriah Waterland #define	BLOCK			256
3515c51f124SMoriah Waterland 
3525c51f124SMoriah Waterland #define	TERM_WIDTH		60
3535c51f124SMoriah Waterland #define	SMALL_DIVISOR		4
3545c51f124SMoriah Waterland #define	MED_DIVISOR		5
3555c51f124SMoriah Waterland #define	LARGE_DIVISOR		10
3565c51f124SMoriah Waterland 
3575c51f124SMoriah Waterland #define	PKGADD			"pkgadd"
3585c51f124SMoriah Waterland 
3595c51f124SMoriah Waterland /* package header magic tokens */
3605c51f124SMoriah Waterland #define	HDR_PREFIX	"# PaCkAgE DaTaStReAm"
3615c51f124SMoriah Waterland #define	HDR_SUFFIX	"# end of header"
3625c51f124SMoriah Waterland 
3635c51f124SMoriah Waterland #define	GROUP	"/etc/group"
3645c51f124SMoriah Waterland #define	PASSWD	"/etc/passwd"
3655c51f124SMoriah Waterland 
3665c51f124SMoriah Waterland /*
3675c51f124SMoriah Waterland  * The next three mean that no mode, owner or group was specified or that the
3685c51f124SMoriah Waterland  * one specified is invalid for some reason. Sometimes this is an error in
3695c51f124SMoriah Waterland  * which case it is generally converted to CUR* with a warning. Other times
3705c51f124SMoriah Waterland  * it means "look it up" by stating the existing file system object pointred
3715c51f124SMoriah Waterland  * to in the prototype file.
3725c51f124SMoriah Waterland  */
3735c51f124SMoriah Waterland #define	NOMODE		(BADMODE-1)
3745c51f124SMoriah Waterland #define	NOOWNER		"@"
3755c51f124SMoriah Waterland #define	NOGROUP		"@"
3765c51f124SMoriah Waterland 
3775c51f124SMoriah Waterland /* string comparitor abbreviators */
3785c51f124SMoriah Waterland 
3795c51f124SMoriah Waterland #define	ci_streq(a, b)		(strcasecmp((a), (b)) == 0)
3805c51f124SMoriah Waterland #define	ci_strneq(a, b, c)	(strncasecmp((a), (b), (c)) == 0)
3815c51f124SMoriah Waterland #define	streq(a, b)		(strcmp((a), (b)) == 0)
3825c51f124SMoriah Waterland #define	strneq(a, b, c)		(strncmp((a), (b), (c)) == 0)
3835c51f124SMoriah Waterland 
3845c51f124SMoriah Waterland extern FILE	*epopen(char *cmd, char *mode);
3855c51f124SMoriah Waterland extern char	**gpkglist(char *dir, char **pkg, char **catg);
3865c51f124SMoriah Waterland extern int	is_not_valid_length(char **category);
3875c51f124SMoriah Waterland extern int	is_not_valid_category(char **category, char *progname);
3885c51f124SMoriah Waterland extern int	is_same_CATEGORY(char **category, char *installed_category);
3895c51f124SMoriah Waterland extern char **get_categories(char *catg_arg);
3905c51f124SMoriah Waterland 
3915c51f124SMoriah Waterland extern void	pkglist_cont(char *keyword);
3925c51f124SMoriah Waterland extern char	**pkgalias(char *pkg);
3935c51f124SMoriah Waterland extern char	*get_prog_name(void);
3945c51f124SMoriah Waterland extern char 	*set_prog_name(char *name);
3955c51f124SMoriah Waterland extern int	averify(int fix, char *ftype, char *path, struct ainfo *ainfo);
3965c51f124SMoriah Waterland extern int	ckparam(char *param, char *value);
3975c51f124SMoriah Waterland extern int	ckvolseq(char *dir, int part, int nparts);
3985c51f124SMoriah Waterland extern int	cverify(int fix, char *ftype, char *path, struct cinfo *cinfo,
3995c51f124SMoriah Waterland 			int allow_checksum);
4005c51f124SMoriah Waterland extern unsigned long	compute_checksum(int *r_cksumerr, char *a_path);
4015c51f124SMoriah Waterland extern int	fverify(int fix, char *ftype, char *path, struct ainfo *ainfo,
4025c51f124SMoriah Waterland 		    struct cinfo *cinfo);
4035c51f124SMoriah Waterland extern char	*getErrbufAddr(void);
4045c51f124SMoriah Waterland extern int	getErrbufSize(void);
4055c51f124SMoriah Waterland extern char	*getErrstr(void);
4065c51f124SMoriah Waterland extern void	setErrstr(char *errstr);
4075c51f124SMoriah Waterland extern int	devtype(char *alias, struct pkgdev *devp);
4085c51f124SMoriah Waterland extern int	ds_totread;	/* total number of parts read */
4095c51f124SMoriah Waterland extern int	ds_close(int pkgendflg);
4105c51f124SMoriah Waterland extern int	ds_findpkg(char *device, char *pkg);
4115c51f124SMoriah Waterland extern int	ds_getinfo(char *string);
4125c51f124SMoriah Waterland extern int	ds_getpkg(char *device, int n, char *dstdir);
4135c51f124SMoriah Waterland extern int	ds_ginit(char *device);
4145c51f124SMoriah Waterland extern boolean_t	ds_fd_open(void);
4155c51f124SMoriah Waterland extern int	ds_init(char *device, char **pkg, char *norewind);
4165c51f124SMoriah Waterland extern int	ds_next(char *, char *);
4175c51f124SMoriah Waterland extern int	ds_readbuf(char *device);
4185c51f124SMoriah Waterland extern int	epclose(FILE *pp);
4195c51f124SMoriah Waterland extern int	esystem(char *cmd, int ifd, int ofd);
4205c51f124SMoriah Waterland extern int	e_ExecCmdArray(int *r_status, char **r_results,
4215c51f124SMoriah Waterland 			char *a_inputFile, char *a_cmd, char **a_args);
4225c51f124SMoriah Waterland extern int	e_ExecCmdList(int *r_status, char **r_results,
4235c51f124SMoriah Waterland 			char *a_inputFile, char *a_cmd, ...);
4245c51f124SMoriah Waterland extern int	gpkgmap(struct cfent *ept, FILE *fp);
4255c51f124SMoriah Waterland extern int	gpkgmapvfp(struct cfent *ept, VFP_T *fpv);
4265c51f124SMoriah Waterland extern void	setmapmode(int mode_no);
4275c51f124SMoriah Waterland extern int	isFdRemote(int a_fd);
4285c51f124SMoriah Waterland extern int	isFstypeRemote(char *a_fstype);
4295c51f124SMoriah Waterland extern int	isPathRemote(char *a_path);
4305c51f124SMoriah Waterland extern int	iscpio(char *path, int *iscomp);
4315c51f124SMoriah Waterland extern int	isdir(char *path);
4325c51f124SMoriah Waterland extern int	isfile(char *dir, char *file);
4335c51f124SMoriah Waterland extern int	fmkdir(char *a_path, int a_mode);
4345c51f124SMoriah Waterland extern int	pkgexecl(char *filein, char *fileout, char *uname, char *gname,
4355c51f124SMoriah Waterland 			...);
4365c51f124SMoriah Waterland extern int	pkgexecv(char *filein, char *fileout, char *uname, char *gname,
4375c51f124SMoriah Waterland 			char *arg[]);
4385c51f124SMoriah Waterland extern int	pkghead(char *device);
4395c51f124SMoriah Waterland extern int	pkgmount(struct pkgdev *devp, char *pkg, int part, int nparts,
4405c51f124SMoriah Waterland 			int getvolflg);
4415c51f124SMoriah Waterland extern int	pkgtrans(char *device1, char *device2, char **pkg,
442*32991bedSPeter Tribble 			int options);
4435c51f124SMoriah Waterland extern int	pkgumount(struct pkgdev *devp);
4445c51f124SMoriah Waterland extern int	ppkgmap(struct cfent *ept, FILE *fp);
4455c51f124SMoriah Waterland extern int	putcfile(struct cfent *ept, FILE *fp);
4465c51f124SMoriah Waterland extern int	putcvfpfile(struct cfent *ept, VFP_T *vfp);
4475c51f124SMoriah Waterland extern int	rrmdir(char *path);
4485c51f124SMoriah Waterland extern void	set_memalloc_failure_func(void (*)(int));
4495c51f124SMoriah Waterland extern void	*xmalloc(size_t size);
4505c51f124SMoriah Waterland extern void	*xrealloc(void *ptr, size_t size);
4515c51f124SMoriah Waterland extern char	*xstrdup(char *str);
4525c51f124SMoriah Waterland 
45362224350SCasper H.S. Dik extern int	srchcfile(struct cfent *ept, char *path, PKGserver server);
4545c51f124SMoriah Waterland extern struct	group *cgrgid(gid_t gid);
4555c51f124SMoriah Waterland extern struct	group *cgrnam(char *nam);
4565c51f124SMoriah Waterland extern struct	passwd *cpwnam(char *nam);
4575c51f124SMoriah Waterland extern struct	passwd *cpwuid(uid_t uid);
4585c51f124SMoriah Waterland extern struct	group *clgrgid(gid_t gid);
4595c51f124SMoriah Waterland extern struct	group *clgrnam(char *nam);
4605c51f124SMoriah Waterland extern struct	passwd *clpwnam(char *nam);
4615c51f124SMoriah Waterland extern struct	passwd *clpwuid(uid_t uid);
4625c51f124SMoriah Waterland extern void	basepath(char *path, char *basedir, char *ir);
4635c51f124SMoriah Waterland extern void	canonize(char *file);
4645c51f124SMoriah Waterland extern void	canonize_slashes(char *file);
4655c51f124SMoriah Waterland extern void	checksum_off(void);
4665c51f124SMoriah Waterland extern void	checksum_on(void);
4675c51f124SMoriah Waterland extern void	cvtpath(char *path, char *copy);
4685c51f124SMoriah Waterland extern void	ds_order(char *list[]);
4694656d474SGarrett D'Amore extern void	ds_putinfo(char *buf, size_t);
4705c51f124SMoriah Waterland extern void	ds_skiptoend(char *device);
4715c51f124SMoriah Waterland extern void	ecleanup(void);
4725c51f124SMoriah Waterland /*PRINTFLIKE1*/
4735c51f124SMoriah Waterland extern void	logerr(char *fmt, ...);
4745c51f124SMoriah Waterland extern int	mappath(int flag, char *path);
4755c51f124SMoriah Waterland extern int	mapvar(int flag, char *varname);
4765c51f124SMoriah Waterland /*PRINTFLIKE1*/
4775c51f124SMoriah Waterland extern void	progerr(char *fmt, ...);
4785c51f124SMoriah Waterland extern void	rpterr(void);
4795c51f124SMoriah Waterland extern void	tputcfent(struct cfent *ept, FILE *fp);
4805c51f124SMoriah Waterland extern void	set_nonABI_symlinks(void);
4815c51f124SMoriah Waterland extern int	nonABI_symlinks(void);
4825c51f124SMoriah Waterland extern void	disable_attribute_check(void);
4835c51f124SMoriah Waterland extern int	get_disable_attribute_check(void);
4845c51f124SMoriah Waterland 
4855c51f124SMoriah Waterland /* pkgstr.c */
4865c51f124SMoriah Waterland void		pkgstrConvertUllToTimeString_r(unsigned long long a_time,
4875c51f124SMoriah Waterland 			char *a_buf, int a_bufLen);
4885c51f124SMoriah Waterland char		*pkgstrConvertPathToBasename(char *a_path);
4895c51f124SMoriah Waterland char		*pkgstrConvertPathToDirname(char *a_path);
4905c51f124SMoriah Waterland char		*pkgstrDup(char *a_str);
4915c51f124SMoriah Waterland char		*pkgstrLocatePathBasename(char *a_path);
4925c51f124SMoriah Waterland void		pkgstrScaleNumericString(char *a_buf, unsigned long long scale);
4935c51f124SMoriah Waterland void		pkgstrAddToken(char **a_old, char *a_new, char a_separator);
4945c51f124SMoriah Waterland boolean_t	pkgstrContainsToken(char *a_string, char *a_token,
4955c51f124SMoriah Waterland 			char *a_separators);
4965c51f124SMoriah Waterland void		pkgstrExpandTokens(char **a_old, char *a_string,
4975c51f124SMoriah Waterland 			char a_separator, char *a_separators);
4985c51f124SMoriah Waterland char		*pkgstrGetToken(char *r_sep, char *a_string, int a_index,
4995c51f124SMoriah Waterland 			char *a_separators);
5005c51f124SMoriah Waterland void		pkgstrGetToken_r(char *r_sep, char *a_string, int a_index,
5015c51f124SMoriah Waterland 			char *a_separators, char *a_buf, int a_bufLen);
5025c51f124SMoriah Waterland unsigned long	pkgstrNumTokens(char *a_string, char *a_separators);
5035c51f124SMoriah Waterland char		*pkgstrPrintf(char *a_format, ...);
5045c51f124SMoriah Waterland void		pkgstrPrintf_r(char *a_buf, int a_bufLen, char *a_format, ...);
5055c51f124SMoriah Waterland void		pkgstrRemoveToken(char **r_string, char *a_token,
5065c51f124SMoriah Waterland 			char *a_separators, int a_index);
5075c51f124SMoriah Waterland void		pkgstrRemoveLeadingWhitespace(char **a_str);
5085c51f124SMoriah Waterland /* vfpops.c */
5095c51f124SMoriah Waterland extern int	vfpCheckpointFile(VFP_T **r_destVfp, VFP_T **a_vfp,
5105c51f124SMoriah Waterland 			char *a_path);
5115c51f124SMoriah Waterland extern int	vfpCheckpointOpen(VFP_T **a_cvfp, VFP_T **r_vfp, char *a_path,
5125c51f124SMoriah Waterland 			char *a_mode, VFPFLAGS_T a_flags);
5135c51f124SMoriah Waterland extern int	vfpClearModified(VFP_T *a_vfp);
5145c51f124SMoriah Waterland extern int	vfpClose(VFP_T **r_vfp);
5155c51f124SMoriah Waterland extern int	vfpGetModified(VFP_T *a_vfp);
5165c51f124SMoriah Waterland extern int	vfpOpen(VFP_T **r_vfp, char *a_path, char *a_mode,
5175c51f124SMoriah Waterland 			VFPFLAGS_T a_flags);
5185c51f124SMoriah Waterland extern void	vfpRewind(VFP_T *a_vfp);
5195c51f124SMoriah Waterland extern ssize_t	vfpSafePwrite(int a_fildes, void *a_buf,
5205c51f124SMoriah Waterland 			size_t a_nbyte, off_t a_offset);
5215c51f124SMoriah Waterland extern ssize_t	vfpSafeWrite(int a_fildes, void *a_buf, size_t a_nbyte);
5225c51f124SMoriah Waterland extern int	vfpSetFlags(VFP_T *a_vfp, VFPFLAGS_T a_flags);
5235c51f124SMoriah Waterland extern int	vfpSetModified(VFP_T *a_vfp);
5245c51f124SMoriah Waterland extern int	vfpSetSize(VFP_T *a_vfp, size_t a_size);
5255c51f124SMoriah Waterland extern void	vfpTruncate(VFP_T *a_vfp);
5265c51f124SMoriah Waterland extern int	vfpWriteToFile(VFP_T *a_vfp, char *a_path);
5275c51f124SMoriah Waterland 
5285c51f124SMoriah Waterland /* handlelocalfs.c */
5295c51f124SMoriah Waterland boolean_t	enable_local_fs(void);
5305c51f124SMoriah Waterland boolean_t	restore_local_fs(void);
5315c51f124SMoriah Waterland 
532*32991bedSPeter Tribble /* path_valid.c */
533*32991bedSPeter Tribble extern boolean_t	path_valid(char *);
534*32991bedSPeter Tribble 
53562224350SCasper H.S. Dik /* pkgserv.c */
53662224350SCasper H.S. Dik extern PKGserver	pkgopenserver(const char *, const char *, boolean_t);
53762224350SCasper H.S. Dik extern void		pkgcloseserver(PKGserver);
53862224350SCasper H.S. Dik extern int		pkgcmd(PKGserver, void *, size_t, char **, size_t *,
53962224350SCasper H.S. Dik     int *);
54062224350SCasper H.S. Dik extern boolean_t	pkgsync_needed(const char *, const char *, boolean_t);
54162224350SCasper H.S. Dik extern int		pkgsync(const char *, const char *, boolean_t);
54262224350SCasper H.S. Dik extern int		pkgservercommitfile(VFP_T *, PKGserver);
54362224350SCasper H.S. Dik extern int		pkgopenfilter(PKGserver server, const char *pkginst);
54462224350SCasper H.S. Dik extern void		pkgclosefilter(PKGserver);
54562224350SCasper H.S. Dik extern char 		*pkggetentry(PKGserver, int *, int *);
54662224350SCasper H.S. Dik extern char 		*pkggetentry_named(PKGserver, const char *, int *,
54762224350SCasper H.S. Dik     int *);
54862224350SCasper H.S. Dik extern void		pkgserversetmode(start_mode_t);
54962224350SCasper H.S. Dik extern start_mode_t	pkgservergetmode(void);
55062224350SCasper H.S. Dik extern start_mode_t	pkgparsemode(const char *);
55162224350SCasper H.S. Dik extern char 		*pkgmodeargument(start_mode_t);
55262224350SCasper H.S. Dik 
5535c51f124SMoriah Waterland #ifdef	__cplusplus
5545c51f124SMoriah Waterland }
5555c51f124SMoriah Waterland #endif
5565c51f124SMoriah Waterland 
5575c51f124SMoriah Waterland #endif	/* _PKGLIB_H */
558