VirtualBox

source: vbox/trunk/include/iprt/formats/cpio.h

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/** @file
2 * IPRT - CPIO archive format.
3 */
4
5/*
6 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_formats_cpio_h
37#define IPRT_INCLUDED_formats_cpio_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/types.h>
43#include <iprt/assertcompile.h>
44
45
46/** @defgroup grp_rt_formats_cpio CPIO Archive format
47 * @ingroup grp_rt_formats
48 *
49 * @{ */
50
51/** This denotes the end of the archive (record with this filename, zero size and
52 * a zero mode). */
53#define CPIO_EOS_FILE_NAME "TRAILER!!!"
54
55
56/**
57 * The old binary header.
58 */
59typedef struct CPIOHDRBIN
60{
61 /** 0x00: Magic identifying the old header. */
62 uint16_t u16Magic;
63 /** 0x02: Device number. */
64 uint16_t u16Dev;
65 /** 0x04: Inode number. */
66 uint16_t u16Inode;
67 /** 0x06: Mode. */
68 uint16_t u16Mode;
69 /** 0x08: User ID. */
70 uint16_t u16Uid;
71 /** 0x0a: Group ID. */
72 uint16_t u16Gid;
73 /** 0x0c: Number of links to this file. */
74 uint16_t u16NLinks;
75 /** 0x0e: Associated device number for block and character device entries. */
76 uint16_t u16RDev;
77 /** 0x10: Modification time stored as two independent 16bit integers. */
78 uint16_t au16MTime[2];
79 /** 0x14: Number of bytes in the path name (including zero terminator) following the header. */
80 uint16_t u16NameSize;
81 /** 0x16: Size of the file stored as two independent 16bit integers. */
82 uint16_t au16FileSize[2];
83} CPIOHDRBIN;
84AssertCompileSize(CPIOHDRBIN, 13 * 2);
85typedef CPIOHDRBIN *PCPIOHDRBIN;
86typedef const CPIOHDRBIN *PCCPIOHDRBIN;
87
88
89/** The magic for the binary header. */
90#define CPIO_HDR_BIN_MAGIC UINT16_C(070707)
91
92
93/**
94 * Portable ASCII format header as defined by SUSv2.
95 */
96typedef struct CPIOHDRSUSV2
97{
98 /** 0x00: Magic identifying the header. */
99 char achMagic[6];
100 /** 0x06: Device number. */
101 char achDev[6];
102 /** 0x0c: Inode number. */
103 char achInode[6];
104 /** 0x12: Mode. */
105 char achMode[6];
106 /** 0x18: User ID. */
107 char achUid[6];
108 /** 0x1e: Group ID. */
109 char achGid[6];
110 /** 0x24: Number of links to this file. */
111 char achNLinks[6];
112 /** 0x2a: Associated device number for block and character device entries. */
113 char achRDev[6];
114 /** 0x30: Modification time stored as two independent 16bit integers. */
115 char achMTime[11];
116 /** 0x36: Number of bytes in the path name (including zero terminator) following the header. */
117 char achNameSize[6];
118 /** 0x3c: Size of the file stored as two independent 16bit integers. */
119 char achFileSize[11];
120} CPIOHDRSUSV2;
121AssertCompileSize(CPIOHDRSUSV2, 9 * 6 + 2 * 11);
122typedef CPIOHDRSUSV2 *PCPIOHDRSUSV2;
123typedef const CPIOHDRSUSV2 *PCCPIOHDRSUSV2;
124
125
126/** The magic for the SuSv2 CPIO header. */
127#define CPIO_HDR_SUSV2_MAGIC "070707"
128
129
130/**
131 * New ASCII format header.
132 */
133typedef struct CPIOHDRNEW
134{
135 /** 0x00: Magic identifying the header. */
136 char achMagic[6];
137 /** 0x06: Inode number. */
138 char achInode[8];
139 /** 0x0e: Mode. */
140 char achMode[8];
141 /** 0x16: User ID. */
142 char achUid[8];
143 /** 0x1e: Group ID. */
144 char achGid[8];
145 /** 0x26: Number of links to this file. */
146 char achNLinks[8];
147 /** 0x2e: Modification time. */
148 char achMTime[8];
149 /** 0x36: Size of the file stored as two independent 16bit integers. */
150 char achFileSize[8];
151 /** 0x3e: Device major number. */
152 char achDevMajor[8];
153 /** 0x46: Device minor number. */
154 char achDevMinor[8];
155 /** 0x4e: Assigned device major number for block or character device files. */
156 char achRDevMajor[8];
157 /** 0x56: Assigned device minor number for block or character device files. */
158 char achRDevMinor[8];
159 /** 0x5e: Number of bytes in the path name (including zero terminator) following the header. */
160 char achNameSize[8];
161 /** 0x66: Checksum of the file data if used. */
162 char achCheck[8];
163} CPIOHDRNEW;
164AssertCompileSize(CPIOHDRNEW, 6 + 13 * 8);
165AssertCompileMemberOffset(CPIOHDRNEW, achMagic, 0x00);
166AssertCompileMemberOffset(CPIOHDRNEW, achInode, 0x06);
167AssertCompileMemberOffset(CPIOHDRNEW, achMode, 0x0e);
168AssertCompileMemberOffset(CPIOHDRNEW, achUid, 0x16);
169AssertCompileMemberOffset(CPIOHDRNEW, achGid, 0x1e);
170AssertCompileMemberOffset(CPIOHDRNEW, achNLinks, 0x26);
171AssertCompileMemberOffset(CPIOHDRNEW, achMTime, 0x2e);
172AssertCompileMemberOffset(CPIOHDRNEW, achFileSize, 0x36);
173AssertCompileMemberOffset(CPIOHDRNEW, achDevMajor, 0x3e);
174AssertCompileMemberOffset(CPIOHDRNEW, achDevMinor, 0x46);
175AssertCompileMemberOffset(CPIOHDRNEW, achRDevMajor, 0x4e);
176AssertCompileMemberOffset(CPIOHDRNEW, achRDevMinor, 0x56);
177AssertCompileMemberOffset(CPIOHDRNEW, achNameSize, 0x5e);
178AssertCompileMemberOffset(CPIOHDRNEW, achCheck, 0x66);
179typedef CPIOHDRNEW *PCPIOHDRNEW;
180typedef const CPIOHDRNEW *PCCPIOHDRNEW;
181
182
183/** The magic for the new ASCII CPIO header. */
184#define CPIO_HDR_NEW_MAGIC "070701"
185/** The magic for the new ASCII CPIO header + checksum. */
186#define CPIO_HDR_NEW_CHKSUM_MAGIC "070702"
187
188
189/**
190 * CPIO header union.
191 */
192typedef union CPIOHDR
193{
194 /** byte view. */
195 uint8_t ab[110];
196 /** The ancient binary header. */
197 CPIOHDRBIN AncientBin;
198 /** The SuSv2 ASCII header. */
199 CPIOHDRSUSV2 AsciiSuSv2;
200 /** The new ASCII header format. */
201 CPIOHDRNEW AsciiNew;
202} CPIOHDR;
203typedef CPIOHDR *PCPIOHDR;
204typedef const CPIOHDR *PCCPIOHDR;
205
206
207/** @} */
208
209#endif /* !IPRT_INCLUDED_formats_cpio_h */
210
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use