disk IO convenience methods More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_DISK_PipeHandle |
Handle used to manage a pipe. More... | |
struct | GetFileSizeData |
Closure for the recursion to determine the file size of a directory. More... | |
struct | GlobClosure |
struct | GNUNET_DISK_MapHandle |
Handle for a memory-mapping operation. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__) |
#define | LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, "util-disk", syscall) |
#define | LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename) |
#define | COPY_BLK_SIZE 65536 |
Block size for IO for copying files. More... | |
#define | _IFMT 0170000 /* type of file */ |
#define | _IFLNK 0120000 /* symbolic link */ |
#define | S_ISLNK(m) (((m)&_IFMT) == _IFLNK) |
#define | MAP_FAILED ((void *) -1) |
Functions | |
static int | translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm) |
Translate GNUnet-internal permission bitmap to UNIX file access permission bitmap. More... | |
static enum GNUNET_GenericReturnValue | get_size_rec (void *cls, const char *fn) |
Iterate over all files in the given directory and accumulate their size. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) |
Checks whether a handle is invalid. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size) |
Get the size of an open file. More... | |
off_t | GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence) |
Move the read/write pointer in a file. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_size (const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode) |
Get the size of the file (or directory) of the given file (in bytes). More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t *dev, uint64_t *ino) |
Obtain some unique identifiers for the given file that can be used to identify it in the local system. More... | |
static char * | mktemp_name (const char *t) |
Create the name for a temporary file or directory from a template. More... | |
void | GNUNET_DISK_fix_permissions (const char *fn, int require_uid_match, int require_gid_match) |
Update POSIX permissions mask of a file on disk. More... | |
char * | GNUNET_DISK_mkdtemp (const char *t) |
Create an (empty) temporary directory on disk. More... | |
char * | GNUNET_DISK_file_backup (const char *fil) |
Move a file out of the way (create a backup) by renaming it to "orig.NUM~" where NUM is the smallest number that is not used yet. More... | |
char * | GNUNET_DISK_mktemp (const char *t) |
Create an (empty) temporary file on disk. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_directory_test (const char *fil, int is_readable) |
Test if fil is a directory and listable. More... | |
static enum GNUNET_GenericReturnValue | file_test_internal (const char *fil, int amode) |
Check if fil can be accessed using amode. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_test (const char *fil) |
Check that fil corresponds to a filename (of a file that exists and that is not a directory). More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_test_read (const char *fil) |
Check that fil corresponds to a filename and the file has read permissions. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_directory_create (const char *dir) |
Implementation of "mkdir -p". More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_directory_create_for_file (const char *filename) |
Create the directory structure for storing a file. More... | |
ssize_t | GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, size_t len) |
Read the contents of a binary file into a buffer. More... | |
ssize_t | GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) |
Read the contents of a binary file into a buffer. More... | |
ssize_t | GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n) |
Write a buffer to a file. More... | |
ssize_t | GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n) |
Write a buffer to a file, blocking, if necessary. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_fn_write (const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode) |
Write a buffer to a file atomically. More... | |
int | GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls) |
Scan a directory for files. More... | |
static bool | glob_match (const char *pattern, const char *str) |
Check for a simple wildcard match. More... | |
static enum GNUNET_GenericReturnValue | glob_cb (void *cls, const char *filename) |
Function called with a filename. More... | |
int | GNUNET_DISK_glob (const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls) |
Find all files matching a glob pattern. More... | |
static enum GNUNET_GenericReturnValue | remove_helper (void *unused, const char *fn) |
Function that removes the given directory by calling GNUNET_DISK_directory_remove(). More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_directory_remove (const char *filename) |
Remove all files in a directory (rm -rf). More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_copy (const char *src, const char *dst) |
Copy a file. More... | |
void | GNUNET_DISK_filename_canonicalize (char *fn) |
Removes special characters as ':' from a filename. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_change_owner (const char *filename, const char *user) |
Change owner of a file. More... | |
struct GNUNET_DISK_FileHandle * | GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm) |
Open a file. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) |
Close an open file. More... | |
struct GNUNET_DISK_FileHandle * | GNUNET_DISK_get_handle_from_int_fd (int fno) |
Get a handle from a native integer FD. More... | |
struct GNUNET_DISK_FileHandle * | GNUNET_DISK_get_handle_from_native (FILE *fd) |
Get a handle from a native FD. More... | |
void * | GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len) |
Map a file into memory. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) |
Unmap a file. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) |
Write file changes to disk. More... | |
struct GNUNET_DISK_PipeHandle * | GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) |
Creates an interprocess channel. More... | |
struct GNUNET_DISK_PipeHandle * | GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, int fd[2]) |
Creates a pipe object from a couple of file descriptors. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end) |
Closes one half of an interprocess channel. More... | |
struct GNUNET_DISK_FileHandle * | GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end) |
Detaches one of the ends from the pipe. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) |
Closes an interprocess channel. More... | |
const struct GNUNET_DISK_FileHandle * | GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n) |
Get the handle to a particular pipe end. More... | |
enum GNUNET_GenericReturnValue | GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, int *dst) |
Retrieve OS file handle. More... | |
static enum GNUNET_GenericReturnValue | purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Helper function for GNUNET_DISK_purge_cfg_dir. More... | |
void | GNUNET_DISK_purge_cfg_dir (const struct GNUNET_OS_ProjectData *pd, const char *cfg_filename, const char *option) |
Remove the directory given under option in section [PATHS] in configuration under cfg_filename. More... | |
disk IO convenience methods
Definition in file disk.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-disk", __VA_ARGS__) |
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-disk", syscall) |
#define LOG_STRERROR_FILE | ( | kind, | |
syscall, | |||
filename | |||
) | GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename) |
#define COPY_BLK_SIZE 65536 |
|
static |
Translate GNUnet-internal permission bitmap to UNIX file access permission bitmap.
perm | file permissions, GNUnet style |
Definition at line 109 of file disk.c.
References GNUNET_DISK_PERM_GROUP_EXEC, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_OTHER_EXEC, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_OTHER_WRITE, GNUNET_DISK_PERM_USER_EXEC, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, and mode.
Referenced by GNUNET_DISK_file_backup(), GNUNET_DISK_file_open(), and GNUNET_DISK_fn_write().
|
static |
Iterate over all files in the given directory and accumulate their size.
cls | closure of type struct GetFileSizeData |
fn | current filename we are looking at |
Definition at line 146 of file disk.c.
References get_size_rec(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GetFileSizeData::include_sym_links, LOG_STRERROR_FILE, S_ISLNK, GetFileSizeData::single_file_mode, and GetFileSizeData::total.
Referenced by get_size_rec(), and GNUNET_DISK_file_size().
|
static |
Create the name for a temporary file or directory from a template.
t | template (without XXXXX or "/tmp/") |
Definition at line 293 of file disk.c.
References getenv(), GNUNET_asprintf(), and t.
Referenced by GNUNET_DISK_mkdtemp(), and GNUNET_DISK_mktemp().
|
static |
Check if fil can be accessed using amode.
fil | file to check for |
amode | access mode |
Definition at line 481 of file disk.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NO, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, LOG_STRERROR_FILE, and ret.
Referenced by GNUNET_DISK_file_test(), and GNUNET_DISK_file_test_read().
|
static |
Check for a simple wildcard match.
Only asterisks are allowed. Asterisks match everything, including slashes.
pattern | pattern with wildcards |
str | string to match against |
Definition at line 910 of file disk.c.
Referenced by glob_cb().
|
static |
Function called with a filename.
cls | closure |
filename | complete filename (absolute path) |
Definition at line 972 of file disk.c.
References GlobClosure::cb, GlobClosure::cls, DIR_SEPARATOR, filename, GlobClosure::glob, glob_match(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, LOG, and GlobClosure::nres.
Referenced by GNUNET_DISK_glob().
|
static |
Function that removes the given directory by calling GNUNET_DISK_directory_remove().
unused | not used |
fn | directory to remove |
Definition at line 1070 of file disk.c.
References GNUNET_DISK_directory_remove(), and GNUNET_OK.
Referenced by GNUNET_DISK_directory_remove().
enum GNUNET_GenericReturnValue GNUNET_DISK_internal_file_handle_ | ( | const struct GNUNET_DISK_FileHandle * | fh, |
int * | dst | ||
) |
Retrieve OS file handle.
fh | GNUnet file descriptor |
dst | destination buffer |
Definition at line 1638 of file disk.c.
References GNUNET_DISK_FileHandle::fd, GNUNET_OK, and GNUNET_SYSERR.
Referenced by GNUNET_NETWORK_fdset_handle_set(), and start_process().
|
static |
Helper function for GNUNET_DISK_purge_cfg_dir.
cls | a const char * with the option to purge |
cfg | our configuration |
Definition at line 1656 of file disk.c.
References cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_directory_remove(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, and GNUNET_SYSERR.
Referenced by GNUNET_DISK_purge_cfg_dir().