GNUnet 0.26.2-16-ge86b66bd5
 
Loading...
Searching...
No Matches
Disk library

Disk IO APIs. More...

Collaboration diagram for Disk library:

Data Structures

struct  GNUNET_DISK_FileHandle
 Handle used to access files (and pipes). More...
 

Enumerations

enum  GNUNET_FILE_Type { GNUNET_DISK_HANLDE_TYPE_EVENT , GNUNET_DISK_HANLDE_TYPE_FILE , GNUNET_DISK_HANLDE_TYPE_PIPE }
 Type of a handle. More...
 
enum  GNUNET_DISK_OpenFlags {
  GNUNET_DISK_OPEN_READ = 1 , GNUNET_DISK_OPEN_WRITE = 2 , GNUNET_DISK_OPEN_READWRITE = 3 , GNUNET_DISK_OPEN_FAILIFEXISTS = 4 ,
  GNUNET_DISK_OPEN_TRUNCATE = 8 , GNUNET_DISK_OPEN_CREATE = 16 , GNUNET_DISK_OPEN_APPEND = 32
}
 Specifies how a file should be opened. More...
 
enum  GNUNET_DISK_MapType { GNUNET_DISK_MAP_TYPE_READ = 1 , GNUNET_DISK_MAP_TYPE_WRITE = 2 , GNUNET_DISK_MAP_TYPE_READWRITE = 3 }
 Specifies what type of memory map is desired. More...
 
enum  GNUNET_DISK_AccessPermissions {
  GNUNET_DISK_PERM_NONE = 0 , GNUNET_DISK_PERM_USER_READ = 1 , GNUNET_DISK_PERM_USER_WRITE = 2 , GNUNET_DISK_PERM_USER_EXEC = 4 ,
  GNUNET_DISK_PERM_GROUP_READ = 8 , GNUNET_DISK_PERM_GROUP_WRITE = 16 , GNUNET_DISK_PERM_GROUP_EXEC = 32 , GNUNET_DISK_PERM_OTHER_READ = 64 ,
  GNUNET_DISK_PERM_OTHER_WRITE = 128 , GNUNET_DISK_PERM_OTHER_EXEC = 256
}
 File access permissions, UNIX-style. More...
 
enum  GNUNET_DISK_Seek { GNUNET_DISK_SEEK_SET = 0 , GNUNET_DISK_SEEK_CUR = 1 , GNUNET_DISK_SEEK_END = 2 }
 Constants for specifying how to seek. More...
 
enum  GNUNET_DISK_PipeEnd { GNUNET_DISK_PIPE_END_READ = 0 , GNUNET_DISK_PIPE_END_WRITE = 1 }
 Enumeration identifying the two ends of a pipe. More...
 
enum  GNUNET_DISK_PipeFlags { GNUNET_DISK_PF_NONE , GNUNET_DISK_PF_BLOCKING_READ = 1 , GNUNET_DISK_PF_BLOCKING_WRITE = 2 , GNUNET_DISK_PF_BLOCKING_RW }
 Flags for GNUNET_DISK_pipe(). More...
 

Functions

enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
 Checks whether a handle is invalid.
 
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).
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read (const char *fil)
 Check that fil corresponds to a filename and the file has read permissions.
 
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.
 
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.
 
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).
 
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.
 
char * GNUNET_DISK_mktemp (const char *t)
 Create an (empty) temporary file on disk.
 
char * GNUNET_DISK_mkdtemp (const char *t)
 Create an (empty) temporary directory on disk.
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
 Open a file.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
 Get the size of an open file.
 
struct GNUNET_DISK_PipeHandleGNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf)
 Creates an interprocess channel.
 
struct GNUNET_DISK_PipeHandleGNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, int fd[2])
 Creates a pipe object from a couple of file descriptors.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 Closes an interprocess channel.
 
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.
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
 Detaches one of the ends from the pipe.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
 Close an open file.
 
const struct GNUNET_DISK_FileHandleGNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
 Get the handle to a particular pipe end.
 
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.
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_get_handle_from_int_fd (int fno)
 Get a handle from a native integer FD.
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_get_handle_from_native (FILE *fd)
 Get a handle from a native FD.
 
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.
 
ssize_t GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
 Read the contents of a binary file into a buffer.
 
ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
 Write a buffer to a file.
 
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.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy (const char *src, const char *dst)
 Copy a file.
 
int GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
 Scan a directory for files.
 
int GNUNET_DISK_glob (const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
 Find all files matching a glob pattern.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file (const char *filename)
 Create the directory structure for storing a file.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test (const char *fil, int is_readable)
 Test if fil is a directory and listable.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove (const char *filename)
 Remove all files in a directory (rm -rf).
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create (const char *dir)
 Implementation of "mkdir -p".
 
void GNUNET_DISK_filename_canonicalize (char *fn)
 Removes special characters as ':' from a filename.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_change_owner (const char *filename, const char *user)
 Change owner of a file.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
 Unmap a file.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
 Write file changes to disk.
 

Detailed Description

Disk IO APIs.

Enumeration Type Documentation

◆ GNUNET_FILE_Type

Type of a handle.

Enumerator
GNUNET_DISK_HANLDE_TYPE_EVENT 

Handle represents an event.

GNUNET_DISK_HANLDE_TYPE_FILE 

Handle represents a file.

GNUNET_DISK_HANLDE_TYPE_PIPE 

Handle represents a pipe.

Definition at line 50 of file gnunet_disk_lib.h.

51{
56
61
66};
@ GNUNET_DISK_HANLDE_TYPE_FILE
Handle represents a file.
@ GNUNET_DISK_HANLDE_TYPE_PIPE
Handle represents a pipe.
@ GNUNET_DISK_HANLDE_TYPE_EVENT
Handle represents an event.

◆ GNUNET_DISK_OpenFlags

Specifies how a file should be opened.

Enumerator
GNUNET_DISK_OPEN_READ 

Open the file for reading.

GNUNET_DISK_OPEN_WRITE 

Open the file for writing.

GNUNET_DISK_OPEN_READWRITE 

Open the file for both reading and writing.

GNUNET_DISK_OPEN_FAILIFEXISTS 

Fail if file already exists.

GNUNET_DISK_OPEN_TRUNCATE 

Truncate file if it exists.

GNUNET_DISK_OPEN_CREATE 

Create file if it doesn't exist.

GNUNET_DISK_OPEN_APPEND 

Append to the file.

Definition at line 101 of file gnunet_disk_lib.h.

102{
107
112
117
122
127
132
137};
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_OPEN_FAILIFEXISTS
Fail if file already exists.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_APPEND
Append to the file.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.

◆ GNUNET_DISK_MapType

Specifies what type of memory map is desired.

Enumerator
GNUNET_DISK_MAP_TYPE_READ 

Read-only memory map.

GNUNET_DISK_MAP_TYPE_WRITE 

Write-able memory map.

GNUNET_DISK_MAP_TYPE_READWRITE 

Read-write memory map.

Definition at line 142 of file gnunet_disk_lib.h.

143{
148
153
158};
@ GNUNET_DISK_MAP_TYPE_WRITE
Write-able memory map.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
@ GNUNET_DISK_MAP_TYPE_READWRITE
Read-write memory map.

◆ GNUNET_DISK_AccessPermissions

File access permissions, UNIX-style.

Enumerator
GNUNET_DISK_PERM_NONE 

Nobody is allowed to do anything to the file.

GNUNET_DISK_PERM_USER_READ 

Owner can read.

GNUNET_DISK_PERM_USER_WRITE 

Owner can write.

GNUNET_DISK_PERM_USER_EXEC 

Owner can execute.

GNUNET_DISK_PERM_GROUP_READ 

Group can read.

GNUNET_DISK_PERM_GROUP_WRITE 

Group can write.

GNUNET_DISK_PERM_GROUP_EXEC 

Group can execute.

GNUNET_DISK_PERM_OTHER_READ 

Everybody can read.

GNUNET_DISK_PERM_OTHER_WRITE 

Everybody can write.

GNUNET_DISK_PERM_OTHER_EXEC 

Everybody can execute.

Definition at line 164 of file gnunet_disk_lib.h.

165{
170
175
180
185
190
195
200
205
210
215};
@ GNUNET_DISK_PERM_OTHER_EXEC
Everybody can execute.
@ GNUNET_DISK_PERM_USER_EXEC
Owner can execute.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_EXEC
Group can execute.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_PERM_OTHER_READ
Everybody can read.
@ GNUNET_DISK_PERM_OTHER_WRITE
Everybody can write.

◆ GNUNET_DISK_Seek

Constants for specifying how to seek.

Do not change values or order, some of the code depends on the specific numeric values!

Enumerator
GNUNET_DISK_SEEK_SET 

Seek an absolute position (from the start of the file).

GNUNET_DISK_SEEK_CUR 

Seek a relative position (from the current offset).

GNUNET_DISK_SEEK_END 

Seek an absolute position from the end of the file.

Definition at line 222 of file gnunet_disk_lib.h.

223{
228
233
238};
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
@ GNUNET_DISK_SEEK_CUR
Seek a relative position (from the current offset).
@ GNUNET_DISK_SEEK_END
Seek an absolute position from the end of the file.

◆ GNUNET_DISK_PipeEnd

Enumeration identifying the two ends of a pipe.

Enumerator
GNUNET_DISK_PIPE_END_READ 

The reading-end of a pipe.

GNUNET_DISK_PIPE_END_WRITE 

The writing-end of a pipe.

Definition at line 244 of file gnunet_disk_lib.h.

245{
250
255};
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.

◆ GNUNET_DISK_PipeFlags

Flags for GNUNET_DISK_pipe().

Enumerator
GNUNET_DISK_PF_NONE 

No special options, use non-blocking read/write operations.

GNUNET_DISK_PF_BLOCKING_READ 

Configure read end to block when reading if set.

GNUNET_DISK_PF_BLOCKING_WRITE 

Configure write end to block when writing if set.

GNUNET_DISK_PF_BLOCKING_RW 

Configure both pipe ends for blocking operations if set.

Definition at line 419 of file gnunet_disk_lib.h.

420{
421
426
431
436
442
443};
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
@ GNUNET_DISK_PF_BLOCKING_WRITE
Configure write end to block when writing if set.
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
@ GNUNET_DISK_PF_BLOCKING_READ
Configure read end to block when reading if set.

Function Documentation

◆ GNUNET_DISK_handle_invalid()

enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid ( const struct GNUNET_DISK_FileHandle h)

Checks whether a handle is invalid.

Parameters
hhandle to check
Returns
GNUNET_YES if invalid, GNUNET_NO if valid

Definition at line 199 of file disk.c.

200{
201 return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
202}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
@ GNUNET_YES
@ GNUNET_NO

References GNUNET_NO, GNUNET_YES, and h.

Referenced by decrementBit(), file_hash_finish(), incrementBit(), maint_child_death(), and shutdown_pipe_cb().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_test()

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).

Parameters
filfilename to check
Returns
GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something else (will print an error message in that case, too).

Definition at line 557 of file disk.c.

558{
559 return file_test_internal (fil,
560 F_OK);
561}
static enum GNUNET_GenericReturnValue file_test_internal(const char *fil, int amode)
Check if fil can be accessed using amode.
Definition disk.c:513

References file_test_internal().

Referenced by callback_scan_for_operations(), create_download_context(), create_unique_cfgs(), database_connect(), database_setup(), database_setup(), database_setup(), database_setup(), database_setup(), ego_callback(), get_path_from_PATH(), get_topo_string_from_file(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_DISK_file_open(), GNUNET_FS_download_start_task_(), GNUNET_HOSTLIST_client_start(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TRANSPORT_TESTING_start_peer(), hosts_directory_scan_callback(), load_hostlist_file(), load_list_messages(), load_list_tunnels(), load_member(), load_member_session(), load_member_session_history(), load_member_session_next(), load_message_store(), load_peer_store(), load_search_strings(), main(), PABC_load_public_parameters(), print_key(), read_file(), read_index_list(), read_update_information_graph(), restore_valid_peers(), run(), run(), run(), run(), run(), run(), run(), start_peer_run(), and start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_test_read()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read ( const char *  fil)

Check that fil corresponds to a filename and the file has read permissions.

Parameters
filfilename to check
Returns
GNUNET_YES if yes, GNUNET_NO if file doesn't exist or has no read permissions, GNUNET_SYSERR if something else (will print an error message in that case, too).

Definition at line 565 of file disk.c.

566{
567 return file_test_internal (fil,
568 R_OK);
569}

References file_test_internal().

Referenced by GNUNET_CONFIGURATION_default_filename(), GNUNET_PQ_exec_sql(), handle_inline(), and load_ikm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_backup()

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.

Parameters
filname of the file to back up
Returns
the backup file name (must be freed by caller)

Definition at line 373 of file disk.c.

374{
375 size_t slen;
376 char *target;
377 unsigned int num;
378
379 slen = strlen (fil) + 20;
380 target = GNUNET_malloc (slen);
381 num = 0;
382
383#if HAVE_RENAMEAT2
384 {
385 int fd;
386
387 do
388 {
389 GNUNET_snprintf (target,
390 slen,
391 "%s.%u~",
392 fil,
393 num++);
394 fd = open (target,
395 O_CREAT | O_EXCL,
397 } while (-1 == fd);
398 if (0 != renameat2 (AT_FDCWD,
399 fil,
400 AT_FDCWD,
401 target,
402 RENAME_EXCHANGE))
403 {
405 "renameat2",
406 fil);
407 GNUNET_break (0 ==
408 close (fd));
409 return NULL;
410 }
411 GNUNET_break (0 ==
412 close (fd));
413 }
414#else
415 do
416 {
417 GNUNET_snprintf (target,
418 slen,
419 "%s.%u~",
420 fil,
421 num++);
422 }
423 while (0 == access (target,
424 F_OK));
425 if (0 != rename (fil,
426 target))
427 {
429 "rename",
430 fil);
431 return NULL;
432 }
433#endif
434 return target;
435}
static int translate_unix_perms(enum GNUNET_DISK_AccessPermissions perm)
Translate GNUnet-internal permission bitmap to UNIX file access permission bitmap.
Definition disk.c:109
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_malloc(size)
Wrapper around malloc.

References GNUNET_break, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_snprintf(), and translate_unix_perms().

Here is the call graph for this function:

◆ GNUNET_DISK_file_seek()

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.

Parameters
hhandle of an open file
offsetposition to move to
whencespecification to which position the offset parameter relates to
Returns
the new position on success, GNUNET_SYSERR otherwise

Definition at line 219 of file disk.c.

222{
223 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
224
225 if (h == NULL)
226 {
227 errno = EINVAL;
228 return GNUNET_SYSERR;
229 }
230 return lseek (h->fd, offset, t[whence]);
231}
static struct GNUNET_SCHEDULER_Task * t
Main task.
@ GNUNET_SYSERR

References GNUNET_SYSERR, h, and t.

Referenced by decrementBit(), delete_store_message(), fh_reader(), get_store_message(), GNUNET_FS_data_reader_file_(), GNUNET_FS_handle_on_demand_block(), incrementBit(), iterate_save_messages(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_peer_store(), process_result_with_request(), read_file(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), save_peer_store(), try_top_down_reconstruction(), and unindex_reader().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_size()

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).

Parameters
filenamename of the file or directory
sizeset to the size of the file (or, in the case of directories, the sum of all sizes of files in the directory)
include_symbolic_linksshould symbolic links be included?
single_file_modeGNUNET_YES to only get size of one file and return GNUNET_SYSERR for directories.
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 235 of file disk.c.

239{
240 struct GetFileSizeData gfsd;
242
243 GNUNET_assert (size != NULL);
244 gfsd.total = 0;
245 gfsd.include_sym_links = include_symbolic_links;
246 gfsd.single_file_mode = single_file_mode;
247 ret = get_size_rec (&gfsd, filename);
248 *size = gfsd.total;
249 return ret;
250}
static enum GNUNET_GenericReturnValue get_size_rec(void *cls, const char *fn)
Iterate over all files in the given directory and accumulate their size.
Definition disk.c:146
static int ret
Final status code.
Definition gnunet-arm.c:93
static char * filename
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
Definition peer.c:68
Closure for the recursion to determine the file size of a directory.
Definition disk.c:83
int single_file_mode
GNUNET_YES if mode is file-only (return total == -1 for directories).
Definition disk.c:97

References filename, get_size_rec(), GNUNET_assert, GetFileSizeData::include_sym_links, ret, GetFileSizeData::single_file_mode, size, and GetFileSizeData::total.

Referenced by create_download_context(), database_setup(), database_setup(), get_topo_string_from_file(), GNUNET_CONFIGURATION_parse(), GNUNET_CRYPTO_hash_file(), GNUNET_DISK_file_copy(), GNUNET_FS_file_information_create_from_file(), GNUNET_FS_unindex_start(), load(), load_file(), load_message_store_entries(), load_message_store_epochs(), load_message_store_links(), load_search_strings(), preprocess_file(), print_key(), run(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_get_identifiers()

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.

This function is used between GNUnet processes to quickly check if two files with the same absolute path are actually identical. The two processes represent the same peer but may communicate over the network (and the file may be on an NFS volume). This function may not be supported on all operating systems.

Parameters
filenamename of the file
devset to the device ID
inoset to the inode ID
Returns
GNUNET_OK on success

Definition at line 254 of file disk.c.

257{
258#if HAVE_STAT
259 {
260 struct stat sbuf;
261
262 if (0 != stat (filename, &sbuf))
263 {
264 return GNUNET_SYSERR;
265 }
266 *ino = (uint64_t) sbuf.st_ino;
267 }
268#else
269 *ino = 0;
270#endif
271#if HAVE_STATVFS
272 {
273 struct statvfs fbuf;
274
275 if (0 != statvfs (filename, &fbuf))
276 {
277 return GNUNET_SYSERR;
278 }
279 *dev = (uint64_t) fbuf.f_fsid;
280 }
281#elif HAVE_STATFS
282 {
283 struct statfs fbuf;
284
285 if (0 != statfs (filename, &fbuf))
286 {
287 return GNUNET_SYSERR;
288 }
289 *dev =
290 ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
291 }
292#else
293 *dev = 0;
294#endif
295 return GNUNET_OK;
296}
@ GNUNET_OK

References filename, GNUNET_OK, and GNUNET_SYSERR.

Referenced by handle_client_index_start(), and hash_for_index_cb().

Here is the caller graph for this function:

◆ GNUNET_DISK_mktemp()

char * GNUNET_DISK_mktemp ( const char *  t)

Create an (empty) temporary file on disk.

If the given name is not an absolute path, the current 'TMPDIR' will be prepended. In any case, 6 random characters will be appended to the name to create a unique filename.

Parameters
tcomponent to use for the name; does NOT contain "XXXXXX" or "/tmp/".
Returns
NULL on error, otherwise name of fresh file on disk in directory for temporary files

Definition at line 439 of file disk.c.

440{
441 int fd;
442 char *fn;
443 mode_t omask;
444
445 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
446 fn = mktemp_name (t);
447 if (-1 == (fd = mkstemp (fn)))
448 {
450 "mkstemp",
451 fn);
452 GNUNET_free (fn);
453 umask (omask);
454 return NULL;
455 }
456 umask (omask);
457 if (0 != close (fd))
459 "close",
460 fn);
461 return fn;
462}
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition disk.c:36
static char * mktemp_name(const char *t)
Create the name for a temporary file or directory from a template.
Definition disk.c:306
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, LOG_STRERROR_FILE, mktemp_name(), and t.

Referenced by create_download_context(), GNUNET_DATACACHE_create(), GNUNET_FS_download_sync_(), libgnunet_plugin_datacache_sqlite_init(), make_serialization_file_name(), and make_serialization_file_name_in_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_mkdtemp()

char * GNUNET_DISK_mkdtemp ( const char *  t)

Create an (empty) temporary directory on disk.

If the given name is not an absolute path, the current 'TMPDIR' will be prepended. In any case, 6 random characters will be appended to the name to create a unique name.

Parameters
tcomponent to use for the name; does NOT contain "XXXXXX" or "/tmp/".
Returns
NULL on error, otherwise name of freshly created directory

Definition at line 353 of file disk.c.

354{
355 char *fn;
356 mode_t omask;
357
358 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
359 fn = mktemp_name (t);
360 if (fn != mkdtemp (fn))
361 {
363 GNUNET_free (fn);
364 umask (omask);
365 return NULL;
366 }
367 umask (omask);
368 return fn;
369}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, LOG_STRERROR_FILE, mktemp_name(), and t.

Referenced by create_response(), and GNUNET_TESTBED_system_create_with_portrange().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_open()

struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open ( const char *  fn,
enum GNUNET_DISK_OpenFlags  flags,
enum GNUNET_DISK_AccessPermissions  perm 
)

Open a file.

Note that the access permissions will only be used if a new file is created and if the underlying operating system supports the given permissions.

Parameters
fnfile name to be opened
flagsopening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags
permpermissions for the newly created file, use GNUNET_DISK_PERM_NONE if a file could not be created by this call (because of flags)
Returns
IO handle on success, NULL on error

Definition at line 1308 of file disk.c.

1311{
1312 char *expfn;
1314
1315 int oflags;
1316 int mode;
1317 int fd;
1318
1319 expfn = GNUNET_STRINGS_filename_expand (fn);
1320 if (NULL == expfn)
1321 return NULL;
1322
1323 mode = 0;
1325 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1326 else if (flags & GNUNET_DISK_OPEN_READ)
1327 oflags = O_RDONLY;
1328 else if (flags & GNUNET_DISK_OPEN_WRITE)
1329 oflags = O_WRONLY;
1330 else
1331 {
1332 GNUNET_break (0);
1333 GNUNET_free (expfn);
1334 return NULL;
1335 }
1337 oflags |= (O_CREAT | O_EXCL);
1338 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1339 oflags |= O_TRUNC;
1340 if (flags & GNUNET_DISK_OPEN_APPEND)
1341 oflags |= O_APPEND;
1342 if (GNUNET_NO == GNUNET_DISK_file_test (fn))
1343 {
1344 if (flags & GNUNET_DISK_OPEN_CREATE)
1345 {
1347 oflags |= O_CREAT;
1348 mode = translate_unix_perms (perm);
1349 }
1350 }
1351
1352 // Setting O_CLOEXEC after pipe() may introduce
1353 // race conditions: https://bugs.gnunet.org/view.php?id=9311
1354 // This is no problem if the platform supports pipe2
1355 fd = open (expfn,
1356 oflags
1357#if O_CLOEXEC
1358 | O_CLOEXEC
1359#endif
1360 | O_LARGEFILE,
1361 mode);
1362 if (fd == -1)
1363 {
1364 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
1366 "open",
1367 expfn);
1368 else
1370 "open",
1371 expfn);
1372 GNUNET_free (expfn);
1373 return NULL;
1374 }
1375
1377
1378 ret->fd = fd;
1379
1380 GNUNET_free (expfn);
1381 return ret;
1382}
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
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).
Definition disk.c:557
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:525
#define O_LARGEFILE
Definition platform.h:213
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.

References GNUNET_DISK_FileHandle::fd, GNUNET_break, GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_APPEND, GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_FAILIFEXISTS, GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_new, GNUNET_NO, GNUNET_STRINGS_filename_expand(), LOG_STRERROR_FILE, mode, O_LARGEFILE, ret, and translate_unix_perms().

Referenced by database_setup(), database_setup(), database_shutdown(), database_shutdown(), full_recursive_download(), get_file_handle(), GNUNET_BIO_read_open_file(), GNUNET_BIO_write_open_file(), GNUNET_CONFIGURATION_write(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_CRYPTO_hash_file(), GNUNET_DISK_file_copy(), GNUNET_DISK_fn_read(), GNUNET_FS_data_reader_file_(), GNUNET_FS_download_start_task_(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_unindex_do_remove_(), GNUNET_TIME_absolute_get_monotonic(), load_etc_hosts(), load_ikm(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store(), load_message_store_entries(), load_message_store_epochs(), load_message_store_links(), load_peer_store(), lookup_dns_servers(), open_static_resource(), print_key(), process_result_with_request(), read_file(), read_from_log(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), run(), run(), run(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), save_peer_store(), start_dump(), start_insert(), store_valid_peers(), to_file_raw(), try_match_block(), write_benchmark_data(), and write_file().

Here is the call graph for this function:

◆ GNUNET_DISK_file_handle_size()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size ( struct GNUNET_DISK_FileHandle fh,
off_t *  size 
)

Get the size of an open file.

Parameters
fhopen file handle
sizewhere to write size of the file
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 206 of file disk.c.

208{
209 struct stat sbuf;
210
211 if (0 != fstat (fh->fd, &sbuf))
212 return GNUNET_SYSERR;
213 *size = sbuf.st_size;
214 return GNUNET_OK;
215}

References GNUNET_DISK_FileHandle::fd, GNUNET_OK, GNUNET_SYSERR, and size.

Referenced by GNUNET_CONTAINER_bloomfilter_load(), GNUNET_TIME_absolute_get_monotonic(), load_etc_hosts(), load_ikm(), lookup_dns_servers(), open_static_resource(), REGEX_TEST_read_from_file(), and restore_valid_peers().

Here is the caller graph for this function:

◆ GNUNET_DISK_pipe()

struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe ( enum GNUNET_DISK_PipeFlags  pf)

Creates an interprocess channel.

Parameters
pfhow to configure the pipe
Returns
handle to the new pipe, NULL on error

Definition at line 1523 of file disk.c.

1524{
1525 int fd[2];
1526
1527#if HAVE_PIPE2 && O_CLOEXEC
1528 if (-1 == pipe2 (fd, O_CLOEXEC))
1529#else
1530 if (-1 == pipe (fd))
1531#endif
1532 {
1533 int eno = errno;
1534
1536 errno = eno;
1537 return NULL;
1538 }
1539 return GNUNET_DISK_pipe_from_fd (pf, fd);
1540}
#define LOG_STRERROR(kind, syscall)
Definition disk.c:33
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.
Definition disk.c:1544

References GNUNET_DISK_PipeHandle::fd, GNUNET_DISK_pipe_from_fd(), GNUNET_ERROR_TYPE_ERROR, and LOG_STRERROR.

Referenced by child_management_start(), GNUNET_ARM_request_service_start(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_SCHEDULER_driver_init(), main(), restart_nat_server(), run(), start_helper(), and start_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_pipe_from_fd()

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.

Useful for wrapping existing pipe FDs.

Parameters
pfhow to configure the pipe
fdan array of two fd values. One of them may be -1 for read-only or write-only pipes
Returns
handle to the new pipe, NULL on error

Definition at line 1544 of file disk.c.

1546{
1547 struct GNUNET_DISK_PipeHandle *p;
1548 int ret = 0;
1549 int flags;
1550 int eno = 0; /* make gcc happy */
1551
1553 if (fd[0] >= 0)
1554 {
1555 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1556 p->fd[0]->fd = fd[0];
1557 if (0 == (GNUNET_DISK_PF_BLOCKING_READ & pf))
1558 {
1559 flags = fcntl (fd[0], F_GETFL);
1560 flags |= O_NONBLOCK;
1561 if (0 > fcntl (fd[0], F_SETFL, flags))
1562 {
1563 ret = -1;
1564 eno = errno;
1565 }
1566 }
1567 flags = fcntl (fd[0], F_GETFD);
1568 flags |= FD_CLOEXEC;
1569 if (0 > fcntl (fd[0], F_SETFD, flags))
1570 {
1571 ret = -1;
1572 eno = errno;
1573 }
1574 }
1575
1576 if (fd[1] >= 0)
1577 {
1578 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1579 p->fd[1]->fd = fd[1];
1580 if (0 == (GNUNET_DISK_PF_BLOCKING_WRITE & pf))
1581 {
1582 flags = fcntl (fd[1], F_GETFL);
1583 flags |= O_NONBLOCK;
1584 if (0 > fcntl (fd[1], F_SETFL, flags))
1585 {
1586 ret = -1;
1587 eno = errno;
1588 }
1589 }
1590 flags = fcntl (fd[1], F_GETFD);
1591 flags |= FD_CLOEXEC;
1592 if (0 > fcntl (fd[1], F_SETFD, flags))
1593 {
1594 ret = -1;
1595 eno = errno;
1596 }
1597 }
1598 if (ret == -1)
1599 {
1600 errno = eno;
1602 if (p->fd[0]->fd >= 0)
1603 GNUNET_break (0 == close (p->fd[0]->fd));
1604 if (p->fd[1]->fd >= 0)
1605 GNUNET_break (0 == close (p->fd[1]->fd));
1606 GNUNET_free (p->fd[0]);
1607 GNUNET_free (p->fd[1]);
1608 GNUNET_free (p);
1609 errno = eno;
1610 return NULL;
1611 }
1612 return p;
1613}
static struct GNUNET_OS_Process * p
Helper process we started.
Definition gnunet-uri.c:38
Handle used to manage a pipe.
Definition disk.c:69
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Definition disk.c:74

References GNUNET_DISK_PipeHandle::fd, GNUNET_break, GNUNET_DISK_PF_BLOCKING_READ, GNUNET_DISK_PF_BLOCKING_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_new, LOG_STRERROR, p, and ret.

Referenced by GNUNET_DISK_pipe().

Here is the caller graph for this function:

◆ GNUNET_DISK_pipe_close()

enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close ( struct GNUNET_DISK_PipeHandle p)

Closes an interprocess channel.

Parameters
ppipe
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1670 of file disk.c.

1671{
1673 enum GNUNET_GenericReturnValue read_end_close;
1674 enum GNUNET_GenericReturnValue write_end_close;
1675 int read_end_close_errno;
1676 int write_end_close_errno;
1677
1678 read_end_close = GNUNET_DISK_pipe_close_end (p,
1680 read_end_close_errno = errno;
1681 write_end_close = GNUNET_DISK_pipe_close_end (p,
1683 write_end_close_errno = errno;
1684 GNUNET_free (p);
1685
1686 if (GNUNET_OK != read_end_close)
1687 {
1688 errno = read_end_close_errno;
1689 ret = read_end_close;
1690 }
1691 else if (GNUNET_OK != write_end_close)
1692 {
1693 errno = write_end_close_errno;
1694 ret = write_end_close;
1695 }
1696
1697 return ret;
1698}
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.
Definition disk.c:1617

References GNUNET_DISK_pipe_close_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_free, GNUNET_OK, p, and ret.

Referenced by child_management_done(), GN_stop_gnunet_nat_server_(), GNUNET_ARM_request_service_start(), GNUNET_HELPER_kill(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_run(), GNUNET_OS_command_stop(), GNUNET_SCHEDULER_driver_done(), main(), nat_server_read(), restart_nat_server(), shutdown_task(), and start_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_pipe_close_end()

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.

Parameters
ppipe to close end of
endwhich end of the pipe to close
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1617 of file disk.c.

1619{
1621
1623 {
1624 if (p->fd[0])
1625 {
1626 ret = GNUNET_DISK_file_close (p->fd[0]);
1627 p->fd[0] = NULL;
1628 }
1629 }
1630 else if (end == GNUNET_DISK_PIPE_END_WRITE)
1631 {
1632 if (p->fd[1])
1633 {
1634 ret = GNUNET_DISK_file_close (p->fd[1]);
1635 p->fd[1] = NULL;
1636 }
1637 }
1638 return ret;
1639}
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386

References end, GNUNET_DISK_file_close(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_OK, p, and ret.

Referenced by GNUNET_DISK_pipe_close(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), restart_nat_server(), and start_helper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_pipe_detach_end()

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.

Detached end is a fully-functional FileHandle, it will not be affected by anything you do with the pipe afterwards. Each end of a pipe can only be detched from it once (i.e. it is not duplicated).

Parameters
ppipe to detach an end from
endwhich end of the pipe to detach
Returns
Detached end on success, NULL on failure (or if that end is not present or is closed).

Definition at line 1643 of file disk.c.

1645{
1646 struct GNUNET_DISK_FileHandle *ret = NULL;
1647
1649 {
1650 if (p->fd[0])
1651 {
1652 ret = p->fd[0];
1653 p->fd[0] = NULL;
1654 }
1655 }
1656 else if (end == GNUNET_DISK_PIPE_END_WRITE)
1657 {
1658 if (p->fd[1])
1659 {
1660 ret = p->fd[1];
1661 p->fd[1] = NULL;
1662 }
1663 }
1664
1665 return ret;
1666}

References end, GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, p, and ret.

Referenced by GNUNET_ARM_request_service_start(), and start_process().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_close()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_close ( struct GNUNET_DISK_FileHandle h)

Close an open file.

Parameters
hfile handle
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1386 of file disk.c.

1387{
1389
1390 if (NULL == h)
1391 {
1392 errno = EINVAL;
1393 return GNUNET_SYSERR;
1394 }
1395
1396 ret = GNUNET_OK;
1397 if (0 != close (h->fd))
1398 {
1400 "close");
1402 }
1403 GNUNET_free (h);
1404 return ret;
1405}

References GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, h, LOG_STRERROR, and ret.

Referenced by check_completed(), clear_message_store(), close_files_iter(), database_setup(), database_setup(), database_shutdown(), database_shutdown(), do_shutdown(), do_shutdown(), file_hash_finish(), full_recursive_download(), get_cb(), GNUNET_ARM_operation_cancel(), GNUNET_ARM_request_service_start(), GNUNET_BIO_flush(), GNUNET_BIO_read_close(), GNUNET_BIO_write_close(), GNUNET_CONFIGURATION_write(), GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_CRYPTO_hash_file_cancel(), GNUNET_DISK_file_copy(), GNUNET_DISK_fn_read(), GNUNET_DISK_pipe_close_end(), GNUNET_FS_data_reader_file_(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_start_task_(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_unindex_stop(), GNUNET_OS_process_destroy(), GNUNET_TIME_absolute_get_monotonic(), load_etc_hosts(), load_ikm(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store(), load_message_store_entries(), load_message_store_epochs(), load_message_store_links(), load_peer_store(), lookup_dns_servers(), notify_starting(), open_static_resource(), parent_control_handler(), print_key(), process_result_with_request(), read_file(), reconstruct_cont(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), run(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), save_peer_store(), shutdown_pch(), shutdown_task(), start_process(), store_valid_peers(), to_file_raw(), try_match_block(), unindex_finish(), write_benchmark_data(), and write_file().

◆ GNUNET_DISK_pipe_handle()

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.

Parameters
ppipe
nend to access
Returns
handle for the respective end

Definition at line 1702 of file disk.c.

1704{
1705 switch (n)
1706 {
1709 return p->fd[n];
1710
1711 default:
1712 GNUNET_break (0);
1713 return NULL;
1714 }
1715}

References GNUNET_break, GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, and p.

Referenced by GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_SCHEDULER_driver_init(), GNUNET_wait_child(), initiate_put_from_pipe_trigger(), maint_child_death(), maint_child_death(), maint_child_death(), restart_nat_server(), run(), run(), run(), shutdown_pipe_cb(), sighandler_child_death(), sighandler_child_death(), sighandler_child_death(), sighandler_child_death(), sighandler_shutdown(), sign_worker(), start_helper(), start_process(), and work().

Here is the caller graph for this function:

◆ GNUNET_DISK_fix_permissions()

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.

If both arguments are GNUNET_NO, the file is made world-read-write-executable (777). Does nothing on W32.

Parameters
fnname of the file to update
require_uid_matchGNUNET_YES means 700
require_gid_matchGNUNET_YES means 770 unless require_uid_match is set

Definition at line 334 of file disk.c.

337{
338 mode_t mode;
339
340 if (GNUNET_YES == require_uid_match)
341 mode = S_IRUSR | S_IWUSR | S_IXUSR;
342 else if (GNUNET_YES == require_gid_match)
343 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
344 else
345 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH
346 | S_IWOTH | S_IXOTH;
347 if (0 != chmod (fn, mode))
349}

References GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file, GNUNET_YES, and mode.

Referenced by create_listen_socket().

Here is the caller graph for this function:

◆ GNUNET_DISK_get_handle_from_int_fd()

struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd ( int  fno)

Get a handle from a native integer FD.

Parameters
fnonative integer file descriptor
Returns
file handle corresponding to the descriptor

Definition at line 1409 of file disk.c.

1410{
1411 struct GNUNET_DISK_FileHandle *fh;
1412
1413 if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
1414 return NULL; /* invalid FD */
1415
1416 fh = GNUNET_new (struct GNUNET_DISK_FileHandle);
1417
1418 fh->fd = fno;
1419
1420 return fh;
1421}

References GNUNET_DISK_FileHandle::fd, and GNUNET_new.

Referenced by extract_handles(), GNUNET_DISK_get_handle_from_native(), GNUNET_OS_install_parent_control_handler(), main(), start_dump(), and start_insert().

Here is the caller graph for this function:

◆ GNUNET_DISK_get_handle_from_native()

struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native ( FILE *  fd)

Get a handle from a native FD.

Parameters
fdnative file descriptor
Returns
file handle corresponding to the descriptor

Definition at line 1425 of file disk.c.

1426{
1427 int fno;
1428
1429 fno = fileno (fd);
1430 if (-1 == fno)
1431 return NULL;
1433}
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition disk.c:1409

References GNUNET_DISK_FileHandle::fd, and GNUNET_DISK_get_handle_from_int_fd().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_read()

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.

Parameters
hhandle to an open file
resultthe buffer to write the result to
lenthe maximum number of bytes to read
Returns
the number of bytes read on success, GNUNET_SYSERR on failure

Definition at line 704 of file disk.c.

707{
708 if (NULL == h)
709 {
710 errno = EINVAL;
711 return GNUNET_SYSERR;
712 }
713 return read (h->fd,
714 result,
715 len);
716}
static int result
Global testing status.

References GNUNET_SYSERR, h, and result.

Referenced by cmd_read(), database_setup(), decrementBit(), fh_reader(), file_hash_task(), get_store_message(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_DISK_file_copy(), GNUNET_DISK_fn_read(), GNUNET_FS_data_reader_file_(), GNUNET_FS_handle_on_demand_block(), helper_read(), incrementBit(), initiate_put_from_pipe_trigger(), load_ikm(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store_attribute(), load_peer_store(), maint_child_death(), maint_child_death(), maint_child_death(), nat_server_read(), parent_control_handler(), print_key(), put_cb(), read_external_ipv4(), read_file(), read_from_file(), read_task(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), run(), shutdown_pipe_cb(), start_insert(), try_top_down_reconstruction(), and unindex_reader().

Here is the caller graph for this function:

◆ GNUNET_DISK_fn_read()

ssize_t GNUNET_DISK_fn_read ( const char *  fn,
void *  result,
size_t  len 
)

Read the contents of a binary file into a buffer.

Parameters
fnfile name
resultthe buffer to write the result to
lenthe maximum number of bytes to read
Returns
number of bytes read, GNUNET_SYSERR on failure

Definition at line 720 of file disk.c.

723{
724 struct GNUNET_DISK_FileHandle *fh;
725 ssize_t ret;
726 int eno;
727
728 fh = GNUNET_DISK_file_open (fn,
731 if (NULL == fh)
732 return GNUNET_SYSERR;
734 result,
735 len);
736 eno = errno;
739 errno = eno;
740 return ret;
741}
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1308
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.
Definition disk.c:704

References GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_OK, GNUNET_SYSERR, result, and ret.

Referenced by ego_callback(), get_topo_string_from_file(), GNUNET_CONFIGURATION_parse(), hosts_directory_scan_callback(), load_file(), load_search_strings(), run(), run(), run(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_write()

ssize_t GNUNET_DISK_file_write ( const struct GNUNET_DISK_FileHandle h,
const void *  buffer,
size_t  n 
)

Write a buffer to a file.

Parameters
hhandle to open file
bufferthe data to write
nnumber of bytes to write
Returns
number of bytes written on success, GNUNET_SYSERR on error

Definition at line 745 of file disk.c.

748{
749 if (NULL == h)
750 {
751 errno = EINVAL;
752 return GNUNET_SYSERR;
753 }
754 return write (h->fd,
755 buffer,
756 n);
757}

References GNUNET_SYSERR, and h.

Referenced by database_shutdown(), decrementBit(), delete_store_message(), do_shutdown(), get_cb(), GNUNET_BIO_flush(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_copy(), GNUNET_OS_process_kill(), GNUNET_TIME_absolute_get_monotonic(), helper_write(), incrementBit(), iterate_save_member_session_history_hentries(), iterate_save_messages(), iterate_save_peers(), load_ikm(), process_result_with_request(), publicize_rm(), regex_found_handler(), save_list_messages(), save_list_tunnels(), sighandler_child_death(), sighandler_child_death(), sighandler_child_death(), sighandler_child_death(), sighandler_shutdown(), sign_worker(), start_dump(), stats_iterator(), store_and_free_entries(), store_and_free_entries(), store_peer_presistently_iterator(), to_file_raw(), try_match_block(), write_file(), and write_task().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_write_blocking()

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.

Parameters
hhandle to open file
bufferthe data to write
nnumber of bytes to write
Returns
number of bytes written on success, GNUNET_SYSERR on error

Definition at line 761 of file disk.c.

764{
765 int flags;
766 ssize_t ret;
767
768 if (NULL == h)
769 {
770 errno = EINVAL;
771 return GNUNET_SYSERR;
772 }
773 /* set to blocking, write, then set back */
774 flags = fcntl (h->fd,
775 F_GETFL);
776 if (0 != (flags & O_NONBLOCK))
777 (void) fcntl (h->fd,
778 F_SETFL,
779 flags - O_NONBLOCK);
780 ret = write (h->fd,
781 buffer,
782 n);
783 if (0 == (flags & O_NONBLOCK))
784 (void) fcntl (h->fd,
785 F_SETFL,
786 flags);
787 return ret;
788}

References GNUNET_SYSERR, h, and ret.

Referenced by write_benchmark_data().

Here is the caller graph for this function:

◆ GNUNET_DISK_fn_write()

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.

The directory is created if necessary. Fail if filename already exists or if not exactly buf with buf_size bytes could be written to filename.

Parameters
fnfile name
bufthe data to write
buf_sizenumber of bytes to write from buf
modefile permissions
Returns
GNUNET_OK on success, GNUNET_NO if a file existed under filename GNUNET_SYSERR on failure

Definition at line 792 of file disk.c.

796{
797 char *tmpl;
798 int fd;
799
800 if (GNUNET_OK !=
802 {
804 "mkstemp",
805 fn);
806 return GNUNET_SYSERR;
807 }
808 {
809 char *dname;
810
811 dname = GNUNET_strdup (fn);
812 GNUNET_asprintf (&tmpl,
813 "%s/XXXXXX",
814 dirname (dname));
815 GNUNET_free (dname);
816 }
817 fd = mkstemp (tmpl);
818 if (-1 == fd)
819 {
821 "mkstemp",
822 tmpl);
823 GNUNET_free (tmpl);
824 return GNUNET_SYSERR;
825 }
826
827 if (0 != fchmod (fd,
829 {
831 "chmod",
832 tmpl);
833 GNUNET_assert (0 == close (fd));
834 if (0 != unlink (tmpl))
836 "unlink",
837 tmpl);
838 GNUNET_free (tmpl);
839 return GNUNET_SYSERR;
840 }
841 if (buf_size !=
842 write (fd,
843 buf,
844 buf_size))
845 {
847 "write",
848 tmpl);
849 GNUNET_assert (0 == close (fd));
850 if (0 != unlink (tmpl))
852 "unlink",
853 tmpl);
854 GNUNET_free (tmpl);
855 return GNUNET_SYSERR;
856 }
857 GNUNET_assert (0 == close (fd));
858
859 if (0 != link (tmpl,
860 fn))
861 {
862 if (0 != unlink (tmpl))
864 "unlink",
865 tmpl);
866 GNUNET_free (tmpl);
867 return GNUNET_NO;
868 }
869 if (0 != unlink (tmpl))
871 "unlink",
872 tmpl);
873 GNUNET_free (tmpl);
874 return GNUNET_OK;
875
876
877}
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_DISK_FileHandle::fd, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, mode, and translate_unix_perms().

Referenced by calculate_pow(), clean_task(), GNUNET_CRYPTO_ecdsa_key_from_file(), GNUNET_CRYPTO_eddsa_key_from_file(), handle_create_message(), run(), shutdown_task(), sync_pow(), and write_proof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_copy()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy ( const char *  src,
const char *  dst 
)

Copy a file.

Parameters
srcfile to copy
dstdestination file name
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1185 of file disk.c.

1187{
1188 char *buf;
1189 uint64_t pos;
1190 uint64_t size;
1191 size_t len;
1192 ssize_t sret;
1193 struct GNUNET_DISK_FileHandle *in;
1194 struct GNUNET_DISK_FileHandle *out;
1195
1196 if (GNUNET_OK !=
1198 &size,
1199 GNUNET_YES,
1200 GNUNET_YES))
1201 {
1203 "stat",
1204 src);
1205 return GNUNET_SYSERR;
1206 }
1207 pos = 0;
1208 in =
1212 if (! in)
1213 {
1215 return GNUNET_SYSERR;
1216 }
1217 out =
1225 if (! out)
1226 {
1229 return GNUNET_SYSERR;
1230 }
1232 while (pos < size)
1233 {
1234 len = COPY_BLK_SIZE;
1235 if (len > size - pos)
1236 len = size - pos;
1237 sret = GNUNET_DISK_file_read (in, buf, len);
1238 if ((sret < 0) || (len != (size_t) sret))
1239 goto FAIL;
1240 sret = GNUNET_DISK_file_write (out, buf, len);
1241 if ((sret < 0) || (len != (size_t) sret))
1242 goto FAIL;
1243 pos += len;
1244 }
1245 GNUNET_free (buf);
1250 return GNUNET_OK;
1251FAIL:
1252 GNUNET_free (buf);
1257 return GNUNET_SYSERR;
1258}
#define COPY_BLK_SIZE
Block size for IO for copying files.
Definition disk.c:42
@ FAIL
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
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).
Definition disk.c:235

References COPY_BLK_SIZE, FAIL, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_FAILIFEXISTS, GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_NONE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and size.

Here is the call graph for this function:

◆ GNUNET_DISK_directory_scan()

int GNUNET_DISK_directory_scan ( const char *  dir_name,
GNUNET_FileNameCallback  callback,
void *  callback_cls 
)

Scan a directory for files.

Parameters
dir_namethe name of the directory
callbackthe method to call for each file
callback_clsclosure for callback
Returns
the number of files found, -1 on error

Definition at line 881 of file disk.c.

884{
885 DIR *dinfo;
886 struct dirent *finfo;
887 int count = 0;
889 char *name;
890 char *dname;
891 unsigned int name_len;
892 unsigned int n_size;
893
894 GNUNET_assert (NULL != dir_name);
896 if (NULL == dname)
897 return GNUNET_SYSERR;
898 while ( (strlen (dname) > 0) &&
899 (dname[strlen (dname) - 1] == DIR_SEPARATOR) )
900 dname[strlen (dname) - 1] = '\0';
901 dinfo = opendir (dname);
902 if (NULL == dinfo)
903 {
905 "opendir",
906 dname);
907 GNUNET_free (dname);
908 return GNUNET_SYSERR;
909 }
910 name_len = 256;
911 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
912 name = GNUNET_malloc (n_size);
913 while (NULL != (finfo = readdir (dinfo)))
914 {
915 if ((0 == strcmp (finfo->d_name, ".")) ||
916 (0 == strcmp (finfo->d_name, "..")))
917 continue;
918 if (NULL != callback)
919 {
920 if (name_len < strlen (finfo->d_name))
921 {
923 name_len = strlen (finfo->d_name);
924 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
925 name = GNUNET_malloc (n_size);
926 }
927 /* dname can end in "/" only if dname == "/";
928 * if dname does not end in "/", we need to add
929 * a "/" (otherwise, we must not!) */
931 n_size,
932 "%s%s%s",
933 dname,
934 (0 == strcmp (dname,
936 ? ""
938 finfo->d_name);
939 ret = callback (callback_cls,
940 name);
941 if (GNUNET_OK != ret)
942 {
943 closedir (dinfo);
945 GNUNET_free (dname);
946 if (GNUNET_NO == ret)
947 return count;
948 return GNUNET_SYSERR;
949 }
950 }
951 count++;
952 }
953 closedir (dinfo);
955 GNUNET_free (dname);
956 return count;
957}
static const char * dir_name
Top-level directory we monitor to auto-publish.
static char * name
Name (label) of the records to list.
#define DIR_SEPARATOR
Definition platform.h:166
#define DIR_SEPARATOR_STR
Definition platform.h:167

References dir_name, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_snprintf(), GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, LOG_STRERROR_FILE, name, and ret.

Referenced by deserialization_master(), deserialize_download(), deserialize_search(), determine_id(), discover_testbed_nodes(), get_size_rec(), GNUNET_CONFIGURATION_load_from(), GNUNET_DISK_directory_remove(), GNUNET_DISK_glob(), GNUNET_PLUGIN_load_all(), iter_testbed_path(), load_member(), load_member_store(), load_operation_store(), preprocess_file(), run(), run(), run(), run(), and scan().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_glob()

int GNUNET_DISK_glob ( const char *  glob_pattern,
GNUNET_FileNameCallback  callback,
void *  callback_cls 
)

Find all files matching a glob pattern.

Currently, the glob_pattern only supports asterisks in the last path component.

Parameters
glob_patternthe glob pattern to search for
callbackthe method to call for each file
callback_clsclosure for callback
Returns
the number of files found, -1 on error

Definition at line 1063 of file disk.c.

1066{
1067 char *mypat = GNUNET_strdup (glob_pattern);
1068 char *sep;
1069 int ret;
1070
1071 if ( (NULL != strrchr (glob_pattern, '+')) ||
1072 (NULL != strrchr (glob_pattern, '[')) ||
1073 (NULL != strrchr (glob_pattern, '~')) )
1074 {
1076 "unsupported glob pattern: '%s'\n",
1077 glob_pattern);
1078 GNUNET_free (mypat);
1079 return -1;
1080 }
1081
1082 sep = strrchr (mypat, DIR_SEPARATOR);
1083 if (NULL == sep)
1084 {
1085 GNUNET_free (mypat);
1086 return -1;
1087 }
1088
1089 *sep = '\0';
1090
1091 if (NULL != strchr (mypat, '*'))
1092 {
1093 GNUNET_free (mypat);
1094 GNUNET_break (0);
1096 "glob pattern may only contain '*' in the final path component\n");
1097 return -1;
1098 }
1099
1100 {
1101 struct GlobClosure gc = {
1102 .glob = sep + 1,
1103 .cb = callback,
1104 .cls = callback_cls,
1105 .nres = 0,
1106 };
1108 "scanning directory '%s' for glob matches on '%s'\n",
1109 mypat,
1110 gc.glob);
1112 glob_cb,
1113 &gc
1114 );
1115 GNUNET_free (mypat);
1116 return (ret < 0) ? ret : gc.nres;
1117 }
1118}
static enum GNUNET_GenericReturnValue glob_cb(void *cls, const char *filename)
Function called with a filename.
Definition disk.c:1032
#define LOG(kind,...)
Definition disk.c:31
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
int nres
Number of files that actually matched the glob pattern.
Definition disk.c:1019
const char * glob
Definition disk.c:1012

References DIR_SEPARATOR, GlobClosure::glob, glob_cb(), GNUNET_break, GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_strdup, LOG, GlobClosure::nres, and ret.

Referenced by do_discover_peers(), and handle_inline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_directory_create_for_file()

enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file ( const char *  filename)

Create the directory structure for storing a file.

Parameters
filenamename of a file in the directory
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure, GNUNET_NO if directory exists but is not writeable

Definition at line 664 of file disk.c.

665{
666 char *rdir;
667 size_t len;
668 int eno;
670
672 if (NULL == rdir)
673 {
674 errno = EINVAL;
675 return GNUNET_SYSERR;
676 }
677 if (0 == access (rdir, W_OK))
678 {
679 GNUNET_free (rdir);
680 return GNUNET_OK;
681 }
682 len = strlen (rdir);
683 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
684 len--;
685 rdir[len] = '\0';
686 /* The empty path is invalid and in this case refers to / */
687 if (0 == len)
688 {
689 GNUNET_free (rdir);
690 rdir = GNUNET_strdup ("/");
691 }
693 if ( (GNUNET_OK == res) &&
694 (0 != access (rdir, W_OK)) )
695 res = GNUNET_NO;
696 eno = errno;
697 GNUNET_free (rdir);
698 errno = eno;
699 return res;
700}
static char * res
Currently read line or NULL on EOF.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition disk.c:573

References DIR_SEPARATOR, filename, GNUNET_DISK_directory_create(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, and res.

Referenced by database_connect(), database_setup(), database_setup(), database_setup(), database_setup(), database_setup(), get_server_addresses(), get_server_addresses(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_open(), GNUNET_DISK_fn_write(), GNUNET_FS_download_sync_(), load_ikm(), make_serialization_file_name(), make_serialization_file_name_in_dir(), run(), run(), save(), save_hostlist_file(), setup_log_file(), store_valid_peers(), and trigger_recursive_download().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_directory_test()

enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test ( const char *  fil,
int  is_readable 
)

Test if fil is a directory and listable.

Optionally, also check if the directory is readable. Will not print an error message if the directory does not exist. Will log errors if GNUNET_SYSERR is returned (i.e., a file exists with the same name).

Parameters
filfilename to test
is_readableGNUNET_YES to additionally check if fil is readable; GNUNET_NO to disable this check
Returns
GNUNET_YES if yes, GNUNET_NO if not; GNUNET_SYSERR if it does not exist or stated

Definition at line 466 of file disk.c.

468{
469 struct stat filestat;
470 int ret;
471
472 ret = stat (fil, &filestat);
473 if (ret != 0)
474 {
475 if (errno != ENOENT)
477 "stat",
478 fil);
479 return GNUNET_SYSERR;
480 }
481 if (! S_ISDIR (filestat.st_mode))
482 {
484 "A file already exits with the same name %s\n",
485 fil);
486 return GNUNET_NO;
487 }
488 if (GNUNET_YES == is_readable)
489 ret = access (fil,
490 R_OK | X_OK);
491 else
492 ret = access (fil,
493 X_OK);
494 if (ret < 0)
495 {
497 "access",
498 fil);
499 return GNUNET_NO;
500 }
501 return GNUNET_YES;
502}
@ GNUNET_ERROR_TYPE_INFO

References GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, LOG, LOG_STRERROR_FILE, and ret.

Referenced by callback_scan_for_members(), callback_scan_for_sessions(), create_service(), deserialization_master(), deserialize_download(), deserialize_search(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_remove(), GNUNET_FS_remove_sync_dir_(), GNUNET_OS_installation_get_path(), iterate_load_next_member_sessions(), iterate_load_next_session(), iterate_save_members(), iterate_save_session(), load_member(), load_member_store(), load_operation_store(), load_srv_room(), move_message_store(), PABC_load_public_parameters(), remove_srv_room(), run(), run(), save_member(), save_member_store(), save_operation_store(), and save_srv_room().

Here is the caller graph for this function:

◆ GNUNET_DISK_directory_remove()

enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove ( const char *  filename)

Remove all files in a directory (rm -rf).

Call with caution.

Parameters
filenamethe file to remove
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1140 of file disk.c.

1141{
1142 struct stat istat;
1143
1144 if (NULL == filename)
1145 {
1146 GNUNET_break (0);
1147 return GNUNET_SYSERR;
1148 }
1149 if (0 != lstat (filename, &istat))
1150 return GNUNET_NO; /* file may not exist... */
1151 (void) chmod (filename,
1152 S_IWUSR | S_IRUSR | S_IXUSR);
1153 if (0 == unlink (filename))
1154 return GNUNET_OK;
1155 if ( (errno != EISDIR) &&
1156 /* EISDIR is not sufficient in all cases, e.g.
1157 * sticky /tmp directory may result in EPERM on BSD.
1158 * So we also explicitly check "isDirectory" */
1159 (GNUNET_YES !=
1161 GNUNET_YES)) )
1162 {
1164 "rmdir",
1165 filename);
1166 return GNUNET_SYSERR;
1167 }
1168 if (GNUNET_SYSERR ==
1171 NULL))
1172 return GNUNET_SYSERR;
1173 if (0 != rmdir (filename))
1174 {
1176 "rmdir",
1177 filename);
1178 return GNUNET_SYSERR;
1179 }
1180 return GNUNET_OK;
1181}
static enum GNUNET_GenericReturnValue remove_helper(void *unused, const char *fn)
Function that removes the given directory by calling GNUNET_DISK_directory_remove().
Definition disk.c:1130
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466

References filename, GNUNET_break, GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG_STRERROR_FILE, and remove_helper().

Referenced by calculate_pow(), clean_task(), create_response(), delete_files(), GNUNET_CONFIGURATION_write(), GNUNET_FS_remove_sync_dir_(), GNUNET_TESTBED_system_destroy(), purge_cfg_dir(), remove_helper(), remove_room_member_session(), remove_srv_room(), and write_proof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_purge_cfg_dir()

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.

Parameters
pdproject data to use to determine paths
cfg_filenameconfiguration file to parse
optionoption with the dir name to purge

Definition at line 1769 of file disk.c.

1772{
1777 (void *) option));
1778}
static enum GNUNET_GenericReturnValue purge_cfg_dir(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Helper function for GNUNET_DISK_purge_cfg_dir.
Definition disk.c:1737
static char * cfg_filename
Name of the configuration file.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.

References cfg_filename, GNUNET_break, GNUNET_CONFIGURATION_parse_and_run(), GNUNET_OK, and purge_cfg_dir().

Here is the call graph for this function:

◆ GNUNET_DISK_directory_create()

enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create ( const char *  dir)

Implementation of "mkdir -p".

Parameters
dirthe directory to create
Returns
GNUNET_SYSERR on failure, GNUNET_OK otherwise

Definition at line 573 of file disk.c.

574{
575 char *rdir;
576 unsigned int len;
577 unsigned int pos;
578 unsigned int pos2;
579 int ret = GNUNET_OK;
580
582 if (rdir == NULL)
583 {
584 GNUNET_break (0);
585 return GNUNET_SYSERR;
586 }
587
588 len = strlen (rdir);
589
590 pos = 1; /* skip heading '/' */
591
592 /* Check which low level directories already exist */
593 pos2 = len;
594 rdir[len] = DIR_SEPARATOR;
595 while (pos <= pos2)
596 {
597 if (DIR_SEPARATOR == rdir[pos2])
598 {
599 rdir[pos2] = '\0';
601 GNUNET_NO);
602 if (GNUNET_NO == ret)
603 {
605 "Creating directory `%s' failed\n",
606 rdir);
607 GNUNET_free (rdir);
608 return GNUNET_SYSERR;
609 }
610 rdir[pos2] = DIR_SEPARATOR;
611 if (GNUNET_YES == ret)
612 {
613 pos2++;
614 break;
615 }
616 }
617 pos2--;
618 }
619 rdir[len] = '\0';
620 if (pos < pos2)
621 pos = pos2;
622 /* Start creating directories */
623 while (pos <= len)
624 {
625 if ( (rdir[pos] == DIR_SEPARATOR) ||
626 (pos == len) )
627 {
628 rdir[pos] = '\0';
630 GNUNET_NO);
631 if (GNUNET_NO == ret)
632 {
634 "Creating directory `%s' failed\n",
635 rdir);
636 GNUNET_free (rdir);
637 return GNUNET_SYSERR;
638 }
639 if (GNUNET_SYSERR == ret)
640 {
641 ret = mkdir (rdir,
642 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
643 | S_IXOTH); /* 755 */
644
645 if ((ret != 0) && (errno != EEXIST))
646 {
648 "mkdir",
649 rdir);
650 GNUNET_free (rdir);
651 return GNUNET_SYSERR;
652 }
653 }
654 rdir[pos] = DIR_SEPARATOR;
655 }
656 pos++;
657 }
658 GNUNET_free (rdir);
659 return GNUNET_OK;
660}
static char * dir
Set to the directory where runtime files are stored.
Definition gnunet-arm.c:88
#define GNUNET_log(kind,...)

References dir, DIR_SEPARATOR, GNUNET_break, GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, LOG_STRERROR_FILE, and ret.

Referenced by create_service(), ensure_folder_exist(), GNUNET_DISK_directory_create_for_file(), init_pabc_dir(), iterate_save_members(), iterate_save_session(), jwks_endpoint(), run(), save_member(), save_member_store(), save_operation_store(), save_srv_room(), token_endpoint(), and write_benchmark_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_filename_canonicalize()

void GNUNET_DISK_filename_canonicalize ( char *  fn)

Removes special characters as ':' from a filename.

Parameters
fnthe filename to canonicalize

Definition at line 1262 of file disk.c.

1263{
1264 char *idx;
1265 char c;
1266
1267 for (idx = fn; *idx; idx++)
1268 {
1269 c = *idx;
1270
1271 if ((c == '/') || (c == '\\') || (c == ':') || (c == '*') || (c == '?') ||
1272 (c ==
1273 '"')
1274 ||
1275 (c == '<') || (c == '>') || (c == '|') )
1276 {
1277 *idx = '_';
1278 }
1279 }
1280}

Referenced by progress_cb().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_change_owner()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_change_owner ( const char *  filename,
const char *  user 
)

Change owner of a file.

Parameters
filenamefile to change
usernew owner of the file
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 1284 of file disk.c.

1286{
1287 struct passwd *pws;
1288
1289 pws = getpwnam (user);
1290 if (NULL == pws)
1291 {
1293 _ ("Cannot obtain information about user `%s': %s\n"),
1294 user,
1295 strerror (errno));
1296 return GNUNET_SYSERR;
1297 }
1298 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
1299 {
1301 return GNUNET_SYSERR;
1302 }
1303 return GNUNET_OK;
1304}
#define _(String)
GNU gettext support macro.
Definition platform.h:179

References _, filename, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, LOG, and LOG_STRERROR_FILE.

◆ GNUNET_DISK_file_map()

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.

Parameters
hopen file handle
mhandle to the new mapping (will be set)
accessaccess specification, GNUNET_DISK_MAP_TYPE_xxx
lensize of the mapping
Returns
pointer to the mapped memory region, NULL on failure

Definition at line 1459 of file disk.c.

1463{
1464 int prot;
1465
1466 if (NULL == h)
1467 {
1468 errno = EINVAL;
1469 return NULL;
1470 }
1471 prot = 0;
1472 if (access & GNUNET_DISK_MAP_TYPE_READ)
1473 prot = PROT_READ;
1474 if (access & GNUNET_DISK_MAP_TYPE_WRITE)
1475 prot |= PROT_WRITE;
1477 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
1478 GNUNET_assert (NULL != (*m)->addr);
1479 if (MAP_FAILED == (*m)->addr)
1480 {
1481 GNUNET_free (*m);
1482 return NULL;
1483 }
1484 (*m)->len = len;
1485 return (*m)->addr;
1486}
#define MAP_FAILED
Definition disk.c:1454
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
Handle for a memory-mapping operation.
Definition disk.c:1440

References GNUNET_assert, GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_MAP_TYPE_WRITE, GNUNET_free, GNUNET_new, h, m, and MAP_FAILED.

Referenced by database_setup(), full_recursive_download(), GNUNET_TIME_absolute_get_monotonic(), load_etc_hosts(), lookup_dns_servers(), and run().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_unmap()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap ( struct GNUNET_DISK_MapHandle h)

Unmap a file.

Parameters
hmapping handle
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1490 of file disk.c.

1491{
1493
1494 if (NULL == h)
1495 {
1496 errno = EINVAL;
1497 return GNUNET_SYSERR;
1498 }
1499 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1500 GNUNET_free (h);
1501 return ret;
1502}

References GNUNET_free, GNUNET_OK, GNUNET_SYSERR, h, and ret.

Referenced by database_setup(), full_recursive_download(), GNUNET_TIME_absolute_get_monotonic(), load_etc_hosts(), lookup_dns_servers(), and run().

Here is the caller graph for this function:

◆ GNUNET_DISK_file_sync()

enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync ( const struct GNUNET_DISK_FileHandle h)

Write file changes to disk.

Parameters
hhandle to an open file
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1506 of file disk.c.

1507{
1508 if (h == NULL)
1509 {
1510 errno = EINVAL;
1511 return GNUNET_SYSERR;
1512 }
1513
1514#if ! defined(__linux__) || ! defined(GNU)
1515 return fsync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1516#else
1517 return fdatasync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1518#endif
1519}

References GNUNET_OK, GNUNET_SYSERR, and h.

Referenced by delete_store_message(), publicize_rm(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), and save_peer_store().

Here is the caller graph for this function: