-removing dead lib header
[oweals/gnunet.git] / src / include / gnunet_disk_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001-2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file include/gnunet_disk_lib.h
22  * @brief disk IO apis
23  * @author Christian Grothoff
24  */
25 #ifndef GNUNET_DISK_LIB_H
26 #define GNUNET_DISK_LIB_H
27
28 #if WINDOWS
29 #define OFF_T uint64_t
30 #else
31 #define OFF_T off_t
32 #endif
33
34 /**
35  * Handle used to manage a pipe.
36  */
37 struct GNUNET_DISK_PipeHandle;
38
39 /**
40  * Type of a handle.
41  */
42 enum GNUNET_FILE_Type
43 {
44   /**
45    * Handle represents a file.
46    */ 
47   GNUNET_DISK_HANLDE_TYPE_FILE, 
48
49   /**
50    * Handle represents a pipe.
51    */
52   GNUNET_DISK_HANLDE_TYPE_PIPE
53 };
54
55 /**
56  * Handle used to access files (and pipes).
57  */
58 struct GNUNET_DISK_FileHandle
59 {
60
61 #if WINDOWS
62   /**
63    * File handle under W32.
64    */
65   HANDLE h;
66
67   /**
68    * Type
69    */
70   enum GNUNET_FILE_Type type;
71
72   /**
73    * Structure for overlapped reading (for pipes)
74    */
75   OVERLAPPED *oOverlapRead;
76
77   /**
78    * Structure for overlapped writing (for pipes)
79    */
80   OVERLAPPED *oOverlapWrite;
81 #else
82
83   /**
84    * File handle on other OSes.
85    */
86   int fd;
87
88 #endif
89 };
90
91
92 /* we need size_t, and since it can be both unsigned int
93    or unsigned long long, this IS platform dependent;
94    but "stdlib.h" should be portable 'enough' to be
95    unconditionally available... */
96 #include <stdlib.h>
97 #include "gnunet_configuration_lib.h"
98 #include "gnunet_scheduler_lib.h"
99
100 #ifdef __cplusplus
101 extern "C"
102 {
103 #if 0                           /* keep Emacsens' auto-indent happy */
104 }
105 #endif
106 #endif
107
108
109 /**
110  * Specifies how a file should be opened.
111  */
112 enum GNUNET_DISK_OpenFlags
113 {
114
115   /**
116    * Open the file for reading
117    */
118   GNUNET_DISK_OPEN_READ = 1,
119
120   /**
121    * Open the file for writing
122    */
123   GNUNET_DISK_OPEN_WRITE = 2,
124
125   /**
126    * Open the file for both reading and writing
127    */
128   GNUNET_DISK_OPEN_READWRITE = 3,
129
130   /**
131    * Fail if file already exists
132    */
133   GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
134
135   /**
136    * Truncate file if it exists
137    */
138   GNUNET_DISK_OPEN_TRUNCATE = 8,
139
140   /**
141    * Create file if it doesn't exist
142    */
143   GNUNET_DISK_OPEN_CREATE = 16,
144
145   /**
146    * Append to the file
147    */
148   GNUNET_DISK_OPEN_APPEND = 32
149 };
150
151 /**
152  * Specifies what type of memory map is desired.
153  */
154 enum GNUNET_DISK_MapType
155 {
156   /**
157    * Read-only memory map.
158    */
159   GNUNET_DISK_MAP_TYPE_READ = 1,
160   
161   /**
162    * Write-able memory map.
163    */
164   GNUNET_DISK_MAP_TYPE_WRITE = 2,
165
166   /**
167    * Read-write memory map.
168    */
169   GNUNET_DISK_MAP_TYPE_READWRITE = 3
170 };
171
172
173 /**
174  * File access permissions, UNIX-style.
175  */
176 enum GNUNET_DISK_AccessPermissions
177 {
178   /**
179    * Nobody is allowed to do anything to the file.
180    */
181   GNUNET_DISK_PERM_NONE = 0,
182
183   /**
184    * Owner can read.
185    */
186   GNUNET_DISK_PERM_USER_READ = 1,
187
188   /**
189    * Owner can write.
190    */
191   GNUNET_DISK_PERM_USER_WRITE = 2,
192
193   /**
194    * Owner can execute.
195    */
196   GNUNET_DISK_PERM_USER_EXEC = 4,
197
198   /**
199    * Group can read.
200    */
201   GNUNET_DISK_PERM_GROUP_READ = 8,
202
203   /**
204    * Group can write.
205    */
206   GNUNET_DISK_PERM_GROUP_WRITE = 16,
207
208   /**
209    * Group can execute.
210    */
211   GNUNET_DISK_PERM_GROUP_EXEC = 32,
212
213   /**
214    * Everybody can read.
215    */
216   GNUNET_DISK_PERM_OTHER_READ = 64,
217
218   /**
219    * Everybody can write.
220    */
221   GNUNET_DISK_PERM_OTHER_WRITE = 128,
222
223   /**
224    * Everybody can execute.
225    */
226   GNUNET_DISK_PERM_OTHER_EXEC = 256
227 };
228
229
230 /**
231  * Constants for specifying how to seek.  Do not change values or order,
232  * some of the code depends on the specific numeric values!
233  */
234 enum GNUNET_DISK_Seek
235 {
236   /**
237    * Seek an absolute position (from the start of the file).
238    */
239   GNUNET_DISK_SEEK_SET = 0,
240
241   /**
242    * Seek a relative position (from the current offset).
243    */
244   GNUNET_DISK_SEEK_CUR = 1,
245
246   /**
247    * Seek an absolute position from the end of the file.
248    */
249   GNUNET_DISK_SEEK_END = 2
250 };
251
252
253 /**
254  * Enumeration identifying the two ends of a pipe.
255  */
256 enum GNUNET_DISK_PipeEnd
257 {
258   /**
259    * The reading-end of a pipe.
260    */
261   GNUNET_DISK_PIPE_END_READ = 0,
262
263   /**
264    * The writing-end of a pipe.
265    */
266   GNUNET_DISK_PIPE_END_WRITE = 1
267 };
268
269
270 /**
271  * Checks whether a handle is invalid
272  *
273  * @param h handle to check
274  * @return GNUNET_YES if invalid, GNUNET_NO if valid
275  */
276 int
277 GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
278
279
280 /**
281  * Check that fil corresponds to a filename
282  * (of a file that exists and that is not a directory).
283  *
284  * @param fil filename to check
285  * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
286  * else (will print an error message in that case, too).
287  */
288 int
289 GNUNET_DISK_file_test (const char *fil);
290
291
292 /**
293  * Move a file out of the way (create a backup) by
294  * renaming it to "orig.NUM~" where NUM is the smallest
295  * number that is not used yet.
296  *
297  * @param fil name of the file to back up
298  */
299 void
300 GNUNET_DISK_file_backup (const char *fil);
301
302
303 /**
304  * Move the read/write pointer in a file
305  * @param h handle of an open file
306  * @param offset position to move to
307  * @param whence specification to which position the offset parameter relates to
308  * @return the new position on success, GNUNET_SYSERR otherwise
309  */
310 OFF_T
311 GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset,
312                        enum GNUNET_DISK_Seek whence);
313
314
315 /**
316  * Get the size of the file (or directory) of the given file (in
317  * bytes).
318  *
319  * @param filename name of the file or directory
320  * @param size set to the size of the file (or,
321  *             in the case of directories, the sum
322  *             of all sizes of files in the directory)
323  * @param include_symbolic_links should symbolic links be
324  *        included?
325  * @param single_file_mode #GNUNET_YES to only get size of one file
326  *        and return #GNUNET_SYSERR for directories.
327  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
328  */
329 int
330 GNUNET_DISK_file_size (const char *filename, uint64_t *size,
331                        int include_symbolic_links, 
332                        int single_file_mode);
333
334
335 /**
336  * Obtain some unique identifiers for the given file
337  * that can be used to identify it in the local system.
338  * This function is used between GNUnet processes to
339  * quickly check if two files with the same absolute path
340  * are actually identical.  The two processes represent
341  * the same peer but may communicate over the network
342  * (and the file may be on an NFS volume).  This function
343  * may not be supported on all operating systems.
344  *
345  * @param filename name of the file
346  * @param dev set to the device ID
347  * @param ino set to the inode ID
348  * @return GNUNET_OK on success
349  */
350 int
351 GNUNET_DISK_file_get_identifiers (const char *filename, 
352                                   uint64_t *dev,
353                                   uint64_t *ino);
354
355
356 /**
357  * Create an (empty) temporary file on disk.  If the given name is not
358  * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
359  * 6 random characters will be appended to the name to create a unique
360  * filename.
361  *
362  * @param t component to use for the name;
363  *        does NOT contain "XXXXXX" or "/tmp/".
364  * @return NULL on error, otherwise name of fresh
365  *         file on disk in directory for temporary files
366  */
367 char *
368 GNUNET_DISK_mktemp (const char *t);
369
370
371 /**
372  * Create an (empty) temporary directory on disk.  If the given name is not an
373  * absolute path, the current 'TMPDIR' will be prepended.  In any case, 6
374  * random characters will be appended to the name to create a unique name.
375  *
376  * @param t component to use for the name;
377  *        does NOT contain "XXXXXX" or "/tmp/".
378  * @return NULL on error, otherwise name of freshly created directory
379  */
380 char *
381 GNUNET_DISK_mkdtemp (const char *t);
382
383
384 /**
385  * Open a file.  Note that the access permissions will only be
386  * used if a new file is created and if the underlying operating
387  * system supports the given permissions.
388  *
389  * @param fn file name to be opened
390  * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags
391  * @param perm permissions for the newly created file, use
392  *             #GNUNET_DISK_PERM_NONE if a file could not be created by this
393  *             call (because of flags)
394  * @return IO handle on success, NULL on error
395  */
396 struct GNUNET_DISK_FileHandle *
397 GNUNET_DISK_file_open (const char *fn, 
398                        enum GNUNET_DISK_OpenFlags flags,
399                        enum GNUNET_DISK_AccessPermissions perm);
400
401
402 /**
403  * Get the size of an open file.
404  *
405  * @param fh open file handle
406  * @param size where to write size of the file
407  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
408  */
409 int
410 GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
411                               OFF_T *size);
412
413
414 /**
415  * Creates an interprocess channel
416  *
417  * @param blocking_read creates an asynchronous pipe for reading if set to #GNUNET_NO
418  * @param blocking_write creates an asynchronous pipe for writing if set to #GNUNET_NO
419  * @param inherit_read 1 to make read handle inheritable, 0 otherwise (NT only)
420  * @param inherit_write 1 to make write handle inheritable, 0 otherwise (NT only)
421  * @return handle to the new pipe, NULL on error
422  */
423 struct GNUNET_DISK_PipeHandle *
424 GNUNET_DISK_pipe (int blocking_read, 
425                   int blocking_write, 
426                   int inherit_read, 
427                   int inherit_write);
428
429
430 /**
431  * Creates a pipe object from a couple of file descriptors.
432  * Useful for wrapping existing pipe FDs.
433  *
434  * @param blocking_read creates an asynchronous pipe for reading if set to #GNUNET_NO
435  * @param blocking_write creates an asynchronous pipe for writing if set to #GNUNET_NO
436  * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes
437  *
438  * @return handle to the new pipe, NULL on error
439  */
440 struct GNUNET_DISK_PipeHandle *
441 GNUNET_DISK_pipe_from_fd (int blocking_read, 
442                           int blocking_write, 
443                           int fd[2]);
444
445
446 /**
447  * Closes an interprocess channel
448  * @param p pipe
449  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
450  */
451 int
452 GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
453
454
455 /**
456  * Closes one half of an interprocess channel
457  *
458  * @param p pipe to close end of
459  * @param end which end of the pipe to close
460  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
461  */
462 int
463 GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
464                             enum GNUNET_DISK_PipeEnd end);
465
466
467 /**
468  * Detaches one of the ends from the pipe.
469  * Detached end is a fully-functional FileHandle, it will
470  * not be affected by anything you do with the pipe afterwards.
471  * Each end of a pipe can only be detched from it once (i.e.
472  * it is not duplicated).
473  *
474  * @param p pipe to detach an end from
475  * @param end which end of the pipe to detach
476  * @return Detached end on success, NULL on failure
477  * (or if that end is not present or is closed).
478  */
479 struct GNUNET_DISK_FileHandle *
480 GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
481                              enum GNUNET_DISK_PipeEnd end);
482
483 /**
484  * Close an open file.
485  *
486  * @param h file handle
487  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
488  */
489 int
490 GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
491
492
493 /**
494  * Get the handle to a particular pipe end
495  *
496  * @param p pipe
497  * @param n end to access
498  * @return handle for the respective end
499  */
500 const struct GNUNET_DISK_FileHandle *
501 GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
502                          enum GNUNET_DISK_PipeEnd n);
503
504
505 #if WINDOWS
506 /**
507  * Get a GNUnet file handle from a W32 handle (W32-only).
508  * Do not call on non-W32 platforms (returns NULL).
509  *
510  * @param handle native handle
511  * @return GNUnet file handle corresponding to the W32 handle
512  */
513 struct GNUNET_DISK_FileHandle *
514 GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh);
515 #endif
516
517
518 /**
519  * Get a handle from a native integer FD.
520  *
521  * @param fno native integer file descriptor
522  * @return file handle corresponding to the descriptor
523  */
524 struct GNUNET_DISK_FileHandle *
525 GNUNET_DISK_get_handle_from_int_fd (int fno);
526
527
528 /**
529  * Get a handle from a native FD.
530  *
531  * @param fd native file descriptor
532  * @return file handle corresponding to the descriptor
533  */
534 struct GNUNET_DISK_FileHandle *
535 GNUNET_DISK_get_handle_from_native (FILE *fd);
536
537
538 /**
539  * Read the contents of a binary file into a buffer.
540  *
541  * @param h handle to an open file
542  * @param result the buffer to write the result to
543  * @param len the maximum number of bytes to read
544  * @return the number of bytes read on success, #GNUNET_SYSERR on failure
545  */
546 ssize_t
547 GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, 
548                        void *result,
549                        size_t len);
550
551
552 /**
553  * Read the contents of a binary file into a buffer.
554  * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
555  * when no data can be read).
556  *
557  * @param h handle to an open file
558  * @param result the buffer to write the result to
559  * @param len the maximum number of bytes to read
560  * @return the number of bytes read on success, #GNUNET_SYSERR on failure
561  */
562 ssize_t
563 GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
564                                     void *result,
565                                     size_t len);
566
567
568 /**
569  * Read the contents of a binary file into a buffer.
570  *
571  * @param fn file name
572  * @param result the buffer to write the result to
573  * @param len the maximum number of bytes to read
574  * @return number of bytes read, #GNUNET_SYSERR on failure
575  */
576 ssize_t
577 GNUNET_DISK_fn_read (const char *fn,
578                      void *result, 
579                      size_t len);
580
581
582 /**
583  * Write a buffer to a file.
584  *
585  * @param h handle to open file
586  * @param buffer the data to write
587  * @param n number of bytes to write
588  * @return number of bytes written on success, #GNUNET_SYSERR on error
589  */
590 ssize_t
591 GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
592                         const void *buffer, 
593                         size_t n);
594
595
596 /**
597  * Write a buffer to a file, blocking, if necessary.
598  *
599  * @param h handle to open file
600  * @param buffer the data to write
601  * @param n number of bytes to write
602  * @return number of bytes written on success, #GNUNET_SYSERR on error
603  */
604 ssize_t
605 GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
606                                  const void *buffer, 
607                                  size_t n);
608
609
610 /**
611  * Write a buffer to a file.  If the file is longer than
612  * the given buffer size, it will be truncated.
613  *
614  * @param fn file name
615  * @param buffer the data to write
616  * @param n number of bytes to write
617  * @param mode file permissions
618  * @return number of bytes written on success, #GNUNET_SYSERR on error
619  */
620 ssize_t
621 GNUNET_DISK_fn_write (const char *fn,
622                       const void *buffer, 
623                       size_t n,
624                       enum GNUNET_DISK_AccessPermissions mode);
625
626
627 /**
628  * Copy a file.
629  *
630  * @param src file to copy
631  * @param dst destination file name
632  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
633  */
634 int
635 GNUNET_DISK_file_copy (const char *src, const char *dst);
636
637
638 /**
639  * Scan a directory for files.
640  *
641  * @param dir_name the name of the directory
642  * @param callback the method to call for each file
643  * @param callback_cls closure for @a callback
644  * @return the number of files found, -1 on error
645  */
646 int
647 GNUNET_DISK_directory_scan (const char *dir_name,
648                             GNUNET_FileNameCallback callback,
649                             void *callback_cls);
650
651
652 /**
653  * Opaque handle used for iterating over a directory.
654  */
655 struct GNUNET_DISK_DirectoryIterator;
656
657
658 /**
659  * Function called to iterate over a directory.
660  *
661  * @param cls closure
662  * @param di argument to pass to #GNUNET_DISK_directory_iterator_next to
663  *           get called on the next entry (or finish cleanly);
664  *           NULL on error (will be the last call in that case)
665  * @param filename complete filename (absolute path)
666  * @param dirname directory name (absolute path)
667  */
668 typedef void (*GNUNET_DISK_DirectoryIteratorCallback) (void *cls,
669                                                        struct GNUNET_DISK_DirectoryIterator *di,
670                                                        const char *filename,
671                                                        const char *dirname);
672
673
674 /**
675  * This function must be called during the DiskIteratorCallback
676  * (exactly once) to schedule the task to process the next
677  * filename in the directory (if there is one).
678  *
679  * @param iter opaque handle for the iterator
680  * @param can set to #GNUNET_YES to terminate the iteration early
681  * @return #GNUNET_YES if iteration will continue,
682  *         #GNUNET_NO if this was the last entry (and iteration is complete),
683  *         #GNUNET_SYSERR if @a can was #GNUNET_YES
684  */
685 int
686 GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
687                                      int can);
688
689
690 /**
691  * Scan a directory for files using the scheduler to run a task for
692  * each entry.  The name of the directory must be expanded first (!).
693  * If a scheduler does not need to be used, GNUNET_DISK_directory_scan
694  * may provide a simpler API.
695  *
696  * @param prio priority to use
697  * @param dir_name the name of the directory
698  * @param callback the method to call for each file
699  * @param callback_cls closure for @a callback
700  * @return #GNUNET_YES if directory is not empty and @a callback
701  *         will be called later, #GNUNET_NO otherwise, #GNUNET_SYSERR on error.
702  */
703 int
704 GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
705                                       const char *dir_name,
706                                       GNUNET_DISK_DirectoryIteratorCallback
707                                       callback, void *callback_cls);
708
709
710 /**
711  * Create the directory structure for storing
712  * a file.
713  *
714  * @param filename name of a file in the directory
715  * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure,
716  *          #GNUNET_NO if directory exists but is not writeable
717  */
718 int
719 GNUNET_DISK_directory_create_for_file (const char *filename);
720
721
722 /**
723  * Test if @a fil is a directory and listable. Optionally, also check if the
724  * directory is readable.  Will not print an error message if the directory does
725  * not exist.  Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists
726  * with the same name).
727  *
728  * @param fil filename to test
729  * @param is_readable #GNUNET_YES to additionally check if @a fil is readable;
730  *          #GNUNET_NO to disable this check
731  * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
732  *           does not exist or `stat`ed
733  */
734 int
735 GNUNET_DISK_directory_test (const char *fil, int is_readable);
736
737
738 /**
739  * Remove all files in a directory (rm -rf). Call with
740  * caution.
741  *
742  * @param filename the file to remove
743  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
744  */
745 int
746 GNUNET_DISK_directory_remove (const char *filename);
747
748
749 /**
750  * Implementation of "mkdir -p"
751  *
752  * @param dir the directory to create
753  * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise
754  */
755 int
756 GNUNET_DISK_directory_create (const char *dir);
757
758
759 /**
760  * Lock a part of a file.
761  *
762  * @param fh file handle
763  * @param lock_start absolute position from where to lock
764  * @param lock_end absolute position until where to lock
765  * @param excl #GNUNET_YES for an exclusive lock
766  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
767  */
768 int
769 GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, 
770                        OFF_T lock_start,
771                        OFF_T lock_end, int excl);
772
773
774 /**
775  * Unlock a part of a file.
776  *
777  * @param fh file handle
778  * @param unlock_start absolute position from where to unlock
779  * @param unlock_end absolute position until where to unlock
780  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
781  */
782 int
783 GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, 
784                          OFF_T unlock_start,
785                          OFF_T unlock_end);
786
787
788 /**
789  * @brief Removes special characters as ':' from a filename.
790  * @param fn the filename to canonicalize
791  */
792 void
793 GNUNET_DISK_filename_canonicalize (char *fn);
794
795
796 /**
797  * @brief Change owner of a file
798  * @param filename file to change
799  * @param user new owner of the file
800  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
801  */
802 int
803 GNUNET_DISK_file_change_owner (const char *filename, const char *user);
804
805
806 /**
807  * Construct full path to a file inside of the private
808  * directory used by GNUnet.  Also creates the corresponding
809  * directory.  If the resulting name is supposed to be
810  * a directory, end the last argument in '/' (or pass
811  * DIR_SEPARATOR_STR as the last argument before NULL).
812  *
813  * @param cfg configuration to use
814  * @param service_name name of the service asking
815  * @param ... is NULL-terminated list of
816  *                path components to append to the
817  *                private directory name.
818  * @return the constructed filename
819  */
820 char *
821 GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
822                                const char *service_name, ...);
823
824
825 /**
826  * Opaque handle for a memory-mapping operation.
827  */
828 struct GNUNET_DISK_MapHandle;
829
830 /**
831  * Map a file into memory
832  * @param h open file handle
833  * @param m handle to the new mapping (will be set)
834  * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx
835  * @param len size of the mapping
836  * @return pointer to the mapped memory region, NULL on failure
837  */
838 void *
839 GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
840                       struct GNUNET_DISK_MapHandle **m,
841                       enum GNUNET_DISK_MapType access, size_t len);
842
843 /**
844  * Unmap a file
845  *
846  * @param h mapping handle
847  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
848  */
849 int
850 GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
851
852 /**
853  * Write file changes to disk
854  * @param h handle to an open file
855  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
856  */
857 int
858 GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
859
860
861 #if 0                           /* keep Emacsens' auto-indent happy */
862 {
863 #endif
864 #ifdef __cplusplus
865 }
866 #endif
867
868
869 /* ifndef GNUNET_DISK_LIB_H */
870 #endif
871 /* end of gnunet_disk_lib.h */