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