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