storagedir.h 2.4 KB

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