68{
74};
75
76
82{
87
92
97};
98
99
107static int
109{
111
131
133}
134
135
146{
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 {
157 }
158#else
159 struct stat buf;
160
161 if (0 != lstat (fn, &buf))
162 {
165 }
166#endif
168 {
169 errno = EISDIR;
171 }
173 {
175 if (NULL == realpath (fn, linkdst))
176 {
179 }
181 }
183 gfsd->
total += buf.st_size;
184 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
186 {
190 gfsd))
192 }
194}
195
196
199{
201}
202
203
207{
208 struct stat sbuf;
209
210 if (0 != fstat (fh->
fd, &sbuf))
212 *
size = sbuf.st_size;
214}
215
216
217off_t
219 off_t offset,
221{
222 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
223
225 {
226 errno = EINVAL;
228 }
229 return lseek (
h->fd, offset,
t[whence]);
230}
231
232
236 int include_symbolic_links,
237 int single_file_mode)
238{
241
249}
250
251
254 uint64_t *dev,
255 uint64_t *ino)
256{
257#if HAVE_STAT
258 {
259 struct stat sbuf;
260
262 {
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
275 {
277 }
278 *dev = (uint64_t) fbuf.f_fsid;
279 }
280#elif HAVE_STATFS
281 {
282 struct statfs fbuf;
283
285 {
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
295}
296
297
304static char *
306{
307 const char *tmpdir;
308 char *tmpl;
309 char *fn;
310
311 if ((
t[0] !=
'/') && (
t[0] !=
'\\'))
312 {
313
314 tmpdir =
getenv (
"TMPDIR");
315 if (NULL == tmpdir)
317 if (NULL == tmpdir)
319 if (NULL == tmpdir)
320 tmpdir = "/tmp";
322 }
323 else
324 {
326 }
327 fn = tmpl;
328 return fn;
329}
330
331
332void
334 int require_uid_match,
335 int require_gid_match)
336{
338
340 mode = S_IRUSR | S_IWUSR | S_IXUSR;
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 *
353{
354 char *fn;
355 mode_t omask;
356
357 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
359 if (fn != mkdtemp (fn))
360 {
363 umask (omask);
364 return NULL;
365 }
366 umask (omask);
367 return fn;
368}
369
370
371char *
373{
374 size_t slen;
375 char *target;
376 unsigned int num;
377
378 slen = strlen (fil) + 20;
380 num = 0;
381
382#if HAVE_RENAMEAT2
383 {
384 int fd;
385
386 do
387 {
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);
407 close (fd));
408 return NULL;
409 }
411 close (fd));
412 }
413#else
414 do
415 {
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 *
439{
440 int fd;
441 char *fn;
442 mode_t omask;
443
444 omask = umask (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH);
446 if (-1 == (fd = mkstemp (fn)))
447 {
449 "mkstemp",
450 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
466 int is_readable)
467{
468 struct stat filestat;
470
471 ret = stat (fil, &filestat);
473 {
474 if (errno != ENOENT)
476 "stat",
477 fil);
479 }
480 if (! S_ISDIR (filestat.st_mode))
481 {
483 "A file already exits with the same name %s\n",
484 fil);
486 }
489 R_OK | X_OK);
490 else
492 X_OK);
494 {
496 "access",
497 fil);
499 }
501}
502
503
513 int amode)
514{
515 struct stat filestat;
517 char *rdir;
518
520 if (rdir == NULL)
522
523 ret = stat (rdir, &filestat);
525 {
526 if (errno != ENOENT)
527 {
529 "stat",
530 rdir);
533 }
536 }
537 if (! S_ISREG (filestat.st_mode))
538 {
541 }
542 if (access (rdir, amode) < 0)
543 {
545 "access",
546 rdir);
549 }
552}
553
554
557{
559 F_OK);
560}
561
562
565{
567 R_OK);
568}
569
570
573{
574 char *rdir;
575 unsigned int len;
576 unsigned int pos;
577 unsigned int pos2;
579
581 if (rdir == NULL)
582 {
585 }
586
587 len = strlen (rdir);
588
589 pos = 1;
590
591
592 pos2 = len;
594 while (pos <= pos2)
595 {
597 {
598 rdir[pos2] = '\0';
602 {
604 "Creating directory `%s' failed\n",
605 rdir);
608 }
611 {
612 pos2++;
613 break;
614 }
615 }
616 pos2--;
617 }
618 rdir[len] = '\0';
619 if (pos < pos2)
620 pos = pos2;
621
622 while (pos <= len)
623 {
625 (pos == len) )
626 {
627 rdir[pos] = '\0';
631 {
633 "Creating directory `%s' failed\n",
634 rdir);
637 }
639 {
641 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
642 | S_IXOTH);
643
644 if ((
ret != 0) && (errno != EEXIST))
645 {
647 "mkdir",
648 rdir);
651 }
652 }
654 }
655 pos++;
656 }
659}
660
661
664{
665 char *rdir;
666 size_t len;
667 int eno;
669
671 if (NULL == rdir)
672 {
673 errno = EINVAL;
675 }
676 if (0 == access (rdir, W_OK))
677 {
680 }
681 len = strlen (rdir);
683 len--;
684 rdir[len] = '\0';
685
686 if (0 == len)
687 {
690 }
693 (0 != access (rdir, W_OK)) )
695 eno = errno;
697 errno = eno;
699}
700
701
702ssize_t
705 size_t len)
706{
708 {
709 errno = EINVAL;
711 }
714 len);
715}
716
717
718ssize_t
721 size_t len)
722{
725 int eno;
726
730 if (NULL == fh)
734 len);
735 eno = errno;
738 errno = eno;
740}
741
742
743ssize_t
745 const void *buffer,
746 size_t n)
747{
749 {
750 errno = EINVAL;
752 }
754 buffer,
755 n);
756}
757
758
759ssize_t
761 const void *buffer,
762 size_t n)
763{
764 int flags;
766
768 {
769 errno = EINVAL;
771 }
772
773 flags = fcntl (
h->fd,
774 F_GETFL);
775 if (0 != (flags & O_NONBLOCK))
777 F_SETFL,
778 flags - O_NONBLOCK);
780 buffer,
781 n);
782 if (0 == (flags & O_NONBLOCK))
784 F_SETFL,
785 flags);
787}
788
789
792 const void *buf,
793 size_t buf_size,
795{
796 char *tmpl;
798
801 {
803 "mkstemp",
804 fn);
806 }
807 {
808 char *dname;
809
812 "%s/XXXXXX",
813 dirname (dname));
815 }
818 {
820 "mkstemp",
821 tmpl);
824 }
825
828 {
830 "chmod",
831 tmpl);
833 if (0 != unlink (tmpl))
835 "unlink",
836 tmpl);
839 }
840 if (buf_size !=
842 buf,
843 buf_size))
844 {
846 "write",
847 tmpl);
849 if (0 != unlink (tmpl))
851 "unlink",
852 tmpl);
855 }
857
858 if (0 != link (tmpl,
859 fn))
860 {
861 if (0 != unlink (tmpl))
863 "unlink",
864 tmpl);
867 }
868 if (0 != unlink (tmpl))
870 "unlink",
871 tmpl);
874
875
876}
877
878
879int
882 void *callback_cls)
883{
884 DIR *dinfo;
885 struct dirent *finfo;
886 int count = 0;
889 char *dname;
890 unsigned int name_len;
891 unsigned int n_size;
892
895 if (NULL == dname)
897 while ( (strlen (dname) > 0) &&
899 dname[strlen (dname) - 1] = '\0';
900 dinfo = opendir (dname);
901 if (NULL == dinfo)
902 {
904 "opendir",
905 dname);
908 }
909 name_len = 256;
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);
925 }
926
927
928
930 n_size,
931 "%s%s%s",
932 dname,
933 (0 == strcmp (dname,
935 ? ""
937 finfo->d_name);
938 ret = callback (callback_cls,
941 {
942 closedir (dinfo);
946 return count;
948 }
949 }
950 count++;
951 }
952 closedir (dinfo);
955 return count;
956}
957
958
968static bool
970{
971
972 const char *str_pos =
str;
973
974 const char *pat_pos = pattern;
975
976 const char *str_bt = NULL;
977
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
999
1000 str_pos = str_bt + 1;
1001 if ('\0' == *str_pos)
1002 return false;
1003 pat_pos = pat_bt;
1004 }
1005 }
1006}
1007
1008
1010{
1014
1019};
1020
1033{
1035 const char *fn;
1036
1038 fn = (NULL == fn) ?
filename : (fn + 1);
1039
1041 "checking glob '%s' against '%s'\n",
1043 fn);
1044
1046 {
1048
1050 "found glob match '%s'\n",
1055 return cbret;
1056 }
1058}
1059
1060
1061int
1064 void *callback_cls)
1065{
1067 char *sep;
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);
1078 return -1;
1079 }
1080
1082 if (NULL == sep)
1083 {
1085 return -1;
1086 }
1087
1088 *sep = '\0';
1089
1090 if (NULL != strchr (mypat, '*'))
1091 {
1095 "glob pattern may only contain '*' in the final path component\n");
1096 return -1;
1097 }
1098
1099 {
1102 .cb = callback,
1103 .cls = callback_cls,
1104 .nres = 0,
1105 };
1107 "scanning directory '%s' for glob matches on '%s'\n",
1108 mypat,
1112 &gc
1113 );
1116 }
1117}
1118
1119
1130 const char *fn)
1131{
1132 (void) unused;
1135}
1136
1137
1140{
1141 struct stat istat;
1142
1144 {
1147 }
1151 S_IWUSR | S_IRUSR | S_IXUSR);
1154 if ( (errno != EISDIR) &&
1155
1156
1157
1161 {
1163 "rmdir",
1166 }
1170 NULL))
1173 {
1175 "rmdir",
1178 }
1180}
1181
1182
1185 const char *dst)
1186{
1187 char *buf;
1188 uint64_t pos;
1190 size_t len;
1191 ssize_t sret;
1194
1200 {
1202 "stat",
1203 src);
1205 }
1206 pos = 0;
1207 in =
1211 if (! in)
1212 {
1215 }
1216 out =
1224 if (! out)
1225 {
1229 }
1232 {
1234 if (len >
size - pos)
1237 if ((sret < 0) || (len != (size_t) sret))
1240 if ((sret < 0) || (len != (size_t) sret))
1242 pos += len;
1243 }
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));
1296 }
1297 if (0 != chown (
filename, pws->pw_uid, pws->pw_gid))
1298 {
1301 }
1303}
1304
1305
1310{
1311 char *expfn;
1313
1314 int oflags;
1317
1319 if (NULL == expfn)
1320 return NULL;
1321
1324 oflags = O_RDWR;
1326 oflags = O_RDONLY;
1328 oflags = O_WRONLY;
1329 else
1330 {
1333 return NULL;
1334 }
1336 oflags |= (O_CREAT | O_EXCL);
1338 oflags |= O_TRUNC;
1340 oflags |= O_APPEND;
1342 {
1344 {
1346 oflags |= O_CREAT;
1348 }
1349 }
1350
1351
1352
1353
1355 oflags
1356#if O_CLOEXEC
1357 | O_CLOEXEC
1358#endif
1362 {
1365 "open",
1366 expfn);
1367 else
1369 "open",
1370 expfn);
1372 return NULL;
1373 }
1374
1376
1378
1381}
1382
1383
1386{
1388
1390 {
1391 errno = EINVAL;
1393 }
1394
1396 if (0 != close (
h->fd))
1397 {
1399 "close");
1401 }
1404}
1405
1406
1409{
1411
1412 if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
1413 return NULL;
1414
1416
1418
1419 return fh;
1420}
1421
1422
1425{
1426 int fno;
1427
1429 if (-1 == fno)
1430 return NULL;
1432}
1433
1434
1439{
1444
1449};
1450
1451
1452#ifndef MAP_FAILED
1453#define MAP_FAILED ((void *) -1)
1454#endif
1455
1456
1457void *
1461 size_t len)
1462{
1463 int prot;
1464
1466 {
1467 errno = EINVAL;
1468 return NULL;
1469 }
1470 prot = 0;
1472 prot = PROT_READ;
1474 prot |= PROT_WRITE;
1476 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED,
h->fd, 0);
1479 {
1481 return NULL;
1482 }
1483 (*m)->len = len;
1484 return (*m)->addr;
1485}
1486
1487
1490{
1492
1494 {
1495 errno = EINVAL;
1497 }
1501}
1502
1503
1506{
1508 {
1509 errno = EINVAL;
1511 }
1512
1513#if ! defined(__linux__) || ! defined(GNU)
1515#else
1517#endif
1518}
1519
1520
1523{
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 }
1539}
1540
1541
1545{
1548 int flags;
1549 int eno = 0;
1550
1553 {
1555 p->fd[0]->fd =
fd[0];
1557 {
1558 flags = fcntl (
fd[0], F_GETFL);
1559 flags |= O_NONBLOCK;
1560 if (0 > fcntl (
fd[0], F_SETFL, flags))
1561 {
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 {
1571 eno = errno;
1572 }
1573 }
1574
1576 {
1578 p->fd[1]->fd =
fd[1];
1580 {
1581 flags = fcntl (
fd[1], F_GETFL);
1582 flags |= O_NONBLOCK;
1583 if (0 > fcntl (
fd[1], F_SETFL, flags))
1584 {
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 {
1594 eno = errno;
1595 }
1596 }
1598 {
1599 errno = eno;
1601 if (
p->fd[0]->fd >= 0)
1603 if (
p->fd[1]->fd >= 0)
1608 errno = eno;
1609 return NULL;
1610 }
1612}
1613
1614
1618{
1620
1622 {
1624 {
1627 }
1628 }
1630 {
1632 {
1635 }
1636 }
1638}
1639
1640
1644{
1646
1648 {
1650 {
1653 }
1654 }
1656 {
1658 {
1661 }
1662 }
1663
1665}
1666
1667
1670{
1674 int read_end_close_errno;
1675 int write_end_close_errno;
1676
1679 read_end_close_errno = errno;
1682 write_end_close_errno = errno;
1684
1686 {
1687 errno = read_end_close_errno;
1688 ret = read_end_close;
1689 }
1691 {
1692 errno = write_end_close_errno;
1693 ret = write_end_close;
1694 }
1695
1697}
1698
1699
1703{
1704 switch (n)
1705 {
1709
1710 default:
1712 return NULL;
1713 }
1714}
1715
1716
1719 int *dst)
1720{
1721 if (NULL == fh)
1725}
1726
1727
1738{
1739 const char *option = cls;
1740 char *tmpname;
1741
1744 "PATHS",
1745 option,
1746 &tmpname))
1747 {
1749 "PATHS",
1750 option);
1752 }
1755 {
1757 "remove",
1758 tmpname);
1761 }
1764}
1765
1766
1767void
1770 const char *option)
1771{
1776 (void *) option));
1777}
1778
1779
1780
static enum GNUNET_GenericReturnValue get_size_rec(void *cls, const char *fn)
Iterate over all files in the given directory and accumulate their size.
#define COPY_BLK_SIZE
Block size for IO for copying files.
static enum GNUNET_GenericReturnValue glob_cb(void *cls, const char *filename)
Function called with a filename.
#define LOG_STRERROR_FILE(kind, syscall, filename)
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 file_test_internal(const char *fil, int amode)
Check if fil can be accessed using amode.
static bool glob_match(const char *pattern, const char *str)
Check for a simple wildcard match.
static enum GNUNET_GenericReturnValue purge_cfg_dir(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Helper function for GNUNET_DISK_purge_cfg_dir.
static char * mktemp_name(const char *t)
Create the name for a temporary file or directory from a template.
#define LOG_STRERROR(kind, syscall)
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_internal_file_handle_(const struct GNUNET_DISK_FileHandle *fh, int *dst)
Retrieve OS file handle.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * dir
Set to the directory where runtime files are stored.
static int end
Set if we are to shutdown all services (including ARM).
static const char * dir_name
Top-level directory we monitor to auto-publish.
static char * cfg_filename
Name of the configuration file.
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.
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
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.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
void GNUNET_DISK_filename_canonicalize(char *fn)
Removes special characters as ':' from a filename.
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_change_owner(const char *filename, const char *user)
Change owner of a file.
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
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_get_identifiers(const char *filename, uint64_t *dev, uint64_t *ino)
Obtain some unique identifiers for the given file that can be used to identify it in the local system...
char * GNUNET_DISK_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 ...
void GNUNET_DISK_fix_permissions(const char *fn, int require_uid_match, int require_gid_match)
Update POSIX permissions mask of a file on disk.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_detach_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Detaches one of the ends from the pipe.
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.
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.
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.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
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_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).
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
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.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy(const char *src, const char *dst)
Copy a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
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.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
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.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
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.
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_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
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.
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.
@ 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.
#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
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.
static unsigned int size
Size of the "table".
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Handle for a memory-mapping operation.
void * addr
Address where the map is in memory.
size_t len
Number of bytes mapped.
Handle used to manage a pipe.
struct GNUNET_DISK_FileHandle * fd[2]
File descriptors for the pipe.
Project-specific data used to help the OS subsystem find installation paths.
Closure for the recursion to determine the file size of a directory.
uint64_t total
Set to the total file size.
int include_sym_links
GNUNET_YES if symbolic links should be included.
int single_file_mode
GNUNET_YES if mode is file-only (return total == -1 for directories).
GNUNET_FileNameCallback cb
int nres
Number of files that actually matched the glob pattern.