選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

imgmgmt.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2007 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 <stdint.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <gpxe/image.h>
  23. #include <gpxe/downloader.h>
  24. #include <gpxe/monojob.h>
  25. #include <gpxe/open.h>
  26. #include <gpxe/uri.h>
  27. #include <usr/imgmgmt.h>
  28. /** @file
  29. *
  30. * Image management
  31. *
  32. */
  33. /**
  34. * Fetch an image
  35. *
  36. * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
  37. * @v name Name for image, or NULL
  38. * @v register_image Image registration routine
  39. * @ret rc Return status code
  40. */
  41. int imgfetch ( struct image *image, const char *uri_string,
  42. int ( * image_register ) ( struct image *image ) ) {
  43. struct uri *uri;
  44. int rc;
  45. if ( ! ( uri = parse_uri ( uri_string ) ) )
  46. return -ENOMEM;
  47. image_set_uri ( image, uri );
  48. if ( ( rc = create_downloader ( &monojob, image, image_register,
  49. LOCATION_URI, uri ) ) == 0 )
  50. rc = monojob_wait ( uri_string );
  51. uri_put ( uri );
  52. return rc;
  53. }
  54. /**
  55. * Load an image
  56. *
  57. * @v image Image
  58. * @ret rc Return status code
  59. */
  60. int imgload ( struct image *image ) {
  61. int rc;
  62. /* Try to load image */
  63. if ( ( rc = image_autoload ( image ) ) != 0 )
  64. return rc;
  65. return 0;
  66. }
  67. /**
  68. * Execute an image
  69. *
  70. * @v image Image
  71. * @ret rc Return status code
  72. */
  73. int imgexec ( struct image *image ) {
  74. return image_exec ( image );
  75. }
  76. /**
  77. * Identify the first loaded image
  78. *
  79. * @ret image Image, or NULL
  80. */
  81. struct image * imgautoselect ( void ) {
  82. struct image *image;
  83. for_each_image ( image ) {
  84. if ( image->flags & IMAGE_LOADED )
  85. return image;
  86. }
  87. return NULL;
  88. }
  89. /**
  90. * Display status of an image
  91. *
  92. * @v image Executable/loadable image
  93. */
  94. void imgstat ( struct image *image ) {
  95. printf ( "%s: %zd bytes", image->name, image->len );
  96. if ( image->type )
  97. printf ( " [%s]", image->type->name );
  98. if ( image->flags & IMAGE_LOADED )
  99. printf ( " [LOADED]" );
  100. if ( image->cmdline )
  101. printf ( " \"%s\"", image->cmdline );
  102. printf ( "\n" );
  103. }
  104. /**
  105. * Free an image
  106. *
  107. * @v image Executable/loadable image
  108. */
  109. void imgfree ( struct image *image ) {
  110. unregister_image ( image );
  111. }