bsdtar.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*-
  2. * Copyright 2006-2009 Colin Percival
  3. * All rights reserved.
  4. *
  5. * Portions of the file below are covered by the following license:
  6. *
  7. * Copyright (c) 2003-2007 Tim Kientzle
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $
  31. */
  32. #include "bsdtar_platform.h"
  33. #include <stdint.h>
  34. #include <stdio.h>
  35. #include "elasticarray.h"
  36. #include "passphrase_entry.h"
  37. ELASTICARRAY_DECL(STRLIST, strlist, char *);
  38. /*
  39. * The internal state for the "tarsnap" program.
  40. *
  41. * Keeping all of the state in a structure like this simplifies memory
  42. * leak testing (at exit, anything left on the heap is suspect). A
  43. * pointer to this structure is passed to most bsdtar internal
  44. * functions.
  45. */
  46. struct bsdtar {
  47. /* Options */
  48. char **tapenames; /* -f tapename */
  49. size_t ntapes;
  50. char *homedir;
  51. char *cachedir; /* --cachedir */
  52. dev_t cachedir_dev;
  53. ino_t cachedir_ino;
  54. int cachecrunch; /* --lowmem / --verylowmem */
  55. time_t snaptime; /* --snaptime */
  56. time_t creationtime; /* --creationtime */
  57. char *pending_chdir; /* -C dir */
  58. const char *names_from_file; /* -T file */
  59. time_t newer_ctime_sec; /* --newer/--newer-than */
  60. long newer_ctime_nsec; /* --newer/--newer-than */
  61. time_t newer_mtime_sec; /* --newer-mtime */
  62. long newer_mtime_nsec; /* --newer-mtime-than */
  63. int verbose; /* -v */
  64. int extract_flags; /* Flags for extract operation */
  65. int strip_components; /* Remove this many leading dirs */
  66. int mode; /* Program mode: 'c', 'd', 'r', 't', 'x' */
  67. const char *modestr; /* -[cdrtx] or --list, --fsck, etc. */
  68. char symlink_mode; /* H or L, per BSD conventions */
  69. char option_absolute_paths; /* -P */
  70. char option_chroot; /* --chroot */
  71. char *option_csv_filename; /* --csv-filename */
  72. char option_dont_traverse_mounts; /* --one-file-system */
  73. char option_dryrun; /* --dry-run / --dry-run-metadata */
  74. char option_fast_read; /* --fast-read */
  75. int option_hashes;
  76. char option_honor_nodump; /* --nodump */
  77. char option_interactive; /* -w */
  78. char option_keep_going; /* --keep-going */
  79. char option_no_owner; /* -o */
  80. char option_no_subdirs; /* -n */
  81. char option_null; /* --null */
  82. char option_numeric_owner; /* --numeric-owner */
  83. char option_print_stats; /* --print-stats */
  84. uint64_t option_progress_bytes; /* --progress-bytes */
  85. char option_stdout; /* -O */
  86. char option_store_atime; /* --store-atime */
  87. char option_totals; /* --totals */
  88. char option_unlink_first; /* -U */
  89. char option_warn_links; /* --check-links */
  90. char day_first; /* show day before month in -tv output */
  91. int have_keys; /* --keyfile */
  92. double bwlimit_rate_up; /* --maxbw-rate(-up)? */
  93. double bwlimit_rate_down; /* --maxbw-rate(-down)? */
  94. int disk_pause; /* --disk-pause */
  95. int option_aggressive_networking_set;
  96. int option_archive_names_set;
  97. int option_cachecrunch_set;
  98. int option_disk_pause_set;
  99. int option_dump_config;
  100. int option_humanize_numbers_set;
  101. int option_maxbw_set;
  102. int option_maxbw_rate_down_set;
  103. int option_maxbw_rate_up_set;
  104. int option_nodump_set;
  105. int option_print_stats_set;
  106. int option_progress_bytes_set;
  107. int option_snaptime_set;
  108. int option_store_atime_set;
  109. int option_totals_set;
  110. int option_no_config_exclude;
  111. int option_no_config_include;
  112. int option_no_config_exclude_set;
  113. int option_no_config_include_set;
  114. int option_quiet;
  115. int option_quiet_set;
  116. int option_retry_forever_set;
  117. int option_resume_extract;
  118. int option_insane_filesystems;
  119. int option_insane_filesystems_set;
  120. int option_iso_dates;
  121. int option_iso_dates_set;
  122. int option_force_resources;
  123. int option_force_resources_set;
  124. const char **configfiles; /* --configfile */
  125. size_t nconfigfiles;
  126. int option_no_default_config; /* --no-default-config */
  127. char *keyfile;
  128. int keyfile_from_config;
  129. char *option_passphrase_arg;
  130. enum passphrase_entry option_passphrase_entry;
  131. /* Miscellaneous state information */
  132. struct archive *archive;
  133. const char *progname;
  134. int argc;
  135. char **argv;
  136. const char *optarg;
  137. size_t gs_width; /* For 'list_item' in read.c */
  138. size_t u_width; /* for 'list_item' in read.c */
  139. uid_t user_uid; /* UID running this program */
  140. int return_value; /* Value returned by main() */
  141. char warned_lead_slash; /* Already displayed warning */
  142. char next_line_is_dir; /* Used for -C parsing in -cT */
  143. /* Config-file parsing strings. */
  144. char *conffile;
  145. char *conf_opt;
  146. char *conf_arg;
  147. FILE *conffile_actual;
  148. char *conffile_buffer;
  149. /* Temporary array for loading archive names. */
  150. STRLIST tapenames_setup;
  151. /* Used for --dryrun with tarsnap.conf.sample with a missing keyfile. */
  152. int config_file_keyfile_failed;
  153. /* Used for communicating with multitape code. */
  154. void *write_cookie;
  155. /* Used for communication with the storage layer. */
  156. int storage_modified;
  157. /* Chunkification cache. */
  158. void *chunk_cache;
  159. /* Original argc/argv, to be stored as archive metadata. */
  160. int argc_orig;
  161. char **argv_orig;
  162. /* Machine number assigned by tarsnap server. */
  163. uint64_t machinenum;
  164. /*
  165. * Data for various subsystems. Full definitions are located in
  166. * the file where they are used.
  167. */
  168. struct delayedopt *delopt; /* for bsdtar.c */
  169. struct delayedopt **delopt_tail; /* for bsdtar.c */
  170. struct archive *diskreader; /* for write.c */
  171. struct archive_entry_linkresolver *resolver; /* for write.c */
  172. struct name_cache *gname_cache; /* for write.c */
  173. char *buff; /* for write.c */
  174. struct matching *matching; /* for matching.c */
  175. struct security *security; /* for read.c */
  176. struct name_cache *uname_cache; /* for write.c */
  177. struct siginfo_data *siginfo; /* for siginfo.c */
  178. struct substitution *substitution; /* for subst.c */
  179. };
  180. /* Fake short equivalents for long options that otherwise lack them. */
  181. enum {
  182. OPTION_AGGRESSIVE_NETWORKING=256,
  183. OPTION_ARCHIVE_NAMES,
  184. OPTION_CACHEDIR,
  185. OPTION_CHECK_LINKS,
  186. OPTION_CHECKPOINT_BYTES,
  187. OPTION_CHROOT,
  188. OPTION_CONFIGFILE,
  189. OPTION_CREATIONTIME,
  190. OPTION_CSV_FILE,
  191. OPTION_DEBUG_NETWORK_STATS,
  192. OPTION_DISK_PAUSE,
  193. OPTION_DRYRUN,
  194. OPTION_DRYRUN_METADATA,
  195. OPTION_DUMP_CONFIG,
  196. OPTION_EXCLUDE,
  197. OPTION_FORCE_RESOURCES,
  198. OPTION_FSCK,
  199. OPTION_FSCK_DELETE, /* Operation mode, not a real option */
  200. OPTION_FSCK_PRUNE,
  201. OPTION_FSCK_WRITE, /* Operation mode, not a real option */
  202. OPTION_HASHES,
  203. OPTION_HELP,
  204. OPTION_INCLUDE,
  205. OPTION_INITIALIZE_CACHEDIR,
  206. OPTION_INSANE_FILESYSTEMS,
  207. OPTION_ISO_DATES,
  208. OPTION_HUMANIZE_NUMBERS,
  209. OPTION_KEYFILE,
  210. OPTION_KEEP_GOING,
  211. OPTION_KEEP_NEWER_FILES,
  212. OPTION_LIST_ARCHIVES,
  213. OPTION_LOWMEM,
  214. OPTION_MAXBW,
  215. OPTION_MAXBW_RATE,
  216. OPTION_MAXBW_RATE_DOWN,
  217. OPTION_MAXBW_RATE_UP,
  218. OPTION_NEWER_CTIME,
  219. OPTION_NEWER_CTIME_THAN,
  220. OPTION_NEWER_MTIME,
  221. OPTION_NEWER_MTIME_THAN,
  222. OPTION_NODUMP,
  223. OPTION_NO_AGGRESSIVE_NETWORKING,
  224. OPTION_NO_CONFIG_EXCLUDE,
  225. OPTION_NO_CONFIG_INCLUDE,
  226. OPTION_NO_DEFAULT_CONFIG,
  227. OPTION_NO_DISK_PAUSE,
  228. OPTION_NO_FORCE_RESOURCES,
  229. OPTION_NO_HUMANIZE_NUMBERS,
  230. OPTION_NO_INSANE_FILESYSTEMS,
  231. OPTION_NO_ISO_DATES,
  232. OPTION_NO_MAXBW,
  233. OPTION_NO_MAXBW_RATE_DOWN,
  234. OPTION_NO_MAXBW_RATE_UP,
  235. OPTION_NO_NODUMP,
  236. OPTION_NO_PRINT_STATS,
  237. OPTION_NO_PROGRESS_BYTES,
  238. OPTION_NO_QUIET,
  239. OPTION_NO_RETRY_FOREVER,
  240. OPTION_NO_SAME_OWNER,
  241. OPTION_NO_SAME_PERMISSIONS,
  242. OPTION_NO_SNAPTIME,
  243. OPTION_NO_STORE_ATIME,
  244. OPTION_NO_TOTALS,
  245. OPTION_NOISY_WARNINGS,
  246. OPTION_NORMALMEM,
  247. OPTION_NUKE,
  248. OPTION_NULL,
  249. OPTION_NUMERIC_OWNER,
  250. OPTION_ONE_FILE_SYSTEM,
  251. OPTION_PASSPHRASE,
  252. OPTION_PRINT_STATS,
  253. OPTION_PROGRESS_BYTES,
  254. OPTION_RECOVER,
  255. OPTION_RECOVER_DELETE, /* Operation mode, not a real option */
  256. OPTION_RECOVER_WRITE, /* Operation mode, not a real option */
  257. OPTION_RESUME_EXTRACT,
  258. OPTION_RETRY_FOREVER,
  259. OPTION_QUIET,
  260. OPTION_SNAPTIME,
  261. OPTION_STORE_ATIME,
  262. OPTION_SAME_OWNER,
  263. OPTION_STRIP_COMPONENTS,
  264. OPTION_TOTALS,
  265. OPTION_VERIFY_CONFIG,
  266. OPTION_VERSION,
  267. OPTION_VERYLOWMEM
  268. };
  269. void bsdtar_errc(struct bsdtar *, int _eval, int _code,
  270. const char *fmt, ...) __LA_DEAD;
  271. int bsdtar_getopt(struct bsdtar *);
  272. void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
  273. void cleanup_exclusions(struct bsdtar *);
  274. void do_chdir(struct bsdtar *);
  275. int edit_pathname(struct bsdtar *, struct archive_entry *);
  276. int exclude(struct bsdtar *, const char *pattern);
  277. int exclude_from_file(struct bsdtar *, const char *pathname);
  278. int excluded(struct bsdtar *, const char *pathname);
  279. int include(struct bsdtar *, const char *pattern);
  280. int include_from_file(struct bsdtar *, const char *pathname);
  281. int pathcmp(const char *a, const char *b);
  282. int process_lines(struct bsdtar *bsdtar, const char *pathname,
  283. int (*process)(struct bsdtar *, const char *), int null);
  284. void safe_fprintf(FILE *, const char *fmt, ...);
  285. void set_chdir(struct bsdtar *, const char *newdir);
  286. void siginfo_init(struct bsdtar *);
  287. void siginfo_setinfo(struct bsdtar *, const char * oper,
  288. const char * path, int64_t size, int file_count,
  289. int64_t archive_uncompressed);
  290. void siginfo_printinfo(struct bsdtar *, off_t progress, int finalmsg);
  291. void siginfo_done(struct bsdtar *);
  292. void tarsnap_mode_print_stats(struct bsdtar *bsdtar);
  293. void tarsnap_mode_c(struct bsdtar *bsdtar);
  294. void tarsnap_mode_d(struct bsdtar *bsdtar);
  295. void tarsnap_mode_r(struct bsdtar *bsdtar);
  296. void tarsnap_mode_t(struct bsdtar *bsdtar);
  297. void tarsnap_mode_x(struct bsdtar *bsdtar);
  298. void tarsnap_mode_fsck(struct bsdtar *bsdtar, int prune, int whichkey);
  299. void tarsnap_mode_initialize_cachedir(struct bsdtar *bsdtar);
  300. void tarsnap_mode_list_archives(struct bsdtar *bsdtar, int print_hashes);
  301. void tarsnap_mode_nuke(struct bsdtar *bsdtar);
  302. void tarsnap_mode_recover(struct bsdtar *bsdtar, int whichkey);
  303. int unmatched_inclusions(struct bsdtar *bsdtar);
  304. int unmatched_inclusions_warn(struct bsdtar *bsdtar, const char *msg);
  305. void usage(struct bsdtar *);
  306. int yes(const char *fmt, ...);
  307. #if HAVE_REGEX_H
  308. void add_substitution(struct bsdtar *, const char *);
  309. int apply_substitution(struct bsdtar *, const char *, char **, int);
  310. void cleanup_substitution(struct bsdtar *);
  311. #endif
  312. void list_item_verbose(struct bsdtar *, FILE *,
  313. struct archive_entry *);