hostfile_unix.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010,2011,2012,2013 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_EMU_HOSTFILE_H
  19. #define GRUB_EMU_HOSTFILE_H 1
  20. #include <config.h>
  21. #include <stdarg.h>
  22. #include <grub/symbol.h>
  23. #include <grub/types.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <fcntl.h>
  27. #include <dirent.h>
  28. #include <unistd.h>
  29. #include <stdio.h>
  30. typedef struct dirent *grub_util_fd_dirent_t;
  31. typedef DIR *grub_util_fd_dir_t;
  32. static inline grub_util_fd_dir_t
  33. grub_util_fd_opendir (const char *name)
  34. {
  35. return opendir (name);
  36. }
  37. static inline void
  38. grub_util_fd_closedir (grub_util_fd_dir_t dirp)
  39. {
  40. closedir (dirp);
  41. }
  42. static inline grub_util_fd_dirent_t
  43. grub_util_fd_readdir (grub_util_fd_dir_t dirp)
  44. {
  45. return readdir (dirp);
  46. }
  47. static inline int
  48. grub_util_unlink (const char *pathname)
  49. {
  50. return unlink (pathname);
  51. }
  52. static inline int
  53. grub_util_rmdir (const char *pathname)
  54. {
  55. return rmdir (pathname);
  56. }
  57. static inline int
  58. grub_util_rename (const char *from, const char *to)
  59. {
  60. return rename (from, to);
  61. }
  62. #define grub_util_mkdir(a) mkdir ((a), 0755)
  63. #if defined (__NetBSD__)
  64. /* NetBSD uses /boot for its boot block. */
  65. # define DEFAULT_DIRECTORY "/"GRUB_DIR_NAME
  66. #else
  67. # define DEFAULT_DIRECTORY "/"GRUB_BOOT_DIR_NAME"/"GRUB_DIR_NAME
  68. #endif
  69. enum grub_util_fd_open_flags_t
  70. {
  71. GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
  72. GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
  73. GRUB_UTIL_FD_O_RDWR = O_RDWR,
  74. GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
  75. GRUB_UTIL_FD_O_SYNC = (0
  76. #ifdef O_SYNC
  77. | O_SYNC
  78. #endif
  79. #ifdef O_FSYNC
  80. | O_FSYNC
  81. #endif
  82. )
  83. };
  84. #define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
  85. typedef int grub_util_fd_t;
  86. #define GRUB_UTIL_FD_INVALID -1
  87. #define GRUB_UTIL_FD_IS_VALID(x) ((x) >= 0)
  88. #define GRUB_UTIL_FD_STAT_IS_FUNCTIONAL 1
  89. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) || defined (__sun__) || defined(__OpenBSD__) || defined(__HAIKU__)
  90. #define GRUB_DISK_DEVS_ARE_CHAR 1
  91. #else
  92. #define GRUB_DISK_DEVS_ARE_CHAR 0
  93. #endif
  94. #endif