@papyrus-sdk/engine-native 0.2.22-beta.9.epub.1 → 0.2.22-beta.9.epub.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/android/build.gradle +0 -1
  2. package/android/src/main/cpp/CMakeLists.txt +0 -137
  3. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +35 -305
  4. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +1 -3
  5. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +5 -195
  6. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +1 -20
  7. package/dist/index.d.mts +4 -614
  8. package/dist/index.d.ts +4 -614
  9. package/dist/index.js +8 -484
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +7 -477
  12. package/dist/index.mjs.map +1 -1
  13. package/ios/PapyrusEngineStore.h +0 -3
  14. package/ios/PapyrusEngineStore.m +6 -32
  15. package/ios/PapyrusNativeEngine.m +5 -684
  16. package/ios/PapyrusNativeEngine.podspec +15 -0
  17. package/ios/PapyrusPageView.m +11 -38
  18. package/package.json +8 -10
  19. package/react-native.config.js +1 -1
  20. package/PapyrusNativeEngine.podspec +0 -45
  21. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +0 -68
  22. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +0 -55
  23. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +0 -240
  24. package/android/src/main/cpp/papyrus_text_word_test.cpp +0 -72
  25. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +0 -14
  26. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +0 -491
  27. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +0 -32
  28. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +0 -38
  29. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +0 -195
  30. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +0 -48
  31. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +0 -22
  32. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +0 -661
  33. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +0 -49
  34. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +0 -43
  35. package/ios/PapyrusComicDocumentView.h +0 -21
  36. package/ios/PapyrusComicDocumentView.m +0 -554
  37. package/ios/PapyrusComicDocumentViewManager.m +0 -23
  38. package/ios/PapyrusPageRotationRegistry.h +0 -29
  39. package/ios/PapyrusPageRotationRegistry.m +0 -179
  40. package/ios/PapyrusPdfDocumentView.h +0 -55
  41. package/ios/PapyrusPdfDocumentView.m +0 -2339
  42. package/ios/PapyrusPdfDocumentViewManager.m +0 -61
  43. package/ios/PapyrusPdfPageTheme.h +0 -15
  44. package/ios/PapyrusPdfPageTheme.m +0 -218
  45. package/ios/PapyrusSelectionMenu.h +0 -27
  46. package/ios/PapyrusTextAnnotationRange.h +0 -2
  47. package/ios/PapyrusTextAnnotationRange.m +0 -29
  48. package/ios/PapyrusTextDocumentView.h +0 -32
  49. package/ios/PapyrusTextDocumentView.m +0 -518
  50. package/ios/PapyrusTextDocumentViewManager.m +0 -34
  51. package/ios/PapyrusTextStore.h +0 -13
  52. package/ios/PapyrusTextStore.m +0 -73
  53. package/third_party_licenses/BLAKE2-NOTICE.txt +0 -11
  54. package/third_party_licenses/libarchive-COPYING +0 -65
  55. package/vendor/libarchive/PapyrusComicArchive.cpp +0 -376
  56. package/vendor/libarchive/PapyrusComicArchive.h +0 -30
  57. package/vendor/libarchive/README.papyrus.md +0 -15
  58. package/vendor/libarchive/android.h +0 -192
  59. package/vendor/libarchive/config/PapyrusArchiveConfig.h +0 -71
  60. package/vendor/libarchive/libarchive/CMakeLists.txt +0 -293
  61. package/vendor/libarchive/libarchive/android_lf.h +0 -36
  62. package/vendor/libarchive/libarchive/archive.h +0 -1266
  63. package/vendor/libarchive/libarchive/archive_acl.c +0 -2025
  64. package/vendor/libarchive/libarchive/archive_acl_private.h +0 -85
  65. package/vendor/libarchive/libarchive/archive_blake2.h +0 -197
  66. package/vendor/libarchive/libarchive/archive_blake2_impl.h +0 -161
  67. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +0 -369
  68. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +0 -361
  69. package/vendor/libarchive/libarchive/archive_check_magic.c +0 -183
  70. package/vendor/libarchive/libarchive/archive_cmdline.c +0 -211
  71. package/vendor/libarchive/libarchive/archive_cmdline_private.h +0 -45
  72. package/vendor/libarchive/libarchive/archive_crc32.h +0 -123
  73. package/vendor/libarchive/libarchive/archive_cryptor.c +0 -534
  74. package/vendor/libarchive/libarchive/archive_cryptor_private.h +0 -199
  75. package/vendor/libarchive/libarchive/archive_digest.c +0 -1584
  76. package/vendor/libarchive/libarchive/archive_digest_private.h +0 -431
  77. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +0 -558
  78. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +0 -712
  79. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +0 -760
  80. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +0 -824
  81. package/vendor/libarchive/libarchive/archive_endian.h +0 -234
  82. package/vendor/libarchive/libarchive/archive_entry.3 +0 -147
  83. package/vendor/libarchive/libarchive/archive_entry.c +0 -2297
  84. package/vendor/libarchive/libarchive/archive_entry.h +0 -763
  85. package/vendor/libarchive/libarchive/archive_entry_acl.3 +0 -458
  86. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +0 -55
  87. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +0 -82
  88. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +0 -472
  89. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +0 -224
  90. package/vendor/libarchive/libarchive/archive_entry_locale.h +0 -90
  91. package/vendor/libarchive/libarchive/archive_entry_misc.3 +0 -63
  92. package/vendor/libarchive/libarchive/archive_entry_paths.3 +0 -153
  93. package/vendor/libarchive/libarchive/archive_entry_perms.3 +0 -210
  94. package/vendor/libarchive/libarchive/archive_entry_private.h +0 -205
  95. package/vendor/libarchive/libarchive/archive_entry_sparse.c +0 -156
  96. package/vendor/libarchive/libarchive/archive_entry_stat.3 +0 -274
  97. package/vendor/libarchive/libarchive/archive_entry_stat.c +0 -121
  98. package/vendor/libarchive/libarchive/archive_entry_strmode.c +0 -69
  99. package/vendor/libarchive/libarchive/archive_entry_time.3 +0 -127
  100. package/vendor/libarchive/libarchive/archive_entry_xattr.c +0 -155
  101. package/vendor/libarchive/libarchive/archive_hmac.c +0 -345
  102. package/vendor/libarchive/libarchive/archive_hmac_private.h +0 -119
  103. package/vendor/libarchive/libarchive/archive_integer.h +0 -267
  104. package/vendor/libarchive/libarchive/archive_match.c +0 -1869
  105. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +0 -54
  106. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +0 -54
  107. package/vendor/libarchive/libarchive/archive_options.c +0 -219
  108. package/vendor/libarchive/libarchive/archive_options_private.h +0 -49
  109. package/vendor/libarchive/libarchive/archive_pack_dev.c +0 -330
  110. package/vendor/libarchive/libarchive/archive_pack_dev.h +0 -49
  111. package/vendor/libarchive/libarchive/archive_parse_date.c +0 -1173
  112. package/vendor/libarchive/libarchive/archive_pathmatch.c +0 -480
  113. package/vendor/libarchive/libarchive/archive_pathmatch.h +0 -50
  114. package/vendor/libarchive/libarchive/archive_platform.h +0 -213
  115. package/vendor/libarchive/libarchive/archive_platform_acl.h +0 -53
  116. package/vendor/libarchive/libarchive/archive_platform_stat.h +0 -45
  117. package/vendor/libarchive/libarchive/archive_platform_xattr.h +0 -45
  118. package/vendor/libarchive/libarchive/archive_ppmd7.c +0 -1173
  119. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +0 -119
  120. package/vendor/libarchive/libarchive/archive_ppmd8.c +0 -1293
  121. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +0 -123
  122. package/vendor/libarchive/libarchive/archive_ppmd_private.h +0 -159
  123. package/vendor/libarchive/libarchive/archive_private.h +0 -209
  124. package/vendor/libarchive/libarchive/archive_random.c +0 -274
  125. package/vendor/libarchive/libarchive/archive_random_private.h +0 -36
  126. package/vendor/libarchive/libarchive/archive_rb.c +0 -709
  127. package/vendor/libarchive/libarchive/archive_rb.h +0 -113
  128. package/vendor/libarchive/libarchive/archive_read.3 +0 -250
  129. package/vendor/libarchive/libarchive/archive_read.c +0 -1814
  130. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +0 -72
  131. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +0 -189
  132. package/vendor/libarchive/libarchive/archive_read_append_filter.c +0 -209
  133. package/vendor/libarchive/libarchive/archive_read_data.3 +0 -128
  134. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +0 -207
  135. package/vendor/libarchive/libarchive/archive_read_disk.3 +0 -422
  136. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +0 -1086
  137. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +0 -2639
  138. package/vendor/libarchive/libarchive/archive_read_disk_private.h +0 -97
  139. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +0 -315
  140. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +0 -2603
  141. package/vendor/libarchive/libarchive/archive_read_extract.3 +0 -135
  142. package/vendor/libarchive/libarchive/archive_read_extract.c +0 -59
  143. package/vendor/libarchive/libarchive/archive_read_extract2.c +0 -154
  144. package/vendor/libarchive/libarchive/archive_read_filter.3 +0 -163
  145. package/vendor/libarchive/libarchive/archive_read_format.3 +0 -190
  146. package/vendor/libarchive/libarchive/archive_read_free.3 +0 -91
  147. package/vendor/libarchive/libarchive/archive_read_header.3 +0 -89
  148. package/vendor/libarchive/libarchive/archive_read_new.3 +0 -57
  149. package/vendor/libarchive/libarchive/archive_read_open.3 +0 -247
  150. package/vendor/libarchive/libarchive/archive_read_open_fd.c +0 -236
  151. package/vendor/libarchive/libarchive/archive_read_open_file.c +0 -257
  152. package/vendor/libarchive/libarchive/archive_read_open_filename.c +0 -652
  153. package/vendor/libarchive/libarchive/archive_read_open_memory.c +0 -188
  154. package/vendor/libarchive/libarchive/archive_read_private.h +0 -274
  155. package/vendor/libarchive/libarchive/archive_read_set_format.c +0 -116
  156. package/vendor/libarchive/libarchive/archive_read_set_options.3 +0 -290
  157. package/vendor/libarchive/libarchive/archive_read_set_options.c +0 -132
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +0 -84
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +0 -68
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +0 -360
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +0 -457
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +0 -108
  163. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +0 -538
  164. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +0 -119
  165. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +0 -829
  166. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +0 -493
  167. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +0 -51
  168. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +0 -497
  169. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +0 -249
  170. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +0 -739
  171. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +0 -792
  172. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +0 -356
  173. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +0 -4650
  174. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +0 -88
  175. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +0 -597
  176. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +0 -76
  177. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +0 -3410
  178. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +0 -1152
  179. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +0 -95
  180. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +0 -3516
  181. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +0 -2931
  182. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +0 -2113
  183. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +0 -3932
  184. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +0 -4501
  185. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +0 -194
  186. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +0 -3785
  187. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +0 -875
  188. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +0 -3770
  189. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +0 -4710
  190. package/vendor/libarchive/libarchive/archive_string.c +0 -4391
  191. package/vendor/libarchive/libarchive/archive_string.h +0 -244
  192. package/vendor/libarchive/libarchive/archive_string_composition.h +0 -2289
  193. package/vendor/libarchive/libarchive/archive_string_sprintf.c +0 -200
  194. package/vendor/libarchive/libarchive/archive_time.c +0 -168
  195. package/vendor/libarchive/libarchive/archive_time_private.h +0 -47
  196. package/vendor/libarchive/libarchive/archive_util.3 +0 -239
  197. package/vendor/libarchive/libarchive/archive_util.c +0 -668
  198. package/vendor/libarchive/libarchive/archive_version_details.c +0 -516
  199. package/vendor/libarchive/libarchive/archive_virtual.c +0 -162
  200. package/vendor/libarchive/libarchive/archive_windows.c +0 -1035
  201. package/vendor/libarchive/libarchive/archive_windows.h +0 -332
  202. package/vendor/libarchive/libarchive/archive_write.3 +0 -266
  203. package/vendor/libarchive/libarchive/archive_write.c +0 -896
  204. package/vendor/libarchive/libarchive/archive_write_add_filter.c +0 -71
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +0 -329
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +0 -76
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +0 -411
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +0 -459
  209. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +0 -143
  210. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +0 -493
  211. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +0 -214
  212. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +0 -710
  213. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +0 -500
  214. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +0 -42
  215. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +0 -398
  216. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +0 -320
  217. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +0 -547
  218. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +0 -608
  219. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +0 -112
  220. package/vendor/libarchive/libarchive/archive_write_data.3 +0 -88
  221. package/vendor/libarchive/libarchive/archive_write_disk.3 +0 -360
  222. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +0 -4789
  223. package/vendor/libarchive/libarchive/archive_write_disk_private.h +0 -43
  224. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +0 -265
  225. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +0 -2952
  226. package/vendor/libarchive/libarchive/archive_write_filter.3 +0 -140
  227. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +0 -77
  228. package/vendor/libarchive/libarchive/archive_write_format.3 +0 -187
  229. package/vendor/libarchive/libarchive/archive_write_free.3 +0 -94
  230. package/vendor/libarchive/libarchive/archive_write_header.3 +0 -71
  231. package/vendor/libarchive/libarchive/archive_write_new.3 +0 -56
  232. package/vendor/libarchive/libarchive/archive_write_open.3 +0 -270
  233. package/vendor/libarchive/libarchive/archive_write_open_fd.c +0 -141
  234. package/vendor/libarchive/libarchive/archive_write_open_file.c +0 -102
  235. package/vendor/libarchive/libarchive/archive_write_open_filename.c +0 -272
  236. package/vendor/libarchive/libarchive/archive_write_open_memory.c +0 -110
  237. package/vendor/libarchive/libarchive/archive_write_private.h +0 -166
  238. package/vendor/libarchive/libarchive/archive_write_set_format.c +0 -124
  239. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +0 -2571
  240. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +0 -540
  241. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +0 -93
  242. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +0 -11
  243. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +0 -618
  244. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +0 -457
  245. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +0 -508
  246. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +0 -141
  247. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +0 -790
  248. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +0 -8216
  249. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +0 -2307
  250. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +0 -2249
  251. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +0 -40
  252. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +0 -123
  253. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +0 -650
  254. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +0 -768
  255. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +0 -648
  256. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +0 -491
  257. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +0 -3799
  258. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +0 -2548
  259. package/vendor/libarchive/libarchive/archive_write_set_options.3 +0 -779
  260. package/vendor/libarchive/libarchive/archive_write_set_options.c +0 -129
  261. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +0 -72
  262. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +0 -95
  263. package/vendor/libarchive/libarchive/archive_xxhash.h +0 -48
  264. package/vendor/libarchive/libarchive/config_freebsd.h +0 -275
  265. package/vendor/libarchive/libarchive/cpio.5 +0 -389
  266. package/vendor/libarchive/libarchive/filter_fork.h +0 -44
  267. package/vendor/libarchive/libarchive/filter_fork_posix.c +0 -269
  268. package/vendor/libarchive/libarchive/filter_fork_windows.c +0 -270
  269. package/vendor/libarchive/libarchive/libarchive-formats.5 +0 -478
  270. package/vendor/libarchive/libarchive/libarchive.3 +0 -297
  271. package/vendor/libarchive/libarchive/libarchive_changes.3 +0 -339
  272. package/vendor/libarchive/libarchive/libarchive_internals.3 +0 -363
  273. package/vendor/libarchive/libarchive/module.modulemap +0 -34
  274. package/vendor/libarchive/libarchive/mtree.5 +0 -323
  275. package/vendor/libarchive/libarchive/tar.5 +0 -947
  276. package/vendor/libarchive/libarchive/xxhash.c +0 -531
@@ -1,1086 +0,0 @@
1
- /*-
2
- * Copyright (c) 2003-2009 Tim Kientzle
3
- * Copyright (c) 2010-2012 Michihiro NAKAJIMA
4
- * Copyright (c) 2016 Martin Matuska
5
- * All rights reserved.
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions
9
- * are met:
10
- * 1. Redistributions of source code must retain the above copyright
11
- * notice, this list of conditions and the following disclaimer.
12
- * 2. Redistributions in binary form must reproduce the above copyright
13
- * notice, this list of conditions and the following disclaimer in the
14
- * documentation and/or other materials provided with the distribution.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- */
27
-
28
- #include "archive_platform.h"
29
-
30
- /* This is the tree-walking code for POSIX systems. */
31
- #if !defined(_WIN32) || defined(__CYGWIN__)
32
-
33
- #ifdef HAVE_SYS_TYPES_H
34
- #include <sys/types.h>
35
- #endif
36
- #ifdef HAVE_SYS_EXTATTR_H
37
- #include <sys/extattr.h>
38
- #endif
39
- #ifdef HAVE_SYS_IOCTL_H
40
- #include <sys/ioctl.h>
41
- #endif
42
- #ifdef HAVE_SYS_PARAM_H
43
- #include <sys/param.h>
44
- #endif
45
- #ifdef HAVE_SYS_STAT_H
46
- #include <sys/stat.h>
47
- #endif
48
- #if defined(HAVE_SYS_XATTR_H)
49
- #include <sys/xattr.h>
50
- #elif defined(HAVE_ATTR_XATTR_H)
51
- #include <attr/xattr.h>
52
- #endif
53
- #ifdef HAVE_SYS_EA_H
54
- #include <sys/ea.h>
55
- #endif
56
- #ifdef HAVE_COPYFILE_H
57
- #include <copyfile.h>
58
- #endif
59
- #ifdef HAVE_ERRNO_H
60
- #include <errno.h>
61
- #endif
62
- #ifdef HAVE_FCNTL_H
63
- #include <fcntl.h>
64
- #endif
65
- #ifdef HAVE_LIMITS_H
66
- #include <limits.h>
67
- #endif
68
- #ifdef HAVE_LINUX_TYPES_H
69
- #include <linux/types.h>
70
- #endif
71
- #ifdef HAVE_LINUX_FIEMAP_H
72
- #include <linux/fiemap.h>
73
- #endif
74
- #ifdef HAVE_LINUX_FS_H
75
- #include <linux/fs.h>
76
- #endif
77
- /*
78
- * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
79
- * As the include guards don't agree, the order of include is important.
80
- */
81
- #ifdef HAVE_LINUX_EXT2_FS_H
82
- #include <linux/ext2_fs.h> /* for Linux file flags */
83
- #endif
84
- #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
85
- #include <ext2fs/ext2_fs.h> /* Linux file flags, broken on Cygwin */
86
- #endif
87
- #ifdef HAVE_PATHS_H
88
- #include <paths.h>
89
- #endif
90
- #ifdef HAVE_UNISTD_H
91
- #include <unistd.h>
92
- #endif
93
-
94
- #include "archive.h"
95
- #include "archive_entry.h"
96
- #include "archive_private.h"
97
- #include "archive_read_disk_private.h"
98
-
99
- #ifndef O_CLOEXEC
100
- #define O_CLOEXEC 0
101
- #endif
102
-
103
- static int setup_mac_metadata(struct archive_read_disk *,
104
- struct archive_entry *, int *fd);
105
- #ifdef ARCHIVE_XATTR_FREEBSD
106
- static int setup_xattrs_namespace(struct archive_read_disk *,
107
- struct archive_entry *, int *, int);
108
- #endif
109
- static int setup_xattrs(struct archive_read_disk *,
110
- struct archive_entry *, int *fd);
111
- static int setup_sparse(struct archive_read_disk *,
112
- struct archive_entry *, int *fd);
113
- #if defined(HAVE_LINUX_FIEMAP_H)
114
- static int setup_sparse_fiemap(struct archive_read_disk *,
115
- struct archive_entry *, int *fd);
116
- #endif
117
-
118
- #if !ARCHIVE_ACL_SUPPORT
119
- int
120
- archive_read_disk_entry_setup_acls(struct archive_read_disk *a,
121
- struct archive_entry *entry, int *fd)
122
- {
123
- (void)a; /* UNUSED */
124
- (void)entry; /* UNUSED */
125
- (void)fd; /* UNUSED */
126
- return (ARCHIVE_OK);
127
- }
128
- #endif
129
-
130
- /*
131
- * Enter working directory and return working pathname of archive_entry.
132
- * If a pointer to an integer is provided and its value is below zero
133
- * open a file descriptor on this pathname.
134
- */
135
- const char *
136
- archive_read_disk_entry_setup_path(struct archive_read_disk *a,
137
- struct archive_entry *entry, int *fd)
138
- {
139
- const char *path;
140
-
141
- path = archive_entry_sourcepath(entry);
142
-
143
- if (path == NULL || (a->tree != NULL &&
144
- a->tree_enter_working_dir(a->tree) != 0))
145
- path = archive_entry_pathname(entry);
146
- if (path == NULL) {
147
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
148
- "Couldn't determine path");
149
- } else if (fd != NULL && *fd < 0 && a->tree != NULL &&
150
- (a->follow_symlinks || archive_entry_filetype(entry) != AE_IFLNK)) {
151
- *fd = a->open_on_current_dir(a->tree, path,
152
- O_RDONLY | O_NONBLOCK);
153
- }
154
- return (path);
155
- }
156
-
157
- int
158
- archive_read_disk_entry_from_file(struct archive *_a,
159
- struct archive_entry *entry,
160
- int fd,
161
- const struct stat *st)
162
- {
163
- struct archive_read_disk *a = (struct archive_read_disk *)_a;
164
- const char *path, *name;
165
- struct stat s;
166
- int initial_fd = fd;
167
- int r, r1;
168
-
169
- archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_ANY,
170
- "archive_read_disk_entry_from_file");
171
-
172
- archive_clear_error(_a);
173
- path = archive_entry_sourcepath(entry);
174
- if (path == NULL)
175
- path = archive_entry_pathname(entry);
176
-
177
- if (a->tree == NULL) {
178
- if (st == NULL) {
179
- #if HAVE_FSTAT
180
- if (fd >= 0) {
181
- if (fstat(fd, &s) != 0) {
182
- archive_set_error(&a->archive, errno,
183
- "Can't fstat");
184
- return (ARCHIVE_FAILED);
185
- }
186
- } else
187
- #endif
188
- #if HAVE_LSTAT
189
- if (!a->follow_symlinks) {
190
- if (lstat(path, &s) != 0) {
191
- archive_set_error(&a->archive, errno,
192
- "Can't lstat %s", path);
193
- return (ARCHIVE_FAILED);
194
- }
195
- } else
196
- #endif
197
- if (la_stat(path, &s) != 0) {
198
- archive_set_error(&a->archive, errno,
199
- "Can't stat %s", path);
200
- return (ARCHIVE_FAILED);
201
- }
202
- st = &s;
203
- }
204
- archive_entry_copy_stat(entry, st);
205
- }
206
-
207
- /* Lookup uname/gname */
208
- name = archive_read_disk_uname(_a, archive_entry_uid(entry));
209
- if (name != NULL)
210
- archive_entry_copy_uname(entry, name);
211
- name = archive_read_disk_gname(_a, archive_entry_gid(entry));
212
- if (name != NULL)
213
- archive_entry_copy_gname(entry, name);
214
-
215
- #ifdef HAVE_STRUCT_STAT_ST_FLAGS
216
- /* On FreeBSD, we get flags for free with the stat. */
217
- /* TODO: Does this belong in copy_stat()? */
218
- if ((a->flags & ARCHIVE_READDISK_NO_FFLAGS) == 0 && st->st_flags != 0)
219
- archive_entry_set_fflags(entry, st->st_flags, 0);
220
- #endif
221
-
222
- #if (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS)) || \
223
- (defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS))
224
- /* Linux requires an extra ioctl to pull the flags. Although
225
- * this is an extra step, it has a nice side-effect: We get an
226
- * open file descriptor which we can use in the subsequent lookups. */
227
- if ((a->flags & ARCHIVE_READDISK_NO_FFLAGS) == 0 &&
228
- (S_ISREG(st->st_mode) || S_ISDIR(st->st_mode))) {
229
- if (fd < 0) {
230
- if (a->tree != NULL)
231
- fd = a->open_on_current_dir(a->tree, path,
232
- O_RDONLY | O_NONBLOCK | O_CLOEXEC);
233
- else
234
- fd = open(path, O_RDONLY | O_NONBLOCK |
235
- O_CLOEXEC);
236
- __archive_ensure_cloexec_flag(fd);
237
- }
238
- if (fd >= 0) {
239
- int stflags;
240
- r = ioctl(fd,
241
- #if defined(FS_IOC_GETFLAGS)
242
- FS_IOC_GETFLAGS,
243
- #else
244
- EXT2_IOC_GETFLAGS,
245
- #endif
246
- &stflags);
247
- if (r == 0 && stflags != 0)
248
- archive_entry_set_fflags(entry, stflags, 0);
249
- }
250
- }
251
- #endif
252
-
253
- #if defined(HAVE_READLINK) || defined(HAVE_READLINKAT)
254
- if (S_ISLNK(st->st_mode)) {
255
- size_t linkbuffer_len = st->st_size;
256
- char *linkbuffer;
257
- ssize_t lnklen;
258
-
259
- if (st->st_size >= SSIZE_MAX) {
260
- archive_set_error(&a->archive, ENOMEM,
261
- "Couldn't read link data");
262
- return (ARCHIVE_FAILED);
263
- }
264
- linkbuffer = malloc(linkbuffer_len + 1);
265
- if (linkbuffer == NULL) {
266
- archive_set_error(&a->archive, ENOMEM,
267
- "Couldn't read link data");
268
- return (ARCHIVE_FAILED);
269
- }
270
- if (a->tree != NULL) {
271
- #ifdef HAVE_READLINKAT
272
- lnklen = readlinkat(a->tree_current_dir_fd(a->tree),
273
- path, linkbuffer, linkbuffer_len);
274
- #else
275
- if (a->tree_enter_working_dir(a->tree) != 0) {
276
- archive_set_error(&a->archive, errno,
277
- "Couldn't read link data");
278
- free(linkbuffer);
279
- return (ARCHIVE_FAILED);
280
- }
281
- lnklen = readlink(path, linkbuffer, linkbuffer_len);
282
- #endif /* HAVE_READLINKAT */
283
- } else
284
- lnklen = readlink(path, linkbuffer, linkbuffer_len);
285
- if (lnklen < 0) {
286
- archive_set_error(&a->archive, errno,
287
- "Couldn't read link data");
288
- free(linkbuffer);
289
- return (ARCHIVE_FAILED);
290
- }
291
- linkbuffer[lnklen] = '\0';
292
- archive_entry_set_symlink(entry, linkbuffer);
293
- free(linkbuffer);
294
- }
295
- #endif /* HAVE_READLINK || HAVE_READLINKAT */
296
-
297
- r = 0;
298
- if ((a->flags & ARCHIVE_READDISK_NO_ACL) == 0)
299
- r = archive_read_disk_entry_setup_acls(a, entry, &fd);
300
- if ((a->flags & ARCHIVE_READDISK_NO_XATTR) == 0) {
301
- r1 = setup_xattrs(a, entry, &fd);
302
- if (r1 < r)
303
- r = r1;
304
- }
305
- if (a->flags & ARCHIVE_READDISK_MAC_COPYFILE) {
306
- r1 = setup_mac_metadata(a, entry, &fd);
307
- if (r1 < r)
308
- r = r1;
309
- }
310
- if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) {
311
- r1 = setup_sparse(a, entry, &fd);
312
- if (r1 < r)
313
- r = r1;
314
- }
315
-
316
- /* If we opened the file earlier in this function, close it. */
317
- if (initial_fd != fd)
318
- close(fd);
319
- return (r);
320
- }
321
-
322
- #if defined(__APPLE__) && defined(HAVE_COPYFILE_H)
323
- /*
324
- * The Mac OS "copyfile()" API copies the extended metadata for a
325
- * file into a separate file in AppleDouble format (see RFC 1740).
326
- *
327
- * Mac OS tar and cpio implementations store this extended
328
- * metadata as a separate entry just before the regular entry
329
- * with a "._" prefix added to the filename.
330
- *
331
- * Note that this is currently done unconditionally; the tar program has
332
- * an option to discard this information before the archive is written.
333
- *
334
- * TODO: If there's a failure, report it and return ARCHIVE_WARN.
335
- */
336
- static int
337
- setup_mac_metadata(struct archive_read_disk *a,
338
- struct archive_entry *entry, int *fd)
339
- {
340
- int tempfd = -1;
341
- int copyfile_flags = COPYFILE_NOFOLLOW | COPYFILE_ACL | COPYFILE_XATTR;
342
- struct stat copyfile_stat;
343
- int ret = ARCHIVE_OK;
344
- void *buff = NULL;
345
- int have_attrs;
346
- const char *name;
347
- struct archive_string tempfile;
348
-
349
- (void)fd; /* UNUSED */
350
-
351
- name = archive_read_disk_entry_setup_path(a, entry, NULL);
352
- if (name == NULL)
353
- return (ARCHIVE_WARN);
354
-
355
- /* Short-circuit if there's nothing to do. */
356
- have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK);
357
- if (have_attrs == -1) {
358
- archive_set_error(&a->archive, errno,
359
- "Could not check extended attributes");
360
- return (ARCHIVE_WARN);
361
- }
362
- if (have_attrs == 0)
363
- return (ARCHIVE_OK);
364
-
365
- archive_string_init(&tempfile);
366
- archive_strcpy(&tempfile, name);
367
- archive_string_dirname(&tempfile);
368
- archive_strcat(&tempfile, "/tar.XXXXXXXX");
369
- tempfd = __archive_mkstemp(tempfile.s);
370
- if (tempfd < 0) {
371
- archive_set_error(&a->archive, errno,
372
- "Could not open extended attribute file");
373
- ret = ARCHIVE_WARN;
374
- goto cleanup;
375
- }
376
- __archive_ensure_cloexec_flag(tempfd);
377
-
378
- /* XXX I wish copyfile() could pack directly to a memory
379
- * buffer; that would avoid the temp file here. For that
380
- * matter, it would be nice if fcopyfile() actually worked,
381
- * that would reduce the many open/close races here. */
382
- if (copyfile(name, tempfile.s, 0, copyfile_flags | COPYFILE_PACK)) {
383
- archive_set_error(&a->archive, errno,
384
- "Could not pack extended attributes");
385
- ret = ARCHIVE_WARN;
386
- goto cleanup;
387
- }
388
- if (fstat(tempfd, &copyfile_stat)) {
389
- archive_set_error(&a->archive, errno,
390
- "Could not check size of extended attributes");
391
- ret = ARCHIVE_WARN;
392
- goto cleanup;
393
- }
394
- buff = malloc(copyfile_stat.st_size);
395
- if (buff == NULL) {
396
- archive_set_error(&a->archive, errno,
397
- "Could not allocate memory for extended attributes");
398
- ret = ARCHIVE_WARN;
399
- goto cleanup;
400
- }
401
- if (copyfile_stat.st_size != read(tempfd, buff, copyfile_stat.st_size)) {
402
- archive_set_error(&a->archive, errno,
403
- "Could not read extended attributes into memory");
404
- ret = ARCHIVE_WARN;
405
- goto cleanup;
406
- }
407
- archive_entry_copy_mac_metadata(entry, buff, copyfile_stat.st_size);
408
-
409
- cleanup:
410
- if (tempfd >= 0) {
411
- close(tempfd);
412
- unlink(tempfile.s);
413
- }
414
- archive_string_free(&tempfile);
415
- free(buff);
416
- return (ret);
417
- }
418
-
419
- #else
420
-
421
- /*
422
- * Stub implementation for non-Mac systems.
423
- */
424
- static int
425
- setup_mac_metadata(struct archive_read_disk *a,
426
- struct archive_entry *entry, int *fd)
427
- {
428
- (void)a; /* UNUSED */
429
- (void)entry; /* UNUSED */
430
- (void)fd; /* UNUSED */
431
- return (ARCHIVE_OK);
432
- }
433
- #endif
434
-
435
- #if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX
436
-
437
- /*
438
- * Linux, Darwin and AIX extended attribute support.
439
- *
440
- * TODO: By using a stack-allocated buffer for the first
441
- * call to getxattr(), we might be able to avoid the second
442
- * call entirely. We only need the second call if the
443
- * stack-allocated buffer is too small. But a modest buffer
444
- * of 1024 bytes or so will often be big enough. Same applies
445
- * to listxattr().
446
- */
447
-
448
-
449
- static int
450
- setup_xattr(struct archive_read_disk *a,
451
- struct archive_entry *entry, const char *name, int fd, const char *accpath)
452
- {
453
- ssize_t size;
454
- void *value = NULL;
455
-
456
-
457
- if (fd >= 0) {
458
- #if ARCHIVE_XATTR_LINUX
459
- size = fgetxattr(fd, name, NULL, 0);
460
- #elif ARCHIVE_XATTR_DARWIN
461
- size = fgetxattr(fd, name, NULL, 0, 0, 0);
462
- #elif ARCHIVE_XATTR_AIX
463
- size = fgetea(fd, name, NULL, 0);
464
- #endif
465
- } else if (!a->follow_symlinks) {
466
- #if ARCHIVE_XATTR_LINUX
467
- size = lgetxattr(accpath, name, NULL, 0);
468
- #elif ARCHIVE_XATTR_DARWIN
469
- size = getxattr(accpath, name, NULL, 0, 0, XATTR_NOFOLLOW);
470
- #elif ARCHIVE_XATTR_AIX
471
- size = lgetea(accpath, name, NULL, 0);
472
- #endif
473
- } else {
474
- #if ARCHIVE_XATTR_LINUX
475
- size = getxattr(accpath, name, NULL, 0);
476
- #elif ARCHIVE_XATTR_DARWIN
477
- size = getxattr(accpath, name, NULL, 0, 0, 0);
478
- #elif ARCHIVE_XATTR_AIX
479
- size = getea(accpath, name, NULL, 0);
480
- #endif
481
- }
482
-
483
- if (size == -1) {
484
- archive_set_error(&a->archive, errno,
485
- "Couldn't query extended attribute");
486
- return (ARCHIVE_WARN);
487
- }
488
-
489
- if (size > 0 && (value = malloc(size)) == NULL) {
490
- archive_set_error(&a->archive, errno, "Out of memory");
491
- return (ARCHIVE_FATAL);
492
- }
493
-
494
-
495
- if (fd >= 0) {
496
- #if ARCHIVE_XATTR_LINUX
497
- size = fgetxattr(fd, name, value, size);
498
- #elif ARCHIVE_XATTR_DARWIN
499
- size = fgetxattr(fd, name, value, size, 0, 0);
500
- #elif ARCHIVE_XATTR_AIX
501
- size = fgetea(fd, name, value, size);
502
- #endif
503
- } else if (!a->follow_symlinks) {
504
- #if ARCHIVE_XATTR_LINUX
505
- size = lgetxattr(accpath, name, value, size);
506
- #elif ARCHIVE_XATTR_DARWIN
507
- size = getxattr(accpath, name, value, size, 0, XATTR_NOFOLLOW);
508
- #elif ARCHIVE_XATTR_AIX
509
- size = lgetea(accpath, name, value, size);
510
- #endif
511
- } else {
512
- #if ARCHIVE_XATTR_LINUX
513
- size = getxattr(accpath, name, value, size);
514
- #elif ARCHIVE_XATTR_DARWIN
515
- size = getxattr(accpath, name, value, size, 0, 0);
516
- #elif ARCHIVE_XATTR_AIX
517
- size = getea(accpath, name, value, size);
518
- #endif
519
- }
520
-
521
- if (size == -1) {
522
- archive_set_error(&a->archive, errno,
523
- "Couldn't read extended attribute");
524
- free(value);
525
- return (ARCHIVE_WARN);
526
- }
527
-
528
- archive_entry_xattr_add_entry(entry, name, value, size);
529
-
530
- free(value);
531
- return (ARCHIVE_OK);
532
- }
533
-
534
- static int
535
- setup_xattrs(struct archive_read_disk *a,
536
- struct archive_entry *entry, int *fd)
537
- {
538
- char *list, *p;
539
- const char *path;
540
- ssize_t list_size;
541
-
542
- path = NULL;
543
-
544
- if (*fd < 0) {
545
- path = archive_read_disk_entry_setup_path(a, entry, fd);
546
- if (path == NULL)
547
- return (ARCHIVE_WARN);
548
- }
549
-
550
- if (*fd >= 0) {
551
- #if ARCHIVE_XATTR_LINUX
552
- list_size = flistxattr(*fd, NULL, 0);
553
- #elif ARCHIVE_XATTR_DARWIN
554
- list_size = flistxattr(*fd, NULL, 0, 0);
555
- #elif ARCHIVE_XATTR_AIX
556
- list_size = flistea(*fd, NULL, 0);
557
- #endif
558
- } else if (!a->follow_symlinks) {
559
- #if ARCHIVE_XATTR_LINUX
560
- list_size = llistxattr(path, NULL, 0);
561
- #elif ARCHIVE_XATTR_DARWIN
562
- list_size = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
563
- #elif ARCHIVE_XATTR_AIX
564
- list_size = llistea(path, NULL, 0);
565
- #endif
566
- } else {
567
- #if ARCHIVE_XATTR_LINUX
568
- list_size = listxattr(path, NULL, 0);
569
- #elif ARCHIVE_XATTR_DARWIN
570
- list_size = listxattr(path, NULL, 0, 0);
571
- #elif ARCHIVE_XATTR_AIX
572
- list_size = listea(path, NULL, 0);
573
- #endif
574
- }
575
-
576
- if (list_size == -1) {
577
- if (errno == ENOTSUP || errno == ENOSYS)
578
- return (ARCHIVE_OK);
579
- archive_set_error(&a->archive, errno,
580
- "Couldn't list extended attributes");
581
- return (ARCHIVE_WARN);
582
- }
583
-
584
- if (list_size == 0)
585
- return (ARCHIVE_OK);
586
-
587
- if ((list = malloc(list_size)) == NULL) {
588
- archive_set_error(&a->archive, errno, "Out of memory");
589
- return (ARCHIVE_FATAL);
590
- }
591
-
592
- if (*fd >= 0) {
593
- #if ARCHIVE_XATTR_LINUX
594
- list_size = flistxattr(*fd, list, list_size);
595
- #elif ARCHIVE_XATTR_DARWIN
596
- list_size = flistxattr(*fd, list, list_size, 0);
597
- #elif ARCHIVE_XATTR_AIX
598
- list_size = flistea(*fd, list, list_size);
599
- #endif
600
- } else if (!a->follow_symlinks) {
601
- #if ARCHIVE_XATTR_LINUX
602
- list_size = llistxattr(path, list, list_size);
603
- #elif ARCHIVE_XATTR_DARWIN
604
- list_size = listxattr(path, list, list_size, XATTR_NOFOLLOW);
605
- #elif ARCHIVE_XATTR_AIX
606
- list_size = llistea(path, list, list_size);
607
- #endif
608
- } else {
609
- #if ARCHIVE_XATTR_LINUX
610
- list_size = listxattr(path, list, list_size);
611
- #elif ARCHIVE_XATTR_DARWIN
612
- list_size = listxattr(path, list, list_size, 0);
613
- #elif ARCHIVE_XATTR_AIX
614
- list_size = listea(path, list, list_size);
615
- #endif
616
- }
617
-
618
- if (list_size == -1) {
619
- archive_set_error(&a->archive, errno,
620
- "Couldn't retrieve extended attributes");
621
- free(list);
622
- return (ARCHIVE_WARN);
623
- }
624
-
625
- for (p = list; (p - list) < list_size; p += strlen(p) + 1) {
626
- #if ARCHIVE_XATTR_LINUX
627
- /* Linux: skip POSIX.1e ACL extended attributes */
628
- if (strncmp(p, "system.", 7) == 0 &&
629
- (strcmp(p + 7, "posix_acl_access") == 0 ||
630
- strcmp(p + 7, "posix_acl_default") == 0))
631
- continue;
632
- if (strncmp(p, "trusted.SGI_", 12) == 0 &&
633
- (strcmp(p + 12, "ACL_DEFAULT") == 0 ||
634
- strcmp(p + 12, "ACL_FILE") == 0))
635
- continue;
636
-
637
- /* Linux: xfsroot namespace is obsolete and unsupported */
638
- if (strncmp(p, "xfsroot.", 8) == 0)
639
- continue;
640
- #endif
641
- setup_xattr(a, entry, p, *fd, path);
642
- }
643
-
644
- free(list);
645
- return (ARCHIVE_OK);
646
- }
647
-
648
- #elif ARCHIVE_XATTR_FREEBSD
649
-
650
- /*
651
- * FreeBSD extattr interface.
652
- */
653
-
654
- /* TODO: Implement this. Follow the Linux model above, but
655
- * with FreeBSD-specific system calls, of course. Be careful
656
- * to not include the system extattrs that hold ACLs; we handle
657
- * those separately.
658
- */
659
- static int
660
- setup_xattr(struct archive_read_disk *a, struct archive_entry *entry,
661
- int namespace, const char *name, const char *fullname, int fd,
662
- const char *path);
663
-
664
- static int
665
- setup_xattr(struct archive_read_disk *a, struct archive_entry *entry,
666
- int namespace, const char *name, const char *fullname, int fd,
667
- const char *accpath)
668
- {
669
- ssize_t size;
670
- void *value = NULL;
671
-
672
- if (fd >= 0)
673
- size = extattr_get_fd(fd, namespace, name, NULL, 0);
674
- else if (!a->follow_symlinks)
675
- size = extattr_get_link(accpath, namespace, name, NULL, 0);
676
- else
677
- size = extattr_get_file(accpath, namespace, name, NULL, 0);
678
-
679
- if (size == -1) {
680
- archive_set_error(&a->archive, errno,
681
- "Couldn't query extended attribute");
682
- return (ARCHIVE_WARN);
683
- }
684
-
685
- if (size > 0 && (value = malloc(size)) == NULL) {
686
- archive_set_error(&a->archive, errno, "Out of memory");
687
- return (ARCHIVE_FATAL);
688
- }
689
-
690
- if (fd >= 0)
691
- size = extattr_get_fd(fd, namespace, name, value, size);
692
- else if (!a->follow_symlinks)
693
- size = extattr_get_link(accpath, namespace, name, value, size);
694
- else
695
- size = extattr_get_file(accpath, namespace, name, value, size);
696
-
697
- if (size == -1) {
698
- free(value);
699
- archive_set_error(&a->archive, errno,
700
- "Couldn't read extended attribute");
701
- return (ARCHIVE_WARN);
702
- }
703
-
704
- archive_entry_xattr_add_entry(entry, fullname, value, size);
705
-
706
- free(value);
707
- return (ARCHIVE_OK);
708
- }
709
-
710
- static int
711
- setup_xattrs_namespace(struct archive_read_disk *a,
712
- struct archive_entry *entry, int *fd, int namespace)
713
- {
714
- char buff[512];
715
- char *list, *p;
716
- ssize_t list_size;
717
- const char *path;
718
-
719
- path = NULL;
720
-
721
- if (*fd < 0) {
722
- path = archive_read_disk_entry_setup_path(a, entry, fd);
723
- if (path == NULL)
724
- return (ARCHIVE_WARN);
725
- }
726
-
727
- if (*fd >= 0)
728
- list_size = extattr_list_fd(*fd, namespace, NULL, 0);
729
- else if (!a->follow_symlinks)
730
- list_size = extattr_list_link(path, namespace, NULL, 0);
731
- else
732
- list_size = extattr_list_file(path, namespace, NULL, 0);
733
-
734
- if (list_size == -1 && errno == EOPNOTSUPP)
735
- return (ARCHIVE_OK);
736
- if (list_size == -1 && errno == EPERM)
737
- return (ARCHIVE_OK);
738
- if (list_size == -1) {
739
- archive_set_error(&a->archive, errno,
740
- "Couldn't list extended attributes");
741
- return (ARCHIVE_WARN);
742
- }
743
-
744
- if (list_size == 0)
745
- return (ARCHIVE_OK);
746
-
747
- if ((list = malloc(list_size)) == NULL) {
748
- archive_set_error(&a->archive, errno, "Out of memory");
749
- return (ARCHIVE_FATAL);
750
- }
751
-
752
- if (*fd >= 0)
753
- list_size = extattr_list_fd(*fd, namespace, list, list_size);
754
- else if (!a->follow_symlinks)
755
- list_size = extattr_list_link(path, namespace, list, list_size);
756
- else
757
- list_size = extattr_list_file(path, namespace, list, list_size);
758
-
759
- if (list_size == -1) {
760
- archive_set_error(&a->archive, errno,
761
- "Couldn't retrieve extended attributes");
762
- free(list);
763
- return (ARCHIVE_WARN);
764
- }
765
-
766
- p = list;
767
- while ((p - list) < list_size) {
768
- size_t len = 255 & (int)*p;
769
- char *name;
770
-
771
- if (namespace == EXTATTR_NAMESPACE_SYSTEM) {
772
- if (!strcmp(p + 1, "nfs4.acl") ||
773
- !strcmp(p + 1, "posix1e.acl_access") ||
774
- !strcmp(p + 1, "posix1e.acl_default")) {
775
- p += 1 + len;
776
- continue;
777
- }
778
- strcpy(buff, "system.");
779
- } else {
780
- strcpy(buff, "user.");
781
- }
782
- name = buff + strlen(buff);
783
- memcpy(name, p + 1, len);
784
- name[len] = '\0';
785
- setup_xattr(a, entry, namespace, name, buff, *fd, path);
786
- p += 1 + len;
787
- }
788
-
789
- free(list);
790
- return (ARCHIVE_OK);
791
- }
792
-
793
- static int
794
- setup_xattrs(struct archive_read_disk *a,
795
- struct archive_entry *entry, int *fd)
796
- {
797
- int namespaces[2];
798
- int i, res;
799
-
800
- namespaces[0] = EXTATTR_NAMESPACE_USER;
801
- namespaces[1] = EXTATTR_NAMESPACE_SYSTEM;
802
-
803
- for (i = 0; i < 2; i++) {
804
- res = setup_xattrs_namespace(a, entry, fd,
805
- namespaces[i]);
806
- switch (res) {
807
- case (ARCHIVE_OK):
808
- case (ARCHIVE_WARN):
809
- break;
810
- default:
811
- return (res);
812
- }
813
- }
814
-
815
- return (ARCHIVE_OK);
816
- }
817
-
818
- #else
819
-
820
- /*
821
- * Generic (stub) extended attribute support.
822
- */
823
- static int
824
- setup_xattrs(struct archive_read_disk *a,
825
- struct archive_entry *entry, int *fd)
826
- {
827
- (void)a; /* UNUSED */
828
- (void)entry; /* UNUSED */
829
- (void)fd; /* UNUSED */
830
- return (ARCHIVE_OK);
831
- }
832
-
833
- #endif
834
-
835
- #if defined(HAVE_LINUX_FIEMAP_H)
836
-
837
- /*
838
- * Linux FIEMAP sparse interface.
839
- *
840
- * The FIEMAP ioctl returns an "extent" for each physical allocation
841
- * on disk. We need to process those to generate a more compact list
842
- * of logical file blocks. We also need to be very careful to use
843
- * FIEMAP_FLAG_SYNC here, since there are reports that Linux sometimes
844
- * does not report allocations for newly-written data that hasn't
845
- * been synced to disk.
846
- *
847
- * It's important to return a minimal sparse file list because we want
848
- * to not trigger sparse file extensions if we don't have to, since
849
- * not all readers support them.
850
- */
851
-
852
- static int
853
- setup_sparse_fiemap(struct archive_read_disk *a,
854
- struct archive_entry *entry, int *fd)
855
- {
856
- char buff[4096];
857
- struct fiemap *fm;
858
- struct fiemap_extent *fe;
859
- int64_t size;
860
- int count, do_fiemap, iters;
861
- int exit_sts = ARCHIVE_OK;
862
- const char *path;
863
-
864
- if (archive_entry_filetype(entry) != AE_IFREG
865
- || archive_entry_size(entry) <= 0
866
- || archive_entry_hardlink(entry) != NULL)
867
- return (ARCHIVE_OK);
868
-
869
- if (*fd < 0) {
870
- path = archive_read_disk_entry_setup_path(a, entry, NULL);
871
- if (path == NULL)
872
- return (ARCHIVE_FAILED);
873
-
874
- if (a->tree != NULL)
875
- *fd = a->open_on_current_dir(a->tree, path,
876
- O_RDONLY | O_NONBLOCK | O_CLOEXEC);
877
- else
878
- *fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
879
- if (*fd < 0) {
880
- archive_set_error(&a->archive, errno,
881
- "Can't open `%s'", path);
882
- return (ARCHIVE_FAILED);
883
- }
884
- __archive_ensure_cloexec_flag(*fd);
885
- }
886
-
887
- /* Initialize buffer to avoid the error valgrind complains about. */
888
- memset(buff, 0, sizeof(buff));
889
- count = (sizeof(buff) - sizeof(*fm))/sizeof(*fe);
890
- fm = (struct fiemap *)buff;
891
- fm->fm_start = 0;
892
- fm->fm_length = ~0ULL;
893
- fm->fm_flags = FIEMAP_FLAG_SYNC;
894
- fm->fm_extent_count = count;
895
- do_fiemap = 1;
896
- size = archive_entry_size(entry);
897
- for (iters = 0; ; ++iters) {
898
- int i, r;
899
-
900
- r = ioctl(*fd, FS_IOC_FIEMAP, fm);
901
- if (r < 0) {
902
- /* When some error happens, it is better we
903
- * should return ARCHIVE_OK because an earlier
904
- * version(<2.6.28) cannot perform FS_IOC_FIEMAP. */
905
- goto exit_setup_sparse_fiemap;
906
- }
907
- if (fm->fm_mapped_extents == 0) {
908
- if (iters == 0) {
909
- /* Fully sparse file; insert a zero-length "data" entry */
910
- archive_entry_sparse_add_entry(entry, 0, 0);
911
- }
912
- break;
913
- }
914
- fe = fm->fm_extents;
915
- for (i = 0; i < (int)fm->fm_mapped_extents; i++, fe++) {
916
- if (!(fe->fe_flags & FIEMAP_EXTENT_UNWRITTEN)) {
917
- /* The fe_length of the last block does not
918
- * adjust itself to its size files. */
919
- int64_t length = fe->fe_length;
920
- if (fe->fe_logical + length > (uint64_t)size)
921
- length -= fe->fe_logical + length - size;
922
- if (fe->fe_logical == 0 && length == size) {
923
- /* This is not sparse. */
924
- do_fiemap = 0;
925
- break;
926
- }
927
- if (length > 0)
928
- archive_entry_sparse_add_entry(entry,
929
- fe->fe_logical, length);
930
- }
931
- if (fe->fe_flags & FIEMAP_EXTENT_LAST)
932
- do_fiemap = 0;
933
- }
934
- if (do_fiemap) {
935
- fe = fm->fm_extents + fm->fm_mapped_extents -1;
936
- fm->fm_start = fe->fe_logical + fe->fe_length;
937
- } else
938
- break;
939
- }
940
- exit_setup_sparse_fiemap:
941
- return (exit_sts);
942
- }
943
-
944
- #if !defined(SEEK_HOLE) || !defined(SEEK_DATA)
945
- static int
946
- setup_sparse(struct archive_read_disk *a,
947
- struct archive_entry *entry, int *fd)
948
- {
949
- return setup_sparse_fiemap(a, entry, fd);
950
- }
951
- #endif
952
- #endif /* defined(HAVE_LINUX_FIEMAP_H) */
953
-
954
- #if defined(SEEK_HOLE) && defined(SEEK_DATA)
955
-
956
- /*
957
- * SEEK_HOLE sparse interface (FreeBSD, Linux, Solaris)
958
- */
959
-
960
- static int
961
- setup_sparse(struct archive_read_disk *a,
962
- struct archive_entry *entry, int *fd)
963
- {
964
- int64_t size;
965
- off_t initial_off;
966
- off_t off_s, off_e;
967
- int exit_sts = ARCHIVE_OK;
968
- int check_fully_sparse = 0;
969
- const char *path;
970
-
971
- if (archive_entry_filetype(entry) != AE_IFREG
972
- || archive_entry_size(entry) <= 0
973
- || archive_entry_hardlink(entry) != NULL)
974
- return (ARCHIVE_OK);
975
-
976
- /* Does filesystem support the reporting of hole ? */
977
- if (*fd < 0)
978
- path = archive_read_disk_entry_setup_path(a, entry, fd);
979
- else
980
- path = NULL;
981
-
982
- if (*fd >= 0) {
983
- #ifdef _PC_MIN_HOLE_SIZE
984
- if (fpathconf(*fd, _PC_MIN_HOLE_SIZE) <= 0)
985
- return (ARCHIVE_OK);
986
- #endif
987
- initial_off = lseek(*fd, 0, SEEK_CUR);
988
- if (initial_off != 0)
989
- lseek(*fd, 0, SEEK_SET);
990
- } else {
991
- if (path == NULL)
992
- return (ARCHIVE_FAILED);
993
- #ifdef _PC_MIN_HOLE_SIZE
994
- if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0)
995
- return (ARCHIVE_OK);
996
- #endif
997
- *fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
998
- if (*fd < 0) {
999
- archive_set_error(&a->archive, errno,
1000
- "Can't open `%s'", path);
1001
- return (ARCHIVE_FAILED);
1002
- }
1003
- __archive_ensure_cloexec_flag(*fd);
1004
- initial_off = 0;
1005
- }
1006
-
1007
- #ifndef _PC_MIN_HOLE_SIZE
1008
- /* Check if the underlying filesystem supports seek hole */
1009
- off_s = lseek(*fd, 0, SEEK_HOLE);
1010
- if (off_s < 0)
1011
- #if defined(HAVE_LINUX_FIEMAP_H)
1012
- return setup_sparse_fiemap(a, entry, fd);
1013
- #else
1014
- goto exit_setup_sparse;
1015
- #endif
1016
- else if (off_s > 0)
1017
- lseek(*fd, 0, SEEK_SET);
1018
- #endif
1019
-
1020
- off_s = 0;
1021
- size = archive_entry_size(entry);
1022
- while (off_s < size) {
1023
- off_s = lseek(*fd, off_s, SEEK_DATA);
1024
- if (off_s == (off_t)-1) {
1025
- if (errno == ENXIO) {
1026
- /* no more hole */
1027
- if (archive_entry_sparse_count(entry) == 0) {
1028
- /* Potentially a fully-sparse file. */
1029
- check_fully_sparse = 1;
1030
- }
1031
- break;
1032
- }
1033
- archive_set_error(&a->archive, errno,
1034
- "lseek(SEEK_HOLE) failed");
1035
- exit_sts = ARCHIVE_FAILED;
1036
- goto exit_setup_sparse;
1037
- }
1038
- off_e = lseek(*fd, off_s, SEEK_HOLE);
1039
- if (off_e == (off_t)-1) {
1040
- if (errno == ENXIO) {
1041
- off_e = lseek(*fd, 0, SEEK_END);
1042
- if (off_e != (off_t)-1)
1043
- break;/* no more data */
1044
- }
1045
- archive_set_error(&a->archive, errno,
1046
- "lseek(SEEK_DATA) failed");
1047
- exit_sts = ARCHIVE_FAILED;
1048
- goto exit_setup_sparse;
1049
- }
1050
- if (off_s == 0 && off_e == size)
1051
- break;/* This is not sparse. */
1052
- archive_entry_sparse_add_entry(entry, off_s,
1053
- off_e - off_s);
1054
- off_s = off_e;
1055
- }
1056
-
1057
- if (check_fully_sparse) {
1058
- if (lseek(*fd, 0, SEEK_HOLE) == 0 &&
1059
- lseek(*fd, 0, SEEK_END) == size) {
1060
- /* Fully sparse file; insert a zero-length "data" entry */
1061
- archive_entry_sparse_add_entry(entry, 0, 0);
1062
- }
1063
- }
1064
- exit_setup_sparse:
1065
- lseek(*fd, initial_off, SEEK_SET);
1066
- return (exit_sts);
1067
- }
1068
-
1069
- #elif !defined(HAVE_LINUX_FIEMAP_H)
1070
-
1071
- /*
1072
- * Generic (stub) sparse support.
1073
- */
1074
- static int
1075
- setup_sparse(struct archive_read_disk *a,
1076
- struct archive_entry *entry, int *fd)
1077
- {
1078
- (void)a; /* UNUSED */
1079
- (void)entry; /* UNUSED */
1080
- (void)fd; /* UNUSED */
1081
- return (ARCHIVE_OK);
1082
- }
1083
-
1084
- #endif
1085
-
1086
- #endif /* !defined(_WIN32) || defined(__CYGWIN__) */