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

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