ar.h revision 176434
1176434Skaiw/*-
2176434Skaiw * Copyright (c) 2007 Kai Wang
3176434Skaiw * All rights reserved.
4176434Skaiw *
5176434Skaiw * Redistribution and use in source and binary forms, with or without
6176434Skaiw * modification, are permitted provided that the following conditions
7176434Skaiw * are met:
8176434Skaiw * 1. Redistributions of source code must retain the above copyright
9176434Skaiw *    notice, this list of conditions and the following disclaimer
10176434Skaiw *    in this position and unchanged.
11176434Skaiw * 2. Redistributions in binary form must reproduce the above copyright
12176434Skaiw *    notice, this list of conditions and the following disclaimer in the
13176434Skaiw *    documentation and/or other materials provided with the distribution.
14176434Skaiw *
15176434Skaiw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16176434Skaiw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17176434Skaiw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18176434Skaiw * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19176434Skaiw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20176434Skaiw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21176434Skaiw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22176434Skaiw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23176434Skaiw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24176434Skaiw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25176434Skaiw *
26176434Skaiw * $FreeBSD: head/usr.bin/ar/ar.h 176434 2008-02-21 10:52:31Z kaiw $
27176434Skaiw */
28176434Skaiw
29176434Skaiw/*
30176434Skaiw * ar(1) options.
31176434Skaiw */
32176434Skaiw#define AR_A	0x0001		/* position-after */
33176434Skaiw#define AR_B	0x0002		/* position-before */
34176434Skaiw#define AR_C	0x0004		/* creating new archive */
35176434Skaiw#define AR_CC	0x0008		/* do not overwrite when extracting */
36176434Skaiw#define AR_J	0x0010		/* bzip2 compression */
37176434Skaiw#define AR_O	0x0020		/* preserve original mtime when extracting */
38176434Skaiw#define AR_S	0x0040		/* write archive symbol table */
39176434Skaiw#define AR_SS	0x0080		/* do not write archive symbol table */
40176434Skaiw#define AR_TR	0x0100		/* only keep first 15 chars for member name */
41176434Skaiw#define AR_U	0x0200		/* only extract or update newer members.*/
42176434Skaiw#define AR_V	0x0400		/* verbose mode */
43176434Skaiw#define AR_Z	0x0800		/* gzip compression */
44176434Skaiw
45176434Skaiw#define DEF_BLKSZ 10240		/* default block size */
46176434Skaiw
47176434Skaiw/*
48176434Skaiw * Convenient wrapper for general libarchive error handling.
49176434Skaiw */
50176434Skaiw#define	AC(CALL) do {					\
51176434Skaiw	if ((CALL))					\
52176434Skaiw		bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s",	\
53176434Skaiw		    archive_error_string(a));		\
54176434Skaiw} while (0)
55176434Skaiw
56176434Skaiw/*
57176434Skaiw * In-memory representation of archive member(object).
58176434Skaiw */
59176434Skaiwstruct ar_obj {
60176434Skaiw	char		 *name;		/* member name */
61176434Skaiw	void		 *maddr;	/* mmap start address */
62176434Skaiw	uid_t		  uid;		/* user id */
63176434Skaiw	gid_t		  gid;		/* group id */
64176434Skaiw	mode_t		  md;		/* octal file permissions */
65176434Skaiw	size_t		  size;		/* member size */
66176434Skaiw	time_t		  mtime;	/* modification time */
67176434Skaiw	int		  fd;		/* file descriptor */
68176434Skaiw	dev_t		  dev;		/* inode's device */
69176434Skaiw	ino_t		  ino;		/* inode's number */
70176434Skaiw
71176434Skaiw	TAILQ_ENTRY(ar_obj) objs;
72176434Skaiw};
73176434Skaiw
74176434Skaiw/*
75176434Skaiw * Structure encapsulates the "global" data for "ar" program.
76176434Skaiw */
77176434Skaiwstruct bsdar {
78176434Skaiw	const char	 *filename;	/* archive name. */
79176434Skaiw	const char	 *posarg;	/* position arg for modifiers -a, -b. */
80176434Skaiw	char		  mode;		/* program mode */
81176434Skaiw	char		  compression;	/* compression mode */
82176434Skaiw	int		  options;	/* command line options */
83176434Skaiw
84176434Skaiw	const char	 *progname;	/* program name */
85176434Skaiw	int		  argc;
86176434Skaiw	char		**argv;
87176434Skaiw
88176434Skaiw	/*
89176434Skaiw	 * Fields for the archive string table.
90176434Skaiw	 */
91176434Skaiw	char		 *as;		/* buffer for archive string table. */
92176434Skaiw	size_t		  as_sz;	/* current size of as table. */
93176434Skaiw	size_t		  as_cap;	/* capacity of as table buffer. */
94176434Skaiw
95176434Skaiw	/*
96176434Skaiw	 * Fields for the archive symbol table.
97176434Skaiw	 */
98176434Skaiw	uint32_t	  s_cnt;	/* current number of symbols. */
99176434Skaiw	uint32_t	 *s_so;		/* symbol offset table. */
100176434Skaiw	size_t		  s_so_cap;	/* capacity of so table buffer. */
101176434Skaiw	char		 *s_sn;		/* symbol name table */
102176434Skaiw	size_t		  s_sn_cap;	/* capacity of sn table buffer. */
103176434Skaiw	size_t		  s_sn_sz;	/* current size of sn table. */
104176434Skaiw	/* Current member's offset (relative to the end of pseudo members.) */
105176434Skaiw	off_t		  rela_off;
106176434Skaiw
107176434Skaiw	TAILQ_HEAD(, ar_obj) v_obj;	/* object(member) list */
108176434Skaiw};
109176434Skaiw
110176434Skaiwvoid	bsdar_errc(struct bsdar *, int _eval, int _code,
111176434Skaiw	    const char *fmt, ...);
112176434Skaiwvoid	bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
113176434Skaiwvoid	ar_mode_d(struct bsdar *bsdar);
114176434Skaiwvoid	ar_mode_m(struct bsdar *bsdar);
115176434Skaiwvoid	ar_mode_p(struct bsdar *bsdar);
116176434Skaiwvoid	ar_mode_r(struct bsdar *bsdar);
117176434Skaiwvoid	ar_mode_s(struct bsdar *bsdar);
118176434Skaiwvoid	ar_mode_t(struct bsdar *bsdar);
119176434Skaiwvoid	ar_mode_x(struct bsdar *bsdar);
120