You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sanboot_cmd.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <errno.h>
  21. #include <getopt.h>
  22. #include <ipxe/command.h>
  23. #include <ipxe/parseopt.h>
  24. #include <ipxe/uri.h>
  25. #include <usr/autoboot.h>
  26. FILE_LICENCE ( GPL2_OR_LATER );
  27. /** @file
  28. *
  29. * SAN commands
  30. *
  31. */
  32. /** "sanboot" options */
  33. struct sanboot_options {};
  34. /** "sanboot" option list */
  35. static struct option_descriptor sanboot_opts[] = {};
  36. /** "sanboot" command descriptor */
  37. static struct command_descriptor sanboot_cmd =
  38. COMMAND_DESC ( struct sanboot_options, sanboot_opts, 1, 1,
  39. "<root-path>" );
  40. /**
  41. * The "sanboot" command
  42. *
  43. * @v argc Argument count
  44. * @v argv Argument list
  45. * @ret rc Return status code
  46. */
  47. static int sanboot_exec ( int argc, char **argv ) {
  48. struct sanboot_options opts;
  49. const char *root_path;
  50. struct uri *uri;
  51. int rc;
  52. /* Parse options */
  53. if ( ( rc = parse_options ( argc, argv, &sanboot_cmd, &opts ) ) != 0 )
  54. goto err_parse_options;
  55. /* Parse root path */
  56. root_path = argv[optind];
  57. uri = parse_uri ( root_path );
  58. if ( ! uri ) {
  59. rc = -ENOMEM;
  60. goto err_parse_uri;
  61. }
  62. /* Boot from root path */
  63. if ( ( rc = uriboot ( NULL, uri ) ) != 0 ) {
  64. printf ( "Could not boot from %s: %s\n",
  65. root_path, strerror ( rc ) );
  66. goto err_uriboot;
  67. }
  68. err_uriboot:
  69. uri_put ( uri );
  70. err_parse_uri:
  71. err_parse_options:
  72. return rc;
  73. }
  74. /** SAN commands */
  75. struct command sanboot_command __command = {
  76. .name = "sanboot",
  77. .exec = sanboot_exec,
  78. };