getroot.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,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. #include <config-util.h>
  19. #include <config.h>
  20. #include <sys/stat.h>
  21. #include <sys/types.h>
  22. #include <assert.h>
  23. #include <fcntl.h>
  24. #include <unistd.h>
  25. #include <string.h>
  26. #include <dirent.h>
  27. #include <errno.h>
  28. #include <error.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <stdint.h>
  32. #ifdef HAVE_LIMITS_H
  33. #include <limits.h>
  34. #endif
  35. #include <grub/types.h>
  36. #include <grub/util/misc.h>
  37. #include <grub/mm.h>
  38. #include <grub/misc.h>
  39. #include <grub/emu/misc.h>
  40. #include <grub/emu/hostdisk.h>
  41. #include <grub/emu/getroot.h>
  42. #include <sys/wait.h>
  43. # include <sys/disk.h>
  44. # include <sys/param.h>
  45. # include <sys/sysctl.h>
  46. # include <sys/mount.h>
  47. char *
  48. grub_util_part_to_disk (const char *os_dev, struct stat *st,
  49. int *is_part)
  50. {
  51. char *path = xstrdup (os_dev);
  52. if (! S_ISCHR (st->st_mode))
  53. {
  54. *is_part = 0;
  55. return path;
  56. }
  57. if (strncmp ("/dev/", path, 5) == 0)
  58. {
  59. char *p;
  60. for (p = path + 5; *p; ++p)
  61. if (grub_isdigit(*p))
  62. {
  63. p = strpbrk (p, "sp");
  64. if (p)
  65. {
  66. *is_part = 1;
  67. *p = '\0';
  68. }
  69. break;
  70. }
  71. }
  72. return path;
  73. }
  74. enum grub_dev_abstraction_types
  75. grub_util_get_dev_abstraction_os (const char *os_dev __attribute__((unused)))
  76. {
  77. return GRUB_DEV_ABSTRACTION_NONE;
  78. }
  79. int
  80. grub_util_pull_device_os (const char *os_dev __attribute__ ((unused)),
  81. enum grub_dev_abstraction_types ab __attribute__ ((unused)))
  82. {
  83. return 0;
  84. }
  85. char *
  86. grub_util_get_grub_dev_os (const char *os_dev __attribute__ ((unused)))
  87. {
  88. return NULL;
  89. }
  90. grub_disk_addr_t
  91. grub_util_find_partition_start_os (const char *dev __attribute__ ((unused)))
  92. {
  93. return 0;
  94. }