您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

blockdev.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <errno.h>
  20. #include <ipxe/interface.h>
  21. #include <ipxe/blockdev.h>
  22. /** @file
  23. *
  24. * Block devices
  25. *
  26. */
  27. /**
  28. * Read from block device
  29. *
  30. * @v control Control interface
  31. * @v data Data interface
  32. * @v lba Starting logical block address
  33. * @v count Number of logical blocks
  34. * @v buffer Data buffer
  35. * @v len Length of data buffer
  36. * @ret rc Return status code
  37. */
  38. int block_read ( struct interface *control, struct interface *data,
  39. uint64_t lba, unsigned int count,
  40. userptr_t buffer, size_t len ) {
  41. struct interface *dest;
  42. block_read_TYPE ( void * ) *op =
  43. intf_get_dest_op ( control, block_read, &dest );
  44. void *object = intf_object ( dest );
  45. int rc;
  46. if ( op ) {
  47. rc = op ( object, data, lba, count, buffer, len );
  48. } else {
  49. /* Default is to fail to issue the command */
  50. rc = -EOPNOTSUPP;
  51. }
  52. intf_put ( dest );
  53. return rc;
  54. }
  55. /**
  56. * Write to block device
  57. *
  58. * @v control Control interface
  59. * @v data Data interface
  60. * @v lba Starting logical block address
  61. * @v count Number of logical blocks
  62. * @v buffer Data buffer
  63. * @v len Length of data buffer
  64. * @ret rc Return status code
  65. */
  66. int block_write ( struct interface *control, struct interface *data,
  67. uint64_t lba, unsigned int count,
  68. userptr_t buffer, size_t len ) {
  69. struct interface *dest;
  70. block_write_TYPE ( void * ) *op =
  71. intf_get_dest_op ( control, block_write, &dest );
  72. void *object = intf_object ( dest );
  73. int rc;
  74. if ( op ) {
  75. rc = op ( object, data, lba, count, buffer, len );
  76. } else {
  77. /* Default is to fail to issue the command */
  78. rc = -EOPNOTSUPP;
  79. }
  80. intf_put ( dest );
  81. return rc;
  82. }
  83. /**
  84. * Read block device capacity
  85. *
  86. * @v control Control interface
  87. * @v data Data interface
  88. * @ret rc Return status code
  89. */
  90. int block_read_capacity ( struct interface *control, struct interface *data ) {
  91. struct interface *dest;
  92. block_read_capacity_TYPE ( void * ) *op =
  93. intf_get_dest_op ( control, block_read_capacity, &dest );
  94. void *object = intf_object ( dest );
  95. int rc;
  96. if ( op ) {
  97. rc = op ( object, data );
  98. } else {
  99. /* Default is to fail to issue the command */
  100. rc = -EOPNOTSUPP;
  101. }
  102. intf_put ( dest );
  103. return rc;
  104. }
  105. /**
  106. * Report block device capacity
  107. *
  108. * @v intf Interface
  109. * @v capacity Block device capacity
  110. */
  111. void block_capacity ( struct interface *intf,
  112. struct block_device_capacity *capacity ) {
  113. struct interface *dest;
  114. block_capacity_TYPE ( void * ) *op =
  115. intf_get_dest_op ( intf, block_capacity, &dest );
  116. void *object = intf_object ( dest );
  117. if ( op ) {
  118. op ( object, capacity );
  119. } else {
  120. /* Default is to do nothing */
  121. }
  122. intf_put ( dest );
  123. }