1 | /* $Id: cpiovfsreader.h 86035 2020-09-06 20:31:16Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - CPIO Virtual Filesystem.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef IPRT_INCLUDED_SRC_common_zip_cpiovfsreader_h
|
---|
28 | #define IPRT_INCLUDED_SRC_common_zip_cpiovfsreader_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/formats/cpio.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * CPIO archive type.
|
---|
38 | */
|
---|
39 | typedef enum RTZIPCPIOTYPE
|
---|
40 | {
|
---|
41 | /** Invalid type value. */
|
---|
42 | RTZIPCPIOTYPE_INVALID = 0,
|
---|
43 | /** Ancient binary archive. */
|
---|
44 | RTZIPCPIOTYPE_ANCIENT_BIN,
|
---|
45 | /** Portable ASCII format as defined by SuSV2. */
|
---|
46 | RTZIPCPIOTYPE_ASCII_SUSV2,
|
---|
47 | /** "New" ASCII format. */
|
---|
48 | RTZIPCPIOTYPE_ASCII_NEW,
|
---|
49 | /** "New" ASCII format with checksumming. */
|
---|
50 | RTZIPCPIOTYPE_ASCII_NEW_CHKSUM,
|
---|
51 | /** End of the valid type values (this is not valid). */
|
---|
52 | RTZIPCPIOTYPE_END,
|
---|
53 | /** The usual type blow up. */
|
---|
54 | RTZIPCPIOTYPE_32BIT_HACK = 0x7fffffff
|
---|
55 | } RTZIPCPIOTYPE;
|
---|
56 | typedef RTZIPCPIOTYPE *PRTZIPCPIOTYPE;
|
---|
57 |
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * CPIO reader instance data.
|
---|
61 | */
|
---|
62 | typedef struct RTZIPCPIOREADER
|
---|
63 | {
|
---|
64 | /** The object info with unix attributes. */
|
---|
65 | RTFSOBJINFO ObjInfo;
|
---|
66 | /** The path length. */
|
---|
67 | uint32_t cbPath;
|
---|
68 | /** The name of the current object. */
|
---|
69 | char szName[RTPATH_MAX];
|
---|
70 | /** The current link target if symlink. */
|
---|
71 | char szTarget[RTPATH_MAX];
|
---|
72 | } RTZIPCPIOREADER;
|
---|
73 | /** Pointer to the CPIO reader instance data. */
|
---|
74 | typedef RTZIPCPIOREADER *PRTZIPCPIOREADER;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * CPIO directory, character device, block device, fifo socket or symbolic link.
|
---|
78 | */
|
---|
79 | typedef struct RTZIPCPIOBASEOBJ
|
---|
80 | {
|
---|
81 | /** The stream offset of the (first) header in the input stream/file. */
|
---|
82 | RTFOFF offHdr;
|
---|
83 | /** The stream offset of the first header of the next object (for truncating the
|
---|
84 | * tar file after this object (updating)). */
|
---|
85 | RTFOFF offNextHdr;
|
---|
86 | /** Pointer to the reader instance data (resides in the filesystem
|
---|
87 | * stream).
|
---|
88 | * @todo Fix this so it won't go stale... Back ref from this obj to fss? */
|
---|
89 | PRTZIPCPIOREADER pCpioReader;
|
---|
90 | /** The object info with unix attributes. */
|
---|
91 | RTFSOBJINFO ObjInfo;
|
---|
92 | } RTZIPCPIOBASEOBJ;
|
---|
93 | /** Pointer to a CPIO filesystem stream base object. */
|
---|
94 | typedef RTZIPCPIOBASEOBJ *PRTZIPCPIOBASEOBJ;
|
---|
95 |
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * CPIO file represented as a VFS I/O stream.
|
---|
99 | */
|
---|
100 | typedef struct RTZIPCPIOIOSTREAM
|
---|
101 | {
|
---|
102 | /** The basic TAR object data. */
|
---|
103 | RTZIPCPIOBASEOBJ BaseObj;
|
---|
104 | /** The number of bytes in the file. */
|
---|
105 | RTFOFF cbFile;
|
---|
106 | /** The current file position. */
|
---|
107 | RTFOFF offFile;
|
---|
108 | /** The start position in the hVfsIos (for seekable hVfsIos). */
|
---|
109 | RTFOFF offStart;
|
---|
110 | /** The number of padding bytes following the file. */
|
---|
111 | uint32_t cbPadding;
|
---|
112 | /** Set if we've reached the end of this file. */
|
---|
113 | bool fEndOfStream;
|
---|
114 | /** The input I/O stream. */
|
---|
115 | RTVFSIOSTREAM hVfsIos;
|
---|
116 | } RTZIPCPIOIOSTREAM;
|
---|
117 | /** Pointer to a the private data of a CPIO file I/O stream. */
|
---|
118 | typedef RTZIPCPIOIOSTREAM *PRTZIPCPIOIOSTREAM;
|
---|
119 |
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * CPIO filesystem stream private data.
|
---|
123 | */
|
---|
124 | typedef struct RTZIPCPIOFSSTREAM
|
---|
125 | {
|
---|
126 | /** The input I/O stream. */
|
---|
127 | RTVFSIOSTREAM hVfsIos;
|
---|
128 |
|
---|
129 | /** The current object (referenced). */
|
---|
130 | RTVFSOBJ hVfsCurObj;
|
---|
131 | /** Pointer to the private data if hVfsCurObj is representing a file. */
|
---|
132 | PRTZIPCPIOIOSTREAM pCurIosData;
|
---|
133 |
|
---|
134 | /** The start offset. */
|
---|
135 | RTFOFF offStart;
|
---|
136 | /** The offset of the next header. */
|
---|
137 | RTFOFF offNextHdr;
|
---|
138 | /** The offset of the first header for the current object.
|
---|
139 | * When reaching the end, this will be the same as offNextHdr which will be
|
---|
140 | * pointing to the first zero header */
|
---|
141 | RTFOFF offCurHdr;
|
---|
142 |
|
---|
143 | /** Set if we've reached the end of the stream. */
|
---|
144 | bool fEndOfStream;
|
---|
145 | /** Set if we've encountered a fatal error. */
|
---|
146 | int rcFatal;
|
---|
147 |
|
---|
148 | /** The CPIO reader instance data. */
|
---|
149 | RTZIPCPIOREADER CpioReader;
|
---|
150 | } RTZIPCPIOFSSTREAM;
|
---|
151 | /** Pointer to a the private data of a CPIO filesystem stream. */
|
---|
152 | typedef RTZIPCPIOFSSTREAM *PRTZIPCPIOFSSTREAM;
|
---|
153 |
|
---|
154 | DECLHIDDEN(void) rtZipCpioReaderInit(PRTZIPCPIOFSSTREAM pThis, RTVFSIOSTREAM hVfsIos, uint64_t offStart);
|
---|
155 | DECL_HIDDEN_CALLBACK(int) rtZipCpioFss_Next(void *pvThis, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
|
---|
156 | DECLHIDDEN(PRTZIPCPIOBASEOBJ) rtZipCpioFsStreamBaseObjToPrivate(PRTZIPCPIOFSSTREAM pThis, RTVFSOBJ hVfsObj);
|
---|
157 |
|
---|
158 | #endif /* !IPRT_INCLUDED_SRC_common_zip_cpiovfsreader_h */
|
---|
159 |
|
---|