xref: /freebsd/usr.bin/ar/ar.h (revision fabed6b2bd69ac582a7af271cb50393738214154)
1d192f3d3SKai Wang /*-
21de7b4b8SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
31de7b4b8SPedro F. Giffuni  *
4d192f3d3SKai Wang  * Copyright (c) 2007 Kai Wang
5d192f3d3SKai Wang  * All rights reserved.
6d192f3d3SKai Wang  *
7d192f3d3SKai Wang  * Redistribution and use in source and binary forms, with or without
8d192f3d3SKai Wang  * modification, are permitted provided that the following conditions
9d192f3d3SKai Wang  * are met:
10d192f3d3SKai Wang  * 1. Redistributions of source code must retain the above copyright
1125f82d56SEd Maste  *    notice, this list of conditions and the following disclaimer.
12d192f3d3SKai Wang  * 2. Redistributions in binary form must reproduce the above copyright
13d192f3d3SKai Wang  *    notice, this list of conditions and the following disclaimer in the
14d192f3d3SKai Wang  *    documentation and/or other materials provided with the distribution.
15d192f3d3SKai Wang  *
1625f82d56SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1725f82d56SEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1825f82d56SEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1925f82d56SEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2025f82d56SEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2125f82d56SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2225f82d56SEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2325f82d56SEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2425f82d56SEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2525f82d56SEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2625f82d56SEd Maste  * SUCH DAMAGE.
27d192f3d3SKai Wang  *
28d192f3d3SKai Wang  * $FreeBSD$
29d192f3d3SKai Wang  */
30d192f3d3SKai Wang 
310c099281SKai Wang #define	BSDAR_VERSION	"1.1.0"
32a856b6c5SDavid E. O'Brien 
33d192f3d3SKai Wang /*
34d192f3d3SKai Wang  * ar(1) options.
35d192f3d3SKai Wang  */
36d192f3d3SKai Wang #define AR_A	0x0001		/* position-after */
37d192f3d3SKai Wang #define AR_B	0x0002		/* position-before */
38d192f3d3SKai Wang #define AR_C	0x0004		/* creating new archive */
39d192f3d3SKai Wang #define AR_CC	0x0008		/* do not overwrite when extracting */
40d192f3d3SKai Wang #define AR_J	0x0010		/* bzip2 compression */
41d192f3d3SKai Wang #define AR_O	0x0020		/* preserve original mtime when extracting */
42d192f3d3SKai Wang #define AR_S	0x0040		/* write archive symbol table */
43d192f3d3SKai Wang #define AR_SS	0x0080		/* do not write archive symbol table */
44d192f3d3SKai Wang #define AR_TR	0x0100		/* only keep first 15 chars for member name */
45d192f3d3SKai Wang #define AR_U	0x0200		/* only extract or update newer members.*/
46d192f3d3SKai Wang #define AR_V	0x0400		/* verbose mode */
47d192f3d3SKai Wang #define AR_Z	0x0800		/* gzip compression */
480e479ac8STim Kientzle #define AR_D	0x1000		/* insert dummy mode, mtime, uid and gid */
49d192f3d3SKai Wang 
50d192f3d3SKai Wang #define DEF_BLKSZ 10240		/* default block size */
51d192f3d3SKai Wang 
52d192f3d3SKai Wang /*
53d192f3d3SKai Wang  * Convenient wrapper for general libarchive error handling.
54d192f3d3SKai Wang  */
55d192f3d3SKai Wang #define	AC(CALL) do {							\
56d192f3d3SKai Wang 	if ((CALL))							\
57ccd8660bSEd Maste 		bsdar_errc(bsdar, EX_SOFTWARE, archive_errno(a), "%s",	\
58d192f3d3SKai Wang 		    archive_error_string(a));				\
59d192f3d3SKai Wang } while (0)
60d192f3d3SKai Wang 
61d192f3d3SKai Wang /*
62d192f3d3SKai Wang  * In-memory representation of archive member(object).
63d192f3d3SKai Wang  */
64d192f3d3SKai Wang struct ar_obj {
65d192f3d3SKai Wang 	char		 *name;		/* member name */
66d192f3d3SKai Wang 	void		 *maddr;	/* mmap start address */
67d192f3d3SKai Wang 	uid_t		  uid;		/* user id */
68d192f3d3SKai Wang 	gid_t		  gid;		/* group id */
69d192f3d3SKai Wang 	mode_t		  md;		/* octal file permissions */
70d192f3d3SKai Wang 	size_t		  size;		/* member size */
71d192f3d3SKai Wang 	time_t		  mtime;	/* modification time */
72d192f3d3SKai Wang 	int		  fd;		/* file descriptor */
73d192f3d3SKai Wang 	dev_t		  dev;		/* inode's device */
74d192f3d3SKai Wang 	ino_t		  ino;		/* inode's number */
75d192f3d3SKai Wang 
76d192f3d3SKai Wang 	TAILQ_ENTRY(ar_obj) objs;
77d192f3d3SKai Wang };
78d192f3d3SKai Wang 
79d192f3d3SKai Wang /*
80d192f3d3SKai Wang  * Structure encapsulates the "global" data for "ar" program.
81d192f3d3SKai Wang  */
82d192f3d3SKai Wang struct bsdar {
83d192f3d3SKai Wang 	const char	 *filename;	/* archive name. */
840c099281SKai Wang 	const char	 *addlib;	/* target of ADDLIB. */
85d192f3d3SKai Wang 	const char	 *posarg;	/* position arg for modifiers -a, -b. */
86d192f3d3SKai Wang 	char		  mode;		/* program mode */
87d192f3d3SKai Wang 	int		  options;	/* command line options */
88d192f3d3SKai Wang 
89d192f3d3SKai Wang 	const char	 *progname;	/* program name */
90d192f3d3SKai Wang 	int		  argc;
91d192f3d3SKai Wang 	char		**argv;
92d192f3d3SKai Wang 
93d192f3d3SKai Wang 	/*
94d192f3d3SKai Wang 	 * Fields for the archive string table.
95d192f3d3SKai Wang 	 */
96d192f3d3SKai Wang 	char		 *as;		/* buffer for archive string table. */
97d192f3d3SKai Wang 	size_t		  as_sz;	/* current size of as table. */
98d192f3d3SKai Wang 	size_t		  as_cap;	/* capacity of as table buffer. */
99d192f3d3SKai Wang 
100d192f3d3SKai Wang 	/*
101d192f3d3SKai Wang 	 * Fields for the archive symbol table.
102d192f3d3SKai Wang 	 */
103*fabed6b2SEd Maste 	uint64_t	  s_cnt;	/* current number of symbols. */
104*fabed6b2SEd Maste 	uint64_t	 *s_so;		/* symbol offset table. */
105*fabed6b2SEd Maste 	uint64_t	  s_so_max;     /* maximum symbol offset. */
106d192f3d3SKai Wang 	size_t		  s_so_cap;	/* capacity of so table buffer. */
107*fabed6b2SEd Maste 
108d192f3d3SKai Wang 	char		 *s_sn;		/* symbol name table */
109d192f3d3SKai Wang 	size_t		  s_sn_cap;	/* capacity of sn table buffer. */
110d192f3d3SKai Wang 	size_t		  s_sn_sz;	/* current size of sn table. */
111d192f3d3SKai Wang 	/* Current member's offset (relative to the end of pseudo members.) */
112d192f3d3SKai Wang 	off_t		  rela_off;
113d192f3d3SKai Wang 
114d192f3d3SKai Wang 	TAILQ_HEAD(, ar_obj) v_obj;	/* object(member) list */
115d192f3d3SKai Wang };
116d192f3d3SKai Wang 
117d192f3d3SKai Wang void	bsdar_errc(struct bsdar *, int _eval, int _code,
1185d08632eSEitan Adler 	    const char *fmt, ...) __dead2;
119d192f3d3SKai Wang void	bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
120d192f3d3SKai Wang void	ar_mode_d(struct bsdar *bsdar);
121d192f3d3SKai Wang void	ar_mode_m(struct bsdar *bsdar);
122d192f3d3SKai Wang void	ar_mode_p(struct bsdar *bsdar);
123cb0dad38SKai Wang void	ar_mode_q(struct bsdar *bsdar);
124d192f3d3SKai Wang void	ar_mode_r(struct bsdar *bsdar);
125d192f3d3SKai Wang void	ar_mode_s(struct bsdar *bsdar);
126d192f3d3SKai Wang void	ar_mode_t(struct bsdar *bsdar);
127d192f3d3SKai Wang void	ar_mode_x(struct bsdar *bsdar);
1280c099281SKai Wang void	ar_mode_A(struct bsdar *bsdar);
1290c099281SKai Wang void	ar_mode_script(struct bsdar *ar);
130