FsVolume.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, uint8_t part,
  29. uint32_t volStart) {
  30. m_fVol = nullptr;
  31. m_xVol = new (m_volMem) ExFatVolume;
  32. if (m_xVol && m_xVol->begin(blockDev, false, part, volStart)) {
  33. goto done;
  34. }
  35. m_xVol = nullptr;
  36. m_fVol = new (m_volMem) FatVolume;
  37. if (m_fVol && m_fVol->begin(blockDev, false, part, volStart)) {
  38. goto done;
  39. }
  40. m_fVol = nullptr;
  41. return false;
  42. done:
  43. if (setCwv || !m_cwv) {
  44. m_cwv = this;
  45. }
  46. return true;
  47. }
  48. //------------------------------------------------------------------------------
  49. bool FsVolume::ls(print_t* pr, const char* path, uint8_t flags) {
  50. FsBaseFile dir;
  51. return dir.open(this, path, O_RDONLY) && dir.ls(pr, flags);
  52. }
  53. //------------------------------------------------------------------------------
  54. FsFile FsVolume::open(const char* path, oflag_t oflag) {
  55. FsFile tmpFile;
  56. tmpFile.open(this, path, oflag);
  57. return tmpFile;
  58. }
  59. #if ENABLE_ARDUINO_STRING
  60. //------------------------------------------------------------------------------
  61. FsFile FsVolume::open(const String& path, oflag_t oflag) {
  62. return open(path.c_str(), oflag);
  63. }
  64. #endif // ENABLE_ARDUINO_STRING