lfs_config.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Configuration and type definitions
  3. *
  4. * Copyright (c) 2017 Christopher Haster
  5. * Distributed under the MIT license
  6. */
  7. #ifndef LFS_CONFIG_H
  8. #define LFS_CONFIG_H
  9. #include <stdint.h>
  10. // Type definitions
  11. typedef uint64_t lfs_lword_t;
  12. typedef uint32_t lfs_word_t;
  13. typedef uint16_t lfs_hword_t;
  14. typedef lfs_word_t lfs_size_t;
  15. typedef lfs_word_t lfs_off_t;
  16. typedef int lfs_error_t;
  17. typedef lfs_lword_t lfs_lsize_t;
  18. typedef lfs_word_t lfs_ino_t;
  19. typedef lfs_hword_t lfs_ioff_t;
  20. // Maximum length of file name
  21. #define LFS_NAME_MAX 255
  22. // Builtin functions
  23. static inline lfs_word_t lfs_max(lfs_word_t a, lfs_word_t b) {
  24. return (a > b) ? a : b;
  25. }
  26. static inline lfs_word_t lfs_min(lfs_word_t a, lfs_word_t b) {
  27. return (a < b) ? a : b;
  28. }
  29. static inline lfs_word_t lfs_ctz(lfs_word_t a) {
  30. return __builtin_ctz(a);
  31. }
  32. static inline lfs_word_t lfs_npw2(lfs_word_t a) {
  33. return 32 - __builtin_clz(a-1);
  34. }
  35. static inline void lfs_swap(lfs_word_t *a, lfs_word_t *b) {
  36. lfs_word_t temp = *a;
  37. *a = *b;
  38. *b = temp;
  39. }
  40. // Attributes
  41. #define lfs_disk_struct struct __attribute__((packed))
  42. // Logging operations
  43. #include <stdio.h>
  44. #define LFS_ERROR(fmt, ...) printf("Error: " fmt "\n", __VA_ARGS__)
  45. #define LFS_WARN(fmt, ...) printf("Warn: " fmt "\n", __VA_ARGS__)
  46. #define LFS_INFO(fmt, ...) printf("Info: " fmt "\n", __VA_ARGS__)
  47. #endif