file.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2002,2007 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_FILE_HEADER
  19. #define GRUB_FILE_HEADER 1
  20. #include <grub/types.h>
  21. #include <grub/err.h>
  22. #include <grub/device.h>
  23. #include <grub/fs.h>
  24. /* File description. */
  25. struct grub_file
  26. {
  27. /* The underlying device. */
  28. grub_device_t device;
  29. /* The underlying filesystem. */
  30. grub_fs_t fs;
  31. /* The current offset. */
  32. grub_off_t offset;
  33. /* The file size. */
  34. grub_off_t size;
  35. /* Filesystem-specific data. */
  36. void *data;
  37. /* This is called when a sector is read. Used only for a disk device. */
  38. void (*read_hook) (grub_disk_addr_t sector,
  39. unsigned offset, unsigned length, void *closure);
  40. void *closure;
  41. int flags;
  42. };
  43. typedef struct grub_file *grub_file_t;
  44. /* Get a device name from NAME. */
  45. char *grub_file_get_device_name (const char *name);
  46. grub_file_t grub_file_open (const char *name);
  47. grub_ssize_t grub_file_read (grub_file_t file, void *buf,
  48. grub_size_t len);
  49. grub_off_t grub_file_seek (grub_file_t file, grub_off_t offset);
  50. grub_err_t grub_file_close (grub_file_t file);
  51. static inline grub_off_t
  52. grub_file_size (const grub_file_t file)
  53. {
  54. return file->size;
  55. }
  56. static inline grub_off_t
  57. grub_file_tell (const grub_file_t file)
  58. {
  59. return file->offset;
  60. }
  61. void grub_blocklist_convert (grub_file_t file);
  62. grub_ssize_t grub_blocklist_write (grub_file_t file, const char *buf,
  63. grub_size_t len);
  64. #define GRUB_FILE_PB_MIN_SIZE (1 << 20)
  65. extern void (*grub_file_pb_init) (void);
  66. extern void (*grub_file_pb_fini) (void);
  67. extern void (*grub_file_pb_show) (int num, int total);
  68. grub_ssize_t grub_file_pb_read (grub_file_t file, void *buf, grub_size_t len,
  69. int total);
  70. #endif /* ! GRUB_FILE_HEADER */