FsVolume.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2011-2022 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "FsLib.h"
  26. FsVolume* FsVolume::m_cwv = nullptr;
  27. //------------------------------------------------------------------------------
  28. bool FsVolume::begin(FsBlockDevice* blockDev, bool setCwv,
  29. uint8_t part, uint32_t volStart) {
  30. m_blockDev = blockDev;
  31. m_fVol = nullptr;
  32. m_xVol = new (m_volMem) ExFatVolume;
  33. if (m_xVol && m_xVol->begin(m_blockDev, false, part, volStart)) {
  34. goto done;
  35. }
  36. m_xVol = nullptr;
  37. m_fVol = new (m_volMem) FatVolume;
  38. if (m_fVol && m_fVol->begin(m_blockDev, false, part, volStart)) {
  39. goto done;
  40. }
  41. m_fVol = nullptr;
  42. return false;
  43. done:
  44. if (setCwv || !m_cwv) {
  45. m_cwv = this;
  46. }
  47. return true;
  48. }
  49. //------------------------------------------------------------------------------
  50. bool FsVolume::ls(print_t* pr, const char* path, uint8_t flags) {
  51. FsBaseFile dir;
  52. return dir.open(this, path, O_RDONLY) && dir.ls(pr, flags);
  53. }
  54. //------------------------------------------------------------------------------
  55. FsFile FsVolume::open(const char *path, oflag_t oflag) {
  56. FsFile tmpFile;
  57. tmpFile.open(this, path, oflag);
  58. return tmpFile;
  59. }
  60. #if ENABLE_ARDUINO_STRING
  61. //------------------------------------------------------------------------------
  62. FsFile FsVolume::open(const String &path, oflag_t oflag) {
  63. return open(path.c_str(), oflag );
  64. }
  65. #endif // ENABLE_ARDUINO_STRING