FsFormatter.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef FsFormatter_h
  26. #define FsFormatter_h
  27. #include "FatLib/FatLib.h"
  28. #include "ExFatLib/ExFatLib.h"
  29. /**
  30. * \class FsFormatter
  31. * \brief Format a exFAT/FAT volume.
  32. */
  33. class FsFormatter {
  34. public:
  35. /**
  36. * Format a FAT volume.
  37. *
  38. * \param[in] dev Block device for volume.
  39. * \param[in] secBuffer buffer for writing to volume.
  40. * \param[in] pr Print device for progress output.
  41. *
  42. * \return true for success or false for failure.
  43. */
  44. bool format(FsBlockDevice* dev, uint8_t* secBuffer, print_t* pr = nullptr) {
  45. uint32_t sectorCount = dev->sectorCount();
  46. if (sectorCount == 0) {
  47. return false;
  48. }
  49. return sectorCount <= 67108864 ?
  50. m_fFmt.format(dev, secBuffer, pr) :
  51. m_xFmt.format(dev, secBuffer, pr);
  52. }
  53. private:
  54. FatFormatter m_fFmt;
  55. ExFatFormatter m_xFmt;
  56. };
  57. #endif // FsFormatter_h