-doxygen fixes
[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 #else
510
511 /**
512  * Update POSIX permissions mask of a file on disk.  If both argumets
513  * are #GNUNET_NO, the file is made world-read-write-executable (777).
514  *
515  * @param fn name of the file to update
516  * @param require_uid_match #GNUNET_YES means 700
517  * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set
518  */
519 void
520 GNUNET_DISK_fix_permissions (const char *fn,
521                              int require_uid_match,
522                              int require_gid_match);
523
524 #endif
525
526
527 /**
528  * Get a handle from a native integer FD.
529  *
530  * @param fno native integer file descriptor
531  * @return file handle corresponding to the descriptor
532  */
533 struct GNUNET_DISK_FileHandle *
534 GNUNET_DISK_get_handle_from_int_fd (int fno);
535
536
537 /**
538  * Get a handle from a native FD.
539  *
540  * @param fd native file descriptor
541  * @return file handle corresponding to the descriptor
542  */
543 struct GNUNET_DISK_FileHandle *
544 GNUNET_DISK_get_handle_from_native (FILE *fd);
545
546
547 /**
548  * Read the contents of a binary file into a buffer.
549  *
550  * @param h handle to an open file
551  * @param result the buffer to write the result to
552  * @param len the maximum number of bytes to read
553  * @return the number of bytes read on success, #GNUNET_SYSERR on failure
554  */
555 ssize_t
556 GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
557                        void *result,
558                        size_t len);
559
560
561 /**
562  * Read the contents of a binary file into a buffer.
563  * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
564  * when no data can be read).
565  *
566  * @param h handle to an open file
567  * @param result the buffer to write the result to
568  * @param len the maximum number of bytes to read
569  * @return the number of bytes read on success, #GNUNET_SYSERR on failure
570  */
571 ssize_t
572 GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
573                                     void *result,
574                                     size_t len);
575
576
577 /**
578  * Read the contents of a binary file into a buffer.
579  *
580  * @param fn file name
581  * @param result the buffer to write the result to
582  * @param len the maximum number of bytes to read
583  * @return number of bytes read, #GNUNET_SYSERR on failure
584  */
585 ssize_t
586 GNUNET_DISK_fn_read (const char *fn,
587                      void *result,
588                      size_t len);
589
590
591 /**
592  * Write a buffer to a file.
593  *
594  * @param h handle to open file
595  * @param buffer the data to write
596  * @param n number of bytes to write
597  * @return number of bytes written on success, #GNUNET_SYSERR on error
598  */
599 ssize_t
600 GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
601                         const void *buffer,
602                         size_t n);
603
604
605 /**
606  * Write a buffer to a file, blocking, if necessary.
607  *
608  * @param h handle to open file
609  * @param buffer the data to write
610  * @param n number of bytes to write
611  * @return number of bytes written on success, #GNUNET_SYSERR on error
612  */
613 ssize_t
614 GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
615                                  const void *buffer,
616                                  size_t n);
617
618
619 /**
620  * Write a buffer to a file.  If the file is longer than
621  * the given buffer size, it will be truncated.
622  *
623  * @param fn file name
624  * @param buffer the data to write
625  * @param n number of bytes to write
626  * @param mode file permissions
627  * @return number of bytes written on success, #GNUNET_SYSERR on error
628  */
629 ssize_t
630 GNUNET_DISK_fn_write (const char *fn,
631                       const void *buffer,
632                       size_t n,
633                       enum GNUNET_DISK_AccessPermissions mode);
634
635
636 /**
637  * Copy a file.
638  *
639  * @param src file to copy
640  * @param dst destination file name
641  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
642  */
643 int
644 GNUNET_DISK_file_copy (const char *src, const char *dst);
645
646
647 /**
648  * Scan a directory for files.
649  *
650  * @param dir_name the name of the directory
651  * @param callback the method to call for each file
652  * @param callback_cls closure for @a callback
653  * @return the number of files found, -1 on error
654  */
655 int
656 GNUNET_DISK_directory_scan (const char *dir_name,
657                             GNUNET_FileNameCallback callback,
658                             void *callback_cls);
659
660
661 /**
662  * Opaque handle used for iterating over a directory.
663  */
664 struct GNUNET_DISK_DirectoryIterator;
665
666
667 /**
668  * Function called to iterate over a directory.
669  *
670  * @param cls closure
671  * @param di argument to pass to #GNUNET_DISK_directory_iterator_next to
672  *           get called on the next entry (or finish cleanly);
673  *           NULL on error (will be the last call in that case)
674  * @param filename complete filename (absolute path)
675  * @param dirname directory name (absolute path)
676  */
677 typedef void (*GNUNET_DISK_DirectoryIteratorCallback) (void *cls,
678                                                        struct GNUNET_DISK_DirectoryIterator *di,
679                                                        const char *filename,
680                                                        const char *dirname);
681
682
683 /**
684  * This function must be called during the DiskIteratorCallback
685  * (exactly once) to schedule the task to process the next
686  * filename in the directory (if there is one).
687  *
688  * @param iter opaque handle for the iterator
689  * @param can set to #GNUNET_YES to terminate the iteration early
690  * @return #GNUNET_YES if iteration will continue,
691  *         #GNUNET_NO if this was the last entry (and iteration is complete),
692  *         #GNUNET_SYSERR if @a can was #GNUNET_YES
693  */
694 int
695 GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
696                                      int can);
697
698
699 /**
700  * Scan a directory for files using the scheduler to run a task for
701  * each entry.  The name of the directory must be expanded first (!).
702  * If a scheduler does not need to be used, GNUNET_DISK_directory_scan
703  * may provide a simpler API.
704  *
705  * @param prio priority to use
706  * @param dir_name the name of the directory
707  * @param callback the method to call for each file
708  * @param callback_cls closure for @a callback
709  * @return #GNUNET_YES if directory is not empty and @a callback
710  *         will be called later, #GNUNET_NO otherwise, #GNUNET_SYSERR on error.
711  */
712 int
713 GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
714                                       const char *dir_name,
715                                       GNUNET_DISK_DirectoryIteratorCallback
716                                       callback, void *callback_cls);
717
718
719 /**
720  * Create the directory structure for storing
721  * a file.
722  *
723  * @param filename name of a file in the directory
724  * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure,
725  *          #GNUNET_NO if directory exists but is not writeable
726  */
727 int
728 GNUNET_DISK_directory_create_for_file (const char *filename);
729
730
731 /**
732  * Test if @a fil is a directory and listable. Optionally, also check if the
733  * directory is readable.  Will not print an error message if the directory does
734  * not exist.  Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists
735  * with the same name).
736  *
737  * @param fil filename to test
738  * @param is_readable #GNUNET_YES to additionally check if @a fil is readable;
739  *          #GNUNET_NO to disable this check
740  * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
741  *           does not exist or `stat`ed
742  */
743 int
744 GNUNET_DISK_directory_test (const char *fil, int is_readable);
745
746
747 /**
748  * Remove all files in a directory (rm -rf). Call with
749  * caution.
750  *
751  * @param filename the file to remove
752  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
753  */
754 int
755 GNUNET_DISK_directory_remove (const char *filename);
756
757
758 /**
759  * Implementation of "mkdir -p"
760  *
761  * @param dir the directory to create
762  * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise
763  */
764 int
765 GNUNET_DISK_directory_create (const char *dir);
766
767
768 /**
769  * Lock a part of a file.
770  *
771  * @param fh file handle
772  * @param lock_start absolute position from where to lock
773  * @param lock_end absolute position until where to lock
774  * @param excl #GNUNET_YES for an exclusive lock
775  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
776  */
777 int
778 GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
779                        off_t lock_start,
780                        off_t lock_end, int excl);
781
782
783 /**
784  * Unlock a part of a file.
785  *
786  * @param fh file handle
787  * @param unlock_start absolute position from where to unlock
788  * @param unlock_end absolute position until where to unlock
789  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
790  */
791 int
792 GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
793                          off_t unlock_start,
794                          off_t unlock_end);
795
796
797 /**
798  * @brief Removes special characters as ':' from a filename.
799  * @param fn the filename to canonicalize
800  */
801 void
802 GNUNET_DISK_filename_canonicalize (char *fn);
803
804
805 /**
806  * @brief Change owner of a file
807  * @param filename file to change
808  * @param user new owner of the file
809  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
810  */
811 int
812 GNUNET_DISK_file_change_owner (const char *filename, const char *user);
813
814
815 /**
816  * Opaque handle for a memory-mapping operation.
817  */
818 struct GNUNET_DISK_MapHandle;
819
820 /**
821  * Map a file into memory
822  * @param h open file handle
823  * @param m handle to the new mapping (will be set)
824  * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx
825  * @param len size of the mapping
826  * @return pointer to the mapped memory region, NULL on failure
827  */
828 void *
829 GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
830                       struct GNUNET_DISK_MapHandle **m,
831                       enum GNUNET_DISK_MapType access, size_t len);
832
833 /**
834  * Unmap a file
835  *
836  * @param h mapping handle
837  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
838  */
839 int
840 GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
841
842 /**
843  * Write file changes to disk
844  * @param h handle to an open file
845  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
846  */
847 int
848 GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
849
850
851 #if 0                           /* keep Emacsens' auto-indent happy */
852 {
853 #endif
854 #ifdef __cplusplus
855 }
856 #endif
857
858
859 /* ifndef GNUNET_DISK_LIB_H */
860 #endif
861 /* end of gnunet_disk_lib.h */