misc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* misc.c - miscellaneous functions */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2005,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. #include <grub/disk.h>
  20. #include <grub/fs.h>
  21. #include <grub/err.h>
  22. #include <grub/misc.h>
  23. #include <grub/mm.h>
  24. #include <grub/datetime.h>
  25. #include <grub/lib.h>
  26. #include <grub/term.h>
  27. #include <grub/i18n.h>
  28. GRUB_EXPORT(grub_wait_after_message);
  29. GRUB_EXPORT(grub_print_device_info);
  30. /* Wait until the user pushes any key so that the user
  31. can see what happened. */
  32. void
  33. grub_wait_after_message (void)
  34. {
  35. grub_putchar ('\n');
  36. grub_printf_ (N_("Press any key to continue..."));
  37. (void) grub_getkey ();
  38. grub_putchar ('\n');
  39. }
  40. /* Print the information on the device NAME. */
  41. grub_err_t
  42. grub_print_device_info (const char *name)
  43. {
  44. grub_device_t dev;
  45. char *p;
  46. p = grub_strchr (name, ',');
  47. if (p)
  48. {
  49. grub_putchar ('\t');
  50. grub_printf_ (N_("Partition %s:"), name);
  51. grub_putchar (' ');
  52. }
  53. else
  54. {
  55. grub_printf_ (N_("Device %s:"), name);
  56. grub_putchar (' ');
  57. }
  58. dev = grub_device_open (name);
  59. if (! dev)
  60. grub_printf ("%s", _("Filesystem cannot be accessed"));
  61. else if (dev->disk)
  62. {
  63. grub_fs_t fs;
  64. fs = grub_fs_probe (dev);
  65. /* Ignore all errors. */
  66. grub_errno = 0;
  67. if (fs)
  68. {
  69. grub_printf_ (N_("Filesystem type %s"), fs->name);
  70. if (fs->label)
  71. {
  72. char *label;
  73. (fs->label) (dev, &label);
  74. if (grub_errno == GRUB_ERR_NONE)
  75. {
  76. if (label && grub_strlen (label))
  77. {
  78. grub_putchar (' ');
  79. grub_printf_ (N_("- Label \"%s\""), label);
  80. }
  81. grub_free (label);
  82. }
  83. grub_errno = GRUB_ERR_NONE;
  84. }
  85. if (fs->mtime)
  86. {
  87. grub_int32_t tm;
  88. struct grub_datetime datetime;
  89. (fs->mtime) (dev, &tm);
  90. if (grub_errno == GRUB_ERR_NONE)
  91. {
  92. grub_unixtime2datetime (tm, &datetime);
  93. grub_putchar (' ');
  94. grub_printf_ (N_("- Last modification time %d-%02d-%02d "
  95. "%02d:%02d:%02d %s"),
  96. datetime.year, datetime.month, datetime.day,
  97. datetime.hour, datetime.minute, datetime.second,
  98. grub_get_weekday_name (&datetime));
  99. }
  100. grub_errno = GRUB_ERR_NONE;
  101. }
  102. if (fs->uuid)
  103. {
  104. char *uuid;
  105. (fs->uuid) (dev, &uuid);
  106. if (grub_errno == GRUB_ERR_NONE)
  107. {
  108. if (uuid && grub_strlen (uuid))
  109. grub_printf (", UUID %s", uuid);
  110. grub_free (uuid);
  111. }
  112. grub_errno = GRUB_ERR_NONE;
  113. }
  114. }
  115. else if (! dev->disk->has_partitions || dev->disk->partition)
  116. grub_printf ("%s", _("Unknown filesystem"));
  117. else
  118. grub_printf ("%s", _("Partition table"));
  119. grub_device_close (dev);
  120. }
  121. grub_putchar ('\n');
  122. return grub_errno;
  123. }