0f36353b009b3bfc308172141dc0bd92e0367e8e
[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 2, 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  * Get the number of blocks that are left on the partition that
272  * contains the given file (for normal users).
273  *
274  * @param part a file on the partition to check
275  * @return -1 on errors, otherwise the number of free blocks
276  */
277 long
278 GNUNET_DISK_get_blocks_available (const char *part);
279
280
281 /**
282  * Checks whether a handle is invalid
283  *
284  * @param h handle to check
285  * @return GNUNET_YES if invalid, GNUNET_NO if valid
286  */
287 int
288 GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
289
290
291 /**
292  * Check that fil corresponds to a filename
293  * (of a file that exists and that is not a directory).
294  *
295  * @param fil filename to check
296  * @return GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something
297  * else (will print an error message in that case, too).
298  */
299 int
300 GNUNET_DISK_file_test (const char *fil);
301
302
303 /**
304  * Move a file out of the way (create a backup) by
305  * renaming it to "orig.NUM~" where NUM is the smallest
306  * number that is not used yet.
307  *
308  * @param fil name of the file to back up
309  */
310 void
311 GNUNET_DISK_file_backup (const char *fil);
312
313
314 /**
315  * Move the read/write pointer in a file
316  * @param h handle of an open file
317  * @param offset position to move to
318  * @param whence specification to which position the offset parameter relates to
319  * @return the new position on success, GNUNET_SYSERR otherwise
320  */
321 OFF_T
322 GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset,
323                        enum GNUNET_DISK_Seek whence);
324
325
326 /**
327  * Get the size of the file (or directory) of the given file (in
328  * bytes).
329  *
330  * @param filename name of the file or directory
331  * @param size set to the size of the file (or,
332  *             in the case of directories, the sum
333  *             of all sizes of files in the directory)
334  * @param includeSymLinks should symbolic links be
335  *        included?
336  * @param singleFileMode GNUNET_YES to only get size of one file
337  *        and return GNUNET_SYSERR for directories.
338  * @return GNUNET_SYSERR on error, GNUNET_OK on success
339  */
340 int
341 GNUNET_DISK_file_size (const char *filename, uint64_t * size,
342                        int includeSymLinks, int singleFileMode);
343
344
345 /**
346  * Obtain some unique identifiers for the given file
347  * that can be used to identify it in the local system.
348  * This function is used between GNUnet processes to
349  * quickly check if two files with the same absolute path
350  * are actually identical.  The two processes represent
351  * the same peer but may communicate over the network
352  * (and the file may be on an NFS volume).  This function
353  * may not be supported on all operating systems.
354  *
355  * @param filename name of the file
356  * @param dev set to the device ID
357  * @param ino set to the inode ID
358  * @return GNUNET_OK on success
359  */
360 int
361 GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
362                                   uint64_t * ino);
363
364
365 /**
366  * Create an (empty) temporary file on disk.  If the given name is not
367  * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
368  * 6 random characters will be appended to the name to create a unique
369  * filename.
370  *
371  * @param t component to use for the name;
372  *        does NOT contain "XXXXXX" or "/tmp/".
373  * @return NULL on error, otherwise name of fresh
374  *         file on disk in directory for temporary files
375  */
376 char *
377 GNUNET_DISK_mktemp (const char *t);
378
379
380 /**
381  * Create an (empty) temporary directory on disk.  If the given name is not an
382  * absolute path, the current 'TMPDIR' will be prepended.  In any case, 6
383  * random characters will be appended to the name to create a unique name.
384  *
385  * @param t component to use for the name;
386  *        does NOT contain "XXXXXX" or "/tmp/".
387  * @return NULL on error, otherwise name of freshly created directory
388  */
389 char *
390 GNUNET_DISK_mkdtemp (const char *t);
391
392
393 /**
394  * Open a file.  Note that the access permissions will only be
395  * used if a new file is created and if the underlying operating
396  * system supports the given permissions.
397  *
398  * @param fn file name to be opened
399  * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags
400  * @param perm permissions for the newly created file, use
401  *             GNUNET_DISK_PERM_NONE if a file could not be created by this
402  *             call (because of flags)
403  * @return IO handle on success, NULL on error
404  */
405 struct GNUNET_DISK_FileHandle *
406 GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
407                        enum GNUNET_DISK_AccessPermissions perm);
408
409
410 /**
411  * Get the size of an open file.
412  *
413  * @param fh open file handle
414  * @param size where to write size of the file
415  * @return GNUNET_OK on success, GNUNET_SYSERR on error
416  */
417 int
418 GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
419                               OFF_T *size);
420
421
422 /**
423  * Creates an interprocess channel
424  *
425  * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO
426  * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO
427  * @param inherit_read 1 to make read handle inheritable, 0 otherwise (NT only)
428  * @param inherit_write 1 to make write handle inheritable, 0 otherwise (NT only)
429  * @return handle to the new pipe, NULL on error
430  */
431 struct GNUNET_DISK_PipeHandle *
432 GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write);
433
434
435 /**
436  * Creates a pipe object from a couple of file descriptors.
437  * Useful for wrapping existing pipe FDs.
438  *
439  * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO
440  * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO
441  * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes
442  *
443  * @return handle to the new pipe, NULL on error
444  */
445 struct GNUNET_DISK_PipeHandle *
446 GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]);
447
448
449 /**
450  * Closes an interprocess channel
451  * @param p pipe
452  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
453  */
454 int
455 GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
456
457
458 /**
459  * Closes one half of an interprocess channel
460  *
461  * @param p pipe to close end of
462  * @param end which end of the pipe to close
463  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
464  */
465 int
466 GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
467                             enum GNUNET_DISK_PipeEnd end);
468
469 /**
470  * Detaches one of the ends from the pipe.
471  * Detached end is a fully-functional FileHandle, it will
472  * not be affected by anything you do with the pipe afterwards.
473  * Each end of a pipe can only be detched from it once (i.e.
474  * it is not duplicated).
475  *
476  * @param p pipe to detach an end from
477  * @param end which end of the pipe to detach
478  * @return Detached end on success, NULL on failure
479  * (or if that end is not present or is closed).
480  */
481 struct GNUNET_DISK_FileHandle *
482 GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
483                              enum GNUNET_DISK_PipeEnd end);
484
485 /**
486  * Close an open file.
487  *
488  * @param h file handle
489  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
490  */
491 int
492 GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
493
494
495 /**
496  * Get the handle to a particular pipe end
497  *
498  * @param p pipe
499  * @param n end to access
500  * @return handle for the respective end
501  */
502 const struct GNUNET_DISK_FileHandle *
503 GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
504                          enum GNUNET_DISK_PipeEnd n);
505
506
507 /**
508  * Get a handle from a native FD.
509  *
510  * @param fd native file descriptor
511  * @return file handle corresponding to the descriptor
512  */
513 struct GNUNET_DISK_FileHandle *
514 GNUNET_DISK_get_handle_from_native (FILE *fd);
515
516
517 /**
518  * Read the contents of a binary file into a buffer.
519  * @param h handle to an open file
520  * @param result the buffer to write the result to
521  * @param len the maximum number of bytes to read
522  * @return the number of bytes read on success, GNUNET_SYSERR on failure
523  */
524 ssize_t
525 GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result,
526                        size_t len);
527
528
529 /**
530  * Read the contents of a binary file into a buffer.
531  * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
532  * when no data can be read).
533  *
534  * @param h handle to an open file
535  * @param result the buffer to write the result to
536  * @param len the maximum number of bytes to read
537  * @return the number of bytes read on success, GNUNET_SYSERR on failure
538  */
539 ssize_t
540 GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
541                                     void *result, size_t len);
542
543
544 /**
545  * Read the contents of a binary file into a buffer.
546  *
547  * @param fn file name
548  * @param result the buffer to write the result to
549  * @param len the maximum number of bytes to read
550  * @return number of bytes read, GNUNET_SYSERR on failure
551  */
552 ssize_t
553 GNUNET_DISK_fn_read (const char *fn, void *result, size_t len);
554
555
556 /**
557  * Write a buffer to a file.
558  *
559  * @param h handle to open file
560  * @param buffer the data to write
561  * @param n number of bytes to write
562  * @return number of bytes written on success, GNUNET_SYSERR on error
563  */
564 ssize_t
565 GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
566                         const void *buffer, size_t n);
567
568
569 /**
570  * Write a buffer to a file, blocking, if necessary.
571  * @param h handle to open file
572  * @param buffer the data to write
573  * @param n number of bytes to write
574  * @return number of bytes written on success, GNUNET_SYSERR on error
575  */
576 ssize_t
577 GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
578     const void *buffer, size_t n);
579
580 /**
581  * Write a buffer to a file.  If the file is longer than
582  * the given buffer size, it will be truncated.
583  *
584  * @param fn file name
585  * @param buffer the data to write
586  * @param n number of bytes to write
587  * @param mode file permissions
588  * @return number of bytes written on success, GNUNET_SYSERR on error
589  */
590 ssize_t
591 GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
592                       enum GNUNET_DISK_AccessPermissions mode);
593
594
595 /**
596  * Copy a file.
597  *
598  * @param src file to copy
599  * @param dst destination file name
600  * @return GNUNET_OK on success, GNUNET_SYSERR on error
601  */
602 int
603 GNUNET_DISK_file_copy (const char *src, const char *dst);
604
605
606 /**
607  * Scan a directory for files.
608  *
609  * @param dirName the name of the directory
610  * @param callback the method to call for each file
611  * @param callback_cls closure for callback
612  * @return the number of files found, -1 on error
613  */
614 int
615 GNUNET_DISK_directory_scan (const char *dirName,
616                             GNUNET_FileNameCallback callback,
617                             void *callback_cls);
618
619
620 /**
621  * Opaque handle used for iterating over a directory.
622  */
623 struct GNUNET_DISK_DirectoryIterator;
624
625
626 /**
627  * Function called to iterate over a directory.
628  *
629  * @param cls closure
630  * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to
631  *           get called on the next entry (or finish cleanly);
632  *           NULL on error (will be the last call in that case)
633  * @param filename complete filename (absolute path)
634  * @param dirname directory name (absolute path)
635  */
636 typedef void (*GNUNET_DISK_DirectoryIteratorCallback) (void *cls,
637                                                        struct
638                                                        GNUNET_DISK_DirectoryIterator
639                                                        * di,
640                                                        const char *filename,
641                                                        const char *dirname);
642
643
644 /**
645  * This function must be called during the DiskIteratorCallback
646  * (exactly once) to schedule the task to process the next
647  * filename in the directory (if there is one).
648  *
649  * @param iter opaque handle for the iterator
650  * @param can set to GNUNET_YES to terminate the iteration early
651  * @return GNUNET_YES if iteration will continue,
652  *         GNUNET_NO if this was the last entry (and iteration is complete),
653  *         GNUNET_SYSERR if "can" was YES
654  */
655 int
656 GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
657                                      int can);
658
659
660 /**
661  * Scan a directory for files using the scheduler to run a task for
662  * each entry.  The name of the directory must be expanded first (!).
663  * If a scheduler does not need to be used, GNUNET_DISK_directory_scan
664  * may provide a simpler API.
665  *
666  * @param prio priority to use
667  * @param dirName the name of the directory
668  * @param callback the method to call for each file
669  * @param callback_cls closure for callback
670  * @return GNUNET_YES if directory is not empty and 'callback'
671  *         will be called later, GNUNET_NO otherwise, GNUNET_SYSERR on error.
672  */
673 int
674 GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
675                                       const char *dirName,
676                                       GNUNET_DISK_DirectoryIteratorCallback
677                                       callback, void *callback_cls);
678
679
680 /**
681  * Create the directory structure for storing
682  * a file.
683  *
684  * @param filename name of a file in the directory
685  * @returns GNUNET_OK on success, GNUNET_SYSERR on failure,
686  *          GNUNET_NO if directory exists but is not writeable
687  */
688 int
689 GNUNET_DISK_directory_create_for_file (const char *filename);
690
691
692 /**
693  * Test if "fil" is a directory and listable. Optionally, also check if the
694  * directory is readable.  Will not print an error message if the directory does
695  * not exist.  Will log errors if GNUNET_SYSERR is returned (i.e., a file exists
696  * with the same name).
697  *
698  * @param fil filename to test
699  * @param is_readable GNUNET_YES to additionally check if "fil" is readable;
700  *          GNUNET_NO to disable this check
701  * @return GNUNET_YES if yes, GNUNET_NO if not; GNUNET_SYSERR if it
702  *           does not exist or stat'ed
703  */
704 int
705 GNUNET_DISK_directory_test (const char *fil, int is_readable);
706
707
708 /**
709  * Remove all files in a directory (rm -rf). Call with
710  * caution.
711  *
712  * @param filename the file to remove
713  * @return GNUNET_OK on success, GNUNET_SYSERR on error
714  */
715 int
716 GNUNET_DISK_directory_remove (const char *filename);
717
718
719 /**
720  * Implementation of "mkdir -p"
721  *
722  * @param dir the directory to create
723  * @returns GNUNET_SYSERR on failure, GNUNET_OK otherwise
724  */
725 int
726 GNUNET_DISK_directory_create (const char *dir);
727
728
729 /**
730  * Lock a part of a file.
731  *
732  * @param fh file handle
733  * @param lockStart absolute position from where to lock
734  * @param lockEnd absolute position until where to lock
735  * @param excl GNUNET_YES for an exclusive lock
736  * @return GNUNET_OK on success, GNUNET_SYSERR on error
737  */
738 int
739 GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart,
740                        OFF_T lockEnd, int excl);
741
742
743 /**
744  * Unlock a part of a file
745  * @param fh file handle
746  * @param unlockStart absolute position from where to unlock
747  * @param unlockEnd absolute position until where to unlock
748  * @return GNUNET_OK on success, GNUNET_SYSERR on error
749  */
750 int
751 GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart,
752                          OFF_T unlockEnd);
753
754
755 /**
756  * @brief Removes special characters as ':' from a filename.
757  * @param fn the filename to canonicalize
758  */
759 void
760 GNUNET_DISK_filename_canonicalize (char *fn);
761
762
763 /**
764  * @brief Change owner of a file
765  * @param filename file to change
766  * @param user new owner of the file
767  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
768  */
769 int
770 GNUNET_DISK_file_change_owner (const char *filename, const char *user);
771
772
773 /**
774  * Construct full path to a file inside of the private
775  * directory used by GNUnet.  Also creates the corresponding
776  * directory.  If the resulting name is supposed to be
777  * a directory, end the last argument in '/' (or pass
778  * DIR_SEPARATOR_STR as the last argument before NULL).
779  *
780  * @param cfg configuration to use
781  * @param serviceName name of the service asking
782  * @param ... is NULL-terminated list of
783  *                path components to append to the
784  *                private directory name.
785  * @return the constructed filename
786  */
787 char *
788 GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
789                                const char *serviceName, ...);
790
791
792 /**
793  * Opaque handle for a memory-mapping operation.
794  */
795 struct GNUNET_DISK_MapHandle;
796
797 /**
798  * Map a file into memory
799  * @param h open file handle
800  * @param m handle to the new mapping (will be set)
801  * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx
802  * @param len size of the mapping
803  * @return pointer to the mapped memory region, NULL on failure
804  */
805 void *
806 GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
807                       struct GNUNET_DISK_MapHandle **m,
808                       enum GNUNET_DISK_MapType access, size_t len);
809
810 /**
811  * Unmap a file
812  *
813  * @param h mapping handle
814  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
815  */
816 int
817 GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
818
819 /**
820  * Write file changes to disk
821  * @param h handle to an open file
822  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
823  */
824 int
825 GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
826
827
828 #if 0                           /* keep Emacsens' auto-indent happy */
829 {
830 #endif
831 #ifdef __cplusplus
832 }
833 #endif
834
835
836 /* ifndef GNUNET_DISK_LIB_H */
837 #endif
838 /* end of gnunet_disk_lib.h */