2019-01-16 18:33:22 +01:00
|
|
|
/* Copyright (c) 2017-2019, The Tor Project, Inc. */
|
2017-03-10 19:22:01 +01:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2018-07-02 02:22:55 +02:00
|
|
|
/**
|
|
|
|
* \file storagedir.h
|
|
|
|
*
|
|
|
|
* \brief Header for storagedir.c
|
|
|
|
**/
|
|
|
|
|
2017-03-10 19:22:01 +01:00
|
|
|
#ifndef TOR_STORAGEDIR_H
|
|
|
|
#define TOR_STORAGEDIR_H
|
|
|
|
|
2018-06-28 15:38:17 +02:00
|
|
|
#include "lib/cc/torint.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-03-10 19:22:01 +01:00
|
|
|
typedef struct storage_dir_t storage_dir_t;
|
2017-03-29 12:55:09 +02:00
|
|
|
struct config_line_t;
|
2017-03-10 19:22:01 +01:00
|
|
|
struct sandbox_cfg_elem;
|
2018-06-28 15:38:17 +02:00
|
|
|
struct tor_mmap_t;
|
|
|
|
struct smartlist_t;
|
2017-03-10 19:22:01 +01:00
|
|
|
|
|
|
|
storage_dir_t * storage_dir_new(const char *dirname, int n_files);
|
2017-11-17 18:27:25 +01:00
|
|
|
void storage_dir_free_(storage_dir_t *d);
|
2017-12-07 16:52:55 +01:00
|
|
|
#define storage_dir_free(d) \
|
|
|
|
FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))
|
2017-11-17 18:27:25 +01:00
|
|
|
|
2017-03-10 19:22:01 +01:00
|
|
|
int storage_dir_register_with_sandbox(storage_dir_t *d,
|
|
|
|
struct sandbox_cfg_elem **cfg);
|
2018-06-28 15:38:17 +02:00
|
|
|
const struct smartlist_t *storage_dir_list(storage_dir_t *d);
|
2017-03-10 19:22:01 +01:00
|
|
|
uint64_t storage_dir_get_usage(storage_dir_t *d);
|
2018-06-28 15:38:17 +02:00
|
|
|
struct tor_mmap_t *storage_dir_map(storage_dir_t *d, const char *fname);
|
2017-03-10 19:22:01 +01:00
|
|
|
uint8_t *storage_dir_read(storage_dir_t *d, const char *fname, int bin,
|
|
|
|
size_t *sz_out);
|
|
|
|
int storage_dir_save_bytes_to_file(storage_dir_t *d,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t length,
|
|
|
|
int binary,
|
|
|
|
char **fname_out);
|
|
|
|
int storage_dir_save_string_to_file(storage_dir_t *d,
|
|
|
|
const char *data,
|
|
|
|
int binary,
|
|
|
|
char **fname_out);
|
2017-03-29 12:55:09 +02:00
|
|
|
int storage_dir_save_labeled_to_file(storage_dir_t *d,
|
|
|
|
const struct config_line_t *labels,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t length,
|
|
|
|
char **fname_out);
|
2018-06-28 15:38:17 +02:00
|
|
|
struct tor_mmap_t *storage_dir_map_labeled(storage_dir_t *dir,
|
2017-03-29 12:55:09 +02:00
|
|
|
const char *fname,
|
|
|
|
struct config_line_t **labels_out,
|
|
|
|
const uint8_t **data_out,
|
|
|
|
size_t *size_out);
|
|
|
|
uint8_t *storage_dir_read_labeled(storage_dir_t *d, const char *fname,
|
|
|
|
struct config_line_t **labels_out,
|
|
|
|
size_t *sz_out);
|
2017-03-10 19:22:01 +01:00
|
|
|
void storage_dir_remove_file(storage_dir_t *d,
|
|
|
|
const char *fname);
|
|
|
|
int storage_dir_shrink(storage_dir_t *d,
|
|
|
|
uint64_t target_size,
|
|
|
|
int min_to_remove);
|
|
|
|
int storage_dir_remove_all(storage_dir_t *d);
|
2017-04-26 16:42:11 +02:00
|
|
|
int storage_dir_get_max_files(storage_dir_t *d);
|
2017-03-10 19:22:01 +01:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_STORAGEDIR_H) */
|