storagedir.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (c) 2017-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file storagedir.h
  5. *
  6. * \brief Header for storagedir.c
  7. **/
  8. #ifndef TOR_STORAGEDIR_H
  9. #define TOR_STORAGEDIR_H
  10. #include "lib/cc/torint.h"
  11. #include <stddef.h>
  12. typedef struct storage_dir_t storage_dir_t;
  13. struct config_line_t;
  14. struct sandbox_cfg_elem;
  15. struct tor_mmap_t;
  16. struct smartlist_t;
  17. storage_dir_t * storage_dir_new(const char *dirname, int n_files);
  18. void storage_dir_free_(storage_dir_t *d);
  19. #define storage_dir_free(d) \
  20. FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))
  21. int storage_dir_register_with_sandbox(storage_dir_t *d,
  22. struct sandbox_cfg_elem **cfg);
  23. const struct smartlist_t *storage_dir_list(storage_dir_t *d);
  24. uint64_t storage_dir_get_usage(storage_dir_t *d);
  25. struct tor_mmap_t *storage_dir_map(storage_dir_t *d, const char *fname);
  26. uint8_t *storage_dir_read(storage_dir_t *d, const char *fname, int bin,
  27. size_t *sz_out);
  28. int storage_dir_save_bytes_to_file(storage_dir_t *d,
  29. const uint8_t *data,
  30. size_t length,
  31. int binary,
  32. char **fname_out);
  33. int storage_dir_save_string_to_file(storage_dir_t *d,
  34. const char *data,
  35. int binary,
  36. char **fname_out);
  37. int storage_dir_save_labeled_to_file(storage_dir_t *d,
  38. const struct config_line_t *labels,
  39. const uint8_t *data,
  40. size_t length,
  41. char **fname_out);
  42. struct tor_mmap_t *storage_dir_map_labeled(storage_dir_t *dir,
  43. const char *fname,
  44. struct config_line_t **labels_out,
  45. const uint8_t **data_out,
  46. size_t *size_out);
  47. uint8_t *storage_dir_read_labeled(storage_dir_t *d, const char *fname,
  48. struct config_line_t **labels_out,
  49. size_t *sz_out);
  50. void storage_dir_remove_file(storage_dir_t *d,
  51. const char *fname);
  52. int storage_dir_shrink(storage_dir_t *d,
  53. uint64_t target_size,
  54. int min_to_remove);
  55. int storage_dir_remove_all(storage_dir_t *d);
  56. int storage_dir_get_max_files(storage_dir_t *d);
  57. #endif /* !defined(TOR_STORAGEDIR_H) */