VirtualBox

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

Last change on this file since 87835 was 86035, checked in by vboxsync, 4 years ago

Runtime/cpiovfs.cpp: A simple CPIO archive reader (WIP, writer comes next and then some cleanup)

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette