| 1 | /*- |
| 2 | * Copyright (c) 2011, 2016 |
| 3 | * mirabilos <[email protected]> |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of the University nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this software |
| 15 | * without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifdef EXTERN |
| 31 | __IDSTRING(rcsid_ar_h, "$MirOS: src/bin/pax/ar.h,v 1.4 2018/12/12 18:08:41 tg Exp $"); |
| 32 | #endif |
| 33 | |
| 34 | /**************************************************** |
| 35 | |
| 36 | Libraries created by the Unix Archiver and compatible |
| 37 | with the DEB file format consist of an initial eight- |
| 38 | octet magic followed by a number of sections, per ar- |
| 39 | chive member, comprised of a header and a data part. |
| 40 | |
| 41 | The magic is "<!arch>\n" (21 3C 61 72 63 68 3E 0A). |
| 42 | |
| 43 | Each archive member section (header followed by data) |
| 44 | is aligned to a multiple of two octets. The magic and |
| 45 | member header are both of even size, so a padding oc- |
| 46 | tet "\n" (0Ah) can be appended after the data part of |
| 47 | that section; an archive always has an even length. A |
| 48 | header is 60 octets long and structured as follows: |
| 49 | +0 char ar_name[16]; |
| 50 | +16 char ar_mtime[12]; |
| 51 | +28 char ar_uid[6]; |
| 52 | +34 char ar_gid[6]; |
| 53 | +40 char ar_mode[8]; |
| 54 | +48 char ar_size[10]; |
| 55 | +58 char ar_magic[2]; |
| 56 | |
| 57 | All header fields are left-justified and space-padded |
| 58 | at the end, if necessary. The composition for ar_name |
| 59 | will be described later. ar_mtime, ar_uid, ar_gid and |
| 60 | ar_size are the unsigned decimental representation of |
| 61 | the mtime as time_t, numeric user and group ID values |
| 62 | and the size of the data part, respectively. ar_mode, |
| 63 | on the other hand, is the octal representation of its |
| 64 | Unix file mode (permissions). ar_magic = { 60h, 0Ah } |
| 65 | |
| 66 | Archive memeber filenames are basenames, i.e. they do |
| 67 | not contain a path. |
| 68 | |
| 69 | If the filename is not longer than 16 octets and does |
| 70 | not contain a space, it is stored as ar_name directly |
| 71 | (although some implementations would trim the part of |
| 72 | the filename before a ".o" extension). Otherwise, the |
| 73 | ar_name field consists of the string "#1/" (23 31 2F) |
| 74 | followed by the length of the filename as decimal un- |
| 75 | signed integer (again space-padded); the APT archival |
| 76 | routines only support extended filenames of less than |
| 77 | 300 octets. The actual filename is then stored as the |
| 78 | first part of the data part consequently incrementing |
| 79 | ar_size by its length. Since some versions of APT al- |
| 80 | so support the SYSV property of ending ar_name with a |
| 81 | slash "/" (2F), on encoding filenames containing them |
| 82 | should be written as extended filenames; on decoding, |
| 83 | a trailing slash in ar_name should be ignored. (Note, |
| 84 | SYSV does not encode filenames that contain spaces as |
| 85 | extended but BSD ar and APT truncate there then.) |
| 86 | |
| 87 | There are no trailers; an archive file ends after its |
| 88 | last member section (including the padding). |
| 89 | |
| 90 | ****************************************************/ |
| 91 | |
| 92 | typedef struct { |
| 93 | char ar_name[16]; |
| 94 | char ar_mtime[12]; |
| 95 | char ar_uid[6]; |
| 96 | char ar_gid[6]; |
| 97 | char ar_mode[8]; |
| 98 | char ar_size[10]; |
| 99 | char ar_magic[2]; |
| 100 | } HD_AR; |