GNUnet  0.11.x
Data Structures | Enumerations | Functions
Disk library

Disk IO APIs. More...

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. 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...
 
void 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...
 
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...
 
char * GNUNET_DISK_mktemp (const char *t)
 Create an (empty) temporary file on disk. More...
 
char * GNUNET_DISK_mkdtemp (const char *t)
 Create an (empty) temporary directory on disk. More...
 
struct GNUNET_DISK_FileHandleGNUNET_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_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
 Get the size of an open file. More...
 
struct GNUNET_DISK_PipeHandleGNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf)
 Creates an interprocess channel. More...
 
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. More...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 Closes an interprocess channel. 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_FileHandleGNUNET_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_file_close (struct GNUNET_DISK_FileHandle *h)
 Close an open file. More...
 
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. 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...
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_get_handle_from_int_fd (int fno)
 Get a handle from a native integer FD. More...
 
struct GNUNET_DISK_FileHandleGNUNET_DISK_get_handle_from_native (FILE *fd)
 Get a handle from a native FD. 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_file_read_non_blocking (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...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy (const char *src, const char *dst)
 Copy a file. More...
 
int GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
 Scan a directory for files. More...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file (const char *filename)
 Create the directory structure for storing a file. More...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test (const char *fil, int is_readable)
 Test if fil is a directory and listable. More...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove (const char *filename)
 Remove all files in a directory (rm -rf). More...
 
void GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option)
 Remove the directory given under option in section [PATHS] in configuration under cfg_filename. More...
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create (const char *dir)
 Implementation of "mkdir -p". 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...
 
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...
 

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 41 of file gnunet_disk_lib.h.

42 {
47 
52 
57 };
Handle represents a file.
Handle represents a pipe.
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 91 of file gnunet_disk_lib.h.

92 {
97 
102 
107 
112 
117 
122 
127 };
Open the file for reading.
Create file if it doesn't exist.
Append to the file.
Truncate file if it exists.
Open the file for writing.
Open the file for both reading and writing.
Fail if file already exists.

◆ 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 132 of file gnunet_disk_lib.h.

133 {
138 
143 
148 };
Read-write memory map.
Read-only memory map.
Write-able 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 154 of file gnunet_disk_lib.h.

155 {
160 
165 
170 
175 
180 
185 
190 
195 
200 
205 };
Everybody can execute.
Nobody is allowed to do anything to the file.
Everybody can write.
Everybody can read.

◆ 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 212 of file gnunet_disk_lib.h.

213 {
218 
223 
228 };
Seek a relative position (from the current offset).
Seek an absolute position from the end of the file.
Seek an absolute position (from the start 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 234 of file gnunet_disk_lib.h.

235 {
240 
245 };
The writing-end of a pipe.
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 396 of file gnunet_disk_lib.h.

397 {
398 
403 
408 
413 
417  GNUNET_DISK_PF_BLOCKING_RW = GNUNET_DISK_PF_BLOCKING_READ
419 
420 };
No special options, use non-blocking read/write operations.
Configure write end to block when writing if set.
Configure both pipe ends for blocking operations if set.
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 186 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_NO, and GNUNET_YES.

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

187 {
188  return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
189 }
int fd
File handle on Unix-like systems.
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 437 of file disk.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NO, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, LOG_STRERROR_FILE, and ret.

Referenced by callback_scan_for_operations(), callback_scan_for_rooms(), create_download_context(), create_unique_cfgs(), database_setup(), ego_callback(), gen_topo_from_file(), get_path_from_PATH(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_DISK_file_open(), GNUNET_FRIENDS_parse(), GNUNET_FRIENDS_write_start(), GNUNET_FS_download_start_task_(), GNUNET_HOSTLIST_client_start(), GNUNET_PQ_run_sql(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_hosts_load_from_file(), GNUNET_TRANSPORT_TESTING_start_peer(), hostkeys_load(), hosts_directory_scan_callback(), LEGACY_SERVICE_run(), 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_search_strings(), policy_filename_cb(), print_key(), read_host_file(), read_index_list(), read_update_information_graph(), restore_valid_peers(), and run().

438 {
439  struct stat filestat;
440  int ret;
441  char *rdir;
442 
443  rdir = GNUNET_STRINGS_filename_expand (fil);
444  if (rdir == NULL)
445  return GNUNET_SYSERR;
446 
447  ret = stat (rdir, &filestat);
448  if (0 != ret)
449  {
450  if (errno != ENOENT)
451  {
453  GNUNET_free (rdir);
454  return GNUNET_SYSERR;
455  }
456  GNUNET_free (rdir);
457  return GNUNET_NO;
458  }
459  if (! S_ISREG (filestat.st_mode))
460  {
461  GNUNET_free (rdir);
462  return GNUNET_NO;
463  }
464  if (access (rdir, F_OK) < 0)
465  {
467  GNUNET_free (rdir);
468  return GNUNET_SYSERR;
469  }
470  GNUNET_free (rdir);
471  return GNUNET_YES;
472 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DISK_file_backup()

void 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

Definition at line 360 of file disk.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_malloc, and GNUNET_snprintf().

Referenced by GNUNET_FRIENDS_write_start().

361 {
362  size_t slen;
363  char *target;
364  unsigned int num;
365 
366  slen = strlen (fil) + 20;
367  target = GNUNET_malloc (slen);
368  num = 0;
369  do
370  {
371  GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
372  }
373  while (0 == access (target, F_OK));
374  if (0 != rename (fil, target))
376  GNUNET_free (target);
377 }
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_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller 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 206 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_SYSERR, 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(), make_empty_file(), process_result_with_request(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), try_top_down_reconstruction(), and unindex_reader().

209 {
210  static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
211 
212  if (h == NULL)
213  {
214  errno = EINVAL;
215  return GNUNET_SYSERR;
216  }
217  return lseek (h->fd, offset, t[whence]);
218 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
int fd
File handle on Unix-like systems.
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 222 of file disk.c.

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

Referenced by create_download_context(), database_setup(), discard_hosts_helper(), gen_topo_from_file(), GNUNET_CONFIGURATION_parse(), GNUNET_CRYPTO_hash_file(), GNUNET_DISK_file_copy(), GNUNET_FRIENDS_parse(), GNUNET_FS_file_information_create_from_file(), GNUNET_FS_unindex_start(), GNUNET_TESTBED_hosts_load_from_file(), hostkeys_load(), load(), load_file(), load_keys(), load_search_strings(), main(), policy_filename_cb(), preprocess_file(), print_key(), run(), server_log(), and setup_ac().

226 {
227  struct GetFileSizeData gfsd;
229 
230  GNUNET_assert (size != NULL);
231  gfsd.total = 0;
232  gfsd.include_sym_links = include_symbolic_links;
233  gfsd.single_file_mode = single_file_mode;
234  ret = get_size_rec (&gfsd, filename);
235  *size = gfsd.total;
236  return ret;
237 }
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
int single_file_mode
GNUNET_YES if mode is file-only (return total == -1 for directories).
Definition: disk.c:97
Closure for the recursion to determine the file size of a directory.
Definition: disk.c:82
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
static char * filename
static unsigned int size
Size of the "table".
Definition: peer.c:67
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 241 of file disk.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by handle_client_index_start(), and hash_for_index_cb().

244 {
245 #if HAVE_STAT
246  {
247  struct stat sbuf;
248 
249  if (0 != stat (filename, &sbuf))
250  {
251  return GNUNET_SYSERR;
252  }
253  *ino = (uint64_t) sbuf.st_ino;
254  }
255 #else
256  *ino = 0;
257 #endif
258 #if HAVE_STATVFS
259  {
260  struct statvfs fbuf;
261 
262  if (0 != statvfs (filename, &fbuf))
263  {
264  return GNUNET_SYSERR;
265  }
266  *dev = (uint64_t) fbuf.f_fsid;
267  }
268 #elif HAVE_STATFS
269  {
270  struct statfs fbuf;
271 
272  if (0 != statfs (filename, &fbuf))
273  {
274  return GNUNET_SYSERR;
275  }
276  *dev =
277  ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
278  }
279 #else
280  *dev = 0;
281 #endif
282  return GNUNET_OK;
283 }
static char * filename
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 381 of file disk.c.

References GNUNET_DISK_PipeHandle::fd, fn, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, LOG_STRERROR_FILE, and mktemp_name().

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

382 {
383  int fd;
384  char *fn;
385  mode_t omask;
386 
387  omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
388  fn = mktemp_name (t);
389  if (-1 == (fd = mkstemp (fn)))
390  {
392  GNUNET_free (fn);
393  umask (omask);
394  return NULL;
395  }
396  umask (omask);
397  if (0 != close (fd))
399  return fn;
400 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
static char * fn
Filename of the unique file.
#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:293
#define GNUNET_free(ptr)
Wrapper around free.
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 340 of file disk.c.

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

Referenced by access_handler_callback(), and GNUNET_TESTING_system_create_with_portrange().

341 {
342  char *fn;
343  mode_t omask;
344 
345  omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
346  fn = mktemp_name (t);
347  if (fn != mkdtemp (fn))
348  {
350  GNUNET_free (fn);
351  umask (omask);
352  return NULL;
353  }
354  umask (omask);
355  return fn;
356 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
static char * fn
Filename of the unique file.
#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:293
#define GNUNET_free(ptr)
Wrapper around free.
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 1055 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_DISK_PipeHandle::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 create_hostkeys(), database_setup(), database_shutdown(), full_recursive_download(), get_file_handle(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_ATS_TEST_logging_write_to_file(), 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_FRIENDS_write_start(), GNUNET_FS_data_reader_file_(), GNUNET_FS_download_start_task_(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_unindex_do_remove_(), GNUNET_TESTING_peer_configure(), GNUNET_TIME_absolute_get_monotonic(), hostkeys_load(), iface_proc(), load_etc_hosts(), load_keys(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store(), load_message_store_entries(), load_message_store_links(), lookup_dns_servers(), main(), print_key(), process_result_with_request(), publish_fs_connect_complete_cb(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), server_log(), start_dump(), start_insert(), store_valid_peers(), to_file_raw(), tofile_(), try_match_block(), write_benchmark_data(), write_bw_gnuplot_script(), write_rtt_gnuplot_script(), and write_throughput_gnuplot_script().

1058 {
1059  char *expfn;
1060  struct GNUNET_DISK_FileHandle *ret;
1061 
1062  int oflags;
1063  int mode;
1064  int fd;
1065 
1067  if (NULL == expfn)
1068  return NULL;
1069 
1070  mode = 0;
1072  oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1073  else if (flags & GNUNET_DISK_OPEN_READ)
1074  oflags = O_RDONLY;
1075  else if (flags & GNUNET_DISK_OPEN_WRITE)
1076  oflags = O_WRONLY;
1077  else
1078  {
1079  GNUNET_break (0);
1080  GNUNET_free (expfn);
1081  return NULL;
1082  }
1083  if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
1084  oflags |= (O_CREAT | O_EXCL);
1085  if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1086  oflags |= O_TRUNC;
1087  if (flags & GNUNET_DISK_OPEN_APPEND)
1088  oflags |= O_APPEND;
1090  {
1091  if (flags & GNUNET_DISK_OPEN_CREATE)
1092  {
1094  oflags |= O_CREAT;
1095  mode = translate_unix_perms (perm);
1096  }
1097  }
1098 
1099  fd = open (expfn,
1100  oflags
1101 #if O_CLOEXEC
1102  | O_CLOEXEC
1103 #endif
1104  | O_LARGEFILE,
1105  mode);
1106  if (fd == -1)
1107  {
1108  if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
1110  else
1111  LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "open", expfn);
1112  GNUNET_free (expfn);
1113  return NULL;
1114  }
1115 
1116  ret = GNUNET_new (struct GNUNET_DISK_FileHandle);
1117 
1118  ret->fd = fd;
1119 
1120  GNUNET_free (expfn);
1121  return ret;
1122 }
Open the file for reading.
Create file if it doesn&#39;t exist.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Append to the file.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
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 O_LARGEFILE
Definition: platform.h:224
static char * fn
Filename of the unique file.
Truncate file if it exists.
Open the file for writing.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
Open the file for both reading and writing.
int fd
File handle on Unix-like systems.
Fail if file already exists.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:562
Handle used to access files (and pipes).
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:437
#define GNUNET_free(ptr)
Wrapper around free.
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 193 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_OK, and GNUNET_SYSERR.

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

195 {
196  struct stat sbuf;
197 
198  if (0 != fstat (fh->fd, &sbuf))
199  return GNUNET_SYSERR;
200  *size = sbuf.st_size;
201  return GNUNET_OK;
202 }
static unsigned int size
Size of the "table".
Definition: peer.c:67
int fd
File handle on Unix-like systems.
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 1262 of file disk.c.

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

Referenced by GNUNET_ARM_request_service_start(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_SCHEDULER_driver_init(), GNUNET_TESTING_setup(), gnunet_uri(), main(), restart_nat_server(), start_helper(), and start_process().

1263 {
1264  int fd[2];
1265 
1266  if (-1 == pipe (fd))
1267  {
1268  int eno = errno;
1269 
1271  errno = eno;
1272  return NULL;
1273  }
1274  return GNUNET_DISK_pipe_from_fd (pf, fd);
1275 }
#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:1279
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 1279 of file disk.c.

References GNUNET_DISK_FileHandle::fd, 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().

1281 {
1282  struct GNUNET_DISK_PipeHandle *p;
1283  int ret = 0;
1284  int flags;
1285  int eno = 0; /* make gcc happy */
1286 
1287  p = GNUNET_new (struct GNUNET_DISK_PipeHandle);
1288  if (fd[0] >= 0)
1289  {
1290  p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1291  p->fd[0]->fd = fd[0];
1292  if (0 == (GNUNET_DISK_PF_BLOCKING_READ & pf))
1293  {
1294  flags = fcntl (fd[0], F_GETFL);
1295  flags |= O_NONBLOCK;
1296  if (0 > fcntl (fd[0], F_SETFL, flags))
1297  {
1298  ret = -1;
1299  eno = errno;
1300  }
1301  }
1302  flags = fcntl (fd[0], F_GETFD);
1303  flags |= FD_CLOEXEC;
1304  if (0 > fcntl (fd[0], F_SETFD, flags))
1305  {
1306  ret = -1;
1307  eno = errno;
1308  }
1309  }
1310 
1311  if (fd[1] >= 0)
1312  {
1313  p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1314  p->fd[1]->fd = fd[1];
1315  if (0 == (GNUNET_DISK_PF_BLOCKING_WRITE & pf))
1316  {
1317  flags = fcntl (fd[1], F_GETFL);
1318  flags |= O_NONBLOCK;
1319  if (0 > fcntl (fd[1], F_SETFL, flags))
1320  {
1321  ret = -1;
1322  eno = errno;
1323  }
1324  }
1325  flags = fcntl (fd[1], F_GETFD);
1326  flags |= FD_CLOEXEC;
1327  if (0 > fcntl (fd[1], F_SETFD, flags))
1328  {
1329  ret = -1;
1330  eno = errno;
1331  }
1332  }
1333  if (ret == -1)
1334  {
1335  errno = eno;
1337  if (p->fd[0]->fd >= 0)
1338  GNUNET_break (0 == close (p->fd[0]->fd));
1339  if (p->fd[1]->fd >= 0)
1340  GNUNET_break (0 == close (p->fd[1]->fd));
1341  GNUNET_free (p->fd[0]);
1342  GNUNET_free (p->fd[1]);
1343  GNUNET_free (p);
1344  errno = eno;
1345  return NULL;
1346  }
1347  return p;
1348 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define LOG_STRERROR(kind, syscall)
Definition: disk.c:33
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Definition: disk.c:74
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Configure write end to block when writing if set.
int fd
File handle on Unix-like systems.
Handle used to access files (and pipes).
Handle used to manage a pipe.
Definition: disk.c:68
#define GNUNET_free(ptr)
Wrapper around free.
Configure read end to block when reading if set.
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 1405 of file disk.c.

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

Referenced by 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(), GNUNET_TESTING_setup(), main(), maint_child_death(), nat_server_read(), restart_nat_server(), and start_process().

1406 {
1407  int ret = GNUNET_OK;
1408 
1409  int read_end_close;
1410  int write_end_close;
1411  int read_end_close_errno;
1412  int write_end_close_errno;
1413 
1415  read_end_close_errno = errno;
1417  write_end_close_errno = errno;
1418  GNUNET_free (p);
1419 
1420  if (GNUNET_OK != read_end_close)
1421  {
1422  errno = read_end_close_errno;
1423  ret = read_end_close;
1424  }
1425  else if (GNUNET_OK != write_end_close)
1426  {
1427  errno = write_end_close_errno;
1428  ret = write_end_close;
1429  }
1430 
1431  return ret;
1432 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:1352
The writing-end of a pipe.
The reading-end of a pipe.
#define GNUNET_free(ptr)
Wrapper around free.
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 1352 of file disk.c.

References GNUNET_DISK_PipeHandle::fd, GNUNET_DISK_file_close(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_OK, and ret.

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

1354 {
1356 
1358  {
1359  if (p->fd[0])
1360  {
1361  ret = GNUNET_DISK_file_close (p->fd[0]);
1362  p->fd[0] = NULL;
1363  }
1364  }
1365  else if (end == GNUNET_DISK_PIPE_END_WRITE)
1366  {
1367  if (p->fd[1])
1368  {
1369  ret = GNUNET_DISK_file_close (p->fd[1]);
1370  p->fd[1] = NULL;
1371  }
1372  }
1373  return ret;
1374 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Definition: disk.c:74
The writing-end of a pipe.
The reading-end of a pipe.
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 1378 of file disk.c.

References GNUNET_DISK_PipeHandle::fd, GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, and ret.

Referenced by GNUNET_ARM_request_service_start(), and start_process().

1380 {
1381  struct GNUNET_DISK_FileHandle *ret = NULL;
1382 
1384  {
1385  if (p->fd[0])
1386  {
1387  ret = p->fd[0];
1388  p->fd[0] = NULL;
1389  }
1390  }
1391  else if (end == GNUNET_DISK_PIPE_END_WRITE)
1392  {
1393  if (p->fd[1])
1394  {
1395  ret = p->fd[1];
1396  p->fd[1] = NULL;
1397  }
1398  }
1399 
1400  return ret;
1401 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Definition: disk.c:74
The writing-end of a pipe.
The reading-end of a pipe.
Handle used to access files (and pipes).
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 1126 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, LOG_STRERROR, and ret.

Referenced by check_completed(), cleanup(), clear_message_store(), close_files_iter(), create_hostkeys(), database_setup(), database_shutdown(), do_shutdown(), file_hash_finish(), full_recursive_download(), get_cb(), GNUNET_ARM_operation_cancel(), GNUNET_ARM_request_service_start(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_ATS_TEST_logging_write_to_file(), 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_FRIENDS_write_stop(), 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_TESTING_peer_configure(), GNUNET_TIME_absolute_get_monotonic(), hostkeys_load(), load_etc_hosts(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store(), load_message_store_entries(), load_message_store_links(), lookup_dns_servers(), main(), parent_control_handler(), print_key(), process_result_with_request(), publish_fs_connect_complete_cb(), reconstruct_cont(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_message_store(), server_log(), shutdown_pch(), shutdown_task(), start_process(), stop_broadcast(), store_valid_peers(), to_file_raw(), tofile_(), try_match_block(), unindex_finish(), unload_keys(), write_benchmark_data(), write_bw_gnuplot_script(), write_rtt_gnuplot_script(), and write_throughput_gnuplot_script().

1127 {
1129 
1130  if (NULL == h)
1131  {
1132  errno = EINVAL;
1133  return GNUNET_SYSERR;
1134  }
1135 
1136  ret = GNUNET_OK;
1137  if (0 != close (h->fd))
1138  {
1140  ret = GNUNET_SYSERR;
1141  }
1142  GNUNET_free (h);
1143  return ret;
1144 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
#define LOG_STRERROR(kind, syscall)
Definition: disk.c:33
int fd
File handle on Unix-like systems.
#define GNUNET_free(ptr)
Wrapper around free.

◆ 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 1436 of file disk.c.

References GNUNET_DISK_PipeHandle::fd, GNUNET_break, GNUNET_DISK_PIPE_END_READ, and GNUNET_DISK_PIPE_END_WRITE.

Referenced by child_death_task(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_SCHEDULER_driver_init(), GNUNET_TESTING_wait_for_sigchld(), gnunet_uri(), maint_child_death(), restart_nat_server(), run(), shutdown_pipe_cb(), sighandler_child_death(), sighandler_chld(), sighandler_shutdown(), start_helper(), start_process(), tokenizer_cb(), and work().

1438 {
1439  switch (n)
1440  {
1443  return p->fd[n];
1444 
1445  default:
1446  GNUNET_break (0);
1447  return NULL;
1448  }
1449 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Definition: disk.c:74
The writing-end of a pipe.
The reading-end of a pipe.
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 argumets 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 321 of file disk.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file, GNUNET_YES, and mode.

Referenced by create_listen_socket(), LEGACY_SERVICE_start(), and service_task().

324 {
325  mode_t mode;
326 
327  if (GNUNET_YES == require_uid_match)
328  mode = S_IRUSR | S_IWUSR | S_IXUSR;
329  else if (GNUNET_YES == require_gid_match)
330  mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
331  else
332  mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH
333  | S_IWOTH | S_IXOTH;
334  if (0 != chmod (fn, mode))
336 }
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
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 1148 of file disk.c.

References GNUNET_DISK_FileHandle::fd, fh, 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().

1149 {
1150  struct GNUNET_DISK_FileHandle *fh;
1151 
1152  if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
1153  return NULL; /* invalid FD */
1154 
1155  fh = GNUNET_new (struct GNUNET_DISK_FileHandle);
1156 
1157  fh->fd = fno;
1158 
1159  return fh;
1160 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int fh
Handle to the unique file.
int fd
File handle on Unix-like systems.
Handle used to access files (and pipes).
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 1164 of file disk.c.

References GNUNET_DISK_get_handle_from_int_fd().

Referenced by run(), and testing_main().

1165 {
1166  int fno;
1167 
1168  fno = fileno (fd);
1169  if (-1 == fno)
1170  return NULL;
1172 }
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1148
int fd
File handle on Unix-like systems.
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 602 of file disk.c.

References GNUNET_DISK_FileHandle::fd, and GNUNET_SYSERR.

Referenced by child_death_task(), 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(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_message_store_entries(), load_message_store_links(), main(), maint_child_death(), nat_server_read(), parent_control_handler(), print_key(), put_cb(), read_external_ipv4(), read_from_file(), read_task(), REGEX_TEST_read_from_file(), restore_valid_peers(), run(), server_log(), shutdown_pipe_cb(), start_insert(), try_top_down_reconstruction(), and unindex_reader().

605 {
606  if (NULL == h)
607  {
608  errno = EINVAL;
609  return GNUNET_SYSERR;
610  }
611  return read (h->fd, result, len);
612 }
static int result
Global testing status.
int fd
File handle on Unix-like systems.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_DISK_file_read_non_blocking()

ssize_t GNUNET_DISK_file_read_non_blocking ( const struct GNUNET_DISK_FileHandle h,
void *  result,
size_t  len 
)

Read the contents of a binary file into a buffer.

Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN when no data can be read).

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 616 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_SYSERR, and ret.

619 {
620  int flags;
621  ssize_t ret;
622 
623  if (NULL == h)
624  {
625  errno = EINVAL;
626  return GNUNET_SYSERR;
627  }
628  /* set to non-blocking, read, then set back */
629  flags = fcntl (h->fd, F_GETFL);
630  if (0 == (flags & O_NONBLOCK))
631  (void) fcntl (h->fd, F_SETFL, flags | O_NONBLOCK);
632  ret = read (h->fd, result, len);
633  if (0 == (flags & O_NONBLOCK))
634  {
635  int eno = errno;
636  (void) fcntl (h->fd, F_SETFL, flags);
637  errno = eno;
638  }
639  return ret;
640 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int result
Global testing status.
int fd
File handle on Unix-like systems.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...

◆ 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 644 of file disk.c.

References fh, 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, and ret.

Referenced by discard_hosts_helper(), ego_callback(), gen_topo_from_file(), GNUNET_CONFIGURATION_parse(), GNUNET_FRIENDS_parse(), GNUNET_TESTBED_hosts_load_from_file(), load_file(), load_search_strings(), policy_filename_cb(), read_host_file(), run(), and setup_ac().

647 {
648  struct GNUNET_DISK_FileHandle *fh;
649  ssize_t ret;
650  int eno;
651 
655  if (NULL == fh)
656  return GNUNET_SYSERR;
657  ret = GNUNET_DISK_file_read (fh, result, len);
658  eno = errno;
660  errno = eno;
661  return ret;
662 }
Open the file for reading.
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:602
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
Nobody is allowed to do anything to the file.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * fn
Filename of the unique file.
static int result
Global testing status.
static int fh
Handle to the unique file.
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:1055
Handle used to access files (and pipes).
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 666 of file disk.c.

References GNUNET_DISK_FileHandle::fd, and GNUNET_SYSERR.

Referenced by create_hostkeys(), database_shutdown(), decrementBit(), delete_store_message(), do_shutdown(), get_cb(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_ATS_TEST_logging_write_to_file(), GNUNET_BIO_flush(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_copy(), GNUNET_FRIENDS_write(), GNUNET_OS_process_kill(), GNUNET_TESTING_peer_configure(), GNUNET_TIME_absolute_get_monotonic(), handle_estimate(), helper_write(), incrementBit(), iterate_save_entries(), iterate_save_links(), iterate_save_member_session_history_hentries(), iterate_save_messages(), main(), make_empty_file(), process_result_with_request(), publicize_rm(), publish_fs_connect_complete_cb(), regex_found_handler(), save_list_messages(), save_list_tunnels(), sighandler_child_death(), sighandler_chld(), sighandler_shutdown(), start_dump(), stat_iterator(), stats_iterator(), store_and_free_entries(), store_peer_presistently_iterator(), to_file_raw(), tofile_(), try_match_block(), write_bw_gnuplot_script(), write_rtt_gnuplot_script(), write_task(), and write_throughput_gnuplot_script().

669 {
670  if (NULL == h)
671  {
672  errno = EINVAL;
673  return GNUNET_SYSERR;
674  }
675 
676  return write (h->fd, buffer, n);
677 }
int fd
File handle on Unix-like systems.
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 681 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_SYSERR, and ret.

Referenced by write_benchmark_data().

684 {
685  int flags;
686  ssize_t ret;
687 
688  if (NULL == h)
689  {
690  errno = EINVAL;
691  return GNUNET_SYSERR;
692  }
693  /* set to blocking, write, then set back */
694  flags = fcntl (h->fd, F_GETFL);
695  if (0 != (flags & O_NONBLOCK))
696  (void) fcntl (h->fd, F_SETFL, flags - O_NONBLOCK);
697  ret = write (h->fd, buffer, n);
698  if (0 == (flags & O_NONBLOCK))
699  (void) fcntl (h->fd, F_SETFL, flags);
700  return ret;
701 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int fd
File handle on Unix-like systems.
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 705 of file disk.c.

References GNUNET_DISK_PipeHandle::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, and translate_unix_perms().

Referenced by calculate_pow(), clean_task(), discard_hosts_helper(), dump_my_hello(), GNUNET_CRYPTO_ecdsa_key_from_file(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_FRIENDS_parse(), handle_create_message(), main(), shutdown_task(), sync_pow(), update_hello(), and write_proof().

709 {
710  char *tmpl;
711  int fd;
712 
713  if (GNUNET_OK !=
715  {
717  "mkstemp",
718  fn);
719  return GNUNET_SYSERR;
720  }
721  {
722  char *dname;
723 
724  dname = GNUNET_strdup (fn);
725  GNUNET_asprintf (&tmpl,
726  "%s/XXXXXX",
727  dirname (dname));
728  GNUNET_free (dname);
729  }
730  fd = mkstemp (tmpl);
731  if (-1 == fd)
732  {
734  "mkstemp",
735  tmpl);
736  GNUNET_free (tmpl);
737  return GNUNET_SYSERR;
738  }
739 
740  if (0 != fchmod (fd,
742  {
744  "chmod",
745  tmpl);
746  GNUNET_assert (0 == close (fd));
747  if (0 != unlink (tmpl))
749  "unlink",
750  tmpl);
751  GNUNET_free (tmpl);
752  return GNUNET_SYSERR;
753  }
754  if (buf_size !=
755  write (fd,
756  buf,
757  buf_size))
758  {
760  "write",
761  tmpl);
762  GNUNET_assert (0 == close (fd));
763  if (0 != unlink (tmpl))
765  "unlink",
766  tmpl);
767  GNUNET_free (tmpl);
768  return GNUNET_SYSERR;
769  }
770  GNUNET_assert (0 == close (fd));
771 
772  if (0 != link (tmpl,
773  fn))
774  {
775  if (0 != unlink (tmpl))
777  "unlink",
778  tmpl);
779  GNUNET_free (tmpl);
780  return GNUNET_NO;
781  }
782  if (0 != unlink (tmpl))
784  "unlink",
785  tmpl);
786  GNUNET_free (tmpl);
787  return GNUNET_OK;
788 
789 
790 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
static char buf[2048]
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int fd
File handle on Unix-like systems.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:562
#define GNUNET_free(ptr)
Wrapper around free.
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 944 of file disk.c.

References buf, COPY_BLK_SIZE, FAIL, 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, len, and size.

946 {
947  char *buf;
948  uint64_t pos;
949  uint64_t size;
950  size_t len;
951  ssize_t sret;
952  struct GNUNET_DISK_FileHandle *in;
953  struct GNUNET_DISK_FileHandle *out;
954 
956  {
958  return GNUNET_SYSERR;
959  }
960  pos = 0;
961  in =
963  if (! in)
964  {
966  return GNUNET_SYSERR;
967  }
968  out =
976  if (! out)
977  {
980  return GNUNET_SYSERR;
981  }
983  while (pos < size)
984  {
985  len = COPY_BLK_SIZE;
986  if (len > size - pos)
987  len = size - pos;
988  sret = GNUNET_DISK_file_read (in, buf, len);
989  if ((sret < 0) || (len != (size_t) sret))
990  goto FAIL;
991  sret = GNUNET_DISK_file_write (out, buf, len);
992  if ((sret < 0) || (len != (size_t) sret))
993  goto FAIL;
994  pos += len;
995  }
996  GNUNET_free (buf);
999  return GNUNET_OK;
1000 FAIL:
1001  GNUNET_free (buf);
1003  GNUNET_DISK_file_close (out);
1004  return GNUNET_SYSERR;
1005 }
Open the file for reading.
Create file if it doesn&#39;t exist.
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:602
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
Nobody is allowed to do anything to the file.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define COPY_BLK_SIZE
Block size for IO for copying files.
Definition: disk.c:42
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:666
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
Open the file for writing.
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:222
Fail if file already exists.
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:1055
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 794 of file disk.c.

References _, 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, LOG_STRERROR_FILE, name, and ret.

Referenced by cron_clean_data_hosts(), cron_scan_directory_data_hosts(), deserialization_master(), deserialize_download(), deserialize_search(), determine_id(), discover_testbed_nodes(), do_directory_scan(), get_size_rec(), GNUNET_CONFIGURATION_load_from(), GNUNET_DISK_directory_remove(), GNUNET_PLUGIN_load_all(), iter_testbed_path(), load_handle_configuration(), load_member(), load_member_store(), load_operation_store(), preprocess_file(), profiler_eval(), run(), and scan().

797 {
798  DIR *dinfo;
799  struct dirent *finfo;
800  struct stat istat;
801  int count = 0;
803  char *name;
804  char *dname;
805  unsigned int name_len;
806  unsigned int n_size;
807 
808  GNUNET_assert (NULL != dir_name);
810  if (NULL == dname)
811  return GNUNET_SYSERR;
812  while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
813  dname[strlen (dname) - 1] = '\0';
814  if (0 != stat (dname, &istat))
815  {
817  GNUNET_free (dname);
818  return GNUNET_SYSERR;
819  }
820  if (! S_ISDIR (istat.st_mode))
821  {
823  _ ("Expected `%s' to be a directory!\n"),
824  dir_name);
825  GNUNET_free (dname);
826  return GNUNET_SYSERR;
827  }
828  errno = 0;
829  dinfo = opendir (dname);
830  if ((EACCES == errno) || (NULL == dinfo))
831  {
832  LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
833  if (NULL != dinfo)
834  closedir (dinfo);
835  GNUNET_free (dname);
836  return GNUNET_SYSERR;
837  }
838  name_len = 256;
839  n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
840  name = GNUNET_malloc (n_size);
841  while (NULL != (finfo = readdir (dinfo)))
842  {
843  if ((0 == strcmp (finfo->d_name, ".")) ||
844  (0 == strcmp (finfo->d_name, "..")))
845  continue;
846  if (NULL != callback)
847  {
848  if (name_len < strlen (finfo->d_name))
849  {
850  GNUNET_free (name);
851  name_len = strlen (finfo->d_name);
852  n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
853  name = GNUNET_malloc (n_size);
854  }
855  /* dname can end in "/" only if dname == "/";
856  * if dname does not end in "/", we need to add
857  * a "/" (otherwise, we must not!) */
858  GNUNET_snprintf (name,
859  n_size,
860  "%s%s%s",
861  dname,
862  (0 == strcmp (dname, DIR_SEPARATOR_STR))
863  ? ""
865  finfo->d_name);
866  ret = callback (callback_cls, name);
867  if (GNUNET_OK != ret)
868  {
869  closedir (dinfo);
870  GNUNET_free (name);
871  GNUNET_free (dname);
872  if (GNUNET_NO == ret)
873  return count;
874  return GNUNET_SYSERR;
875  }
876  }
877  count++;
878  }
879  closedir (dinfo);
880  GNUNET_free (name);
881  GNUNET_free (dname);
882  return count;
883 }
static const char * dir_name
Top-level directory we monitor to auto-publish.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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 DIR_SEPARATOR_STR
Definition: platform.h:171
#define LOG(kind,...)
Definition: disk.c:31
#define DIR_SEPARATOR
Definition: platform.h:170
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
const char * name
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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 562 of file disk.c.

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

Referenced by callback_set_handle_name(), create_hostkeys(), database_setup(), get_server_addresses(), GNUNET_ATS_solver_logging_write_to_disk(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_file_open(), GNUNET_DISK_fn_write(), GNUNET_FRIENDS_write_start(), GNUNET_FS_download_sync_(), LEGACY_SERVICE_get_server_addresses(), main(), make_serialization_file_name(), make_serialization_file_name_in_dir(), run(), save(), save_hostlist_file(), setup_log_file(), store_valid_peers(), trigger_recursive_download(), unix_transport_server_start(), and update_hello().

563 {
564  char *rdir;
565  size_t len;
566  int eno;
568 
570  if (NULL == rdir)
571  {
572  errno = EINVAL;
573  return GNUNET_SYSERR;
574  }
575  if (0 == access (rdir, W_OK))
576  {
577  GNUNET_free (rdir);
578  return GNUNET_OK;
579  }
580  len = strlen (rdir);
581  while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
582  len--;
583  rdir[len] = '\0';
584  /* The empty path is invalid and in this case refers to / */
585  if (0 == len)
586  {
587  GNUNET_free (rdir);
588  rdir = GNUNET_strdup ("/");
589  }
590  res = GNUNET_DISK_directory_create (rdir);
591  if ( (GNUNET_OK == res) &&
592  (0 != access (rdir, W_OK)) )
593  res = GNUNET_NO;
594  eno = errno;
595  GNUNET_free (rdir);
596  errno = eno;
597  return res;
598 }
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * filename
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:476
static int res
#define DIR_SEPARATOR
Definition: platform.h:170
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 404 of file disk.c.

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(), callback_set_handle_name(), 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_handle_configuration(), load_member(), load_member_store(), load_operation_store(), load_room(), run(), save_handle_configuration(), save_member(), save_member_store(), save_operation_store(), and save_room().

405 {
406  struct stat filestat;
407  int ret;
408 
409  ret = stat (fil, &filestat);
410  if (ret != 0)
411  {
412  if (errno != ENOENT)
414  return GNUNET_SYSERR;
415  }
416  if (! S_ISDIR (filestat.st_mode))
417  {
419  "A file already exits with the same name %s\n",
420  fil);
421  return GNUNET_NO;
422  }
423  if (GNUNET_YES == is_readable)
424  ret = access (fil, R_OK | X_OK);
425  else
426  ret = access (fil, X_OK);
427  if (ret < 0)
428  {
430  return GNUNET_NO;
431  }
432  return GNUNET_YES;
433 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define LOG(kind,...)
Definition: disk.c:31
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
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 905 of file disk.c.

References 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 access_handler_callback(), calculate_pow(), clean_task(), delete_files(), discard_hosts_helper(), GNUNET_CONFIGURATION_write(), GNUNET_FS_remove_sync_dir_(), GNUNET_TESTING_system_destroy(), main(), publish_timeout(), purge_cfg_dir(), remove_helper(), remove_room_member_session(), report_uri(), run(), and write_proof().

906 {
907  struct stat istat;
908 
909  if (NULL == filename)
910  {
911  GNUNET_break (0);
912  return GNUNET_SYSERR;
913  }
914  if (0 != lstat (filename, &istat))
915  return GNUNET_NO; /* file may not exist... */
916  (void) chmod (filename,
917  S_IWUSR | S_IRUSR | S_IXUSR);
918  if (0 == unlink (filename))
919  return GNUNET_OK;
920  if ( (errno != EISDIR) &&
921  /* EISDIR is not sufficient in all cases, e.g.
922  * sticky /tmp directory may result in EPERM on BSD.
923  * So we also explicitly check "isDirectory" */
924  (GNUNET_YES !=
926  GNUNET_YES)) )
927  {
929  return GNUNET_SYSERR;
930  }
931  if (GNUNET_SYSERR ==
933  return GNUNET_SYSERR;
934  if (0 != rmdir (filename))
935  {
937  return GNUNET_SYSERR;
938  }
939  return GNUNET_OK;
940 }
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:895
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:794
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * filename
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
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 char *  cfg_filename,
const char *  option 
)

Remove the directory given under option in section [PATHS] in configuration under cfg_filename.

Parameters
cfg_filenameconfiguration file to parse
optionoption with the dir name to purge

Definition at line 1498 of file disk.c.

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

1500 {
1503  &purge_cfg_dir,
1504  (void *) option));
1505 }
static char * cfg_filename
Name of the configuration file.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * option
Name of the option.
Definition: gnunet-config.c:38
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:1474
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(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...
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 476 of file disk.c.

References 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, len, LOG_STRERROR_FILE, and ret.

Referenced by create_service(), cron_scan_directory_data_hosts(), ensure_folder_exist(), GNUNET_DISK_directory_create_for_file(), iterate_save_members(), iterate_save_session(), run(), save_handle_configuration(), save_member(), save_member_store(), save_operation_store(), save_room(), write_benchmark_data(), and write_pid_file().

477 {
478  char *rdir;
479  unsigned int len;
480  unsigned int pos;
481  unsigned int pos2;
482  int ret = GNUNET_OK;
483 
485  if (rdir == NULL)
486  {
487  GNUNET_break (0);
488  return GNUNET_SYSERR;
489  }
490 
491  len = strlen (rdir);
492 
493  pos = 1; /* skip heading '/' */
494 
495  /* Check which low level directories already exist */
496  pos2 = len;
497  rdir[len] = DIR_SEPARATOR;
498  while (pos <= pos2)
499  {
500  if (DIR_SEPARATOR == rdir[pos2])
501  {
502  rdir[pos2] = '\0';
504  if (GNUNET_NO == ret)
505  {
507  "Creating directory `%s' failed",
508  rdir);
509  GNUNET_free (rdir);
510  return GNUNET_SYSERR;
511  }
512  rdir[pos2] = DIR_SEPARATOR;
513  if (GNUNET_YES == ret)
514  {
515  pos2++;
516  break;
517  }
518  }
519  pos2--;
520  }
521  rdir[len] = '\0';
522  if (pos < pos2)
523  pos = pos2;
524  /* Start creating directories */
525  while (pos <= len)
526  {
527  if ((rdir[pos] == DIR_SEPARATOR) || (pos == len))
528  {
529  rdir[pos] = '\0';
531  if (GNUNET_NO == ret)
532  {
534  "Creating directory `%s' failed",
535  rdir);
536  GNUNET_free (rdir);
537  return GNUNET_SYSERR;
538  }
539  if (GNUNET_SYSERR == ret)
540  {
541  ret = mkdir (rdir,
542  S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
543  | S_IXOTH); /* 755 */
544 
545  if ((ret != 0) && (errno != EEXIST))
546  {
548  GNUNET_free (rdir);
549  return GNUNET_SYSERR;
550  }
551  }
552  rdir[pos] = DIR_SEPARATOR;
553  }
554  pos++;
555  }
556  GNUNET_free (rdir);
557  return GNUNET_OK;
558 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define DIR_SEPARATOR
Definition: platform.h:170
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 1009 of file disk.c.

Referenced by progress_cb().

1010 {
1011  char *idx;
1012  char c;
1013 
1014  for (idx = fn; *idx; idx++)
1015  {
1016  c = *idx;
1017 
1018  if ((c == '/') || (c == '\\') || (c == ':') || (c == '*') || (c == '?') ||
1019  (c ==
1020  '"')
1021  ||
1022  (c == '<') || (c == '>') || (c == '|') )
1023  {
1024  *idx = '_';
1025  }
1026  }
1027 }
static char * fn
Filename of the unique file.
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 1031 of file disk.c.

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

Referenced by write_pid_file().

1033 {
1034  struct passwd *pws;
1035 
1036  pws = getpwnam (user);
1037  if (NULL == pws)
1038  {
1040  _ ("Cannot obtain information about user `%s': %s\n"),
1041  user,
1042  strerror (errno));
1043  return GNUNET_SYSERR;
1044  }
1045  if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
1046  {
1048  return GNUNET_SYSERR;
1049  }
1050  return GNUNET_OK;
1051 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * filename
#define LOG(kind,...)
Definition: disk.c:31
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: disk.c:36
Here is the caller graph for this function:

◆ 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 1198 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_assert, GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_MAP_TYPE_WRITE, GNUNET_free, GNUNET_new, len, and MAP_FAILED.

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

1202 {
1203  int prot;
1204 
1205  if (NULL == h)
1206  {
1207  errno = EINVAL;
1208  return NULL;
1209  }
1210  prot = 0;
1211  if (access & GNUNET_DISK_MAP_TYPE_READ)
1212  prot = PROT_READ;
1213  if (access & GNUNET_DISK_MAP_TYPE_WRITE)
1214  prot |= PROT_WRITE;
1215  *m = GNUNET_new (struct GNUNET_DISK_MapHandle);
1216  (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
1217  GNUNET_assert (NULL != (*m)->addr);
1218  if (MAP_FAILED == (*m)->addr)
1219  {
1220  GNUNET_free (*m);
1221  return NULL;
1222  }
1223  (*m)->len = len;
1224  return (*m)->addr;
1225 }
#define MAP_FAILED
Definition: disk.c:1193
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Read-only memory map.
Write-able memory map.
int fd
File handle on Unix-like systems.
Handle for a memory-mapping operation.
Definition: disk.c:1178
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 1229 of file disk.c.

References GNUNET_DISK_MapHandle::addr, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, GNUNET_DISK_MapHandle::len, and ret.

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

1230 {
1232 
1233  if (NULL == h)
1234  {
1235  errno = EINVAL;
1236  return GNUNET_SYSERR;
1237  }
1238  ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1239  GNUNET_free (h);
1240  return ret;
1241 }
void * addr
Address where the map is in memory.
Definition: disk.c:1183
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
size_t len
Number of bytes mapped.
Definition: disk.c:1188
#define GNUNET_free(ptr)
Wrapper around free.
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 1245 of file disk.c.

References GNUNET_DISK_FileHandle::fd, GNUNET_OK, and GNUNET_SYSERR.

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

1246 {
1247  if (h == NULL)
1248  {
1249  errno = EINVAL;
1250  return GNUNET_SYSERR;
1251  }
1252 
1253 #if ! defined(__linux__) || ! defined(GNU)
1254  return fsync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1255 #else
1256  return fdatasync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1257 #endif
1258 }
int fd
File handle on Unix-like systems.
Here is the caller graph for this function: