gnunet_disk_lib.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001-2012 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * Disk IO APIs
  21. *
  22. * @defgroup disk Disk library
  23. * Disk IO APIs
  24. * @{
  25. */
  26. #ifndef GNUNET_DISK_LIB_H
  27. #define GNUNET_DISK_LIB_H
  28. /**
  29. * Handle used to manage a pipe.
  30. */
  31. struct GNUNET_DISK_PipeHandle;
  32. /**
  33. * Type of a handle.
  34. */
  35. enum GNUNET_FILE_Type
  36. {
  37. /**
  38. * Handle represents an event.
  39. */
  40. GNUNET_DISK_HANLDE_TYPE_EVENT,
  41. /**
  42. * Handle represents a file.
  43. */
  44. GNUNET_DISK_HANLDE_TYPE_FILE,
  45. /**
  46. * Handle represents a pipe.
  47. */
  48. GNUNET_DISK_HANLDE_TYPE_PIPE
  49. };
  50. /**
  51. * Handle used to access files (and pipes).
  52. */
  53. struct GNUNET_DISK_FileHandle
  54. {
  55. /**
  56. * File handle on Unix-like systems.
  57. */
  58. int fd;
  59. };
  60. /* we need size_t, and since it can be both unsigned int
  61. or unsigned long long, this IS platform dependent;
  62. but "stdlib.h" should be portable 'enough' to be
  63. unconditionally available... */
  64. #include <stdlib.h>
  65. #include "gnunet_configuration_lib.h"
  66. #include "gnunet_scheduler_lib.h"
  67. #ifdef __cplusplus
  68. extern "C"
  69. {
  70. #if 0 /* keep Emacsens' auto-indent happy */
  71. }
  72. #endif
  73. #endif
  74. /**
  75. * Specifies how a file should be opened.
  76. */
  77. enum GNUNET_DISK_OpenFlags
  78. {
  79. /**
  80. * Open the file for reading
  81. */
  82. GNUNET_DISK_OPEN_READ = 1,
  83. /**
  84. * Open the file for writing
  85. */
  86. GNUNET_DISK_OPEN_WRITE = 2,
  87. /**
  88. * Open the file for both reading and writing
  89. */
  90. GNUNET_DISK_OPEN_READWRITE = 3,
  91. /**
  92. * Fail if file already exists
  93. */
  94. GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
  95. /**
  96. * Truncate file if it exists
  97. */
  98. GNUNET_DISK_OPEN_TRUNCATE = 8,
  99. /**
  100. * Create file if it doesn't exist
  101. */
  102. GNUNET_DISK_OPEN_CREATE = 16,
  103. /**
  104. * Append to the file
  105. */
  106. GNUNET_DISK_OPEN_APPEND = 32
  107. };
  108. /**
  109. * Specifies what type of memory map is desired.
  110. */
  111. enum GNUNET_DISK_MapType
  112. {
  113. /**
  114. * Read-only memory map.
  115. */
  116. GNUNET_DISK_MAP_TYPE_READ = 1,
  117. /**
  118. * Write-able memory map.
  119. */
  120. GNUNET_DISK_MAP_TYPE_WRITE = 2,
  121. /**
  122. * Read-write memory map.
  123. */
  124. GNUNET_DISK_MAP_TYPE_READWRITE = 3
  125. };
  126. /**
  127. * File access permissions, UNIX-style.
  128. */
  129. enum GNUNET_DISK_AccessPermissions
  130. {
  131. /**
  132. * Nobody is allowed to do anything to the file.
  133. */
  134. GNUNET_DISK_PERM_NONE = 0,
  135. /**
  136. * Owner can read.
  137. */
  138. GNUNET_DISK_PERM_USER_READ = 1,
  139. /**
  140. * Owner can write.
  141. */
  142. GNUNET_DISK_PERM_USER_WRITE = 2,
  143. /**
  144. * Owner can execute.
  145. */
  146. GNUNET_DISK_PERM_USER_EXEC = 4,
  147. /**
  148. * Group can read.
  149. */
  150. GNUNET_DISK_PERM_GROUP_READ = 8,
  151. /**
  152. * Group can write.
  153. */
  154. GNUNET_DISK_PERM_GROUP_WRITE = 16,
  155. /**
  156. * Group can execute.
  157. */
  158. GNUNET_DISK_PERM_GROUP_EXEC = 32,
  159. /**
  160. * Everybody can read.
  161. */
  162. GNUNET_DISK_PERM_OTHER_READ = 64,
  163. /**
  164. * Everybody can write.
  165. */
  166. GNUNET_DISK_PERM_OTHER_WRITE = 128,
  167. /**
  168. * Everybody can execute.
  169. */
  170. GNUNET_DISK_PERM_OTHER_EXEC = 256
  171. };
  172. /**
  173. * Constants for specifying how to seek. Do not change values or order,
  174. * some of the code depends on the specific numeric values!
  175. */
  176. enum GNUNET_DISK_Seek
  177. {
  178. /**
  179. * Seek an absolute position (from the start of the file).
  180. */
  181. GNUNET_DISK_SEEK_SET = 0,
  182. /**
  183. * Seek a relative position (from the current offset).
  184. */
  185. GNUNET_DISK_SEEK_CUR = 1,
  186. /**
  187. * Seek an absolute position from the end of the file.
  188. */
  189. GNUNET_DISK_SEEK_END = 2
  190. };
  191. /**
  192. * Enumeration identifying the two ends of a pipe.
  193. */
  194. enum GNUNET_DISK_PipeEnd
  195. {
  196. /**
  197. * The reading-end of a pipe.
  198. */
  199. GNUNET_DISK_PIPE_END_READ = 0,
  200. /**
  201. * The writing-end of a pipe.
  202. */
  203. GNUNET_DISK_PIPE_END_WRITE = 1
  204. };
  205. /**
  206. * Checks whether a handle is invalid
  207. *
  208. * @param h handle to check
  209. * @return #GNUNET_YES if invalid, #GNUNET_NO if valid
  210. */
  211. int
  212. GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
  213. /**
  214. * Check that fil corresponds to a filename
  215. * (of a file that exists and that is not a directory).
  216. *
  217. * @param fil filename to check
  218. * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
  219. * else (will print an error message in that case, too).
  220. */
  221. int
  222. GNUNET_DISK_file_test (const char *fil);
  223. /**
  224. * Move a file out of the way (create a backup) by
  225. * renaming it to "orig.NUM~" where NUM is the smallest
  226. * number that is not used yet.
  227. *
  228. * @param fil name of the file to back up
  229. */
  230. void
  231. GNUNET_DISK_file_backup (const char *fil);
  232. /**
  233. * Move the read/write pointer in a file
  234. * @param h handle of an open file
  235. * @param offset position to move to
  236. * @param whence specification to which position the offset parameter relates to
  237. * @return the new position on success, GNUNET_SYSERR otherwise
  238. */
  239. off_t
  240. GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
  241. enum GNUNET_DISK_Seek whence);
  242. /**
  243. * Get the size of the file (or directory) of the given file (in
  244. * bytes).
  245. *
  246. * @param filename name of the file or directory
  247. * @param size set to the size of the file (or,
  248. * in the case of directories, the sum
  249. * of all sizes of files in the directory)
  250. * @param include_symbolic_links should symbolic links be
  251. * included?
  252. * @param single_file_mode #GNUNET_YES to only get size of one file
  253. * and return #GNUNET_SYSERR for directories.
  254. * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
  255. */
  256. int
  257. GNUNET_DISK_file_size (const char *filename,
  258. uint64_t *size,
  259. int include_symbolic_links,
  260. int single_file_mode);
  261. /**
  262. * Obtain some unique identifiers for the given file
  263. * that can be used to identify it in the local system.
  264. * This function is used between GNUnet processes to
  265. * quickly check if two files with the same absolute path
  266. * are actually identical. The two processes represent
  267. * the same peer but may communicate over the network
  268. * (and the file may be on an NFS volume). This function
  269. * may not be supported on all operating systems.
  270. *
  271. * @param filename name of the file
  272. * @param dev set to the device ID
  273. * @param ino set to the inode ID
  274. * @return #GNUNET_OK on success
  275. */
  276. int
  277. GNUNET_DISK_file_get_identifiers (const char *filename,
  278. uint64_t *dev,
  279. uint64_t *ino);
  280. /**
  281. * Create an (empty) temporary file on disk. If the given name is not
  282. * an absolute path, the current 'TMPDIR' will be prepended. In any case,
  283. * 6 random characters will be appended to the name to create a unique
  284. * filename.
  285. *
  286. * @param t component to use for the name;
  287. * does NOT contain "XXXXXX" or "/tmp/".
  288. * @return NULL on error, otherwise name of fresh
  289. * file on disk in directory for temporary files
  290. */
  291. char *
  292. GNUNET_DISK_mktemp (const char *t);
  293. /**
  294. * Create an (empty) temporary directory on disk. If the given name is not an
  295. * absolute path, the current 'TMPDIR' will be prepended. In any case, 6
  296. * random characters will be appended to the name to create a unique name.
  297. *
  298. * @param t component to use for the name;
  299. * does NOT contain "XXXXXX" or "/tmp/".
  300. * @return NULL on error, otherwise name of freshly created directory
  301. */
  302. char *
  303. GNUNET_DISK_mkdtemp (const char *t);
  304. /**
  305. * Open a file. Note that the access permissions will only be
  306. * used if a new file is created and if the underlying operating
  307. * system supports the given permissions.
  308. *
  309. * @param fn file name to be opened
  310. * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags
  311. * @param perm permissions for the newly created file, use
  312. * #GNUNET_DISK_PERM_NONE if a file could not be created by this
  313. * call (because of flags)
  314. * @return IO handle on success, NULL on error
  315. */
  316. struct GNUNET_DISK_FileHandle *
  317. GNUNET_DISK_file_open (const char *fn,
  318. enum GNUNET_DISK_OpenFlags flags,
  319. enum GNUNET_DISK_AccessPermissions perm);
  320. /**
  321. * Get the size of an open file.
  322. *
  323. * @param fh open file handle
  324. * @param size where to write size of the file
  325. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  326. */
  327. int
  328. GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
  329. off_t *size);
  330. /**
  331. * Creates an interprocess channel
  332. *
  333. * @param blocking_read creates an asynchronous pipe for reading if set to #GNUNET_NO
  334. * @param blocking_write creates an asynchronous pipe for writing if set to #GNUNET_NO
  335. * @param inherit_read 1 to make read handle inheritable, 0 otherwise (NT only)
  336. * @param inherit_write 1 to make write handle inheritable, 0 otherwise (NT only)
  337. * @return handle to the new pipe, NULL on error
  338. */
  339. struct GNUNET_DISK_PipeHandle *
  340. GNUNET_DISK_pipe (int blocking_read,
  341. int blocking_write,
  342. int inherit_read,
  343. int inherit_write);
  344. /**
  345. * Creates a pipe object from a couple of file descriptors.
  346. * Useful for wrapping existing pipe FDs.
  347. *
  348. * @param blocking_read creates an asynchronous pipe for reading if set to #GNUNET_NO
  349. * @param blocking_write creates an asynchronous pipe for writing if set to #GNUNET_NO
  350. * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes
  351. *
  352. * @return handle to the new pipe, NULL on error
  353. */
  354. struct GNUNET_DISK_PipeHandle *
  355. GNUNET_DISK_pipe_from_fd (int blocking_read,
  356. int blocking_write,
  357. int fd[2]);
  358. /**
  359. * Closes an interprocess channel
  360. * @param p pipe
  361. * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  362. */
  363. int
  364. GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
  365. /**
  366. * Closes one half of an interprocess channel
  367. *
  368. * @param p pipe to close end of
  369. * @param end which end of the pipe to close
  370. * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  371. */
  372. int
  373. GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
  374. enum GNUNET_DISK_PipeEnd end);
  375. /**
  376. * Detaches one of the ends from the pipe.
  377. * Detached end is a fully-functional FileHandle, it will
  378. * not be affected by anything you do with the pipe afterwards.
  379. * Each end of a pipe can only be detched from it once (i.e.
  380. * it is not duplicated).
  381. *
  382. * @param p pipe to detach an end from
  383. * @param end which end of the pipe to detach
  384. * @return Detached end on success, NULL on failure
  385. * (or if that end is not present or is closed).
  386. */
  387. struct GNUNET_DISK_FileHandle *
  388. GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
  389. enum GNUNET_DISK_PipeEnd end);
  390. /**
  391. * Close an open file.
  392. *
  393. * @param h file handle
  394. * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  395. */
  396. int
  397. GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
  398. /**
  399. * Get the handle to a particular pipe end
  400. *
  401. * @param p pipe
  402. * @param n end to access
  403. * @return handle for the respective end
  404. */
  405. const struct GNUNET_DISK_FileHandle *
  406. GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
  407. enum GNUNET_DISK_PipeEnd n);
  408. /**
  409. * Update POSIX permissions mask of a file on disk. If both argumets
  410. * are #GNUNET_NO, the file is made world-read-write-executable (777).
  411. * Does nothing on W32.
  412. *
  413. * @param fn name of the file to update
  414. * @param require_uid_match #GNUNET_YES means 700
  415. * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set
  416. */
  417. void
  418. GNUNET_DISK_fix_permissions (const char *fn,
  419. int require_uid_match,
  420. int require_gid_match);
  421. /**
  422. * Get a handle from a native integer FD.
  423. *
  424. * @param fno native integer file descriptor
  425. * @return file handle corresponding to the descriptor
  426. */
  427. struct GNUNET_DISK_FileHandle *
  428. GNUNET_DISK_get_handle_from_int_fd (int fno);
  429. /**
  430. * Get a handle from a native FD.
  431. *
  432. * @param fd native file descriptor
  433. * @return file handle corresponding to the descriptor
  434. */
  435. struct GNUNET_DISK_FileHandle *
  436. GNUNET_DISK_get_handle_from_native (FILE *fd);
  437. /**
  438. * Read the contents of a binary file into a buffer.
  439. *
  440. * @param h handle to an open file
  441. * @param result the buffer to write the result to
  442. * @param len the maximum number of bytes to read
  443. * @return the number of bytes read on success, #GNUNET_SYSERR on failure
  444. */
  445. ssize_t
  446. GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
  447. void *result,
  448. size_t len);
  449. /**
  450. * Read the contents of a binary file into a buffer.
  451. * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
  452. * when no data can be read).
  453. *
  454. * @param h handle to an open file
  455. * @param result the buffer to write the result to
  456. * @param len the maximum number of bytes to read
  457. * @return the number of bytes read on success, #GNUNET_SYSERR on failure
  458. */
  459. ssize_t
  460. GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
  461. void *result,
  462. size_t len);
  463. /**
  464. * Read the contents of a binary file into a buffer.
  465. *
  466. * @param fn file name
  467. * @param result the buffer to write the result to
  468. * @param len the maximum number of bytes to read
  469. * @return number of bytes read, #GNUNET_SYSERR on failure
  470. */
  471. ssize_t
  472. GNUNET_DISK_fn_read (const char *fn,
  473. void *result,
  474. size_t len);
  475. /**
  476. * Write a buffer to a file.
  477. *
  478. * @param h handle to open file
  479. * @param buffer the data to write
  480. * @param n number of bytes to write
  481. * @return number of bytes written on success, #GNUNET_SYSERR on error
  482. */
  483. ssize_t
  484. GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
  485. const void *buffer,
  486. size_t n);
  487. /**
  488. * Write a buffer to a file, blocking, if necessary.
  489. *
  490. * @param h handle to open file
  491. * @param buffer the data to write
  492. * @param n number of bytes to write
  493. * @return number of bytes written on success, #GNUNET_SYSERR on error
  494. */
  495. ssize_t
  496. GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
  497. const void *buffer,
  498. size_t n);
  499. /**
  500. * Write a buffer to a file. If the file is longer than
  501. * the given buffer size, it will be truncated.
  502. *
  503. * @param fn file name
  504. * @param buffer the data to write
  505. * @param n number of bytes to write
  506. * @param mode file permissions
  507. * @return number of bytes written on success, #GNUNET_SYSERR on error
  508. */
  509. ssize_t
  510. GNUNET_DISK_fn_write (const char *fn,
  511. const void *buffer,
  512. size_t n,
  513. enum GNUNET_DISK_AccessPermissions mode);
  514. /**
  515. * Copy a file.
  516. *
  517. * @param src file to copy
  518. * @param dst destination file name
  519. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  520. */
  521. int
  522. GNUNET_DISK_file_copy (const char *src,
  523. const char *dst);
  524. /**
  525. * Scan a directory for files.
  526. *
  527. * @param dir_name the name of the directory
  528. * @param callback the method to call for each file
  529. * @param callback_cls closure for @a callback
  530. * @return the number of files found, -1 on error
  531. */
  532. int
  533. GNUNET_DISK_directory_scan (const char *dir_name,
  534. GNUNET_FileNameCallback callback,
  535. void *callback_cls);
  536. /**
  537. * Create the directory structure for storing
  538. * a file.
  539. *
  540. * @param filename name of a file in the directory
  541. * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure,
  542. * #GNUNET_NO if directory exists but is not writeable
  543. */
  544. int
  545. GNUNET_DISK_directory_create_for_file (const char *filename);
  546. /**
  547. * Test if @a fil is a directory and listable. Optionally, also check if the
  548. * directory is readable. Will not print an error message if the directory does
  549. * not exist. Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists
  550. * with the same name).
  551. *
  552. * @param fil filename to test
  553. * @param is_readable #GNUNET_YES to additionally check if @a fil is readable;
  554. * #GNUNET_NO to disable this check
  555. * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
  556. * does not exist or `stat`ed
  557. */
  558. int
  559. GNUNET_DISK_directory_test (const char *fil, int is_readable);
  560. /**
  561. * Remove all files in a directory (rm -rf). Call with
  562. * caution.
  563. *
  564. * @param filename the file to remove
  565. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  566. */
  567. int
  568. GNUNET_DISK_directory_remove (const char *filename);
  569. /**
  570. * Remove the directory given under @a option in
  571. * section [PATHS] in configuration under @a cfg_filename
  572. *
  573. * @param cfg_filename configuration file to parse
  574. * @param option option with the dir name to purge
  575. */
  576. void
  577. GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
  578. const char *option);
  579. /**
  580. * Implementation of "mkdir -p"
  581. *
  582. * @param dir the directory to create
  583. * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise
  584. */
  585. int
  586. GNUNET_DISK_directory_create (const char *dir);
  587. /**
  588. * Lock a part of a file.
  589. *
  590. * @param fh file handle
  591. * @param lock_start absolute position from where to lock
  592. * @param lock_end absolute position until where to lock
  593. * @param excl #GNUNET_YES for an exclusive lock
  594. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  595. */
  596. int
  597. GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
  598. off_t lock_start,
  599. off_t lock_end, int excl);
  600. /**
  601. * Unlock a part of a file.
  602. *
  603. * @param fh file handle
  604. * @param unlock_start absolute position from where to unlock
  605. * @param unlock_end absolute position until where to unlock
  606. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  607. */
  608. int
  609. GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
  610. off_t unlock_start,
  611. off_t unlock_end);
  612. /**
  613. * @brief Removes special characters as ':' from a filename.
  614. * @param fn the filename to canonicalize
  615. */
  616. void
  617. GNUNET_DISK_filename_canonicalize (char *fn);
  618. /**
  619. * @brief Change owner of a file
  620. * @param filename file to change
  621. * @param user new owner of the file
  622. * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
  623. */
  624. int
  625. GNUNET_DISK_file_change_owner (const char *filename,
  626. const char *user);
  627. /**
  628. * Opaque handle for a memory-mapping operation.
  629. */
  630. struct GNUNET_DISK_MapHandle;
  631. /**
  632. * Map a file into memory
  633. * @param h open file handle
  634. * @param m handle to the new mapping (will be set)
  635. * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx
  636. * @param len size of the mapping
  637. * @return pointer to the mapped memory region, NULL on failure
  638. */
  639. void *
  640. GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
  641. struct GNUNET_DISK_MapHandle **m,
  642. enum GNUNET_DISK_MapType access,
  643. size_t len);
  644. /**
  645. * Unmap a file
  646. *
  647. * @param h mapping handle
  648. * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  649. */
  650. int
  651. GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
  652. /**
  653. * Write file changes to disk
  654. *
  655. * @param h handle to an open file
  656. * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  657. */
  658. int
  659. GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
  660. #if 0 /* keep Emacsens' auto-indent happy */
  661. {
  662. #endif
  663. #ifdef __cplusplus
  664. }
  665. #endif
  666. /* ifndef GNUNET_DISK_LIB_H */
  667. #endif
  668. /** @} */ /* end of group */
  669. /* end of gnunet_disk_lib.h */