Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sanboot_cmd.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <errno.h>
  26. #include <getopt.h>
  27. #include <ipxe/command.h>
  28. #include <ipxe/parseopt.h>
  29. #include <ipxe/uri.h>
  30. #include <ipxe/sanboot.h>
  31. #include <usr/autoboot.h>
  32. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  33. /** @file
  34. *
  35. * SAN commands
  36. *
  37. */
  38. /** "sanboot" options */
  39. struct sanboot_options {
  40. /** Drive number */
  41. unsigned int drive;
  42. /** Do not describe SAN device */
  43. int no_describe;
  44. /** Keep SAN device */
  45. int keep;
  46. /** Filename */
  47. char *filename;
  48. };
  49. /** "sanboot" option list */
  50. static union {
  51. /* "sanboot" takes all four options */
  52. struct option_descriptor sanboot[4];
  53. /* "sanhook" takes only --drive and --no-describe */
  54. struct option_descriptor sanhook[2];
  55. /* "sanunhook" takes only --drive */
  56. struct option_descriptor sanunhook[1];
  57. } opts = {
  58. .sanboot = {
  59. OPTION_DESC ( "drive", 'd', required_argument,
  60. struct sanboot_options, drive, parse_integer ),
  61. OPTION_DESC ( "no-describe", 'n', no_argument,
  62. struct sanboot_options, no_describe, parse_flag ),
  63. OPTION_DESC ( "keep", 'k', no_argument,
  64. struct sanboot_options, keep, parse_flag ),
  65. OPTION_DESC ( "filename", 'f', required_argument,
  66. struct sanboot_options, filename, parse_string ),
  67. },
  68. };
  69. /** "sanhook" command descriptor */
  70. static struct command_descriptor sanhook_cmd =
  71. COMMAND_DESC ( struct sanboot_options, opts.sanhook, 1, MAX_ARGUMENTS,
  72. "<root-path>" );
  73. /** "sanboot" command descriptor */
  74. static struct command_descriptor sanboot_cmd =
  75. COMMAND_DESC ( struct sanboot_options, opts.sanboot, 0, MAX_ARGUMENTS,
  76. "[<root-path>]" );
  77. /** "sanunhook" command descriptor */
  78. static struct command_descriptor sanunhook_cmd =
  79. COMMAND_DESC ( struct sanboot_options, opts.sanunhook, 0, 0, NULL );
  80. /**
  81. * The "sanboot", "sanhook" and "sanunhook" commands
  82. *
  83. * @v argc Argument count
  84. * @v argv Argument list
  85. * @v default_flags Default set of flags for uriboot()
  86. * @v no_root_path_flags Additional flags to apply if no root path is present
  87. * @ret rc Return status code
  88. */
  89. static int sanboot_core_exec ( int argc, char **argv,
  90. struct command_descriptor *cmd,
  91. int default_flags, int no_root_path_flags ) {
  92. struct sanboot_options opts;
  93. struct uri *uris[argc];
  94. int count;
  95. int flags;
  96. int i;
  97. int rc;
  98. /* Initialise options */
  99. memset ( &opts, 0, sizeof ( opts ) );
  100. opts.drive = san_default_drive();
  101. /* Parse options */
  102. if ( ( rc = reparse_options ( argc, argv, cmd, &opts ) ) != 0 )
  103. goto err_parse_options;
  104. /* Parse root paths, if present */
  105. count = ( argc - optind );
  106. for ( i = 0 ; i < count ; i++ ) {
  107. uris[i] = parse_uri ( argv[ optind + i ] );
  108. if ( ! uris[i] ) {
  109. rc = -ENOMEM;
  110. goto err_parse_uri;
  111. }
  112. }
  113. /* Construct flags */
  114. flags = default_flags;
  115. if ( opts.no_describe )
  116. flags |= URIBOOT_NO_SAN_DESCRIBE;
  117. if ( opts.keep )
  118. flags |= URIBOOT_NO_SAN_UNHOOK;
  119. if ( ! count )
  120. flags |= no_root_path_flags;
  121. /* Boot from root path */
  122. if ( ( rc = uriboot ( NULL, uris, count, opts.drive, opts.filename,
  123. flags ) ) != 0 )
  124. goto err_uriboot;
  125. err_uriboot:
  126. i = count;
  127. err_parse_uri:
  128. for ( i-- ; i >= 0 ; i-- )
  129. uri_put ( uris[i] );
  130. err_parse_options:
  131. return rc;
  132. }
  133. /**
  134. * The "sanhook" command
  135. *
  136. * @v argc Argument count
  137. * @v argv Argument list
  138. * @ret rc Return status code
  139. */
  140. static int sanhook_exec ( int argc, char **argv ) {
  141. return sanboot_core_exec ( argc, argv, &sanhook_cmd,
  142. ( URIBOOT_NO_SAN_BOOT |
  143. URIBOOT_NO_SAN_UNHOOK ), 0 );
  144. }
  145. /**
  146. * The "sanboot" command
  147. *
  148. * @v argc Argument count
  149. * @v argv Argument list
  150. * @ret rc Return status code
  151. */
  152. static int sanboot_exec ( int argc, char **argv ) {
  153. return sanboot_core_exec ( argc, argv, &sanboot_cmd,
  154. 0, URIBOOT_NO_SAN_UNHOOK );
  155. }
  156. /**
  157. * The "sanunhook" command
  158. *
  159. * @v argc Argument count
  160. * @v argv Argument list
  161. * @ret rc Return status code
  162. */
  163. static int sanunhook_exec ( int argc, char **argv ) {
  164. return sanboot_core_exec ( argc, argv, &sanunhook_cmd,
  165. ( URIBOOT_NO_SAN_DESCRIBE |
  166. URIBOOT_NO_SAN_BOOT ), 0 );
  167. }
  168. /** SAN commands */
  169. struct command sanboot_commands[] __command = {
  170. {
  171. .name = "sanhook",
  172. .exec = sanhook_exec,
  173. },
  174. {
  175. .name = "sanboot",
  176. .exec = sanboot_exec,
  177. },
  178. {
  179. .name = "sanunhook",
  180. .exec = sanunhook_exec,
  181. },
  182. };