FsNew.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 FsNew_h
  26. #define FsNew_h
  27. #include <stddef.h>
  28. #include <stdint.h>
  29. /** 32-bit alignment */
  30. typedef uint32_t newalign_t;
  31. /** Size required for exFAT or FAT class. */
  32. #define FS_SIZE(etype, ftype) \
  33. (sizeof(ftype) < sizeof(etype) ? sizeof(etype) : sizeof(ftype))
  34. /** Dimension of aligned area. */
  35. #define NEW_ALIGN_DIM(n) \
  36. (((size_t)(n) + sizeof(newalign_t) - 1U)/sizeof(newalign_t))
  37. /** Dimension of aligned area for etype or ftype class. */
  38. #define FS_ALIGN_DIM(etype, ftype) NEW_ALIGN_DIM(FS_SIZE(etype, ftype))
  39. /** Custom new placement operator */
  40. void* operator new(size_t size, newalign_t* ptr);
  41. #endif // FsNew_h