multitape.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef MULTITAPE_H_
  2. #define MULTITAPE_H_
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. typedef struct multitape_read_internal TAPE_R;
  8. typedef struct multitape_write_internal TAPE_W;
  9. typedef struct multitape_delete_internal TAPE_D;
  10. typedef struct multitape_stats_internal TAPE_S;
  11. struct chunkheader;
  12. /**
  13. * readtape_open(machinenum, tapename):
  14. * Open the tape with the given name, and return a cookie which can be used
  15. * for accessing it.
  16. */
  17. TAPE_R * readtape_open(uint64_t, const char *);
  18. /**
  19. * readtape_read(d, buffer):
  20. * Read some data from the tape associated with ${d}, make ${*buffer}
  21. * point to the data, and return the number of bytes read.
  22. */
  23. ssize_t readtape_read(TAPE_R *, const void **);
  24. /**
  25. * readtape_readchunk(d, ch):
  26. * Obtain a chunk header suitable for passing to writetape_writechunk.
  27. * Return the length of the chunk, or 0 if no chunk is available (EOF or if
  28. * the tape position isn't aligned at a chunk boundary).
  29. */
  30. ssize_t readtape_readchunk(TAPE_R *, struct chunkheader **);
  31. /**
  32. * readtape_skip(d, request):
  33. * Skip up to ${request} bytes from the tape associated with ${d},
  34. * and return the length skipped.
  35. */
  36. off_t readtape_skip(TAPE_R *, off_t);
  37. /**
  38. * readtape_close(d):
  39. * Close the tape associated with ${d}.
  40. */
  41. int readtape_close(TAPE_R *);
  42. /**
  43. * writetape_open(machinenum, cachedir, tapename, argc, argv, printstats,
  44. * dryrun, creationtime, csv_filename, storage_modified):
  45. * Create a tape with the given name, and return a cookie which can be used
  46. * for accessing it. The argument vector must be long-lived. If ${dryrun}
  47. * is 2, do not pass any data to the chunkifier or chunk layer; and in this
  48. * case, ${printstats} cannot be non-zero.
  49. */
  50. TAPE_W * writetape_open(uint64_t, const char *, const char *, int, char **,
  51. int, int, time_t, const char *, int *);
  52. /**
  53. * writetape_setcallbacks(d, callback_chunk, callback_trailer,
  54. * callback_cookie):
  55. * On the tape associated with ${d}, set ${callback_chunk} to be called
  56. * with the ${callback_cookie} parameter whenever a chunk header is written
  57. * which corresponds to data provided via writetape_write. Set
  58. * ${callback_trailer} to be called whenever a trailer (i.e., file data which
  59. * is not in a chunk) is written.
  60. */
  61. void writetape_setcallback(TAPE_W *,
  62. int (*)(void *, struct chunkheader *),
  63. int (*)(void *, const uint8_t *, size_t),
  64. void *);
  65. /**
  66. * writetape_write(d, buffer, nbytes):
  67. * Write ${nbytes} bytes of data from ${buffer} to the tape associated with
  68. * ${d}. Return ${nbytes} on success.
  69. */
  70. ssize_t writetape_write(TAPE_W *, const void *, size_t);
  71. /**
  72. * writetape_ischunkpresent(d, ch):
  73. * If the specified chunk exists, return its length; otherwise, return 0.
  74. */
  75. ssize_t writetape_ischunkpresent(TAPE_W *, struct chunkheader *);
  76. /**
  77. * writetape_writechunk(d, ch):
  78. * Attempt to add a (copy of a) pre-existing chunk to the tape being written.
  79. * Return the length of the chunk if successful; 0 if the chunk cannot be
  80. * added written via this interface but must instead be written using the
  81. * writetape_write interface (e.g., if the chunk does not exist or if the
  82. * tape is not in a state where a chunk can be written); or -1 if an error
  83. * occurs.
  84. */
  85. ssize_t writetape_writechunk(TAPE_W *, struct chunkheader *);
  86. /**
  87. * writetape_setmode(d, mode):
  88. * Set the tape mode to 0 (HEADER), 1 (DATA), or 2 (finished archive entry).
  89. */
  90. int writetape_setmode(TAPE_W *, int);
  91. /**
  92. * writetape_truncate(d):
  93. * Record that the archive is being truncated at the current position.
  94. */
  95. void writetape_truncate(TAPE_W *);
  96. /**
  97. * writetape_checkpoint(d):
  98. * Create a checkpoint in the tape associated with ${d}.
  99. */
  100. int writetape_checkpoint(TAPE_W *);
  101. /**
  102. * writetape_close(d):
  103. * Close the tape associated with ${d}.
  104. */
  105. int writetape_close(TAPE_W *);
  106. /**
  107. * writetape_free(d):
  108. * Free memory associated with ${d}; the archive is being cancelled.
  109. */
  110. void writetape_free(TAPE_W *);
  111. /**
  112. * deletetape_init(machinenum):
  113. * Return a cookie which can be passed to deletetape.
  114. */
  115. TAPE_D * deletetape_init(uint64_t);
  116. /**
  117. * deletetape(d, machinenum, cachedir, tapename, printstats, withname,
  118. * csv_filename, storage_modified):
  119. * Delete the specified tape, and print statistics to stderr if requested.
  120. * If ${withname} is non-zero, print statistics with the archive name, not
  121. * just as "This archive". Return 0 on success, 1 if the tape does not exist,
  122. * or -1 on other errors. If ${csv_filename} is specified, output in CSV
  123. * format instead of to stderr. If the data on the server has been modified,
  124. * set ${*storage_modified} to 1.
  125. */
  126. int deletetape(TAPE_D *, uint64_t, const char *, const char *, int, int,
  127. const char *, int *);
  128. /**
  129. * deletetape_free(d):
  130. * Free the delete cookie ${d}.
  131. */
  132. void deletetape_free(TAPE_D *);
  133. /**
  134. * statstape_open(machinenum, cachedir):
  135. * Open the archive set in preparation for calls to _printglobal, _printall,
  136. * and _print.
  137. */
  138. TAPE_S * statstape_open(uint64_t, const char *);
  139. /**
  140. * statstape_printglobal(d, csv_filename):
  141. * Print global statistics relating to a set of archives. If ${csv_filename}
  142. * is not NULL, output will be written in CSV format to that filename.
  143. */
  144. int statstape_printglobal(TAPE_S *, const char *);
  145. /**
  146. * statstape_printall(d, csv_filename):
  147. * Print statistics relating to each of the archives in a set. If
  148. * ${csv_filename} is not NULL, output will be written in CSV format to that
  149. * filename.
  150. */
  151. int statstape_printall(TAPE_S *, const char *);
  152. /**
  153. * statstape_printlist_item(d, tapehash, verbose, print_nulls, print_hash):
  154. * Print the name of the archive with ${tapehash}. If ${verbose} > 0, print
  155. * the creation times; if ${verbose} > 1, print the argument vector of the
  156. * program invocation which created the archive. If ${print_nulls} > 0, print
  157. * null character(s) between archives names and fields instead of newlines,
  158. * tabs, and spaces. If ${print_hash} > 0 and ${verbose} is 0, print the hash
  159. * instead of the archive name. If ${print_hash} > 0 and ${verbose} > 0,
  160. * print hash in addition to the normal behaviour.
  161. */
  162. int statstape_printlist_item(TAPE_S *, const uint8_t[32], int, int, int);
  163. /**
  164. * statstape_printlist(d, verbose, print_nulls, print_hashes):
  165. * Print the names of each of the archives in a set. If ${verbose} > 0, print
  166. * the creation times; if ${verbose} > 1, print the argument vector of the
  167. * program invocation which created the archive. If ${print_nulls} > 0, print
  168. * null character(s) between archives names and fields instead of newlines,
  169. * tabs, and spaces. If ${print_hashes} > 0 and ${verbose} is 0, print hashes
  170. * instead of archive names. If ${print_hashes} > 0 and ${verbose} > 0, print
  171. * hashes in addition to the normal behaviour.
  172. */
  173. int statstape_printlist(TAPE_S *, int, int, int);
  174. /**
  175. * statstape_print(d, tapename, csv_filename):
  176. * Print statistics relating to a specific archive in a set. Return 0 on
  177. * success, 1 if the tape does not exist, or -1 on other errors. If
  178. * ${csv_filename} is not NULL, output will be written in CSV format to that
  179. * filename.
  180. */
  181. int statstape_print(TAPE_S *, const char *, const char *);
  182. /**
  183. * statstape_close(d):
  184. * Close the given archive set.
  185. */
  186. int statstape_close(TAPE_S *);
  187. /**
  188. * fscktape(machinenum, cachedir, prune, whichkey, storage_modified):
  189. * Correct any inconsistencies in the archive set (by removing orphaned or
  190. * corrupt files) and reconstruct the chunk directory in ${cachedir}. If
  191. * ${prune} is zero, don't correct inconsistencies; instead, exit with an
  192. * error. If ${whichkey} is zero, use the write key (for non-pruning fsck
  193. * only); otherwise, use the delete key. If the data on the server has been
  194. * modified, set ${*storage_modified} to 1.
  195. */
  196. int fscktape(uint64_t, const char *, int, int, int *);
  197. /**
  198. * statstape_initialize(machinenum, cachedir):
  199. * Initialize an empty chunk directory in ${cachedir} so that --print-stats
  200. * works. This requires the "directory" file, but no other files. Return 0
  201. * on success, -1 on error, and 1 if the cachedir is already initialized.
  202. */
  203. int statstape_initialize(uint64_t, const char *);
  204. /**
  205. * recovertape(machinenum, cachedir, whichkey, storage_modified):
  206. * Complete any pending checkpoint or commit, including a checkpoint in a
  207. * write transaction being performed by a different machine (if any). If
  208. * ${whichkey} is zero, use the write key; otherwise, use the delete key.
  209. * If the data on the server has been modified, set ${*storage_modified} to 1.
  210. */
  211. int recovertape(uint64_t, const char *, int, int *);
  212. /**
  213. * nuketape(machinenum, storage_modified):
  214. * Delete all files in the archive set. If the data on the server has been
  215. * modified, set ${*storage_modified} to 1.
  216. */
  217. int nuketape(uint64_t, int *);
  218. #endif /* !MULTITAPE_H_ */