ManPageArchiveEntryLinkify3.wiki 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ARCHIVE_ENTRY_LINKIFY(3) manual page
  2. == NAME ==
  3. '''archive_entry_linkresolver''',
  4. '''archive_entry_linkresolver_new''',
  5. '''archive_entry_linkresolver_set_strategy''',
  6. '''archive_entry_linkresolver_free''',
  7. '''archive_entry_linkify'''
  8. - hardlink resolver functions
  9. == LIBRARY ==
  10. Streaming Archive Library (libarchive, -larchive)
  11. == SYNOPSIS ==
  12. '''<nowiki>#include <archive_entry.h></nowiki>'''
  13. <br>
  14. ''struct archive_entry_linkresolver *''
  15. <br>
  16. '''archive_entry_linkresolver_new'''(''void'');
  17. <br>
  18. ''void''
  19. <br>
  20. '''archive_entry_linkresolver_set_strategy'''(''struct archive_entry_linkresolver *resolver'', ''int format'');
  21. <br>
  22. ''void''
  23. <br>
  24. '''archive_entry_linkresolver_free'''(''struct archive_entry_linkresolver *resolver'');
  25. <br>
  26. ''void''
  27. <br>
  28. '''archive_entry_linkify'''(''struct archive_entry_linkresolver *resolver'', ''struct archive_entry **entry'', ''struct archive_entry **sparse'');
  29. == DESCRIPTION ==
  30. Programs that want to create archives have to deal with hardlinks.
  31. Hardlinks are handled in different ways by the archive formats.
  32. The basic strategies are:
  33. <ol>
  34. <li>
  35. Ignore hardlinks and store the body for each reference (old cpio, zip).
  36. </li><li>
  37. Store the body the first time an inode is seen (ustar, pax).
  38. </li><li>
  39. Store the body the last time an inode is seen (new cpio).
  40. </li></ol>
  41. The
  42. '''archive_entry_linkresolver'''
  43. functions help by providing a unified interface and handling the complexity
  44. behind the scene.
  45. The
  46. '''archive_entry_linkresolver'''
  47. functions assume that
  48. ''archive_entry''
  49. instances have valid nlinks, inode and device values.
  50. The inode and device value is used to match entries.
  51. The nlinks value is used to determined if all references have been found and
  52. if the internal references can be recycled.
  53. The
  54. '''archive_entry_linkresolver_new'''()
  55. function allocates a new link resolver.
  56. The instance can be freed using
  57. '''archive_entry_linkresolver_free'''().
  58. All deferred entries are flushed and the internal storage is freed.
  59. The
  60. '''archive_entry_linkresolver_set_strategy'''()
  61. function selects the optimal hardlink strategy for the given format.
  62. The format code can be obtained from
  63. [[ManPageArchiveFormat3]].
  64. The function can be called more than once, but it is recommended to
  65. flush all deferred entries first.
  66. The
  67. '''archive_entry_linkify'''()
  68. function is the core of
  69. '''archive_entry_linkresolver'''.
  70. The
  71. '''entry'''()
  72. argument points to the
  73. ''archive_entry''
  74. that should be written.
  75. Depending on the strategy one of the following actions is taken:
  76. <ol>
  77. <li>
  78. For the simple archive formats
  79. ''*entry''
  80. is left unmodified and
  81. ''*sparse''
  82. is set to
  83. NULL.
  84. </li><li>
  85. For tar like archive formats,
  86. ''*sparse''
  87. is set to
  88. NULL.
  89. If
  90. ''*entry''
  91. is
  92. NULL,
  93. no action is taken.
  94. If the hardlink count of
  95. ''*entry''
  96. is larger than 1 and the file type is a regular file or symbolic link,
  97. the internal list is searched for a matching inode.
  98. If such an inode is found, the link count is decremented and the file size
  99. of
  100. ''*entry''
  101. is set to 0 to notify that no body should be written.
  102. If no such inode is found, a copy of the entry is added to the internal cache
  103. with a link count reduced by one.
  104. </li><li>
  105. For new cpio like archive formats a value for
  106. ''*entry''
  107. of
  108. NULL
  109. is used to flush deferred entries.
  110. In that case
  111. ''*entry''
  112. is set to an arbitrary deferred entry and the entry itself is removed from the
  113. internal list.
  114. If the internal list is empty,
  115. ''*entry''
  116. is set to
  117. NULL.
  118. In either case,
  119. ''*sparse''
  120. is set to
  121. NULL
  122. and the function returns.
  123. If the hardlink count of
  124. ''*entry''
  125. is one or the file type is a directory or device,
  126. ''*sparse''
  127. is set to
  128. NULL
  129. and no further action is taken.
  130. Otherwise, the internal list is searched for a matching inode.
  131. If such an inode is not found, the entry is added to the internal list,
  132. both
  133. ''*entry''
  134. and
  135. ''*sparse''
  136. are set to
  137. NULL
  138. and the function returns.
  139. If such an inode is found, the link count is decremented.
  140. If it remains larger than one, the existing entry on the internal list
  141. is swapped with
  142. ''*entry''
  143. after retaining the link count.
  144. The existing entry is returned in
  145. ''*entry''.
  146. If the link count reached one, the new entry is also removed from the
  147. internal list and returned in
  148. ''*sparse''.
  149. Otherwise
  150. ''*sparse''
  151. is set to
  152. NULL.
  153. </li></ol>
  154. The general usage is therefore:
  155. <ol>
  156. <li>
  157. For each new archive entry, call
  158. '''archive_entry_linkify'''().
  159. </li><li>
  160. Keep in mind that the entries returned may have a size of 0 now.
  161. </li><li>
  162. If
  163. ''*entry''
  164. is not
  165. NULL,
  166. archive it.
  167. </li><li>
  168. If
  169. ''*sparse''
  170. is not
  171. NULL,
  172. archive it.
  173. </li><li>
  174. After all entries have been written to disk, call
  175. '''archive_entry_linkify'''()
  176. with
  177. ''*entry''
  178. set to
  179. NULL
  180. and archive the returned entry as long as it is not
  181. NULL.
  182. </li></ol>
  183. == RETURN VALUES ==
  184. '''archive_entry_linkresolver_new'''()
  185. returns
  186. NULL
  187. on
  188. [[malloc(3)|http://www.freebsd.org/cgi/man.cgi?query=malloc&sektion=3]]
  189. failures.
  190. == SEE ALSO ==
  191. [[ManPageArchiveEntry3]]