aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_disk_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_disk_lib.h')
-rw-r--r--src/include/gnunet_disk_lib.h187
1 files changed, 97 insertions, 90 deletions
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index fdccebab0..5732a27d6 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -36,7 +36,8 @@ struct GNUNET_DISK_FileHandle;
36struct GNUNET_DISK_PipeHandle; 36struct GNUNET_DISK_PipeHandle;
37 37
38 38
39enum GNUNET_FILE_Type { 39enum GNUNET_FILE_Type
40{
40 GNUNET_DISK_FILE, GNUNET_PIPE 41 GNUNET_DISK_FILE, GNUNET_PIPE
41}; 42};
42 43
@@ -74,7 +75,7 @@ struct GNUNET_DISK_FileHandle
74 int fd; 75 int fd;
75 76
76#endif /* 77#endif /*
77 */ 78 */
78}; 79};
79 80
80 81
@@ -99,159 +100,159 @@ extern "C"
99 * Specifies how a file should be opened. 100 * Specifies how a file should be opened.
100 */ 101 */
101enum GNUNET_DISK_OpenFlags 102enum GNUNET_DISK_OpenFlags
102 { 103{
103 104
104 /** 105 /**
105 * Open the file for reading 106 * Open the file for reading
106 */ 107 */
107 GNUNET_DISK_OPEN_READ = 1, 108 GNUNET_DISK_OPEN_READ = 1,
108 109
109 /** 110 /**
110 * Open the file for writing 111 * Open the file for writing
111 */ 112 */
112 GNUNET_DISK_OPEN_WRITE = 2, 113 GNUNET_DISK_OPEN_WRITE = 2,
113 114
114 /** 115 /**
115 * Open the file for both reading and writing 116 * Open the file for both reading and writing
116 */ 117 */
117 GNUNET_DISK_OPEN_READWRITE = 3, 118 GNUNET_DISK_OPEN_READWRITE = 3,
118 119
119 /** 120 /**
120 * Fail if file already exists 121 * Fail if file already exists
121 */ 122 */
122 GNUNET_DISK_OPEN_FAILIFEXISTS = 4, 123 GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
123 124
124 /** 125 /**
125 * Truncate file if it exists 126 * Truncate file if it exists
126 */ 127 */
127 GNUNET_DISK_OPEN_TRUNCATE = 8, 128 GNUNET_DISK_OPEN_TRUNCATE = 8,
128 129
129 /** 130 /**
130 * Create file if it doesn't exist 131 * Create file if it doesn't exist
131 */ 132 */
132 GNUNET_DISK_OPEN_CREATE = 16, 133 GNUNET_DISK_OPEN_CREATE = 16,
133 134
134 /** 135 /**
135 * Append to the file 136 * Append to the file
136 */ 137 */
137 GNUNET_DISK_OPEN_APPEND = 32 138 GNUNET_DISK_OPEN_APPEND = 32
138 }; 139};
139 140
140/** 141/**
141 * Specifies what type of memory map is desired. 142 * Specifies what type of memory map is desired.
142 */ 143 */
143enum GNUNET_DISK_MapType 144enum GNUNET_DISK_MapType
144 { 145{
145 /** 146 /**
146 * Read-only memory map. 147 * Read-only memory map.
147 */ 148 */
148 GNUNET_DISK_MAP_TYPE_READ = 1, 149 GNUNET_DISK_MAP_TYPE_READ = 1,
149 150
150 /** 151 /**
151 * Write-able memory map. 152 * Write-able memory map.
152 */ 153 */
153 GNUNET_DISK_MAP_TYPE_WRITE = 2, 154 GNUNET_DISK_MAP_TYPE_WRITE = 2,
154 /** 155 /**
155 * Read-write memory map. 156 * Read-write memory map.
156 */ 157 */
157 GNUNET_DISK_MAP_TYPE_READWRITE = 3 158 GNUNET_DISK_MAP_TYPE_READWRITE = 3
158 }; 159};
159 160
160 161
161/** 162/**
162 * File access permissions, UNIX-style. 163 * File access permissions, UNIX-style.
163 */ 164 */
164enum GNUNET_DISK_AccessPermissions 165enum GNUNET_DISK_AccessPermissions
165 { 166{
166 /** 167 /**
167 * Nobody is allowed to do anything to the file. 168 * Nobody is allowed to do anything to the file.
168 */ 169 */
169 GNUNET_DISK_PERM_NONE = 0, 170 GNUNET_DISK_PERM_NONE = 0,
170 171
171 /** 172 /**
172 * Owner can read. 173 * Owner can read.
173 */ 174 */
174 GNUNET_DISK_PERM_USER_READ = 1, 175 GNUNET_DISK_PERM_USER_READ = 1,
175 176
176 /** 177 /**
177 * Owner can write. 178 * Owner can write.
178 */ 179 */
179 GNUNET_DISK_PERM_USER_WRITE = 2, 180 GNUNET_DISK_PERM_USER_WRITE = 2,
180 181
181 /** 182 /**
182 * Owner can execute. 183 * Owner can execute.
183 */ 184 */
184 GNUNET_DISK_PERM_USER_EXEC = 4, 185 GNUNET_DISK_PERM_USER_EXEC = 4,
185 186
186 /** 187 /**
187 * Group can read. 188 * Group can read.
188 */ 189 */
189 GNUNET_DISK_PERM_GROUP_READ = 8, 190 GNUNET_DISK_PERM_GROUP_READ = 8,
190 191
191 /** 192 /**
192 * Group can write. 193 * Group can write.
193 */ 194 */
194 GNUNET_DISK_PERM_GROUP_WRITE = 16, 195 GNUNET_DISK_PERM_GROUP_WRITE = 16,
195 196
196 /** 197 /**
197 * Group can execute. 198 * Group can execute.
198 */ 199 */
199 GNUNET_DISK_PERM_GROUP_EXEC = 32, 200 GNUNET_DISK_PERM_GROUP_EXEC = 32,
200 201
201 /** 202 /**
202 * Everybody can read. 203 * Everybody can read.
203 */ 204 */
204 GNUNET_DISK_PERM_OTHER_READ = 64, 205 GNUNET_DISK_PERM_OTHER_READ = 64,
205 206
206 /** 207 /**
207 * Everybody can write. 208 * Everybody can write.
208 */ 209 */
209 GNUNET_DISK_PERM_OTHER_WRITE = 128, 210 GNUNET_DISK_PERM_OTHER_WRITE = 128,
210 211
211 /** 212 /**
212 * Everybody can execute. 213 * Everybody can execute.
213 */ 214 */
214 GNUNET_DISK_PERM_OTHER_EXEC = 256 215 GNUNET_DISK_PERM_OTHER_EXEC = 256
215 }; 216};
216 217
217 218
218/** 219/**
219 * Constants for specifying how to seek. 220 * Constants for specifying how to seek.
220 */ 221 */
221enum GNUNET_DISK_Seek 222enum GNUNET_DISK_Seek
222 { 223{
223 /** 224 /**
224 * Seek an absolute position (from the start of the file). 225 * Seek an absolute position (from the start of the file).
225 */ 226 */
226 GNUNET_DISK_SEEK_SET, 227 GNUNET_DISK_SEEK_SET,
227 228
228 /** 229 /**
229 * Seek a relative position (from the current offset). 230 * Seek a relative position (from the current offset).
230 */ 231 */
231 GNUNET_DISK_SEEK_CUR, 232 GNUNET_DISK_SEEK_CUR,
232 233
233 /** 234 /**
234 * Seek an absolute position from the end of the file. 235 * Seek an absolute position from the end of the file.
235 */ 236 */
236 GNUNET_DISK_SEEK_END 237 GNUNET_DISK_SEEK_END
237 }; 238};
238 239
239 240
240/** 241/**
241 * Enumeration identifying the two ends of a pipe. 242 * Enumeration identifying the two ends of a pipe.
242 */ 243 */
243enum GNUNET_DISK_PipeEnd 244enum GNUNET_DISK_PipeEnd
244 { 245{
245 /** 246 /**
246 * The reading-end of a pipe. 247 * The reading-end of a pipe.
247 */ 248 */
248 GNUNET_DISK_PIPE_END_READ = 0, 249 GNUNET_DISK_PIPE_END_READ = 0,
249 250
250 /** 251 /**
251 * The writing-end of a pipe. 252 * The writing-end of a pipe.
252 */ 253 */
253 GNUNET_DISK_PIPE_END_WRITE = 1 254 GNUNET_DISK_PIPE_END_WRITE = 1
254 }; 255};
255 256
256 257
257/** 258/**
@@ -292,9 +293,8 @@ int GNUNET_DISK_file_test (const char *fil);
292 * @return the new position on success, GNUNET_SYSERR otherwise 293 * @return the new position on success, GNUNET_SYSERR otherwise
293 */ 294 */
294off_t 295off_t
295GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, 296GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
296 off_t offset, 297 off_t offset, enum GNUNET_DISK_Seek whence);
297 enum GNUNET_DISK_Seek whence);
298 298
299 299
300/** 300/**
@@ -310,8 +310,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
310 * @return GNUNET_OK on success, GNUNET_SYSERR on error 310 * @return GNUNET_OK on success, GNUNET_SYSERR on error
311 */ 311 */
312int GNUNET_DISK_file_size (const char *filename, 312int GNUNET_DISK_file_size (const char *filename,
313 uint64_t *size, 313 uint64_t * size, int includeSymLinks);
314 int includeSymLinks);
315 314
316 315
317/** 316/**
@@ -330,9 +329,8 @@ int GNUNET_DISK_file_size (const char *filename,
330 * @return GNUNET_OK on success 329 * @return GNUNET_OK on success
331 */ 330 */
332int GNUNET_DISK_file_get_identifiers (const char *filename, 331int GNUNET_DISK_file_get_identifiers (const char *filename,
333 uint64_t *dev, 332 uint64_t * dev, uint64_t * ino);
334 uint64_t *ino); 333
335
336 334
337/** 335/**
338 * Create an (empty) temporary file on disk. If the given name is not 336 * Create an (empty) temporary file on disk. If the given name is not
@@ -345,8 +343,7 @@ int GNUNET_DISK_file_get_identifiers (const char *filename,
345 * @return NULL on error, otherwise name of fresh 343 * @return NULL on error, otherwise name of fresh
346 * file on disk in directory for temporary files 344 * file on disk in directory for temporary files
347 */ 345 */
348char * 346char *GNUNET_DISK_mktemp (const char *t);
349GNUNET_DISK_mktemp (const char *t);
350 347
351 348
352/** 349/**
@@ -362,8 +359,11 @@ GNUNET_DISK_mktemp (const char *t);
362 * @return IO handle on success, NULL on error 359 * @return IO handle on success, NULL on error
363 */ 360 */
364struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn, 361struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn,
365 enum GNUNET_DISK_OpenFlags flags, 362 enum GNUNET_DISK_OpenFlags
366 enum GNUNET_DISK_AccessPermissions perm); 363 flags,
364 enum
365 GNUNET_DISK_AccessPermissions
366 perm);
367 367
368/** 368/**
369 * Creates an interprocess channel 369 * Creates an interprocess channel
@@ -373,8 +373,8 @@ struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn,
373 * @return handle to the new pipe, NULL on error 373 * @return handle to the new pipe, NULL on error
374 */ 374 */
375struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking, 375struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking,
376 int inherit_read, 376 int inherit_read,
377 int inherit_write); 377 int inherit_write);
378 378
379 379
380/** 380/**
@@ -392,8 +392,8 @@ int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
392 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 392 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
393 */ 393 */
394int 394int
395GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, 395GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
396 enum GNUNET_DISK_PipeEnd end); 396 enum GNUNET_DISK_PipeEnd end);
397 397
398/** 398/**
399 * Close an open file. 399 * Close an open file.
@@ -411,11 +411,12 @@ int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
411 * @param n end to access 411 * @param n end to access
412 * @return handle for the respective end 412 * @return handle for the respective end
413 */ 413 */
414const struct GNUNET_DISK_FileHandle * 414const struct GNUNET_DISK_FileHandle *GNUNET_DISK_pipe_handle (const struct
415GNUNET_DISK_pipe_handle (const struct 415 GNUNET_DISK_PipeHandle
416 GNUNET_DISK_PipeHandle 416 *p,
417 *p, 417 enum
418 enum GNUNET_DISK_PipeEnd n); 418 GNUNET_DISK_PipeEnd
419 n);
419 420
420/** 421/**
421 * Read the contents of a binary file into a buffer. 422 * Read the contents of a binary file into a buffer.
@@ -424,8 +425,8 @@ GNUNET_DISK_pipe_handle (const struct
424 * @param len the maximum number of bytes to read 425 * @param len the maximum number of bytes to read
425 * @return the number of bytes read on success, GNUNET_SYSERR on failure 426 * @return the number of bytes read on success, GNUNET_SYSERR on failure
426 */ 427 */
427ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, 428ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
428 size_t len); 429 void *result, size_t len);
429 430
430 431
431/** 432/**
@@ -436,9 +437,7 @@ ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *res
436 * @param len the maximum number of bytes to read 437 * @param len the maximum number of bytes to read
437 * @return number of bytes read, GNUNET_SYSERR on failure 438 * @return number of bytes read, GNUNET_SYSERR on failure
438 */ 439 */
439ssize_t GNUNET_DISK_fn_read (const char *fn, 440ssize_t GNUNET_DISK_fn_read (const char *fn, void *result, size_t len);
440 void *result,
441 size_t len);
442 441
443 442
444/** 443/**
@@ -449,9 +448,8 @@ ssize_t GNUNET_DISK_fn_read (const char *fn,
449 * @param n number of bytes to write 448 * @param n number of bytes to write
450 * @return number of bytes written on success, GNUNET_SYSERR on error 449 * @return number of bytes written on success, GNUNET_SYSERR on error
451 */ 450 */
452ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, 451ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
453 const void *buffer, 452 const void *buffer, size_t n);
454 size_t n);
455 453
456 454
457/** 455/**
@@ -464,10 +462,10 @@ ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
464 * @param mode file permissions 462 * @param mode file permissions
465 * @return number of bytes written on success, GNUNET_SYSERR on error 463 * @return number of bytes written on success, GNUNET_SYSERR on error
466 */ 464 */
467ssize_t GNUNET_DISK_fn_write (const char *fn, 465ssize_t GNUNET_DISK_fn_write (const char *fn,
468 const void *buffer, 466 const void *buffer,
469 size_t n, 467 size_t n,
470 enum GNUNET_DISK_AccessPermissions mode); 468 enum GNUNET_DISK_AccessPermissions mode);
471 469
472 470
473/** 471/**
@@ -489,8 +487,8 @@ int GNUNET_DISK_file_copy (const char *src, const char *dst);
489 * @return the number of files found, -1 on error 487 * @return the number of files found, -1 on error
490 */ 488 */
491int GNUNET_DISK_directory_scan (const char *dirName, 489int GNUNET_DISK_directory_scan (const char *dirName,
492 GNUNET_FileNameCallback callback, 490 GNUNET_FileNameCallback callback,
493 void *callback_cls); 491 void *callback_cls);
494 492
495 493
496/** 494/**
@@ -603,7 +601,7 @@ int GNUNET_DISK_directory_create (const char *dir);
603 */ 601 */
604int 602int
605GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, 603GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
606 off_t lockEnd, int excl); 604 off_t lockEnd, int excl);
607 605
608 606
609/** 607/**
@@ -614,9 +612,8 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
614 * @return GNUNET_OK on success, GNUNET_SYSERR on error 612 * @return GNUNET_OK on success, GNUNET_SYSERR on error
615 */ 613 */
616int 614int
617GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, 615GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
618 off_t unlockStart, 616 off_t unlockStart, off_t unlockEnd);
619 off_t unlockEnd);
620 617
621 618
622/** 619/**
@@ -649,8 +646,8 @@ int GNUNET_DISK_file_change_owner (const char *filename, const char *user);
649 * private directory name. 646 * private directory name.
650 * @return the constructed filename 647 * @return the constructed filename
651 */ 648 */
652char *GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, 649char *GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle
653 const char *serviceName, ...); 650 *cfg, const char *serviceName, ...);
654 651
655 652
656/** 653/**
@@ -666,9 +663,9 @@ struct GNUNET_DISK_MapHandle;
666 * @param len size of the mapping 663 * @param len size of the mapping
667 * @return pointer to the mapped memory region, NULL on failure 664 * @return pointer to the mapped memory region, NULL on failure
668 */ 665 */
669void *GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, 666void *GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
670 struct GNUNET_DISK_MapHandle **m, 667 struct GNUNET_DISK_MapHandle **m,
671 enum GNUNET_DISK_MapType access, size_t len); 668 enum GNUNET_DISK_MapType access, size_t len);
672 669
673/** 670/**
674 * Unmap a file 671 * Unmap a file
@@ -693,7 +690,12 @@ int GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
693 * @return pipe handle on success, NULL on error 690 * @return pipe handle on success, NULL on error
694 */ 691 */
695struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_create (char **fn, 692struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_create (char **fn,
696 enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm); 693 enum
694 GNUNET_DISK_OpenFlags
695 flags,
696 enum
697 GNUNET_DISK_AccessPermissions
698 perm);
697 699
698/** 700/**
699 * Opens already existing named pipe/FIFO 701 * Opens already existing named pipe/FIFO
@@ -704,7 +706,12 @@ struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_create (char **fn,
704 * @return pipe handle on success, NULL on error 706 * @return pipe handle on success, NULL on error
705 */ 707 */
706struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_open (const char *fn, 708struct GNUNET_DISK_FileHandle *GNUNET_DISK_npipe_open (const char *fn,
707 enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm); 709 enum
710 GNUNET_DISK_OpenFlags
711 flags,
712 enum
713 GNUNET_DISK_AccessPermissions
714 perm);
708 715
709/** 716/**
710 * Closes a named pipe/FIFO 717 * Closes a named pipe/FIFO