1 | /** @file
|
---|
2 | * IPRT - Tar archive I/O.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009-2014 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_tar_h
|
---|
27 | #define ___iprt_tar_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/time.h>
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_tar RTTar - Tar archive I/O
|
---|
36 | * @ingroup grp_rt
|
---|
37 | *
|
---|
38 | * @deprecated Only used for legacy code and writing. Migrate new code to the
|
---|
39 | * VFS interface, add the write part when needed.
|
---|
40 | *
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** A tar handle */
|
---|
45 | typedef R3PTRTYPE(struct RTTARINTERNAL *) RTTAR;
|
---|
46 | /** Pointer to a RTTAR interface handle. */
|
---|
47 | typedef RTTAR *PRTTAR;
|
---|
48 | /** Nil RTTAR interface handle. */
|
---|
49 | #define NIL_RTTAR ((RTTAR)0)
|
---|
50 |
|
---|
51 | /** A tar file handle */
|
---|
52 | typedef R3PTRTYPE(struct RTTARFILEINTERNAL *) RTTARFILE;
|
---|
53 | /** Pointer to a RTTARFILE interface handle. */
|
---|
54 | typedef RTTARFILE *PRTTARFILE;
|
---|
55 | /** Nil RTTARFILE interface handle. */
|
---|
56 | #define NIL_RTTARFILE ((RTTARFILE)0)
|
---|
57 |
|
---|
58 | /** Maximum length of a tar filename, excluding the terminating '\0'. More
|
---|
59 | * does not fit into a tar record. */
|
---|
60 | #define RTTAR_NAME_MAX 99
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Opens a Tar archive.
|
---|
64 | *
|
---|
65 | * Use the mask to specify the access type. In create mode the target file
|
---|
66 | * have not to exists.
|
---|
67 | *
|
---|
68 | * @returns IPRT status code.
|
---|
69 | *
|
---|
70 | * @param phTar Where to store the RTTAR handle.
|
---|
71 | * @param pszTarname The file name of the tar archive to open.
|
---|
72 | * @param fMode Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
73 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
74 | * @param fStream Open the file in stream mode. Within this mode no
|
---|
75 | * seeking is allowed. Use this together with
|
---|
76 | * RTTarFileCurrent, RTTarFileOpenCurrent,
|
---|
77 | * RTTarFileSeekNextFile and the read method to
|
---|
78 | * sequential read a tar file. Currently ignored with
|
---|
79 | * RTFILE_O_WRITE.
|
---|
80 | */
|
---|
81 | RTR3DECL(int) RTTarOpen(PRTTAR phTar, const char *pszTarname, uint32_t fMode, bool fStream);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Close the Tar archive.
|
---|
85 | *
|
---|
86 | * @returns IPRT status code.
|
---|
87 | *
|
---|
88 | * @param hTar Handle to the RTTAR interface.
|
---|
89 | */
|
---|
90 | RTR3DECL(int) RTTarClose(RTTAR hTar);
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Jumps to the next file from the current RTTar position.
|
---|
94 | *
|
---|
95 | * @returns IPRT status code.
|
---|
96 | *
|
---|
97 | * @param hTar Handle to the RTTAR interface.
|
---|
98 | */
|
---|
99 | RTR3DECL(int) RTTarSeekNextFile(RTTAR hTar);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Return the filename where RTTar currently stays at.
|
---|
103 | *
|
---|
104 | * @returns IPRT status code.
|
---|
105 | *
|
---|
106 | * @param hTar Handle to the RTTAR interface.
|
---|
107 | * @param ppszFilename On success the filename.
|
---|
108 | */
|
---|
109 | RTR3DECL(int) RTTarCurrentFile(RTTAR hTar, char **ppszFilename);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Opens the file where RTTar currently stays at.
|
---|
113 | *
|
---|
114 | * The current file can only be opened once. The next call will open the next
|
---|
115 | * file, implicitly calling RTTarSeekNextFile().
|
---|
116 | *
|
---|
117 | * @returns IPRT status code.
|
---|
118 | *
|
---|
119 | * @param hTar Handle to the RTTAR interface.
|
---|
120 | * @param phFile Where to store the handle to the opened file.
|
---|
121 | * @param ppszFilename On success the filename.
|
---|
122 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
123 | * The ACCESS, ACTION flags are mandatory! Currently
|
---|
124 | * only RTFILE_O_OPEN | RTFILE_O_READ is supported.
|
---|
125 | */
|
---|
126 | RTR3DECL(int) RTTarFileOpenCurrentFile(RTTAR hTar, PRTTARFILE phFile, char **ppszFilename, uint32_t fOpen);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Open a file in the Tar archive.
|
---|
130 | *
|
---|
131 | * @returns IPRT status code.
|
---|
132 | *
|
---|
133 | * @param hTar The handle of the tar archive.
|
---|
134 | * @param phFile Where to store the handle to the opened file.
|
---|
135 | * @param pszFilename Path to the file which is to be opened. (UTF-8)
|
---|
136 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
137 | * The ACCESS, ACTION flags are mandatory! DENY flags
|
---|
138 | * are currently not supported.
|
---|
139 | *
|
---|
140 | * @remarks Write mode means append mode only. It is not possible to make
|
---|
141 | * changes to existing files.
|
---|
142 | *
|
---|
143 | * @remarks Currently it is not possible to open more than one file in write
|
---|
144 | * mode. Although open more than one file in read only mode (even when
|
---|
145 | * one file is opened in write mode) is always possible.
|
---|
146 | */
|
---|
147 | RTR3DECL(int) RTTarFileOpen(RTTAR hTar, PRTTARFILE phFile, const char *pszFilename, uint32_t fOpen);
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Close the file opened by RTTarFileOpen.
|
---|
151 | *
|
---|
152 | * @returns IPRT status code.
|
---|
153 | *
|
---|
154 | * @param hFile The file handle to close.
|
---|
155 | */
|
---|
156 | RTR3DECL(int) RTTarFileClose(RTTARFILE hFile);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Read bytes from a file at a given offset.
|
---|
160 | * This function may modify the file position.
|
---|
161 | *
|
---|
162 | * @returns IPRT status code.
|
---|
163 | *
|
---|
164 | * @param hFile Handle to the file.
|
---|
165 | * @param off Where to read.
|
---|
166 | * @param pvBuf Where to put the bytes we read.
|
---|
167 | * @param cbToRead How much to read.
|
---|
168 | * @param pcbRead Where to return how much we actually read. If NULL
|
---|
169 | * an error will be returned for a partial read.
|
---|
170 | */
|
---|
171 | RTR3DECL(int) RTTarFileReadAt(RTTARFILE hFile, uint64_t off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Write bytes to a file at a given offset.
|
---|
175 | * This function may modify the file position.
|
---|
176 | *
|
---|
177 | * @returns IPRT status code.
|
---|
178 | *
|
---|
179 | * @param hFile Handle to the file.
|
---|
180 | * @param off Where to write.
|
---|
181 | * @param pvBuf What to write.
|
---|
182 | * @param cbToWrite How much to write.
|
---|
183 | * @param pcbWritten Where to return how much we actually wrote. If NULL
|
---|
184 | * an error will be returned for a partial write.
|
---|
185 | */
|
---|
186 | RTR3DECL(int) RTTarFileWriteAt(RTTARFILE hFile, uint64_t off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Query the size of the file.
|
---|
190 | *
|
---|
191 | * @returns IPRT status code.
|
---|
192 | *
|
---|
193 | * @param hFile Handle to the file.
|
---|
194 | * @param pcbSize Where to store the filesize.
|
---|
195 | */
|
---|
196 | RTR3DECL(int) RTTarFileGetSize(RTTARFILE hFile, uint64_t *pcbSize);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Set the size of the file.
|
---|
200 | *
|
---|
201 | * @returns IPRT status code.
|
---|
202 | *
|
---|
203 | * @param hFile Handle to the file.
|
---|
204 | * @param cbSize The new file size.
|
---|
205 | */
|
---|
206 | RTR3DECL(int) RTTarFileSetSize(RTTARFILE hFile, uint64_t cbSize);
|
---|
207 |
|
---|
208 | /** @} */
|
---|
209 |
|
---|
210 | RT_C_DECLS_END
|
---|
211 |
|
---|
212 | #endif
|
---|
213 |
|
---|