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