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