Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2015 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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * Hyper Text Transfer Protocol (HTTP) block device
  28. *
  29. */
  30. #include <stdint.h>
  31. #include <ipxe/uaccess.h>
  32. #include <ipxe/blocktrans.h>
  33. #include <ipxe/blockdev.h>
  34. #include <ipxe/acpi.h>
  35. #include <ipxe/http.h>
  36. /** Block size used for HTTP block device requests */
  37. #define HTTP_BLKSIZE 512
  38. /**
  39. * Read from block device
  40. *
  41. * @v http HTTP transaction
  42. * @v data Data interface
  43. * @v lba Starting logical block address
  44. * @v count Number of logical blocks
  45. * @v buffer Data buffer
  46. * @v len Length of data buffer
  47. * @ret rc Return status code
  48. */
  49. int http_block_read ( struct http_transaction *http, struct interface *data,
  50. uint64_t lba, unsigned int count, userptr_t buffer,
  51. size_t len ) {
  52. struct http_request_range range;
  53. int rc;
  54. /* Sanity check */
  55. assert ( len == ( count * HTTP_BLKSIZE ) );
  56. /* Construct request range descriptor */
  57. range.start = ( lba * HTTP_BLKSIZE );
  58. range.len = len;
  59. /* Start a range request to retrieve the block(s) */
  60. if ( ( rc = http_open ( data, &http_get, http->uri, &range,
  61. NULL ) ) != 0 )
  62. goto err_open;
  63. /* Insert block device translator */
  64. if ( ( rc = block_translate ( data, buffer, len ) ) != 0 ) {
  65. DBGC ( http, "HTTP %p could not insert block translator: %s\n",
  66. http, strerror ( rc ) );
  67. goto err_translate;
  68. }
  69. return 0;
  70. err_translate:
  71. intf_restart ( data, rc );
  72. err_open:
  73. return rc;
  74. }
  75. /**
  76. * Read block device capacity
  77. *
  78. * @v control Control interface
  79. * @v data Data interface
  80. * @ret rc Return status code
  81. */
  82. int http_block_read_capacity ( struct http_transaction *http,
  83. struct interface *data ) {
  84. int rc;
  85. /* Start a HEAD request to retrieve the capacity */
  86. if ( ( rc = http_open ( data, &http_head, http->uri, NULL,
  87. NULL ) ) != 0 )
  88. goto err_open;
  89. /* Insert block device translator */
  90. if ( ( rc = block_translate ( data, UNULL, HTTP_BLKSIZE ) ) != 0 ) {
  91. DBGC ( http, "HTTP %p could not insert block translator: %s\n",
  92. http, strerror ( rc ) );
  93. goto err_translate;
  94. }
  95. return 0;
  96. err_translate:
  97. intf_restart ( data, rc );
  98. err_open:
  99. return rc;
  100. }