fs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /* For embedding types. */
  26. #ifdef GRUB_UTIL
  27. #include <grub/partition.h>
  28. #endif
  29. /* Forward declaration is required, because of mutual reference. */
  30. struct grub_file;
  31. struct grub_dirhook_info
  32. {
  33. unsigned dir:1;
  34. unsigned mtimeset:1;
  35. unsigned case_insensitive:1;
  36. unsigned inodeset:1;
  37. grub_int64_t mtime;
  38. grub_uint64_t inode;
  39. };
  40. typedef int (*grub_fs_dir_hook_t) (const char *filename,
  41. const struct grub_dirhook_info *info,
  42. void *data);
  43. /* Filesystem descriptor. */
  44. struct grub_fs
  45. {
  46. /* The next filesystem. */
  47. struct grub_fs *next;
  48. struct grub_fs **prev;
  49. /* My name. */
  50. const char *name;
  51. /* Call HOOK with each file under DIR. */
  52. grub_err_t (*fs_dir) (grub_device_t device, const char *path,
  53. grub_fs_dir_hook_t hook, void *hook_data);
  54. /* Open a file named NAME and initialize FILE. */
  55. grub_err_t (*fs_open) (struct grub_file *file, const char *name);
  56. /* Read LEN bytes data from FILE into BUF. */
  57. grub_ssize_t (*fs_read) (struct grub_file *file, char *buf, grub_size_t len);
  58. /* Close the file FILE. */
  59. grub_err_t (*fs_close) (struct grub_file *file);
  60. /* Return the label of the device DEVICE in LABEL. The label is
  61. returned in a grub_malloc'ed buffer and should be freed by the
  62. caller. */
  63. grub_err_t (*fs_label) (grub_device_t device, char **label);
  64. /* Return the uuid of the device DEVICE in UUID. The uuid is
  65. returned in a grub_malloc'ed buffer and should be freed by the
  66. caller. */
  67. grub_err_t (*fs_uuid) (grub_device_t device, char **uuid);
  68. /* Get writing time of filesystem. */
  69. grub_err_t (*fs_mtime) (grub_device_t device, grub_int64_t *timebuf);
  70. #ifdef GRUB_UTIL
  71. /* Determine sectors available for embedding. */
  72. grub_err_t (*fs_embed) (grub_device_t device, unsigned int *nsectors,
  73. unsigned int max_nsectors,
  74. grub_embed_type_t embed_type,
  75. grub_disk_addr_t **sectors);
  76. /* Whether this filesystem reserves first sector for DOS-style boot. */
  77. int reserved_first_sector;
  78. /* Whether blocklist installs have a chance to work. */
  79. int blocklist_install;
  80. #endif
  81. };
  82. typedef struct grub_fs *grub_fs_t;
  83. /* This is special, because block lists are not files in usual sense. */
  84. extern struct grub_fs grub_fs_blocklist;
  85. /* This hook is used to automatically load filesystem modules.
  86. If this hook loads a module, return non-zero. Otherwise return zero.
  87. The newly loaded filesystem is assumed to be inserted into the head of
  88. the linked list GRUB_FS_LIST through the function grub_fs_register. */
  89. typedef int (*grub_fs_autoload_hook_t) (void);
  90. extern grub_fs_autoload_hook_t EXPORT_VAR(grub_fs_autoload_hook);
  91. extern grub_fs_t EXPORT_VAR (grub_fs_list);
  92. #ifndef GRUB_LST_GENERATOR
  93. static inline void
  94. grub_fs_register (grub_fs_t fs)
  95. {
  96. grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
  97. }
  98. #endif
  99. static inline void
  100. grub_fs_unregister (grub_fs_t fs)
  101. {
  102. grub_list_remove (GRUB_AS_LIST (fs));
  103. }
  104. #define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
  105. grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
  106. #endif /* ! GRUB_FS_HEADER */