1 | /** @file
|
---|
2 | * IPRT - Tar archive I/O.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009-2010 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 | */
|
---|
39 |
|
---|
40 | /** A tar handle */
|
---|
41 | typedef R3PTRTYPE(struct RTTARINTERNAL *) RTTAR;
|
---|
42 | /** Pointer to a RTTAR interface handle. */
|
---|
43 | typedef RTTAR *PRTTAR;
|
---|
44 | /** Nil RTTAR interface handle. */
|
---|
45 | #define NIL_RTTAR ((RTTAR)0)
|
---|
46 |
|
---|
47 | /** A tar file handle */
|
---|
48 | typedef R3PTRTYPE(struct RTTARFILEINTERNAL *) RTTARFILE;
|
---|
49 | /** Pointer to a RTTARFILE interface handle. */
|
---|
50 | typedef RTTARFILE *PRTTARFILE;
|
---|
51 | /** Nil RTTARFILE interface handle. */
|
---|
52 | #define NIL_RTTARFILE ((RTTARFILE)0)
|
---|
53 |
|
---|
54 | /** Maximum length of a tar filename, excluding the terminating '\0'. More
|
---|
55 | * does not fit into a tar record. */
|
---|
56 | #define RTTAR_NAME_MAX 99
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Opens a Tar archive.
|
---|
60 | *
|
---|
61 | * Use the mask to specify the access type. In create mode the target file
|
---|
62 | * have not to exists.
|
---|
63 | *
|
---|
64 | * @returns IPRT status code.
|
---|
65 | *
|
---|
66 | * @param phTar Where to store the RTTAR handle.
|
---|
67 | * @param pszTarname The file name of the tar archive to open.
|
---|
68 | * @param fMode Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
69 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
70 | * @param fStream Open the file in stream mode. Within this mode no
|
---|
71 | * seeking is allowed. Use this together with
|
---|
72 | * RTTarFileCurrent, RTTarFileOpenCurrent,
|
---|
73 | * RTTarFileSeekNextFile and the read method to
|
---|
74 | * sequential read a tar file. Currently ignored with
|
---|
75 | * RTFILE_O_WRITE.
|
---|
76 | */
|
---|
77 | RTR3DECL(int) RTTarOpen(PRTTAR phTar, const char *pszTarname, uint32_t fMode, bool fStream);
|
---|
78 |
|
---|
79 | #if 0
|
---|
80 | /**
|
---|
81 | * Opens a Tar archive by handle.
|
---|
82 | *
|
---|
83 | * Use the mask to specify the access type. In create mode the target file
|
---|
84 | * have not to exists.
|
---|
85 | *
|
---|
86 | * @returns IPRT status code.
|
---|
87 | *
|
---|
88 | * @param phTar Where to store the RTTAR handle.
|
---|
89 | * @param hFile The file handle of the tar file. This is expected
|
---|
90 | * to be a regular file at the moment.
|
---|
91 | * @param fStream Open the file in stream mode. Within this mode no
|
---|
92 | * seeking is allowed. Use this together with
|
---|
93 | * RTTarFileCurrent, RTTarFileOpenCurrent,
|
---|
94 | * RTTarFileSeekNextFile and the read method to
|
---|
95 | * sequential read a tar file. Currently ignored with
|
---|
96 | * RTFILE_O_WRITE.
|
---|
97 | */
|
---|
98 | RTR3DECL(int) RTTarOpenByHandle(PRTTAR phTar, RTFILE hFile, uint32_t fMode, bool fStream);
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Close the Tar archive.
|
---|
103 | *
|
---|
104 | * @returns IPRT status code.
|
---|
105 | *
|
---|
106 | * @param hTar Handle to the RTTAR interface.
|
---|
107 | */
|
---|
108 | RTR3DECL(int) RTTarClose(RTTAR hTar);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Open a file in the Tar archive.
|
---|
112 | *
|
---|
113 | * @returns IPRT status code.
|
---|
114 | *
|
---|
115 | * @param hTar The handle of the tar archive.
|
---|
116 | * @param phFile Where to store the handle to the opened file.
|
---|
117 | * @param pszFilename Path to the file which is to be opened. (UTF-8)
|
---|
118 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
119 | * The ACCESS, ACTION flags are mandatory! DENY flags
|
---|
120 | * are currently not supported.
|
---|
121 | *
|
---|
122 | * @remarks Write mode means append mode only. It is not possible to make
|
---|
123 | * changes to existing files.
|
---|
124 | *
|
---|
125 | * @remarks Currently it is not possible to open more than one file in write
|
---|
126 | * mode. Although open more than one file in read only mode (even when
|
---|
127 | * one file is opened in write mode) is always possible.
|
---|
128 | */
|
---|
129 | RTR3DECL(int) RTTarFileOpen(RTTAR hTar, PRTTARFILE phFile, const char *pszFilename, uint32_t fOpen);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Close the file opened by RTTarFileOpen.
|
---|
133 | *
|
---|
134 | * @returns IPRT status code.
|
---|
135 | *
|
---|
136 | * @param hFile The file handle to close.
|
---|
137 | */
|
---|
138 | RTR3DECL(int) RTTarFileClose(RTTARFILE hFile);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Changes the read & write position in a file.
|
---|
142 | *
|
---|
143 | * @returns IPRT status code.
|
---|
144 | *
|
---|
145 | * @param hFile Handle to the file.
|
---|
146 | * @param offSeek Offset to seek.
|
---|
147 | * @param uMethod Seek method, i.e. one of the RTFILE_SEEK_* defines.
|
---|
148 | * @param poffActual Where to store the new file position.
|
---|
149 | * NULL is allowed.
|
---|
150 | */
|
---|
151 | RTR3DECL(int) RTTarFileSeek(RTTARFILE hFile, uint64_t offSeek, unsigned uMethod, uint64_t *poffActual);
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Gets the current file position.
|
---|
155 | *
|
---|
156 | * @returns File offset.
|
---|
157 | * @returns UINT64_MAX on failure.
|
---|
158 | *
|
---|
159 | * @param hFile Handle to the file.
|
---|
160 | */
|
---|
161 | RTR3DECL(uint64_t) RTTarFileTell(RTTARFILE hFile);
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Read bytes from a file.
|
---|
165 | *
|
---|
166 | * @returns IPRT status code.
|
---|
167 | *
|
---|
168 | * @param hFile Handle to the file.
|
---|
169 | * @param pvBuf Where to put the bytes we read.
|
---|
170 | * @param cbToRead How much to read.
|
---|
171 | * @param *pcbRead How much we actually read .
|
---|
172 | * If NULL an error will be returned for a partial read.
|
---|
173 | */
|
---|
174 | RTR3DECL(int) RTTarFileRead(RTTARFILE hFile, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Read bytes from a file at a given offset.
|
---|
178 | * This function may modify the file position.
|
---|
179 | *
|
---|
180 | * @returns IPRT status code.
|
---|
181 | *
|
---|
182 | * @param hFile Handle to the file.
|
---|
183 | * @param off Where to read.
|
---|
184 | * @param pvBuf Where to put the bytes we read.
|
---|
185 | * @param cbToRead How much to read.
|
---|
186 | * @param *pcbRead How much we actually read .
|
---|
187 | * If NULL an error will be returned for a partial read.
|
---|
188 | */
|
---|
189 | RTR3DECL(int) RTTarFileReadAt(RTTARFILE hFile, uint64_t off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Write bytes to a file.
|
---|
193 | *
|
---|
194 | * @returns IPRT status code.
|
---|
195 | *
|
---|
196 | * @param hFile Handle to the file.
|
---|
197 | * @param pvBuf What to write.
|
---|
198 | * @param cbToWrite How much to write.
|
---|
199 | * @param *pcbWritten How much we actually wrote.
|
---|
200 | * If NULL an error will be returned for a partial write.
|
---|
201 | */
|
---|
202 | RTR3DECL(int) RTTarFileWrite(RTTARFILE hFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Write bytes to a file at a given offset.
|
---|
206 | * This function may modify the file position.
|
---|
207 | *
|
---|
208 | * @returns IPRT status code.
|
---|
209 | *
|
---|
210 | * @param hFile Handle to the file.
|
---|
211 | * @param off Where to write.
|
---|
212 | * @param pvBuf What to write.
|
---|
213 | * @param cbToWrite How much to write.
|
---|
214 | * @param *pcbWritten How much we actually wrote.
|
---|
215 | * If NULL an error will be returned for a partial write.
|
---|
216 | */
|
---|
217 | RTR3DECL(int) RTTarFileWriteAt(RTTARFILE hFile, uint64_t off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Query the size of the file.
|
---|
221 | *
|
---|
222 | * @returns IPRT status code.
|
---|
223 | *
|
---|
224 | * @param hFile Handle to the file.
|
---|
225 | * @param pcbSize Where to store the filesize.
|
---|
226 | */
|
---|
227 | RTR3DECL(int) RTTarFileGetSize(RTTARFILE hFile, uint64_t *pcbSize);
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * Set the size of the file.
|
---|
231 | *
|
---|
232 | * @returns IPRT status code.
|
---|
233 | *
|
---|
234 | * @param hFile Handle to the file.
|
---|
235 | * @param cbSize The new file size.
|
---|
236 | */
|
---|
237 | RTR3DECL(int) RTTarFileSetSize(RTTARFILE hFile, uint64_t cbSize);
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Changes the mode flags of an open file.
|
---|
241 | *
|
---|
242 | * @returns IPRT status code.
|
---|
243 | *
|
---|
244 | * @param hFile Handle to the file.
|
---|
245 | * @param fMode The new file mode, see @ref grp_rt_fs for details.
|
---|
246 | */
|
---|
247 | RTR3DECL(int) RTTarFileSetMode(RTTARFILE hFile, uint32_t fMode);
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Sets the modification timestamp of the file.
|
---|
251 | *
|
---|
252 | * @returns IPRT status code.
|
---|
253 | *
|
---|
254 | * @param pFile Handle to the file.
|
---|
255 | * @param pTime The time to store.
|
---|
256 | */
|
---|
257 | RTR3DECL(int) RTTarFileSetTime(RTTARFILE hFile, PRTTIMESPEC pTime);
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Changes the owner and/or group of an open file.
|
---|
261 | *
|
---|
262 | * @returns IPRT status code.
|
---|
263 | *
|
---|
264 | * @param hFile Handle to the file.
|
---|
265 | * @param uid The new file owner user id. Use -1 (or ~0) to leave this unchanged.
|
---|
266 | * @param gid The new group id. Use -1 (or ~0) to leave this unchanged.
|
---|
267 | */
|
---|
268 | RTR3DECL(int) RTTarFileSetOwner(RTTARFILE hFile, uint32_t uid, uint32_t gid);
|
---|
269 |
|
---|
270 | /******************************************************************************
|
---|
271 | * Convenience Functions *
|
---|
272 | ******************************************************************************/
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Create a file list from a Tar archive.
|
---|
276 | *
|
---|
277 | * @note Currently only regular files are supported.
|
---|
278 | *
|
---|
279 | * @returns IPRT status code.
|
---|
280 | *
|
---|
281 | * @param pszTarFile Tar file to list files from.
|
---|
282 | * @param ppapszFiles On success an array with array with the filenames is
|
---|
283 | * returned. The names must be freed with RTStrFree and
|
---|
284 | * the array with RTMemFree.
|
---|
285 | * @param pcFiles On success the number of entries in ppapszFiles.
|
---|
286 | */
|
---|
287 | RTR3DECL(int) RTTarList(const char *pszTarFile, char ***ppapszFiles, size_t *pcFiles);
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Create a Tar archive out of the given files.
|
---|
291 | *
|
---|
292 | * @note Currently only regular files are supported.
|
---|
293 | *
|
---|
294 | * @returns IPRT status code.
|
---|
295 | *
|
---|
296 | * @param pszTarFile Where to create the Tar archive.
|
---|
297 | * @param papszFiles Which files should be included.
|
---|
298 | * @param cFiles The number of files in papszFiles.
|
---|
299 | * @param pfnProgressCallback Progress callback function. Optional.
|
---|
300 | * @param pvUser User defined data for the progress
|
---|
301 | * callback. Optional.
|
---|
302 | */
|
---|
303 | RTR3DECL(int) RTTarCreate(const char *pszTarFile, const char * const *papszFiles, size_t cFiles, PFNRTPROGRESS pfnProgressCallback, void *pvUser);
|
---|
304 |
|
---|
305 | /******************************************************************************
|
---|
306 | * Streaming Functions *
|
---|
307 | ******************************************************************************/
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Return the filename where RTTar currently stays at.
|
---|
311 | *
|
---|
312 | * @returns IPRT status code.
|
---|
313 | *
|
---|
314 | * @param hTar Handle to the RTTAR interface.
|
---|
315 | * @param ppszFilename On success the filename.
|
---|
316 | */
|
---|
317 | RTR3DECL(int) RTTarCurrentFile(RTTAR hTar, char **ppszFilename);
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Jumps to the next file from the current RTTar position.
|
---|
321 | *
|
---|
322 | * @returns IPRT status code.
|
---|
323 | *
|
---|
324 | * @param hTar Handle to the RTTAR interface.
|
---|
325 | */
|
---|
326 | RTR3DECL(int) RTTarSeekNextFile(RTTAR hTar);
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Opens the file where RTTar currently stays at.
|
---|
330 | *
|
---|
331 | * @returns IPRT status code.
|
---|
332 | *
|
---|
333 | * @param hTar Handle to the RTTAR interface.
|
---|
334 | * @param phFile Where to store the handle to the opened file.
|
---|
335 | * @param ppszFilename On success the filename.
|
---|
336 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
337 | * The ACCESS, ACTION flags are mandatory! Currently
|
---|
338 | * only RTFILE_O_OPEN | RTFILE_O_READ is supported.
|
---|
339 | */
|
---|
340 | RTR3DECL(int) RTTarFileOpenCurrentFile(RTTAR hTar, PRTTARFILE phFile, char **ppszFilename, uint32_t fOpen);
|
---|
341 |
|
---|
342 |
|
---|
343 | /** @} */
|
---|
344 |
|
---|
345 | RT_C_DECLS_END
|
---|
346 |
|
---|
347 | #endif /* ___iprt_tar_h */
|
---|
348 |
|
---|