Changeset 98325 in vbox for trunk/include/iprt/formats
- Timestamp:
- Jan 26, 2023 4:16:07 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 155544
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/formats/tar.h
r98322 r98325 35 35 */ 36 36 37 #ifndef IPRT_INCLUDED_ SRC_common_zip_tar_h38 #define IPRT_INCLUDED_ SRC_common_zip_tar_h37 #ifndef IPRT_INCLUDED_formats_tar_h 38 #define IPRT_INCLUDED_formats_tar_h 39 39 #ifndef RT_WITHOUT_PRAGMA_ONCE 40 40 # pragma once … … 295 295 AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, devminor, RTZIPTARHDRGNU, devminor); 296 296 297 298 299 /** 300 * Tar header union. 301 */ 302 typedef union RTZIPTARHDR 303 { 304 /** Byte view. */ 305 char ab[512]; 306 /** The standard header. */ 307 RTZIPTARHDRANCIENT Ancient; 308 /** The standard header. */ 309 RTZIPTARHDRPOSIX Posix; 310 /** The GNU header. */ 311 RTZIPTARHDRGNU Gnu; 312 /** The bits common to both GNU and the standard header. */ 313 RTZIPTARHDRCOMMON Common; 314 /** GNU sparse header. */ 315 RTZIPTARHDRGNUSPARSE GnuSparse; 316 } RTZIPTARHDR; 317 AssertCompileSize(RTZIPTARHDR, 512); 318 /** Pointer to a tar file header. */ 319 typedef RTZIPTARHDR *PRTZIPTARHDR; 320 /** Pointer to a const tar file header. */ 321 typedef RTZIPTARHDR const *PCRTZIPTARHDR; 322 323 324 /** 325 * Tar header type. 326 */ 327 typedef enum RTZIPTARTYPE 328 { 329 /** Invalid type value. */ 330 RTZIPTARTYPE_INVALID = 0, 331 /** Posix header. */ 332 RTZIPTARTYPE_POSIX, 333 /** The old GNU header, has layout conflicting with posix. */ 334 RTZIPTARTYPE_GNU, 335 /** Ancient tar header which does not use anything beyond the magic. */ 336 RTZIPTARTYPE_ANCIENT, 337 /** End of the valid type values (this is not valid). */ 338 RTZIPTARTYPE_END, 339 /** The usual type blow up. */ 340 RTZIPTARTYPE_32BIT_HACK = 0x7fffffff 341 } RTZIPTARTYPE; 342 typedef RTZIPTARTYPE *PRTZIPTARTYPE; 343 344 345 /** 346 * Calculates the TAR header checksums and detects if it's all zeros. 347 * 348 * @returns true if all zeros, false if not. 349 * @param pHdr The header to checksum. 350 * @param pi32Unsigned Where to store the checksum calculated using 351 * unsigned chars. This is the one POSIX specifies. 352 * @param pi32Signed Where to store the checksum calculated using 353 * signed chars. 354 * 355 * @remarks The reason why we calculate the checksum as both signed and unsigned 356 * has to do with various the char C type being signed on some hosts 357 * and unsigned on others. 358 */ 359 DECLINLINE(bool) rtZipTarCalcChkSum(PCRTZIPTARHDR pHdr, int32_t *pi32Unsigned, int32_t *pi32Signed) 360 { 361 int32_t i32Unsigned = 0; 362 int32_t i32Signed = 0; 363 364 /* 365 * Sum up the entire header. 366 */ 367 const char *pch = (const char *)pHdr; 368 const char *pchEnd = pch + sizeof(*pHdr); 369 do 370 { 371 i32Unsigned += *(unsigned char *)pch; 372 i32Signed += *(signed char *)pch; 373 } while (++pch != pchEnd); 374 375 /* 376 * Check if it's all zeros and replace the chksum field with spaces. 377 */ 378 bool const fZeroHdr = i32Unsigned == 0; 379 380 pch = pHdr->Common.chksum; 381 pchEnd = pch + sizeof(pHdr->Common.chksum); 382 do 383 { 384 i32Unsigned -= *(unsigned char *)pch; 385 i32Signed -= *(signed char *)pch; 386 } while (++pch != pchEnd); 387 388 i32Unsigned += (unsigned char)' ' * sizeof(pHdr->Common.chksum); 389 i32Signed += (signed char)' ' * sizeof(pHdr->Common.chksum); 390 391 *pi32Unsigned = i32Unsigned; 392 if (pi32Signed) 393 *pi32Signed = i32Signed; 394 return fZeroHdr; 395 } 396 397 398 #endif /* !IPRT_INCLUDED_SRC_common_zip_tar_h */ 399 297 #endif /* !IPRT_INCLUDED_formats_tar_h */ 298
Note:
See TracChangeset
for help on using the changeset viewer.