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