1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/export.h>
6 * fs on-disk file type to dirent file type conversion
8 static const unsigned char fs_dtype_by_ftype
[FT_MAX
] = {
9 [FT_UNKNOWN
] = DT_UNKNOWN
,
10 [FT_REG_FILE
] = DT_REG
,
20 * fs_ftype_to_dtype() - fs on-disk file type to dirent type.
21 * @filetype: The on-disk file type to convert.
23 * This function converts the on-disk file type value (FT_*) to the directory
26 * Context: Any context.
28 * * DT_UNKNOWN - Unknown type
30 * * DT_CHR - Character device
31 * * DT_DIR - Directory
32 * * DT_BLK - Block device
33 * * DT_REG - Regular file
34 * * DT_LNK - Symbolic link
35 * * DT_SOCK - Local-domain socket
37 unsigned char fs_ftype_to_dtype(unsigned int filetype
)
39 if (filetype
>= FT_MAX
)
42 return fs_dtype_by_ftype
[filetype
];
44 EXPORT_SYMBOL_GPL(fs_ftype_to_dtype
);
47 * dirent file type to fs on-disk file type conversion
48 * Values not initialized explicitly are FT_UNKNOWN (0).
50 static const unsigned char fs_ftype_by_dtype
[DT_MAX
] = {
51 [DT_REG
] = FT_REG_FILE
,
53 [DT_LNK
] = FT_SYMLINK
,
61 * fs_umode_to_ftype() - file mode to on-disk file type.
62 * @mode: The file mode to convert.
64 * This function converts the file mode value to the on-disk file type (FT_*).
66 * Context: Any context.
68 * * FT_UNKNOWN - Unknown type
69 * * FT_REG_FILE - Regular file
70 * * FT_DIR - Directory
71 * * FT_CHRDEV - Character device
72 * * FT_BLKDEV - Block device
74 * * FT_SOCK - Local-domain socket
75 * * FT_SYMLINK - Symbolic link
77 unsigned char fs_umode_to_ftype(umode_t mode
)
79 return fs_ftype_by_dtype
[S_DT(mode
)];
81 EXPORT_SYMBOL_GPL(fs_umode_to_ftype
);
84 * fs_umode_to_dtype() - file mode to dirent file type.
85 * @mode: The file mode to convert.
87 * This function converts the file mode value to the directory
90 * Context: Any context.
92 * * DT_UNKNOWN - Unknown type
94 * * DT_CHR - Character device
95 * * DT_DIR - Directory
96 * * DT_BLK - Block device
97 * * DT_REG - Regular file
98 * * DT_LNK - Symbolic link
99 * * DT_SOCK - Local-domain socket
101 unsigned char fs_umode_to_dtype(umode_t mode
)
103 return fs_ftype_to_dtype(fs_umode_to_ftype(mode
));
105 EXPORT_SYMBOL_GPL(fs_umode_to_dtype
);