fs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* fs.h - filesystem manager */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef GRUB_FS_HEADER
  20. #define GRUB_FS_HEADER 1
  21. #include <grub/device.h>
  22. #include <grub/symbol.h>
  23. #include <grub/types.h>
  24. #include <grub/list.h>
  25. /* Forward declaration is required, because of mutual reference. */
  26. struct grub_file;
  27. struct grub_dirhook_info
  28. {
  29. int dir:1;
  30. int mtimeset:1;
  31. int case_insensitive:1;
  32. grub_int32_t mtime;
  33. };
  34. /* Filesystem descriptor. */
  35. struct grub_fs
  36. {
  37. /* The next filesystem. */
  38. struct grub_fs *next;
  39. /* My name. */
  40. const char *name;
  41. /* Call HOOK with each file under DIR. */
  42. grub_err_t (*dir) (grub_device_t device, const char *path,
  43. int (*hook) (const char *filename,
  44. const struct grub_dirhook_info *info,
  45. void *closure),
  46. void *closure);
  47. /* Open a file named NAME and initialize FILE. */
  48. grub_err_t (*open) (struct grub_file *file, const char *name);
  49. /* Read LEN bytes data from FILE into BUF. */
  50. grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len);
  51. /* Close the file FILE. */
  52. grub_err_t (*close) (struct grub_file *file);
  53. /* Return the label of the device DEVICE in LABEL. The label is
  54. returned in a grub_malloc'ed buffer and should be freed by the
  55. caller. */
  56. grub_err_t (*label) (grub_device_t device, char **label);
  57. /* Return the uuid of the device DEVICE in UUID. The uuid is
  58. returned in a grub_malloc'ed buffer and should be freed by the
  59. caller. */
  60. grub_err_t (*uuid) (grub_device_t device, char **uuid);
  61. /* Get writing time of filesystem. */
  62. grub_err_t (*mtime) (grub_device_t device, grub_int32_t *timebuf);
  63. #ifdef GRUB_UTIL
  64. /* Whether this filesystem reserves first sector for DOS-style boot. */
  65. int reserved_first_sector;
  66. #endif
  67. };
  68. typedef struct grub_fs *grub_fs_t;
  69. /* This is special, because block lists are not files in usual sense. */
  70. extern struct grub_fs grub_fs_blocklist;
  71. /* This hook is used to automatically load filesystem modules.
  72. If this hook loads a module, return non-zero. Otherwise return zero.
  73. The newly loaded filesystem is assumed to be inserted into the head of
  74. the linked list GRUB_FS_LIST through the function grub_fs_register. */
  75. typedef int (*grub_fs_autoload_hook_t) (void);
  76. extern grub_fs_autoload_hook_t grub_fs_autoload_hook;
  77. extern grub_fs_t grub_fs_list;
  78. static inline void
  79. grub_fs_register (grub_fs_t fs)
  80. {
  81. grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
  82. GRUB_MODATTR ("fs", "");
  83. }
  84. static inline void
  85. grub_fs_unregister (grub_fs_t fs)
  86. {
  87. grub_list_remove (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
  88. }
  89. static inline void
  90. grub_fs_iterate (int (*hook) (const grub_fs_t fs, void *closure),
  91. void *closure)
  92. {
  93. grub_list_iterate (GRUB_AS_LIST (grub_fs_list), (grub_list_hook_t) hook,
  94. closure);
  95. }
  96. grub_fs_t grub_fs_probe (grub_device_t device);
  97. #endif /* ! GRUB_FS_HEADER */