fs_types.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_FS_TYPES_H
  3. #define _LINUX_FS_TYPES_H
  4. /*
  5. * This is a header for the common implementation of dirent
  6. * to fs on-disk file type conversion. Although the fs on-disk
  7. * bits are specific to every file system, in practice, many
  8. * file systems use the exact same on-disk format to describe
  9. * the lower 3 file type bits that represent the 7 POSIX file
  10. * types.
  11. *
  12. * It is important to note that the definitions in this
  13. * header MUST NOT change. This would break both the
  14. * userspace ABI and the on-disk format of filesystems
  15. * using this code.
  16. *
  17. * All those file systems can use this generic code for the
  18. * conversions.
  19. */
  20. /*
  21. * struct dirent file types
  22. * exposed to user via getdents(2), readdir(3)
  23. *
  24. * These match bits 12..15 of stat.st_mode
  25. * (ie "(i_mode >> 12) & 15").
  26. */
  27. #define S_DT_SHIFT 12
  28. #define S_DT(mode) (((mode) & S_IFMT) >> S_DT_SHIFT)
  29. #define S_DT_MASK (S_IFMT >> S_DT_SHIFT)
  30. /* these are defined by POSIX and also present in glibc's dirent.h */
  31. #define DT_UNKNOWN 0
  32. #define DT_FIFO 1
  33. #define DT_CHR 2
  34. #define DT_DIR 4
  35. #define DT_BLK 6
  36. #define DT_REG 8
  37. #define DT_LNK 10
  38. #define DT_SOCK 12
  39. #define DT_WHT 14
  40. #define DT_MAX (S_DT_MASK + 1) /* 16 */
  41. /*
  42. * fs on-disk file types.
  43. * Only the low 3 bits are used for the POSIX file types.
  44. * Other bits are reserved for fs private use.
  45. * These definitions are shared and used by multiple filesystems,
  46. * and MUST NOT change under any circumstances.
  47. *
  48. * Note that no fs currently stores the whiteout type on-disk,
  49. * so whiteout dirents are exposed to user as DT_CHR.
  50. */
  51. #define FT_UNKNOWN 0
  52. #define FT_REG_FILE 1
  53. #define FT_DIR 2
  54. #define FT_CHRDEV 3
  55. #define FT_BLKDEV 4
  56. #define FT_FIFO 5
  57. #define FT_SOCK 6
  58. #define FT_SYMLINK 7
  59. #define FT_MAX 8
  60. /*
  61. * declarations for helper functions, accompanying implementation
  62. * is in fs/fs_types.c
  63. */
  64. extern unsigned char fs_ftype_to_dtype(unsigned int filetype);
  65. extern unsigned char fs_umode_to_ftype(umode_t mode);
  66. extern unsigned char fs_umode_to_dtype(umode_t mode);
  67. #endif