ar.h revision 272461
1156283Srwatson/*- 2156283Srwatson * Copyright (c) 2007 Kai Wang 3156283Srwatson * All rights reserved. 4156283Srwatson * 5156283Srwatson * Redistribution and use in source and binary forms, with or without 6156283Srwatson * modification, are permitted provided that the following conditions 7156283Srwatson * are met: 8156283Srwatson * 1. Redistributions of source code must retain the above copyright 9156283Srwatson * notice, this list of conditions and the following disclaimer 10156283Srwatson * in this position and unchanged. 11156283Srwatson * 2. Redistributions in binary form must reproduce the above copyright 12156283Srwatson * notice, this list of conditions and the following disclaimer in the 13156283Srwatson * documentation and/or other materials provided with the distribution. 14156283Srwatson * 15156283Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16156283Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17156283Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18156283Srwatson * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19156283Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20156283Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21156283Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22156283Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23156283Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24156283Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25156283Srwatson * 26156283Srwatson * $FreeBSD: releng/10.1/usr.bin/ar/ar.h 241827 2012-10-22 02:12:06Z eadler $ 27156283Srwatson */ 28156283Srwatson 29156283Srwatson#define BSDAR_VERSION "1.1.0" 30156283Srwatson 31156283Srwatson/* 32156283Srwatson * ar(1) options. 33156283Srwatson */ 34156283Srwatson#define AR_A 0x0001 /* position-after */ 35156283Srwatson#define AR_B 0x0002 /* position-before */ 36156283Srwatson#define AR_C 0x0004 /* creating new archive */ 37156283Srwatson#define AR_CC 0x0008 /* do not overwrite when extracting */ 38156283Srwatson#define AR_J 0x0010 /* bzip2 compression */ 39156283Srwatson#define AR_O 0x0020 /* preserve original mtime when extracting */ 40156283Srwatson#define AR_S 0x0040 /* write archive symbol table */ 41156283Srwatson#define AR_SS 0x0080 /* do not write archive symbol table */ 42156283Srwatson#define AR_TR 0x0100 /* only keep first 15 chars for member name */ 43156283Srwatson#define AR_U 0x0200 /* only extract or update newer members.*/ 44156283Srwatson#define AR_V 0x0400 /* verbose mode */ 45156283Srwatson#define AR_Z 0x0800 /* gzip compression */ 46156283Srwatson#define AR_D 0x1000 /* insert dummy mode, mtime, uid and gid */ 47156283Srwatson 48156283Srwatson#define DEF_BLKSZ 10240 /* default block size */ 49156283Srwatson 50156283Srwatson/* 51156283Srwatson * Convenient wrapper for general libarchive error handling. 52156283Srwatson */ 53156283Srwatson#define AC(CALL) do { \ 54156283Srwatson if ((CALL)) \ 55156283Srwatson bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s", \ 56156283Srwatson archive_error_string(a)); \ 57156283Srwatson} while (0) 58156283Srwatson 59156283Srwatson/* 60156283Srwatson * In-memory representation of archive member(object). 61156283Srwatson */ 62156283Srwatsonstruct ar_obj { 63156283Srwatson char *name; /* member name */ 64156283Srwatson void *maddr; /* mmap start address */ 65156283Srwatson uid_t uid; /* user id */ 66156283Srwatson gid_t gid; /* group id */ 67156283Srwatson mode_t md; /* octal file permissions */ 68156283Srwatson size_t size; /* member size */ 69156283Srwatson time_t mtime; /* modification time */ 70156283Srwatson int fd; /* file descriptor */ 71156283Srwatson dev_t dev; /* inode's device */ 72156283Srwatson ino_t ino; /* inode's number */ 73156283Srwatson 74156283Srwatson TAILQ_ENTRY(ar_obj) objs; 75156283Srwatson}; 76156283Srwatson 77156283Srwatson/* 78156283Srwatson * Structure encapsulates the "global" data for "ar" program. 79156283Srwatson */ 80156283Srwatsonstruct bsdar { 81156283Srwatson const char *filename; /* archive name. */ 82156283Srwatson const char *addlib; /* target of ADDLIB. */ 83156283Srwatson const char *posarg; /* position arg for modifiers -a, -b. */ 84156283Srwatson char mode; /* program mode */ 85156283Srwatson int options; /* command line options */ 86156283Srwatson 87156283Srwatson const char *progname; /* program name */ 88156283Srwatson int argc; 89156283Srwatson char **argv; 90156283Srwatson 91156283Srwatson /* 92156283Srwatson * Fields for the archive string table. 93156283Srwatson */ 94156283Srwatson char *as; /* buffer for archive string table. */ 95156283Srwatson size_t as_sz; /* current size of as table. */ 96156283Srwatson size_t as_cap; /* capacity of as table buffer. */ 97156283Srwatson 98156283Srwatson /* 99156283Srwatson * Fields for the archive symbol table. 100156283Srwatson */ 101156283Srwatson uint32_t s_cnt; /* current number of symbols. */ 102156283Srwatson uint32_t *s_so; /* symbol offset table. */ 103156283Srwatson size_t s_so_cap; /* capacity of so table buffer. */ 104156283Srwatson char *s_sn; /* symbol name table */ 105156283Srwatson size_t s_sn_cap; /* capacity of sn table buffer. */ 106156283Srwatson size_t s_sn_sz; /* current size of sn table. */ 107156283Srwatson /* Current member's offset (relative to the end of pseudo members.) */ 108156283Srwatson off_t rela_off; 109156283Srwatson 110156283Srwatson TAILQ_HEAD(, ar_obj) v_obj; /* object(member) list */ 111156283Srwatson}; 112156283Srwatson 113156283Srwatsonvoid bsdar_errc(struct bsdar *, int _eval, int _code, 114156283Srwatson const char *fmt, ...) __dead2; 115156283Srwatsonvoid bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...); 116156283Srwatsonvoid ar_mode_d(struct bsdar *bsdar); 117156283Srwatsonvoid ar_mode_m(struct bsdar *bsdar); 118156283Srwatsonvoid ar_mode_p(struct bsdar *bsdar); 119156283Srwatsonvoid ar_mode_q(struct bsdar *bsdar); 120156283Srwatsonvoid ar_mode_r(struct bsdar *bsdar); 121156283Srwatsonvoid ar_mode_s(struct bsdar *bsdar); 122156283Srwatsonvoid ar_mode_t(struct bsdar *bsdar); 123156283Srwatsonvoid ar_mode_x(struct bsdar *bsdar); 124156283Srwatsonvoid ar_mode_A(struct bsdar *bsdar); 125156283Srwatsonvoid ar_mode_script(struct bsdar *ar); 126156283Srwatson