Macros | Functions
storagedir.h File Reference

Header for storagedir.c. More...

#include "lib/cc/torint.h"
#include <stddef.h>

Go to the source code of this file.


#define storage_dir_free(d)    FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))


storage_dir_tstorage_dir_new (const char *dirname, int n_files)
void storage_dir_free_ (storage_dir_t *d)
int storage_dir_register_with_sandbox (storage_dir_t *d, struct sandbox_cfg_elem_t **cfg)
const struct smartlist_tstorage_dir_list (storage_dir_t *d)
uint64_t storage_dir_get_usage (storage_dir_t *d)
struct tor_mmap_tstorage_dir_map (storage_dir_t *d, const char *fname)
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)
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)
struct tor_mmap_tstorage_dir_map_labeled (storage_dir_t *dir, 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)
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)
int storage_dir_get_max_files (storage_dir_t *d)

Detailed Description

Header for storagedir.c.

Definition in file storagedir.h.

Macro Definition Documentation

◆ storage_dir_free

#define storage_dir_free (   d)     FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))

Definition at line 24 of file storagedir.h.

Function Documentation

◆ storage_dir_free_()

void storage_dir_free_ ( storage_dir_t d)

Drop all in-RAM storage for d. Does not delete any files.

Definition at line 83 of file storagedir.c.

◆ storage_dir_get_max_files()

int storage_dir_get_max_files ( storage_dir_t d)

Return the largest number of non-temporary files we're willing to store in d.

Definition at line 603 of file storagedir.c.

◆ storage_dir_get_usage()

uint64_t storage_dir_get_usage ( storage_dir_t d)

Return the total number of bytes used for storage in d.

Definition at line 190 of file storagedir.c.

Referenced by storage_dir_shrink().

◆ storage_dir_list()

const struct smartlist_t * storage_dir_list ( storage_dir_t d)

Return a smartlist containing the filenames within d.

Definition at line 179 of file storagedir.c.

Referenced by consensus_cache_rescan(), and storage_dir_get_usage().

◆ storage_dir_map()

struct tor_mmap_t * storage_dir_map ( storage_dir_t d,
const char *  fname 

Mmap a specified file within d.

On failure, return NULL and set errno as for tor_mmap_file().

Definition at line 215 of file storagedir.c.

Referenced by storage_dir_map_labeled().

◆ storage_dir_map_labeled()

struct tor_mmap_t * storage_dir_map_labeled ( storage_dir_t dir,
const char *  fname,
config_line_t **  labels_out,
const uint8_t **  data_out,
size_t *  sz_out 

Map a file that was created with storage_dir_save_labeled_to_file(). On failure, return NULL. On success, write a set of newly allocated labels into *labels_out, a pointer to the data into *data_out, and the data's size into *sz_out. On success, also return a tor_mmap_t object whose contents should not be used – it needs to be kept around, though, for as long as data_out is going to be valid.

On failure, set errno as for tor_mmap_file() if the file was missing or empty, and set errno to EINVAL if the file was not in the labeled format expected.

Definition at line 399 of file storagedir.c.

Referenced by consensus_cache_entry_map(), consensus_cache_rescan(), and storage_dir_read_labeled().

◆ storage_dir_new()

storage_dir_t * storage_dir_new ( const char *  dirname,
int  max_files 

Create or open a new storage directory at dirname, with capacity for up to max_files files.

Definition at line 68 of file storagedir.c.

◆ storage_dir_read()

uint8_t * storage_dir_read ( storage_dir_t d,
const char *  fname,
int  bin,
size_t *  sz_out 

Read a file within d into a newly allocated buffer. Set *sz_out to its size.

Definition at line 230 of file storagedir.c.

◆ storage_dir_read_labeled()

uint8_t * storage_dir_read_labeled ( storage_dir_t dir,
const char *  fname,
config_line_t **  labels_out,
size_t *  sz_out 

As storage_dir_map_labeled, but return a new byte array containing the data.

Definition at line 435 of file storagedir.c.

◆ storage_dir_remove_all()

int storage_dir_remove_all ( storage_dir_t d)

Remove all files in d.

Definition at line 593 of file storagedir.c.

◆ storage_dir_remove_file()

void storage_dir_remove_file ( storage_dir_t d,
const char *  fname 

Remove the file called fname from d.

Definition at line 480 of file storagedir.c.

◆ storage_dir_save_bytes_to_file()

int storage_dir_save_bytes_to_file ( storage_dir_t d,
const uint8_t *  data,
size_t  length,
int  binary,
char **  fname_out 

Try to write the length bytes at data into a new file in d. On success, return 0 and set *fname_out to a newly allocated string containing the filename. On failure, return -1.

Definition at line 311 of file storagedir.c.

Referenced by storage_dir_save_string_to_file().

◆ storage_dir_save_string_to_file()

int storage_dir_save_string_to_file ( storage_dir_t d,
const char *  str,
int  binary,
char **  fname_out 

As storage_dir_save_bytes_to_file, but saves a NUL-terminated string str.

Definition at line 330 of file storagedir.c.

◆ storage_dir_shrink()

int storage_dir_shrink ( storage_dir_t d,
uint64_t  target_size,
int  min_to_remove 

Try to free space by removing the oldest files in d. Delete until no more than target_size bytes are left, and at least min_to_remove files have been removed... or until there is nothing left to remove.

Return 0 on success; -1 on failure.

Definition at line 540 of file storagedir.c.

Referenced by storage_dir_remove_all().