gnunet_disk_lib.h 20 KB

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