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 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <getopt.h>
  4. #include <gpxe/command.h>
  5. #include <usr/autoboot.h>
  6. FILE_LICENCE ( GPL2_OR_LATER );
  7. /**
  8. * "sanboot" command syntax message
  9. *
  10. * @v argv Argument list
  11. */
  12. static void sanboot_syntax ( char **argv ) {
  13. printf ( "Usage:\n"
  14. " %s <root-path>\n"
  15. "\n"
  16. "Boot from SAN target\n",
  17. argv[0] );
  18. }
  19. /**
  20. * The "sanboot" command
  21. *
  22. * @v argc Argument count
  23. * @v argv Argument list
  24. * @ret rc Exit code
  25. */
  26. static int sanboot_exec ( int argc, char **argv ) {
  27. static struct option longopts[] = {
  28. { "help", 0, NULL, 'h' },
  29. { NULL, 0, NULL, 0 },
  30. };
  31. const char *root_path = NULL;
  32. int c;
  33. int rc;
  34. /* Parse options */
  35. while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
  36. switch ( c ) {
  37. case 'h':
  38. /* Display help text */
  39. default:
  40. /* Unrecognised/invalid option */
  41. sanboot_syntax ( argv );
  42. return 1;
  43. }
  44. }
  45. /* Need exactly one image name remaining after the options */
  46. if ( optind != ( argc - 1 ) ) {
  47. sanboot_syntax ( argv );
  48. return 1;
  49. }
  50. root_path = argv[optind];
  51. /* Boot from root path */
  52. if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
  53. printf ( "Could not boot from %s: %s\n",
  54. root_path, strerror ( rc ) );
  55. return 1;
  56. }
  57. return 0;
  58. }
  59. struct command sanboot_command __command = {
  60. .name = "sanboot",
  61. .exec = sanboot_exec,
  62. };