GNUnet  0.10.x
gnunet_disk_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2001-2012 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
30 #ifndef GNUNET_DISK_LIB_H
31 #define GNUNET_DISK_LIB_H
32 
37 
42 {
47 
52 
57 };
58 
63 {
64 
65 #if WINDOWS
66 
69  HANDLE h;
70 
75 
79  OVERLAPPED *oOverlapRead;
80 
84  OVERLAPPED *oOverlapWrite;
85 #else
86 
90  int fd;
91 
92 #endif
93 };
94 
95 
96 /* we need size_t, and since it can be both unsigned int
97  or unsigned long long, this IS platform dependent;
98  but "stdlib.h" should be portable 'enough' to be
99  unconditionally available... */
100 #include <stdlib.h>
102 #include "gnunet_scheduler_lib.h"
103 
104 #ifdef __cplusplus
105 extern "C"
106 {
107 #if 0 /* keep Emacsens' auto-indent happy */
108 }
109 #endif
110 #endif
111 
112 
117 {
118 
123 
128 
133 
138 
143 
148 
153 };
154 
159 {
164 
169 
174 };
175 
176 
181 {
186 
191 
196 
201 
206 
211 
216 
221 
226 
231 };
232 
233 
239 {
244 
249 
254 };
255 
256 
261 {
266 
271 };
272 
273 
280 int
282 
283 
292 int
293 GNUNET_DISK_file_test (const char *fil);
294 
295 
303 void
304 GNUNET_DISK_file_backup (const char *fil);
305 
306 
314 off_t
315 GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
316  enum GNUNET_DISK_Seek whence);
317 
318 
333 int
334 GNUNET_DISK_file_size (const char *filename,
335  uint64_t *size,
336  int include_symbolic_links,
337  int single_file_mode);
338 
339 
355 int
357  uint64_t *dev,
358  uint64_t *ino);
359 
360 
372 char *
373 GNUNET_DISK_mktemp (const char *t);
374 
375 
385 char *
386 GNUNET_DISK_mkdtemp (const char *t);
387 
388 
401 struct GNUNET_DISK_FileHandle *
402 GNUNET_DISK_file_open (const char *fn,
403  enum GNUNET_DISK_OpenFlags flags,
405 
406 
414 int
416  off_t *size);
417 
418 
428 struct GNUNET_DISK_PipeHandle *
429 GNUNET_DISK_pipe (int blocking_read,
430  int blocking_write,
431  int inherit_read,
432  int inherit_write);
433 
434 
445 struct GNUNET_DISK_PipeHandle *
446 GNUNET_DISK_pipe_from_fd (int blocking_read,
447  int blocking_write,
448  int fd[2]);
449 
450 
456 int
458 
459 
467 int
469  enum GNUNET_DISK_PipeEnd end);
470 
471 
484 struct GNUNET_DISK_FileHandle *
486  enum GNUNET_DISK_PipeEnd end);
487 
494 int
496 
497 
505 const struct GNUNET_DISK_FileHandle *
507  enum GNUNET_DISK_PipeEnd n);
508 
509 
510 #if WINDOWS
511 
518 struct GNUNET_DISK_FileHandle *
519 GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh);
520 #endif
521 
531 void
532 GNUNET_DISK_fix_permissions (const char *fn,
533  int require_uid_match,
534  int require_gid_match);
535 
536 
543 struct GNUNET_DISK_FileHandle *
545 
546 
553 struct GNUNET_DISK_FileHandle *
555 
556 
565 ssize_t
567  void *result,
568  size_t len);
569 
570 
581 ssize_t
583  void *result,
584  size_t len);
585 
586 
595 ssize_t
596 GNUNET_DISK_fn_read (const char *fn,
597  void *result,
598  size_t len);
599 
600 
609 ssize_t
611  const void *buffer,
612  size_t n);
613 
614 
623 ssize_t
625  const void *buffer,
626  size_t n);
627 
628 
639 ssize_t
640 GNUNET_DISK_fn_write (const char *fn,
641  const void *buffer,
642  size_t n,
644 
645 
653 int
654 GNUNET_DISK_file_copy (const char *src,
655  const char *dst);
656 
657 
666 int
668  GNUNET_FileNameCallback callback,
669  void *callback_cls);
670 
671 
680 int
682 
683 
696 int
697 GNUNET_DISK_directory_test (const char *fil, int is_readable);
698 
699 
707 int
709 
710 
718 void
720  const char *option);
721 
722 
729 int
730 GNUNET_DISK_directory_create (const char *dir);
731 
732 
742 int
744  off_t lock_start,
745  off_t lock_end, int excl);
746 
747 
756 int
758  off_t unlock_start,
759  off_t unlock_end);
760 
761 
766 void
768 
769 
776 int
778  const char *user);
779 
780 
784 struct GNUNET_DISK_MapHandle;
785 
786 
795 void *
797  struct GNUNET_DISK_MapHandle **m,
798  enum GNUNET_DISK_MapType access,
799  size_t len);
800 
801 
808 int
810 
811 
818 int
820 
821 
822 #if 0 /* keep Emacsens' auto-indent happy */
823 {
824 #endif
825 #ifdef __cplusplus
826 }
827 #endif
828 
829 /* ifndef GNUNET_DISK_LIB_H */
830 #endif
831  /* end of group */
833 
834 /* end of gnunet_disk_lib.h */
void GNUNET_DISK_purge_cfg_dir(const char *cfg_filename, const char *option)
Remove the directory given under option in section [PATHS] in configuration under cfg_filename...
Definition: disk.c:2731
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:669
Open the file for reading.
int GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:2133
static char * cfg_filename
Name of the configuration file.
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:84
Create file if it doesn&#39;t exist.
GNUNET_DISK_MapType
Specifies what type of memory map is desired.
static const char * dir_name
Top-level directory we monitor to auto-publish.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
int GNUNET_DISK_file_copy(const char *src, const char *dst)
Copy a file.
Definition: disk.c:1411
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
int GNUNET_DISK_file_unlock(struct GNUNET_DISK_FileHandle *fh, off_t unlock_start, off_t unlock_end)
Unlock a part of a file.
Definition: disk.c:1618
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:881
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:714
Read-write memory map.
Seek a relative position (from the current offset).
GNUNET_FILE_Type
Type of a handle.
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:2020
Handle represents a file.
Everybody can execute.
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:628
Nobody is allowed to do anything to the file.
GNUNET_DISK_Seek
Constants for specifying how to seek.
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
Append to the file.
int GNUNET_DISK_file_get_identifiers(const char *filename, uint64_t *dev, uint64_t *ino)
Obtain some unique identifiers for the given file that can be used to identify it in the local system...
Definition: disk.c:323
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
static struct GNUNET_SCHEDULER_Task * t
Main task.
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:241
ssize_t GNUNET_DISK_fn_write(const char *fn, const void *buffer, size_t n, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file.
Definition: disk.c:1203
int GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
Definition: disk.c:191
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:593
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_detach_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Detaches one of the ends from the pipe.
Definition: disk.c:2570
static char * fn
Filename of the unique file.
Truncate file if it exists.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1359
Read-only memory map.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char * filename
static int result
Global testing status.
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
The writing-end of a pipe.
The reading-end of a pipe.
static int fh
Handle to the unique file.
void GNUNET_DISK_file_backup(const char *fil)
Move a file out of the way (create a backup) by renaming it to "orig.NUM~" where NUM is the smallest ...
Definition: disk.c:557
int(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
ssize_t GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file, blocking, if necessary.
Definition: disk.c:1139
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:2289
Handle represents a pipe.
int GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh, off_t lock_start, off_t lock_end, int excl)
Lock a part of a file.
Definition: disk.c:1564
static unsigned int size
Size of the "table".
Definition: peer.c:67
Seek an absolute position from the end of the file.
Everybody can write.
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
Open the file for writing.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:530
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe_from_fd(int blocking_read, int blocking_write, int fd[2])
Creates a pipe object from a couple of file descriptors.
Definition: disk.c:2410
Everybody can read.
int GNUNET_DISK_pipe_close_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Closes one half of an interprocess channel.
Definition: disk.c:2532
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1937
Seek an absolute position (from the start of the file).
int GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:208
GNUNET_DISK_OpenFlags
Specifies how a file should be opened.
Handle represents an event.
Open the file for both reading and writing.
int GNUNET_DISK_file_change_owner(const char *filename, const char *user)
Change owner of a file.
Definition: disk.c:1525
Write-able memory map.
void GNUNET_DISK_fix_permissions(const char *fn, int require_uid_match, int require_gid_match)
Update POSIX permissions mask of a file on disk.
Definition: disk.c:498
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
int fd
File handle on other OSes.
Fail if file already exists.
ssize_t GNUNET_DISK_file_read_non_blocking(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:941
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
Definition: disk.c:1970
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
GNUNET_DISK_PipeEnd
Enumeration identifying the two ends of a pipe.
Handle used to access files (and pipes).
Handle used to manage a pipe.
Definition: disk.c:66
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:1019
void GNUNET_DISK_filename_canonicalize(char *fn)
Removes special characters as &#39;:&#39; from a filename.
Definition: disk.c:1497
static enum @11 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
Handle for a memory-mapping operation.
Definition: disk.c:1985
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...