ar.h revision 177064
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 177064 2008-03-11 18:35:51Z kaiw $ 27176434Skaiw */ 28176434Skaiw 29176453Sobrien#define BSDAR_VERSION "1.0.2" 30176453Sobrien 31176434Skaiw/* 32176434Skaiw * ar(1) options. 33176434Skaiw */ 34176434Skaiw#define AR_A 0x0001 /* position-after */ 35176434Skaiw#define AR_B 0x0002 /* position-before */ 36176434Skaiw#define AR_C 0x0004 /* creating new archive */ 37176434Skaiw#define AR_CC 0x0008 /* do not overwrite when extracting */ 38176434Skaiw#define AR_J 0x0010 /* bzip2 compression */ 39176434Skaiw#define AR_O 0x0020 /* preserve original mtime when extracting */ 40176434Skaiw#define AR_S 0x0040 /* write archive symbol table */ 41176434Skaiw#define AR_SS 0x0080 /* do not write archive symbol table */ 42176434Skaiw#define AR_TR 0x0100 /* only keep first 15 chars for member name */ 43176434Skaiw#define AR_U 0x0200 /* only extract or update newer members.*/ 44176434Skaiw#define AR_V 0x0400 /* verbose mode */ 45176434Skaiw#define AR_Z 0x0800 /* gzip compression */ 46176434Skaiw 47176434Skaiw#define DEF_BLKSZ 10240 /* default block size */ 48176434Skaiw 49176434Skaiw/* 50176434Skaiw * Convenient wrapper for general libarchive error handling. 51176434Skaiw */ 52176434Skaiw#define AC(CALL) do { \ 53176434Skaiw if ((CALL)) \ 54176434Skaiw bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s", \ 55176434Skaiw archive_error_string(a)); \ 56176434Skaiw} while (0) 57176434Skaiw 58176434Skaiw/* 59176434Skaiw * In-memory representation of archive member(object). 60176434Skaiw */ 61176434Skaiwstruct ar_obj { 62176434Skaiw char *name; /* member name */ 63176434Skaiw void *maddr; /* mmap start address */ 64176434Skaiw uid_t uid; /* user id */ 65176434Skaiw gid_t gid; /* group id */ 66176434Skaiw mode_t md; /* octal file permissions */ 67176434Skaiw size_t size; /* member size */ 68176434Skaiw time_t mtime; /* modification time */ 69176434Skaiw int fd; /* file descriptor */ 70176434Skaiw dev_t dev; /* inode's device */ 71176434Skaiw ino_t ino; /* inode's number */ 72176434Skaiw 73176434Skaiw TAILQ_ENTRY(ar_obj) objs; 74176434Skaiw}; 75176434Skaiw 76176434Skaiw/* 77176434Skaiw * Structure encapsulates the "global" data for "ar" program. 78176434Skaiw */ 79176434Skaiwstruct bsdar { 80176434Skaiw const char *filename; /* archive name. */ 81176434Skaiw const char *posarg; /* position arg for modifiers -a, -b. */ 82176434Skaiw char mode; /* program mode */ 83176434Skaiw char compression; /* compression mode */ 84176434Skaiw int options; /* command line options */ 85176434Skaiw 86176434Skaiw const char *progname; /* program name */ 87176434Skaiw int argc; 88176434Skaiw char **argv; 89176434Skaiw 90176434Skaiw /* 91176434Skaiw * Fields for the archive string table. 92176434Skaiw */ 93176434Skaiw char *as; /* buffer for archive string table. */ 94176434Skaiw size_t as_sz; /* current size of as table. */ 95176434Skaiw size_t as_cap; /* capacity of as table buffer. */ 96176434Skaiw 97176434Skaiw /* 98176434Skaiw * Fields for the archive symbol table. 99176434Skaiw */ 100176434Skaiw uint32_t s_cnt; /* current number of symbols. */ 101176434Skaiw uint32_t *s_so; /* symbol offset table. */ 102176434Skaiw size_t s_so_cap; /* capacity of so table buffer. */ 103176434Skaiw char *s_sn; /* symbol name table */ 104176434Skaiw size_t s_sn_cap; /* capacity of sn table buffer. */ 105176434Skaiw size_t s_sn_sz; /* current size of sn table. */ 106176434Skaiw /* Current member's offset (relative to the end of pseudo members.) */ 107176434Skaiw off_t rela_off; 108176434Skaiw 109176434Skaiw TAILQ_HEAD(, ar_obj) v_obj; /* object(member) list */ 110176434Skaiw}; 111176434Skaiw 112176434Skaiwvoid bsdar_errc(struct bsdar *, int _eval, int _code, 113176434Skaiw const char *fmt, ...); 114176434Skaiwvoid bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...); 115176434Skaiwvoid ar_mode_d(struct bsdar *bsdar); 116176434Skaiwvoid ar_mode_m(struct bsdar *bsdar); 117176434Skaiwvoid ar_mode_p(struct bsdar *bsdar); 118177064Skaiwvoid ar_mode_q(struct bsdar *bsdar); 119176434Skaiwvoid ar_mode_r(struct bsdar *bsdar); 120176434Skaiwvoid ar_mode_s(struct bsdar *bsdar); 121176434Skaiwvoid ar_mode_t(struct bsdar *bsdar); 122176434Skaiwvoid ar_mode_x(struct bsdar *bsdar); 123