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