lfs_config.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 int32_t lfs_ssize_t;
  16. typedef lfs_word_t lfs_off_t;
  17. typedef int lfs_error_t;
  18. typedef lfs_lword_t lfs_lsize_t;
  19. typedef lfs_word_t lfs_ino_t;
  20. typedef lfs_hword_t lfs_ioff_t;
  21. // Maximum length of file name
  22. #define LFS_NAME_MAX 255
  23. // Builtin functions
  24. static inline lfs_word_t lfs_max(lfs_word_t a, lfs_word_t b) {
  25. return (a > b) ? a : b;
  26. }
  27. static inline lfs_word_t lfs_min(lfs_word_t a, lfs_word_t b) {
  28. return (a < b) ? a : b;
  29. }
  30. static inline lfs_word_t lfs_ctz(lfs_word_t a) {
  31. return __builtin_ctz(a);
  32. }
  33. static inline lfs_word_t lfs_npw2(lfs_word_t a) {
  34. return 32 - __builtin_clz(a-1);
  35. }
  36. static inline void lfs_swap(lfs_word_t *a, lfs_word_t *b) {
  37. lfs_word_t temp = *a;
  38. *a = *b;
  39. *b = temp;
  40. }
  41. // Attributes
  42. #define lfs_disk_struct struct __attribute__((packed))
  43. // Logging operations
  44. #include <stdio.h>
  45. #define LFS_ERROR(fmt, ...) printf("Error: " fmt "\n", __VA_ARGS__)
  46. #define LFS_WARN(fmt, ...) printf("Warn: " fmt "\n", __VA_ARGS__)
  47. #define LFS_INFO(fmt, ...) printf("Info: " fmt "\n", __VA_ARGS__)
  48. #endif