geometry.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * BURG - Brand-new Universal loadeR from GRUB
  3. * Copyright 2010 Bean Lee - All Rights Reserved
  4. *
  5. * BURG 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. * BURG 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 BURG. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/dl.h>
  19. #include <grub/env.h>
  20. #include <grub/misc.h>
  21. #include <grub/command.h>
  22. #include <grub/machine/biosdisk.h>
  23. #include <grub/i18n.h>
  24. static grub_err_t
  25. grub_cmd_geometry (grub_command_t cmd __attribute__ ((unused)),
  26. int argc __attribute__ ((unused)),
  27. char **args __attribute__ ((unused)))
  28. {
  29. int n;
  30. struct grub_biosdisk_data *p;
  31. grub_printf ("drive flags spt heads max sectors\n");
  32. n = grub_biosdisk_num;
  33. p = grub_biosdisk_geom;
  34. for (; n > 0; n--, p++)
  35. {
  36. char fg[4];
  37. long long total_sectors;
  38. fg[0] = (p->flags & GRUB_BIOSDISK_FLAG_LBA) ? 'L' : '-';
  39. fg[1] = (p->flags & GRUB_BIOSDISK_FLAG_CDROM) ? 'C' : '-';
  40. fg[2] = (p->flags & GRUB_BIOSDISK_FLAG_FB) ? 'F' : '-';
  41. fg[3] = 0;
  42. total_sectors = (p->flags & GRUB_BIOSDISK_FLAG_CDROM) ?
  43. 0 : p->total_sectors;
  44. grub_printf ("%02x %s %-2ld %-3ld %-3d %lld\n",
  45. p->drive, fg, p->sectors, p->heads, p->max_sectors,
  46. total_sectors);
  47. }
  48. return 0;
  49. }
  50. static grub_command_t cmd;
  51. GRUB_MOD_INIT(geom)
  52. {
  53. cmd = grub_register_command ("geometry", grub_cmd_geometry,
  54. 0, N_("Display drive geometry."));
  55. }
  56. GRUB_MOD_FINI(geom)
  57. {
  58. grub_unregister_command (cmd);
  59. }