GNUnet 0.26.2-17-g3d7c5992e
 
Loading...
Searching...
No Matches
disk.c File Reference

disk IO convenience methods More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "disk.h"
#include <sys/types.h>
Include dependency graph for disk.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DISK_PipeHandle
 Handle used to manage a pipe. More...
 
struct  GetFileSizeData
 Closure for the recursion to determine the file size of a directory. More...
 
struct  GlobClosure
 
struct  GNUNET_DISK_MapHandle
 Handle for a memory-mapping operation. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
 
#define LOG_STRERROR(kind, syscall)    GNUNET_log_from_strerror (kind, "util-disk", syscall)
 
#define LOG_STRERROR_FILE(kind, syscall, filename)    GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
 
#define COPY_BLK_SIZE   65536
 Block size for IO for copying files.
 
#define _IFMT   0170000 /* type of file */
 
#define _IFLNK   0120000 /* symbolic link */
 
#define S_ISLNK(m)   (((m)&_IFMT) == _IFLNK)
 
#define MAP_FAILED   ((void *) -1)
 

Functions

static int translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm)
 Translate GNUnet-internal permission bitmap to UNIX file access permission bitmap.
 
static enum GNUNET_GenericReturnValue get_size_rec (void *cls, const char *fn)
 Iterate over all files in the given directory and accumulate their size.
 
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_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
 Get the size of an open file.
 
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.
 
static char * mktemp_name (const char *t)
 Create the name for a temporary file or directory from a template.
 
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.
 
char * GNUNET_DISK_mkdtemp (const char *t)
 Create an (empty) temporary directory on disk.
 
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.
 
char * GNUNET_DISK_mktemp (const char *t)
 Create an (empty) temporary file on disk.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test (const char *fil, int is_readable)
 Test if fil is a directory and listable.
 
static enum GNUNET_GenericReturnValue file_test_internal (const char *fil, int amode)
 Check if fil can be accessed using amode.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create (const char *dir)
 Implementation of "mkdir -p".
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file (const char *filename)
 Create the directory structure for storing a file.
 
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.
 
int GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
 Scan a directory for files.
 
static bool glob_match (const char *pattern, const char *str)
 Check for a simple wildcard match.
 
static enum GNUNET_GenericReturnValue glob_cb (void *cls, const char *filename)
 Function called with a filename.
 
int GNUNET_DISK_glob (const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
 Find all files matching a glob pattern.
 
static enum GNUNET_GenericReturnValue remove_helper (void *unused, const char *fn)
 Function that removes the given directory by calling GNUNET_DISK_directory_remove().
 
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove (const char *filename)
 Remove all files in a directory (rm -rf).
 
enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy (const char *src, const char *dst)
 Copy a file.
 
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.
 
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_close (struct GNUNET_DISK_FileHandle *h)
 Close an open file.
 
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.
 
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.
 
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_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_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 Closes an interprocess channel.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, int *dst)
 Retrieve OS file handle.
 
static enum GNUNET_GenericReturnValue purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Helper function for 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.
 

Detailed Description

disk IO convenience methods

Author
Christian Grothoff
Nils Durner

Definition in file disk.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-disk", __VA_ARGS__)

Definition at line 31 of file disk.c.

◆ LOG_STRERROR

#define LOG_STRERROR (   kind,
  syscall 
)     GNUNET_log_from_strerror (kind, "util-disk", syscall)

Definition at line 33 of file disk.c.

68{
73 struct GNUNET_DISK_FileHandle *fd[2];
74};
75
76
81struct GetFileSizeData
82{
86 uint64_t total;
87
92
97};
98
99
107static int
109{
110 int mode;
111
112 mode = 0;
114 mode |= S_IRUSR;
116 mode |= S_IWUSR;
118 mode |= S_IXUSR;
120 mode |= S_IRGRP;
122 mode |= S_IWGRP;
124 mode |= S_IXGRP;
126 mode |= S_IROTH;
128 mode |= S_IWOTH;
130 mode |= S_IXOTH;
131
132 return mode;
133}
134
135
145get_size_rec (void *cls, const char *fn)
146{
147 struct GetFileSizeData *gfsd = cls;
148
149#if defined(HAVE_STAT64) && \
150 ! (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
151 struct stat64 buf;
152
153 if (0 != lstat64 (fn, &buf))
154 {
156 return GNUNET_SYSERR;
157 }
158#else
159 struct stat buf;
160
161 if (0 != lstat (fn, &buf))
162 {
164 return GNUNET_SYSERR;
165 }
166#endif
167 if ((S_ISDIR (buf.st_mode)) && (gfsd->single_file_mode == GNUNET_YES))
168 {
169 errno = EISDIR;
170 return GNUNET_SYSERR;
171 }
172 if ((S_ISLNK (buf.st_mode)) && (gfsd->include_sym_links == GNUNET_NO))
173 {
174 char linkdst[PATH_MAX];
175 if (NULL == realpath (fn, linkdst))
176 {
178 return GNUNET_SYSERR;
179 }
180 return get_size_rec (gfsd, linkdst);
181 }
182 if ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
183 gfsd->total += buf.st_size;
184 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
185 ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
186 {
187 if (GNUNET_SYSERR ==
190 gfsd))
191 return GNUNET_SYSERR;
192 }
193 return GNUNET_OK;
194}
195
196
199{
200 return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
201}
202
203
206 off_t *size)
207{
208 struct stat sbuf;
209
210 if (0 != fstat (fh->fd, &sbuf))
211 return GNUNET_SYSERR;
212 *size = sbuf.st_size;
213 return GNUNET_OK;
214}
215
216
217off_t
219 off_t offset,
220 enum GNUNET_DISK_Seek whence)
221{
222 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
223
224 if (h == NULL)
225 {
226 errno = EINVAL;
227 return GNUNET_SYSERR;
228 }
229 return lseek (h->fd, offset, t[whence]);
230}
231
232
235 uint64_t *size,
236 int include_symbolic_links,
237 int single_file_mode)
238{
239 struct GetFileSizeData gfsd;
241
242 GNUNET_assert (size != NULL);
243 gfsd.total = 0;
244 gfsd.include_sym_links = include_symbolic_links;
246 ret = get_size_rec (&gfsd, filename);
247 *size = gfsd.total;
248 return ret;
249}
250
251
254 uint64_t *dev,
255 uint64_t *ino)
256{
257#if HAVE_STAT
258 {
259 struct stat sbuf;
260
261 if (0 != stat (filename, &sbuf))
262 {
263 return GNUNET_SYSERR;
264 }
265 *ino = (uint64_t) sbuf.st_ino;
266 }
267#else
268 *ino = 0;
269#endif
270#if HAVE_STATVFS
271 {
272 struct statvfs fbuf;
273
274 if (0 != statvfs (filename, &fbuf))
275 {
276 return GNUNET_SYSERR;
277 }
278 *dev = (uint64_t) fbuf.f_fsid;
279 }
280#elif HAVE_STATFS
281 {
282 struct statfs fbuf;
283
284 if (0 != statfs (filename, &fbuf))
285 {
286 return GNUNET_SYSERR;
287 }
288 *dev =
289 ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
290 }
291#else
292 *dev = 0;
293#endif
294 return GNUNET_OK;
295}
296
297
304static char *
305mktemp_name (const char *t)
306{
307 const char *tmpdir;
308 char *tmpl;
309 char *fn;
310
311 if ((t[0] != '/') && (t[0] != '\\'))
312 {
313 /* FIXME: This uses system codepage on W32, not UTF-8 */
314 tmpdir = getenv ("TMPDIR");
315 if (NULL == tmpdir)
316 tmpdir = getenv ("TMP");
317 if (NULL == tmpdir)
318 tmpdir = getenv ("TEMP");
319 if (NULL == tmpdir)
320 tmpdir = "/tmp";
321 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
322 }
323 else
324 {
325 GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
326 }
327 fn = tmpl;
328 return fn;
329}
330
331
332void
333GNUNET_DISK_fix_permissions (const char *fn,
334 int require_uid_match,
335 int require_gid_match)
336{
337 mode_t mode;
338
339 if (GNUNET_YES == require_uid_match)
340 mode = S_IRUSR | S_IWUSR | S_IXUSR;
341 else if (GNUNET_YES == require_gid_match)
342 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
343 else
344 mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH
345 | S_IWOTH | S_IXOTH;
346 if (0 != chmod (fn, mode))
348}
349
350
351char *
352GNUNET_DISK_mkdtemp (const char *t)
353{
354 char *fn;
355 mode_t omask;
356
357 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
358 fn = mktemp_name (t);
359 if (fn != mkdtemp (fn))
360 {
362 GNUNET_free (fn);
363 umask (omask);
364 return NULL;
365 }
366 umask (omask);
367 return fn;
368}
369
370
371char *
372GNUNET_DISK_file_backup (const char *fil)
373{
374 size_t slen;
375 char *target;
376 unsigned int num;
377
378 slen = strlen (fil) + 20;
379 target = GNUNET_malloc (slen);
380 num = 0;
381
382#if HAVE_RENAMEAT2
383 {
384 int fd;
385
386 do
387 {
388 GNUNET_snprintf (target,
389 slen,
390 "%s.%u~",
391 fil,
392 num++);
393 fd = open (target,
394 O_CREAT | O_EXCL,
396 } while (-1 == fd);
397 if (0 != renameat2 (AT_FDCWD,
398 fil,
399 AT_FDCWD,
400 target,
401 RENAME_EXCHANGE))
402 {
404 "renameat2",
405 fil);
406 GNUNET_break (0 ==
407 close (fd));
408 return NULL;
409 }
410 GNUNET_break (0 ==
411 close (fd));
412 }
413#else
414 do
415 {
416 GNUNET_snprintf (target,
417 slen,
418 "%s.%u~",
419 fil,
420 num++);
421 }
422 while (0 == access (target,
423 F_OK));
424 if (0 != rename (fil,
425 target))
426 {
428 "rename",
429 fil);
430 return NULL;
431 }
432#endif
433 return target;
434}
435
436
437char *
438GNUNET_DISK_mktemp (const char *t)
439{
440 int fd;
441 char *fn;
442 mode_t omask;
443
444 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
445 fn = mktemp_name (t);
446 if (-1 == (fd = mkstemp (fn)))
447 {
449 "mkstemp",
450 fn);
451 GNUNET_free (fn);
452 umask (omask);
453 return NULL;
454 }
455 umask (omask);
456 if (0 != close (fd))
458 "close",
459 fn);
460 return fn;
461}
462
463
465GNUNET_DISK_directory_test (const char *fil,
466 int is_readable)
467{
468 struct stat filestat;
469 int ret;
470
471 ret = stat (fil, &filestat);
472 if (ret != 0)
473 {
474 if (errno != ENOENT)
476 "stat",
477 fil);
478 return GNUNET_SYSERR;
479 }
480 if (! S_ISDIR (filestat.st_mode))
481 {
483 "A file already exits with the same name %s\n",
484 fil);
485 return GNUNET_NO;
486 }
487 if (GNUNET_YES == is_readable)
488 ret = access (fil,
489 R_OK | X_OK);
490 else
491 ret = access (fil,
492 X_OK);
493 if (ret < 0)
494 {
496 "access",
497 fil);
498 return GNUNET_NO;
499 }
500 return GNUNET_YES;
501}
502
503
512file_test_internal (const char *fil,
513 int amode)
514{
515 struct stat filestat;
516 int ret;
517 char *rdir;
518
520 if (rdir == NULL)
521 return GNUNET_SYSERR;
522
523 ret = stat (rdir, &filestat);
524 if (0 != ret)
525 {
526 if (errno != ENOENT)
527 {
529 "stat",
530 rdir);
531 GNUNET_free (rdir);
532 return GNUNET_SYSERR;
533 }
534 GNUNET_free (rdir);
535 return GNUNET_NO;
536 }
537 if (! S_ISREG (filestat.st_mode))
538 {
539 GNUNET_free (rdir);
540 return GNUNET_NO;
541 }
542 if (access (rdir, amode) < 0)
543 {
545 "access",
546 rdir);
547 GNUNET_free (rdir);
548 return GNUNET_SYSERR;
549 }
550 GNUNET_free (rdir);
551 return GNUNET_YES;
552}
553
554
556GNUNET_DISK_file_test (const char *fil)
557{
558 return file_test_internal (fil,
559 F_OK);
560}
561
562
564GNUNET_DISK_file_test_read (const char *fil)
565{
566 return file_test_internal (fil,
567 R_OK);
568}
569
570
573{
574 char *rdir;
575 unsigned int len;
576 unsigned int pos;
577 unsigned int pos2;
578 int ret = GNUNET_OK;
579
581 if (rdir == NULL)
582 {
583 GNUNET_break (0);
584 return GNUNET_SYSERR;
585 }
586
587 len = strlen (rdir);
588
589 pos = 1; /* skip heading '/' */
590
591 /* Check which low level directories already exist */
592 pos2 = len;
593 rdir[len] = DIR_SEPARATOR;
594 while (pos <= pos2)
595 {
596 if (DIR_SEPARATOR == rdir[pos2])
597 {
598 rdir[pos2] = '\0';
600 GNUNET_NO);
601 if (GNUNET_NO == ret)
602 {
604 "Creating directory `%s' failed\n",
605 rdir);
606 GNUNET_free (rdir);
607 return GNUNET_SYSERR;
608 }
609 rdir[pos2] = DIR_SEPARATOR;
610 if (GNUNET_YES == ret)
611 {
612 pos2++;
613 break;
614 }
615 }
616 pos2--;
617 }
618 rdir[len] = '\0';
619 if (pos < pos2)
620 pos = pos2;
621 /* Start creating directories */
622 while (pos <= len)
623 {
624 if ( (rdir[pos] == DIR_SEPARATOR) ||
625 (pos == len) )
626 {
627 rdir[pos] = '\0';
629 GNUNET_NO);
630 if (GNUNET_NO == ret)
631 {
633 "Creating directory `%s' failed\n",
634 rdir);
635 GNUNET_free (rdir);
636 return GNUNET_SYSERR;
637 }
638 if (GNUNET_SYSERR == ret)
639 {
640 ret = mkdir (rdir,
641 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
642 | S_IXOTH); /* 755 */
643
644 if ((ret != 0) && (errno != EEXIST))
645 {
647 "mkdir",
648 rdir);
649 GNUNET_free (rdir);
650 return GNUNET_SYSERR;
651 }
652 }
653 rdir[pos] = DIR_SEPARATOR;
654 }
655 pos++;
656 }
657 GNUNET_free (rdir);
658 return GNUNET_OK;
659}
660
661
664{
665 char *rdir;
666 size_t len;
667 int eno;
669
671 if (NULL == rdir)
672 {
673 errno = EINVAL;
674 return GNUNET_SYSERR;
675 }
676 if (0 == access (rdir, W_OK))
677 {
678 GNUNET_free (rdir);
679 return GNUNET_OK;
680 }
681 len = strlen (rdir);
682 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
683 len--;
684 rdir[len] = '\0';
685 /* The empty path is invalid and in this case refers to / */
686 if (0 == len)
687 {
688 GNUNET_free (rdir);
689 rdir = GNUNET_strdup ("/");
690 }
692 if ( (GNUNET_OK == res) &&
693 (0 != access (rdir, W_OK)) )
694 res = GNUNET_NO;
695 eno = errno;
696 GNUNET_free (rdir);
697 errno = eno;
698 return res;
699}
700
701
702ssize_t
704 void *result,
705 size_t len)
706{
707 if (NULL == h)
708 {
709 errno = EINVAL;
710 return GNUNET_SYSERR;
711 }
712 return read (h->fd,
713 result,
714 len);
715}
716
717
718ssize_t
719GNUNET_DISK_fn_read (const char *fn,
720 void *result,
721 size_t len)
722{
723 struct GNUNET_DISK_FileHandle *fh;
724 ssize_t ret;
725 int eno;
726
727 fh = GNUNET_DISK_file_open (fn,
730 if (NULL == fh)
731 return GNUNET_SYSERR;
733 result,
734 len);
735 eno = errno;
738 errno = eno;
739 return ret;
740}
741
742
743ssize_t
745 const void *buffer,
746 size_t n)
747{
748 if (NULL == h)
749 {
750 errno = EINVAL;
751 return GNUNET_SYSERR;
752 }
753 return write (h->fd,
754 buffer,
755 n);
756}
757
758
759ssize_t
761 const void *buffer,
762 size_t n)
763{
764 int flags;
765 ssize_t ret;
766
767 if (NULL == h)
768 {
769 errno = EINVAL;
770 return GNUNET_SYSERR;
771 }
772 /* set to blocking, write, then set back */
773 flags = fcntl (h->fd,
774 F_GETFL);
775 if (0 != (flags & O_NONBLOCK))
776 (void) fcntl (h->fd,
777 F_SETFL,
778 flags - O_NONBLOCK);
779 ret = write (h->fd,
780 buffer,
781 n);
782 if (0 == (flags & O_NONBLOCK))
783 (void) fcntl (h->fd,
784 F_SETFL,
785 flags);
786 return ret;
787}
788
789
791GNUNET_DISK_fn_write (const char *fn,
792 const void *buf,
793 size_t buf_size,
795{
796 char *tmpl;
797 int fd;
798
799 if (GNUNET_OK !=
801 {
803 "mkstemp",
804 fn);
805 return GNUNET_SYSERR;
806 }
807 {
808 char *dname;
809
810 dname = GNUNET_strdup (fn);
811 GNUNET_asprintf (&tmpl,
812 "%s/XXXXXX",
813 dirname (dname));
814 GNUNET_free (dname);
815 }
816 fd = mkstemp (tmpl);
817 if (-1 == fd)
818 {
820 "mkstemp",
821 tmpl);
822 GNUNET_free (tmpl);
823 return GNUNET_SYSERR;
824 }
825
826 if (0 != fchmod (fd,
828 {
830 "chmod",
831 tmpl);
832 GNUNET_assert (0 == close (fd));
833 if (0 != unlink (tmpl))
835 "unlink",
836 tmpl);
837 GNUNET_free (tmpl);
838 return GNUNET_SYSERR;
839 }
840 if (buf_size !=
841 write (fd,
842 buf,
843 buf_size))
844 {
846 "write",
847 tmpl);
848 GNUNET_assert (0 == close (fd));
849 if (0 != unlink (tmpl))
851 "unlink",
852 tmpl);
853 GNUNET_free (tmpl);
854 return GNUNET_SYSERR;
855 }
856 GNUNET_assert (0 == close (fd));
857
858 if (0 != link (tmpl,
859 fn))
860 {
861 if (0 != unlink (tmpl))
863 "unlink",
864 tmpl);
865 GNUNET_free (tmpl);
866 return GNUNET_NO;
867 }
868 if (0 != unlink (tmpl))
870 "unlink",
871 tmpl);
872 GNUNET_free (tmpl);
873 return GNUNET_OK;
874
875
876}
877
878
879int
882 void *callback_cls)
883{
884 DIR *dinfo;
885 struct dirent *finfo;
886 int count = 0;
888 char *name;
889 char *dname;
890 unsigned int name_len;
891 unsigned int n_size;
892
893 GNUNET_assert (NULL != dir_name);
895 if (NULL == dname)
896 return GNUNET_SYSERR;
897 while ( (strlen (dname) > 0) &&
898 (dname[strlen (dname) - 1] == DIR_SEPARATOR) )
899 dname[strlen (dname) - 1] = '\0';
900 dinfo = opendir (dname);
901 if (NULL == dinfo)
902 {
904 "opendir",
905 dname);
906 GNUNET_free (dname);
907 return GNUNET_SYSERR;
908 }
909 name_len = 256;
910 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
911 name = GNUNET_malloc (n_size);
912 while (NULL != (finfo = readdir (dinfo)))
913 {
914 if ((0 == strcmp (finfo->d_name, ".")) ||
915 (0 == strcmp (finfo->d_name, "..")))
916 continue;
917 if (NULL != callback)
918 {
919 if (name_len < strlen (finfo->d_name))
920 {
922 name_len = strlen (finfo->d_name);
923 n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
924 name = GNUNET_malloc (n_size);
925 }
926 /* dname can end in "/" only if dname == "/";
927 * if dname does not end in "/", we need to add
928 * a "/" (otherwise, we must not!) */
930 n_size,
931 "%s%s%s",
932 dname,
933 (0 == strcmp (dname,
935 ? ""
937 finfo->d_name);
938 ret = callback (callback_cls,
939 name);
940 if (GNUNET_OK != ret)
941 {
942 closedir (dinfo);
944 GNUNET_free (dname);
945 if (GNUNET_NO == ret)
946 return count;
947 return GNUNET_SYSERR;
948 }
949 }
950 count++;
951 }
952 closedir (dinfo);
954 GNUNET_free (dname);
955 return count;
956}
957
958
968static bool
969glob_match (const char *pattern, const char *str)
970{
971 /* Position in the input string */
972 const char *str_pos = str;
973 /* Position in the pattern */
974 const char *pat_pos = pattern;
975 /* Backtrack position in string */
976 const char *str_bt = NULL;
977 /* Backtrack position in pattern */
978 const char *pat_bt = NULL;
979
980 for (;;)
981 {
982 if (*pat_pos == '*')
983 {
984 str_bt = str_pos;
985 pat_bt = pat_pos++;
986 }
987 else if (*pat_pos == *str_pos)
988 {
989 if ('\0' == *pat_pos)
990 return true;
991 str_pos++;
992 pat_pos++;
993 }
994 else
995 {
996 if (NULL == str_bt)
997 return false;
998 /* Backtrack to match one more
999 character as part of the asterisk. */
1000 str_pos = str_bt + 1;
1001 if ('\0' == *str_pos)
1002 return false;
1003 pat_pos = pat_bt;
1004 }
1005 }
1006}
1007
1008
1009struct GlobClosure
1010{
1011 const char *glob;
1013 void *cls;
1014
1018 int nres;
1019};
1020
1030static enum GNUNET_GenericReturnValue
1031glob_cb (void *cls,
1032 const char *filename)
1033{
1034 struct GlobClosure *gc = cls;
1035 const char *fn;
1036
1037 fn = strrchr (filename, DIR_SEPARATOR);
1038 fn = (NULL == fn) ? filename : (fn + 1);
1039
1041 "checking glob '%s' against '%s'\n",
1042 gc->glob,
1043 fn);
1044
1045 if (glob_match (gc->glob, fn))
1046 {
1047 enum GNUNET_GenericReturnValue cbret;
1048
1050 "found glob match '%s'\n",
1051 filename);
1052 gc->nres++;
1053 cbret = gc->cb (gc->cls, filename);
1054 if (GNUNET_OK != cbret)
1055 return cbret;
1056 }
1057 return GNUNET_OK;
1058}
1059
1060
1061int
1062GNUNET_DISK_glob (const char *glob_pattern,
1063 GNUNET_FileNameCallback callback,
1064 void *callback_cls)
1065{
1066 char *mypat = GNUNET_strdup (glob_pattern);
1067 char *sep;
1068 int ret;
1069
1070 if ( (NULL != strrchr (glob_pattern, '+')) ||
1071 (NULL != strrchr (glob_pattern, '[')) ||
1072 (NULL != strrchr (glob_pattern, '~')) )
1073 {
1075 "unsupported glob pattern: '%s'\n",
1076 glob_pattern);
1077 GNUNET_free (mypat);
1078 return -1;
1079 }
1080
1081 sep = strrchr (mypat, DIR_SEPARATOR);
1082 if (NULL == sep)
1083 {
1084 GNUNET_free (mypat);
1085 return -1;
1086 }
1087
1088 *sep = '\0';
1089
1090 if (NULL != strchr (mypat, '*'))
1091 {
1092 GNUNET_free (mypat);
1093 GNUNET_break (0);
1095 "glob pattern may only contain '*' in the final path component\n");
1096 return -1;
1097 }
1098
1099 {
1100 struct GlobClosure gc = {
1101 .glob = sep + 1,
1102 .cb = callback,
1103 .cls = callback_cls,
1104 .nres = 0,
1105 };
1107 "scanning directory '%s' for glob matches on '%s'\n",
1108 mypat,
1109 gc.glob);
1111 glob_cb,
1112 &gc
1113 );
1114 GNUNET_free (mypat);
1115 return (ret < 0) ? ret : gc.nres;
1116 }
1117}
1118
1119
1128static enum GNUNET_GenericReturnValue
1129remove_helper (void *unused,
1130 const char *fn)
1131{
1132 (void) unused;
1133 (void) GNUNET_DISK_directory_remove (fn);
1134 return GNUNET_OK;
1135}
1136
1137
1140{
1141 struct stat istat;
1142
1143 if (NULL == filename)
1144 {
1145 GNUNET_break (0);
1146 return GNUNET_SYSERR;
1147 }
1148 if (0 != lstat (filename, &istat))
1149 return GNUNET_NO; /* file may not exist... */
1150 (void) chmod (filename,
1151 S_IWUSR | S_IRUSR | S_IXUSR);
1152 if (0 == unlink (filename))
1153 return GNUNET_OK;
1154 if ( (errno != EISDIR) &&
1155 /* EISDIR is not sufficient in all cases, e.g.
1156 * sticky /tmp directory may result in EPERM on BSD.
1157 * So we also explicitly check "isDirectory" */
1158 (GNUNET_YES !=
1160 GNUNET_YES)) )
1161 {
1163 "rmdir",
1164 filename);
1165 return GNUNET_SYSERR;
1166 }
1167 if (GNUNET_SYSERR ==
1170 NULL))
1171 return GNUNET_SYSERR;
1172 if (0 != rmdir (filename))
1173 {
1175 "rmdir",
1176 filename);
1177 return GNUNET_SYSERR;
1178 }
1179 return GNUNET_OK;
1180}
1181
1182
1184GNUNET_DISK_file_copy (const char *src,
1185 const char *dst)
1186{
1187 char *buf;
1188 uint64_t pos;
1189 uint64_t size;
1190 size_t len;
1191 ssize_t sret;
1192 struct GNUNET_DISK_FileHandle *in;
1193 struct GNUNET_DISK_FileHandle *out;
1194
1195 if (GNUNET_OK !=
1197 &size,
1198 GNUNET_YES,
1199 GNUNET_YES))
1200 {
1202 "stat",
1203 src);
1204 return GNUNET_SYSERR;
1205 }
1206 pos = 0;
1207 in =
1211 if (! in)
1212 {
1214 return GNUNET_SYSERR;
1215 }
1216 out =
1224 if (! out)
1225 {
1228 return GNUNET_SYSERR;
1229 }
1231 while (pos < size)
1232 {
1233 len = COPY_BLK_SIZE;
1234 if (len > size - pos)
1235 len = size - pos;
1236 sret = GNUNET_DISK_file_read (in, buf, len);
1237 if ((sret < 0) || (len != (size_t) sret))
1238 goto FAIL;
1239 sret = GNUNET_DISK_file_write (out, buf, len);
1240 if ((sret < 0) || (len != (size_t) sret))
1241 goto FAIL;
1242 pos += len;
1243 }
1244 GNUNET_free (buf);
1249 return GNUNET_OK;
1250FAIL:
1251 GNUNET_free (buf);
1256 return GNUNET_SYSERR;
1257}
1258
1259
1260void
1262{
1263 char *idx;
1264 char c;
1265
1266 for (idx = fn; *idx; idx++)
1267 {
1268 c = *idx;
1269
1270 if ((c == '/') || (c == '\\') || (c == ':') || (c == '*') || (c == '?') ||
1271 (c ==
1272 '"')
1273 ||
1274 (c == '<') || (c == '>') || (c == '|') )
1275 {
1276 *idx = '_';
1277 }
1278 }
1279}
1280
1281
1284 const char *user)
1285{
1286 struct passwd *pws;
1287
1288 pws = getpwnam (user);
1289 if (NULL == pws)
1290 {
1292 _ ("Cannot obtain information about user `%s': %s\n"),
1293 user,
1294 strerror (errno));
1295 return GNUNET_SYSERR;
1296 }
1297 if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
1298 {
1300 return GNUNET_SYSERR;
1301 }
1302 return GNUNET_OK;
1303}
1304
1305
1307GNUNET_DISK_file_open (const char *fn,
1308 enum GNUNET_DISK_OpenFlags flags,
1310{
1311 char *expfn;
1313
1314 int oflags;
1315 int mode;
1316 int fd;
1317
1318 expfn = GNUNET_STRINGS_filename_expand (fn);
1319 if (NULL == expfn)
1320 return NULL;
1321
1322 mode = 0;
1324 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1325 else if (flags & GNUNET_DISK_OPEN_READ)
1326 oflags = O_RDONLY;
1327 else if (flags & GNUNET_DISK_OPEN_WRITE)
1328 oflags = O_WRONLY;
1329 else
1330 {
1331 GNUNET_break (0);
1332 GNUNET_free (expfn);
1333 return NULL;
1334 }
1336 oflags |= (O_CREAT | O_EXCL);
1337 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1338 oflags |= O_TRUNC;
1339 if (flags & GNUNET_DISK_OPEN_APPEND)
1340 oflags |= O_APPEND;
1341 if (GNUNET_NO == GNUNET_DISK_file_test (fn))
1342 {
1343 if (flags & GNUNET_DISK_OPEN_CREATE)
1344 {
1346 oflags |= O_CREAT;
1347 mode = translate_unix_perms (perm);
1348 }
1349 }
1350
1351 // Setting O_CLOEXEC after pipe() may introduce
1352 // race conditions: https://bugs.gnunet.org/view.php?id=9311
1353 // This is no problem if the platform supports pipe2
1354 fd = open (expfn,
1355 oflags
1356#if O_CLOEXEC
1357 | O_CLOEXEC
1358#endif
1359 | O_LARGEFILE,
1360 mode);
1361 if (fd == -1)
1362 {
1363 if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
1365 "open",
1366 expfn);
1367 else
1369 "open",
1370 expfn);
1371 GNUNET_free (expfn);
1372 return NULL;
1373 }
1374
1376
1377 ret->fd = fd;
1378
1379 GNUNET_free (expfn);
1380 return ret;
1381}
1382
1383
1386{
1388
1389 if (NULL == h)
1390 {
1391 errno = EINVAL;
1392 return GNUNET_SYSERR;
1393 }
1394
1395 ret = GNUNET_OK;
1396 if (0 != close (h->fd))
1397 {
1399 "close");
1401 }
1402 GNUNET_free (h);
1403 return ret;
1404}
1405
1406
1409{
1410 struct GNUNET_DISK_FileHandle *fh;
1411
1412 if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
1413 return NULL; /* invalid FD */
1414
1415 fh = GNUNET_new (struct GNUNET_DISK_FileHandle);
1416
1417 fh->fd = fno;
1418
1419 return fh;
1420}
1421
1422
1425{
1426 int fno;
1427
1428 fno = fileno (fd);
1429 if (-1 == fno)
1430 return NULL;
1432}
1433
1434
1439{
1443 void *addr;
1444
1448 size_t len;
1449};
1450
1451
1452#ifndef MAP_FAILED
1453#define MAP_FAILED ((void *) -1)
1454#endif
1455
1456
1457void *
1459 struct GNUNET_DISK_MapHandle **m,
1460 enum GNUNET_DISK_MapType access,
1461 size_t len)
1462{
1463 int prot;
1464
1465 if (NULL == h)
1466 {
1467 errno = EINVAL;
1468 return NULL;
1469 }
1470 prot = 0;
1471 if (access & GNUNET_DISK_MAP_TYPE_READ)
1472 prot = PROT_READ;
1473 if (access & GNUNET_DISK_MAP_TYPE_WRITE)
1474 prot |= PROT_WRITE;
1476 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
1477 GNUNET_assert (NULL != (*m)->addr);
1478 if (MAP_FAILED == (*m)->addr)
1479 {
1480 GNUNET_free (*m);
1481 return NULL;
1482 }
1483 (*m)->len = len;
1484 return (*m)->addr;
1485}
1486
1487
1490{
1492
1493 if (NULL == h)
1494 {
1495 errno = EINVAL;
1496 return GNUNET_SYSERR;
1497 }
1498 ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
1499 GNUNET_free (h);
1500 return ret;
1501}
1502
1503
1506{
1507 if (h == NULL)
1508 {
1509 errno = EINVAL;
1510 return GNUNET_SYSERR;
1511 }
1512
1513#if ! defined(__linux__) || ! defined(GNU)
1514 return fsync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1515#else
1516 return fdatasync (h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
1517#endif
1518}
1519
1520
1523{
1524 int fd[2];
1525
1526#if HAVE_PIPE2 && O_CLOEXEC
1527 if (-1 == pipe2 (fd, O_CLOEXEC))
1528#else
1529 if (-1 == pipe (fd))
1530#endif
1531 {
1532 int eno = errno;
1533
1535 errno = eno;
1536 return NULL;
1537 }
1538 return GNUNET_DISK_pipe_from_fd (pf, fd);
1539}
1540
1541
1544 int fd[2])
1545{
1546 struct GNUNET_DISK_PipeHandle *p;
1547 int ret = 0;
1548 int flags;
1549 int eno = 0; /* make gcc happy */
1550
1552 if (fd[0] >= 0)
1553 {
1554 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1555 p->fd[0]->fd = fd[0];
1556 if (0 == (GNUNET_DISK_PF_BLOCKING_READ & pf))
1557 {
1558 flags = fcntl (fd[0], F_GETFL);
1559 flags |= O_NONBLOCK;
1560 if (0 > fcntl (fd[0], F_SETFL, flags))
1561 {
1562 ret = -1;
1563 eno = errno;
1564 }
1565 }
1566 flags = fcntl (fd[0], F_GETFD);
1567 flags |= FD_CLOEXEC;
1568 if (0 > fcntl (fd[0], F_SETFD, flags))
1569 {
1570 ret = -1;
1571 eno = errno;
1572 }
1573 }
1574
1575 if (fd[1] >= 0)
1576 {
1577 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
1578 p->fd[1]->fd = fd[1];
1579 if (0 == (GNUNET_DISK_PF_BLOCKING_WRITE & pf))
1580 {
1581 flags = fcntl (fd[1], F_GETFL);
1582 flags |= O_NONBLOCK;
1583 if (0 > fcntl (fd[1], F_SETFL, flags))
1584 {
1585 ret = -1;
1586 eno = errno;
1587 }
1588 }
1589 flags = fcntl (fd[1], F_GETFD);
1590 flags |= FD_CLOEXEC;
1591 if (0 > fcntl (fd[1], F_SETFD, flags))
1592 {
1593 ret = -1;
1594 eno = errno;
1595 }
1596 }
1597 if (ret == -1)
1598 {
1599 errno = eno;
1601 if (p->fd[0]->fd >= 0)
1602 GNUNET_break (0 == close (p->fd[0]->fd));
1603 if (p->fd[1]->fd >= 0)
1604 GNUNET_break (0 == close (p->fd[1]->fd));
1605 GNUNET_free (p->fd[0]);
1606 GNUNET_free (p->fd[1]);
1607 GNUNET_free (p);
1608 errno = eno;
1609 return NULL;
1610 }
1611 return p;
1612}
1613
1614
1618{
1620
1622 {
1623 if (p->fd[0])
1624 {
1625 ret = GNUNET_DISK_file_close (p->fd[0]);
1626 p->fd[0] = NULL;
1627 }
1628 }
1629 else if (end == GNUNET_DISK_PIPE_END_WRITE)
1630 {
1631 if (p->fd[1])
1632 {
1633 ret = GNUNET_DISK_file_close (p->fd[1]);
1634 p->fd[1] = NULL;
1635 }
1636 }
1637 return ret;
1638}
1639
1640
1644{
1645 struct GNUNET_DISK_FileHandle *ret = NULL;
1646
1648 {
1649 if (p->fd[0])
1650 {
1651 ret = p->fd[0];
1652 p->fd[0] = NULL;
1653 }
1654 }
1655 else if (end == GNUNET_DISK_PIPE_END_WRITE)
1656 {
1657 if (p->fd[1])
1658 {
1659 ret = p->fd[1];
1660 p->fd[1] = NULL;
1661 }
1662 }
1663
1664 return ret;
1665}
1666
1667
1670{
1672 enum GNUNET_GenericReturnValue read_end_close;
1673 enum GNUNET_GenericReturnValue write_end_close;
1674 int read_end_close_errno;
1675 int write_end_close_errno;
1676
1677 read_end_close = GNUNET_DISK_pipe_close_end (p,
1679 read_end_close_errno = errno;
1680 write_end_close = GNUNET_DISK_pipe_close_end (p,
1682 write_end_close_errno = errno;
1683 GNUNET_free (p);
1684
1685 if (GNUNET_OK != read_end_close)
1686 {
1687 errno = read_end_close_errno;
1688 ret = read_end_close;
1689 }
1690 else if (GNUNET_OK != write_end_close)
1691 {
1692 errno = write_end_close_errno;
1693 ret = write_end_close;
1694 }
1695
1696 return ret;
1697}
1698
1699
1700const struct GNUNET_DISK_FileHandle *
1702 enum GNUNET_DISK_PipeEnd n)
1703{
1704 switch (n)
1705 {
1708 return p->fd[n];
1709
1710 default:
1711 GNUNET_break (0);
1712 return NULL;
1713 }
1714}
1715
1716
1719 int *dst)
1720{
1721 if (NULL == fh)
1722 return GNUNET_SYSERR;
1723 *dst = fh->fd;
1724 return GNUNET_OK;
1725}
1726
1727
1735static enum GNUNET_GenericReturnValue
1736purge_cfg_dir (void *cls,
1737 const struct GNUNET_CONFIGURATION_Handle *cfg)
1738{
1739 const char *option = cls;
1740 char *tmpname;
1741
1742 if (GNUNET_OK !=
1744 "PATHS",
1745 option,
1746 &tmpname))
1747 {
1749 "PATHS",
1750 option);
1751 return GNUNET_NO;
1752 }
1753 if (GNUNET_SYSERR ==
1755 {
1757 "remove",
1758 tmpname);
1759 GNUNET_free (tmpname);
1760 return GNUNET_OK;
1761 }
1762 GNUNET_free (tmpname);
1763 return GNUNET_OK;
1764}
1765
1766
1767void
1769 const char *cfg_filename,
1770 const char *option)
1771{
1776 (void *) option));
1777}
1778
1779
1780/* end of disk.c */
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
#define COPY_BLK_SIZE
Block size for IO for copying files.
Definition disk.c:42
static enum GNUNET_GenericReturnValue glob_cb(void *cls, const char *filename)
Function called with a filename.
Definition disk.c:1032
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition disk.c:36
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
static enum GNUNET_GenericReturnValue file_test_internal(const char *fil, int amode)
Check if fil can be accessed using amode.
Definition disk.c:513
#define S_ISLNK(m)
Definition disk.c:61
#define MAP_FAILED
Definition disk.c:1454
static bool glob_match(const char *pattern, const char *str)
Check for a simple wildcard match.
Definition disk.c:970
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
#define LOG(kind,...)
Definition disk.c:31
static char * mktemp_name(const char *t)
Create the name for a temporary file or directory from a template.
Definition disk.c:306
#define LOG_STRERROR(kind, syscall)
Definition disk.c:33
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_internal_file_handle_(const struct GNUNET_DISK_FileHandle *fh, int *dst)
Retrieve OS file handle.
Definition disk.c:1719
char * getenv()
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static char * dir
Set to the directory where runtime files are stored.
Definition gnunet-arm.c:88
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static const char * dir_name
Top-level directory we monitor to auto-publish.
static char * cfg_filename
Name of the configuration file.
static char * filename
static char * name
Name (label) of the records to list.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition gnunet-uri.c:38
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
@ FAIL
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
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.
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.
Definition disk.c:1702
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
void GNUNET_DISK_filename_canonicalize(char *fn)
Removes special characters as ':' from a filename.
Definition disk.c:1262
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition disk.c:1063
enum GNUNET_GenericReturnValue GNUNET_DISK_file_change_owner(const char *filename, const char *user)
Change owner of a file.
Definition disk.c:1284
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition disk.c:439
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_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...
Definition disk.c:254
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 ...
Definition disk.c:373
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.
Definition disk.c:334
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.
Definition disk.c:1643
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
GNUNET_DISK_OpenFlags
Specifies how a file should be opened.
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
GNUNET_DISK_PipeFlags
Flags for GNUNET_DISK_pipe().
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.
Definition disk.c:219
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1523
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition disk.c:565
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
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1670
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.
Definition disk.c:792
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition disk.c:353
enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy(const char *src, const char *dst)
Copy a file.
Definition disk.c:1185
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition disk.c:1140
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition disk.c:1506
GNUNET_DISK_Seek
Constants for specifying how to seek.
enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
Definition disk.c:199
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
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
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.
Definition disk.c:1769
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
Definition disk.c:1425
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
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.
Definition disk.c:1459
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
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
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition disk.c:206
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
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.
Definition disk.c:761
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition disk.c:1490
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition disk.c:573
GNUNET_DISK_PipeEnd
Enumeration identifying the two ends of a pipe.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:720
GNUNET_DISK_MapType
Specifies what type of memory map is desired.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
@ 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_PF_BLOCKING_WRITE
Configure write end to block when writing if set.
@ GNUNET_DISK_PF_BLOCKING_READ
Configure read end to block when reading if set.
@ 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_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
@ GNUNET_DISK_MAP_TYPE_WRITE
Write-able memory map.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#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_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:525
static unsigned int size
Size of the "table".
Definition peer.c:68
#define DIR_SEPARATOR
Definition platform.h:166
#define O_LARGEFILE
Definition platform.h:213
#define DIR_SEPARATOR_STR
Definition platform.h:167
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define PATH_MAX
Assumed maximum path length.
Definition platform.h:242
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Handle for a memory-mapping operation.
Definition disk.c:1440
void * addr
Address where the map is in memory.
Definition disk.c:1444
size_t len
Number of bytes mapped.
Definition disk.c:1449
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
Project-specific data used to help the OS subsystem find installation paths.
Closure for the recursion to determine the file size of a directory.
Definition disk.c:83
uint64_t total
Set to the total file size.
Definition disk.c:87
int include_sym_links
GNUNET_YES if symbolic links should be included.
Definition disk.c:92
int single_file_mode
GNUNET_YES if mode is file-only (return total == -1 for directories).
Definition disk.c:97
GNUNET_FileNameCallback cb
Definition disk.c:1013
void * cls
Definition disk.c:1014
int nres
Number of files that actually matched the glob pattern.
Definition disk.c:1019
const char * glob
Definition disk.c:1012
const char * str
Definition time.c:1252

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)     GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)

Definition at line 36 of file disk.c.

◆ COPY_BLK_SIZE

#define COPY_BLK_SIZE   65536

Block size for IO for copying files.

Definition at line 42 of file disk.c.

◆ _IFMT

#define _IFMT   0170000 /* type of file */

Definition at line 59 of file disk.c.

◆ _IFLNK

#define _IFLNK   0120000 /* symbolic link */

Definition at line 60 of file disk.c.

◆ S_ISLNK

#define S_ISLNK (   m)    (((m)&_IFMT) == _IFLNK)

Definition at line 61 of file disk.c.

◆ MAP_FAILED

#define MAP_FAILED   ((void *) -1)

Definition at line 1454 of file disk.c.

Function Documentation

◆ translate_unix_perms()

static int translate_unix_perms ( enum GNUNET_DISK_AccessPermissions  perm)
static

Translate GNUnet-internal permission bitmap to UNIX file access permission bitmap.

Parameters
permfile permissions, GNUnet style
Returns
file permissions, UNIX style

Definition at line 109 of file disk.c.

110{
111 int mode;
112
113 mode = 0;
115 mode |= S_IRUSR;
117 mode |= S_IWUSR;
119 mode |= S_IXUSR;
121 mode |= S_IRGRP;
123 mode |= S_IWGRP;
125 mode |= S_IXGRP;
127 mode |= S_IROTH;
129 mode |= S_IWOTH;
131 mode |= S_IXOTH;
132
133 return mode;
134}

References GNUNET_DISK_PERM_GROUP_EXEC, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_OTHER_EXEC, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_OTHER_WRITE, GNUNET_DISK_PERM_USER_EXEC, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, and mode.

Referenced by GNUNET_DISK_file_backup(), GNUNET_DISK_file_open(), and GNUNET_DISK_fn_write().

Here is the caller graph for this function:

◆ get_size_rec()

static enum GNUNET_GenericReturnValue get_size_rec ( void *  cls,
const char *  fn 
)
static

Iterate over all files in the given directory and accumulate their size.

Parameters
clsclosure of type struct GetFileSizeData
fncurrent filename we are looking at
Returns
GNUNET_SYSERR on serious errors, otherwise GNUNET_OK

Definition at line 146 of file disk.c.

147{
148 struct GetFileSizeData *gfsd = cls;
149
150#if defined(HAVE_STAT64) && \
151 ! (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
152 struct stat64 buf;
153
154 if (0 != lstat64 (fn, &buf))
155 {
157 return GNUNET_SYSERR;
158 }
159#else
160 struct stat buf;
161
162 if (0 != lstat (fn, &buf))
163 {
165 return GNUNET_SYSERR;
166 }
167#endif
168 if ((S_ISDIR (buf.st_mode)) && (gfsd->single_file_mode == GNUNET_YES))
169 {
170 errno = EISDIR;
171 return GNUNET_SYSERR;
172 }
173 if ((S_ISLNK (buf.st_mode)) && (gfsd->include_sym_links == GNUNET_NO))
174 {
175 char linkdst[PATH_MAX];
176 if (NULL == realpath (fn, linkdst))
177 {
179 return GNUNET_SYSERR;
180 }
181 return get_size_rec (gfsd, linkdst);
182 }
183 if ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
184 gfsd->total += buf.st_size;
185 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
186 ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
187 {
188 if (GNUNET_SYSERR ==
191 gfsd))
192 return GNUNET_SYSERR;
193 }
194 return GNUNET_OK;
195}

References get_size_rec(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GetFileSizeData::include_sym_links, LOG_STRERROR_FILE, PATH_MAX, S_ISLNK, GetFileSizeData::single_file_mode, and GetFileSizeData::total.

Referenced by get_size_rec(), and GNUNET_DISK_file_size().

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

◆ mktemp_name()

static char * mktemp_name ( const char *  t)
static

Create the name for a temporary file or directory from a template.

Parameters
ttemplate (without XXXXX or "/tmp/")
Returns
name ready for passing to 'mktemp' or 'mkdtemp', NULL on error

Definition at line 306 of file disk.c.

307{
308 const char *tmpdir;
309 char *tmpl;
310 char *fn;
311
312 if ((t[0] != '/') && (t[0] != '\\'))
313 {
314 /* FIXME: This uses system codepage on W32, not UTF-8 */
315 tmpdir = getenv ("TMPDIR");
316 if (NULL == tmpdir)
317 tmpdir = getenv ("TMP");
318 if (NULL == tmpdir)
319 tmpdir = getenv ("TEMP");
320 if (NULL == tmpdir)
321 tmpdir = "/tmp";
322 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
323 }
324 else
325 {
326 GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX");
327 }
328 fn = tmpl;
329 return fn;
330}

References getenv(), GNUNET_asprintf(), and t.

Referenced by GNUNET_DISK_mkdtemp(), and GNUNET_DISK_mktemp().

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

◆ file_test_internal()

static enum GNUNET_GenericReturnValue file_test_internal ( const char *  fil,
int  amode 
)
static

Check if fil can be accessed using amode.

Parameters
filfile to check for
amodeaccess mode
Returns
GNUnet error code

Definition at line 513 of file disk.c.

515{
516 struct stat filestat;
517 int ret;
518 char *rdir;
519
521 if (rdir == NULL)
522 return GNUNET_SYSERR;
523
524 ret = stat (rdir, &filestat);
525 if (0 != ret)
526 {
527 if (errno != ENOENT)
528 {
530 "stat",
531 rdir);
532 GNUNET_free (rdir);
533 return GNUNET_SYSERR;
534 }
535 GNUNET_free (rdir);
536 return GNUNET_NO;
537 }
538 if (! S_ISREG (filestat.st_mode))
539 {
540 GNUNET_free (rdir);
541 return GNUNET_NO;
542 }
543 if (access (rdir, amode) < 0)
544 {
546 "access",
547 rdir);
548 GNUNET_free (rdir);
549 return GNUNET_SYSERR;
550 }
551 GNUNET_free (rdir);
552 return GNUNET_YES;
553}

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

Referenced by GNUNET_DISK_file_test(), and GNUNET_DISK_file_test_read().

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

◆ glob_match()

static bool glob_match ( const char *  pattern,
const char *  str 
)
static

Check for a simple wildcard match.

Only asterisks are allowed. Asterisks match everything, including slashes.

Parameters
patternpattern with wildcards
strstring to match against
Returns
true on match, false otherwise

Definition at line 970 of file disk.c.

971{
972 /* Position in the input string */
973 const char *str_pos = str;
974 /* Position in the pattern */
975 const char *pat_pos = pattern;
976 /* Backtrack position in string */
977 const char *str_bt = NULL;
978 /* Backtrack position in pattern */
979 const char *pat_bt = NULL;
980
981 for (;;)
982 {
983 if (*pat_pos == '*')
984 {
985 str_bt = str_pos;
986 pat_bt = pat_pos++;
987 }
988 else if (*pat_pos == *str_pos)
989 {
990 if ('\0' == *pat_pos)
991 return true;
992 str_pos++;
993 pat_pos++;
994 }
995 else
996 {
997 if (NULL == str_bt)
998 return false;
999 /* Backtrack to match one more
1000 character as part of the asterisk. */
1001 str_pos = str_bt + 1;
1002 if ('\0' == *str_pos)
1003 return false;
1004 pat_pos = pat_bt;
1005 }
1006 }
1007}

References str.

Referenced by glob_cb().

Here is the caller graph for this function:

◆ glob_cb()

static enum GNUNET_GenericReturnValue glob_cb ( void *  cls,
const char *  filename 
)
static

Function called with a filename.

Parameters
clsclosure
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_NO to stop iteration with no error, GNUNET_SYSERR to abort iteration with error!

Definition at line 1032 of file disk.c.

1034{
1035 struct GlobClosure *gc = cls;
1036 const char *fn;
1037
1038 fn = strrchr (filename, DIR_SEPARATOR);
1039 fn = (NULL == fn) ? filename : (fn + 1);
1040
1042 "checking glob '%s' against '%s'\n",
1043 gc->glob,
1044 fn);
1045
1046 if (glob_match (gc->glob, fn))
1047 {
1048 enum GNUNET_GenericReturnValue cbret;
1049
1051 "found glob match '%s'\n",
1052 filename);
1053 gc->nres++;
1054 cbret = gc->cb (gc->cls, filename);
1055 if (GNUNET_OK != cbret)
1056 return cbret;
1057 }
1058 return GNUNET_OK;
1059}

References GlobClosure::cb, GlobClosure::cls, DIR_SEPARATOR, filename, GlobClosure::glob, glob_match(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, LOG, and GlobClosure::nres.

Referenced by GNUNET_DISK_glob().

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

◆ remove_helper()

static enum GNUNET_GenericReturnValue remove_helper ( void *  unused,
const char *  fn 
)
static

Function that removes the given directory by calling GNUNET_DISK_directory_remove().

Parameters
unusednot used
fndirectory to remove
Returns
GNUNET_OK

Definition at line 1130 of file disk.c.

1132{
1133 (void) unused;
1134 (void) GNUNET_DISK_directory_remove (fn);
1135 return GNUNET_OK;
1136}

References GNUNET_DISK_directory_remove(), and GNUNET_OK.

Referenced by GNUNET_DISK_directory_remove().

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

◆ GNUNET_DISK_internal_file_handle_()

enum GNUNET_GenericReturnValue GNUNET_DISK_internal_file_handle_ ( const struct GNUNET_DISK_FileHandle fh,
int *  dst 
)

Retrieve OS file handle.

Parameters
fhGNUnet file descriptor
dstdestination buffer
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1719 of file disk.c.

1721{
1722 if (NULL == fh)
1723 return GNUNET_SYSERR;
1724 *dst = fh->fd;
1725 return GNUNET_OK;
1726}

References GNUNET_DISK_FileHandle::fd, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_NETWORK_fdset_handle_set(), and start_process().

Here is the caller graph for this function:

◆ purge_cfg_dir()

static enum GNUNET_GenericReturnValue purge_cfg_dir ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Helper function for GNUNET_DISK_purge_cfg_dir.

Parameters
clsa const char * with the option to purge
cfgour configuration
Returns
GNUNET_OK on success

Definition at line 1737 of file disk.c.

1739{
1740 const char *option = cls;
1741 char *tmpname;
1742
1743 if (GNUNET_OK !=
1745 "PATHS",
1746 option,
1747 &tmpname))
1748 {
1750 "PATHS",
1751 option);
1752 return GNUNET_NO;
1753 }
1754 if (GNUNET_SYSERR ==
1756 {
1758 "remove",
1759 tmpname);
1760 GNUNET_free (tmpname);
1761 return GNUNET_OK;
1762 }
1763 GNUNET_free (tmpname);
1764 return GNUNET_OK;
1765}

References cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_directory_remove(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_DISK_purge_cfg_dir().

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