zfs_diskio.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
  3. /*-----------------------------------------------------------------------*/
  4. /* If a working storage control module is available, it should be */
  5. /* attached to the FatFs via a glue function rather than modifying it. */
  6. /* This is an example of glue functions to attach various exsisting */
  7. /* storage control modules to the FatFs module with a defined API. */
  8. /*-----------------------------------------------------------------------*/
  9. /*----------------------------------------------------------------------------/
  10. / FatFs - Generic FAT file system module R0.12a /
  11. /-----------------------------------------------------------------------------/
  12. /
  13. / Copyright (C) 2016, ChaN, all right reserved.
  14. /
  15. / FatFs module is an open source software. Redistribution and use of FatFs in
  16. / source and binary forms, with or without modification, are permitted provided
  17. / that the following condition is met:
  18. / 1. Redistributions of source code must retain the above copyright notice,
  19. / this condition and the following disclaimer.
  20. /
  21. / This software is provided by the copyright holder and contributors "AS IS"
  22. / and any warranties related to this software are DISCLAIMED.
  23. / The copyright owner or contributors be NOT LIABLE for any damages caused
  24. / by use of this software.
  25. /----------------------------------------------------------------------------*/
  26. #include <diskio.h> /* FatFs lower layer API */
  27. #include <ffconf.h>
  28. #include <disk/disk_access.h>
  29. static const char* const pdrv_str[] = {_VOLUME_STRS};
  30. /*-----------------------------------------------------------------------*/
  31. /* Get Drive Status */
  32. /*-----------------------------------------------------------------------*/
  33. DSTATUS disk_status(BYTE pdrv)
  34. {
  35. __ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
  36. if (disk_access_status(pdrv_str[pdrv]) != 0) {
  37. return STA_NOINIT;
  38. } else {
  39. return RES_OK;
  40. }
  41. }
  42. /*-----------------------------------------------------------------------*/
  43. /* Initialize a Drive */
  44. /*-----------------------------------------------------------------------*/
  45. DSTATUS disk_initialize(BYTE pdrv)
  46. {
  47. __ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
  48. if (disk_access_init(pdrv_str[pdrv]) != 0) {
  49. return STA_NOINIT;
  50. } else {
  51. return RES_OK;
  52. }
  53. }
  54. /*-----------------------------------------------------------------------*/
  55. /* Read Sector(s) */
  56. /*-----------------------------------------------------------------------*/
  57. DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
  58. {
  59. __ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
  60. if (disk_access_read(pdrv_str[pdrv], buff, sector, count) != 0) {
  61. return RES_ERROR;
  62. } else {
  63. return RES_OK;
  64. }
  65. }
  66. /*-----------------------------------------------------------------------*/
  67. /* Write Sector(s) */
  68. /*-----------------------------------------------------------------------*/
  69. DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
  70. {
  71. __ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
  72. if(disk_access_write(pdrv_str[pdrv], buff, sector, count) != 0) {
  73. return RES_ERROR;
  74. } else {
  75. return RES_OK;
  76. }
  77. }
  78. /*-----------------------------------------------------------------------*/
  79. /* Miscellaneous Functions */
  80. /*-----------------------------------------------------------------------*/
  81. DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
  82. {
  83. int ret = RES_OK;
  84. __ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
  85. switch (cmd) {
  86. case CTRL_SYNC:
  87. if(disk_access_ioctl(pdrv_str[pdrv],
  88. DISK_IOCTL_CTRL_SYNC, buff) != 0) {
  89. ret = RES_ERROR;
  90. }
  91. break;
  92. case GET_SECTOR_COUNT:
  93. if (disk_access_ioctl(pdrv_str[pdrv],
  94. DISK_IOCTL_GET_SECTOR_COUNT, buff) != 0) {
  95. ret = RES_ERROR;
  96. }
  97. break;
  98. case GET_BLOCK_SIZE:
  99. if (disk_access_ioctl(pdrv_str[pdrv],
  100. DISK_IOCTL_GET_ERASE_BLOCK_SZ, buff) != 0) {
  101. ret = RES_ERROR;
  102. }
  103. break;
  104. default:
  105. ret = RES_PARERR;
  106. break;
  107. }
  108. return ret;
  109. }