GNUnet  0.11.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 {
67  int fd;
68 };
69 
70 
71 /* we need size_t, and since it can be both unsigned int
72  or unsigned long long, this IS platform dependent;
73  but "stdlib.h" should be portable 'enough' to be
74  unconditionally available... */
75 #include <stdlib.h>
77 #include "gnunet_scheduler_lib.h"
78 
79 #ifdef __cplusplus
80 extern "C"
81 {
82 #if 0 /* keep Emacsens' auto-indent happy */
83 }
84 #endif
85 #endif
86 
87 
92 {
97 
102 
107 
112 
117 
122 
127 };
128 
133 {
138 
143 
148 };
149 
150 
155 {
160 
165 
170 
175 
180 
185 
190 
195 
200 
205 };
206 
207 
213 {
218 
223 
228 };
229 
230 
235 {
240 
245 };
246 
247 
254 int
256 
257 
266 int
267 GNUNET_DISK_file_test (const char *fil);
268 
269 
277 void
278 GNUNET_DISK_file_backup (const char *fil);
279 
280 
288 off_t
289 GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
290  enum GNUNET_DISK_Seek whence);
291 
292 
307 int
308 GNUNET_DISK_file_size (const char *filename,
309  uint64_t *size,
310  int include_symbolic_links,
311  int single_file_mode);
312 
313 
329 int
331  uint64_t *dev,
332  uint64_t *ino);
333 
334 
346 char *
347 GNUNET_DISK_mktemp (const char *t);
348 
349 
359 char *
360 GNUNET_DISK_mkdtemp (const char *t);
361 
362 
375 struct GNUNET_DISK_FileHandle *
376 GNUNET_DISK_file_open (const char *fn,
377  enum GNUNET_DISK_OpenFlags flags,
379 
380 
388 int
390  off_t *size);
391 
392 
402 struct GNUNET_DISK_PipeHandle *
403 GNUNET_DISK_pipe (int blocking_read,
404  int blocking_write,
405  int inherit_read,
406  int inherit_write);
407 
408 
418 struct GNUNET_DISK_PipeHandle *
419 GNUNET_DISK_pipe_from_fd (int blocking_read,
420  int blocking_write,
421  int fd[2]);
422 
423 
429 int
431 
432 
440 int
442  enum GNUNET_DISK_PipeEnd end);
443 
444 
457 struct GNUNET_DISK_FileHandle *
459  enum GNUNET_DISK_PipeEnd end);
460 
467 int
469 
470 
478 const struct GNUNET_DISK_FileHandle *
480  enum GNUNET_DISK_PipeEnd n);
481 
491 void
492 GNUNET_DISK_fix_permissions (const char *fn,
493  int require_uid_match,
494  int require_gid_match);
495 
496 
503 struct GNUNET_DISK_FileHandle *
505 
506 
513 struct GNUNET_DISK_FileHandle *
515 
516 
525 ssize_t
527  void *result,
528  size_t len);
529 
530 
541 ssize_t
543  void *result,
544  size_t len);
545 
546 
555 ssize_t
556 GNUNET_DISK_fn_read (const char *fn,
557  void *result,
558  size_t len);
559 
560 
569 ssize_t
571  const void *buffer,
572  size_t n);
573 
574 
583 ssize_t
585  const void *buffer,
586  size_t n);
587 
588 
599 ssize_t
600 GNUNET_DISK_fn_write (const char *fn,
601  const void *buffer,
602  size_t n,
604 
605 
613 int
614 GNUNET_DISK_file_copy (const char *src,
615  const char *dst);
616 
617 
626 int
628  GNUNET_FileNameCallback callback,
629  void *callback_cls);
630 
631 
640 int
642 
643 
656 int
657 GNUNET_DISK_directory_test (const char *fil, int is_readable);
658 
659 
667 int
669 
670 
678 void
680  const char *option);
681 
682 
689 int
690 GNUNET_DISK_directory_create (const char *dir);
691 
692 
702 int
704  off_t lock_start,
705  off_t lock_end, int excl);
706 
707 
716 int
718  off_t unlock_start,
719  off_t unlock_end);
720 
721 
726 void
728 
729 
736 int
738  const char *user);
739 
740 
744 struct GNUNET_DISK_MapHandle;
745 
746 
755 void *
757  struct GNUNET_DISK_MapHandle **m,
758  enum GNUNET_DISK_MapType access,
759  size_t len);
760 
761 
768 int
770 
771 
778 int
780 
781 
782 #if 0 /* keep Emacsens' auto-indent happy */
783 {
784 #endif
785 #ifdef __cplusplus
786 }
787 #endif
788 
789 /* ifndef GNUNET_DISK_LIB_H */
790 #endif
791  /* end of group */
793 
794 /* 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:1831
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:544
Open the file for reading.
int GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1500
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:89
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:1345
int GNUNET_DISK_file_copy(const char *src, const char *dst)
Copy a file.
Definition: disk.c:1072
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:1233
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:732
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:589
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:1440
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:503
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:684
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:291
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:912
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:226
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
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:880
int GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
Definition: disk.c:192
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:1753
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
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:1682
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:820
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
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:436
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:844
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:1526
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:1201
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:1477
Open the file for writing.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:409
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:257
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1715
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:1560
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:1643
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1375
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:206
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:1169
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:379
int fd
File handle on Unix-like systems.
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:757
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
Definition: disk.c:1397
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:1268
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:68
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:794
void GNUNET_DISK_filename_canonicalize(char *fn)
Removes special characters as &#39;:&#39; from a filename.
Definition: disk.c:1140
Handle for a memory-mapping operation.
Definition: disk.c:1412
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...