~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/fs_types.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/fs.h>
  3 #include <linux/export.h>
  4 
  5 /*
  6  * fs on-disk file type to dirent file type conversion
  7  */
  8 static const unsigned char fs_dtype_by_ftype[FT_MAX] = {
  9         [FT_UNKNOWN]    = DT_UNKNOWN,
 10         [FT_REG_FILE]   = DT_REG,
 11         [FT_DIR]        = DT_DIR,
 12         [FT_CHRDEV]     = DT_CHR,
 13         [FT_BLKDEV]     = DT_BLK,
 14         [FT_FIFO]       = DT_FIFO,
 15         [FT_SOCK]       = DT_SOCK,
 16         [FT_SYMLINK]    = DT_LNK
 17 };
 18 
 19 /**
 20  * fs_ftype_to_dtype() - fs on-disk file type to dirent type.
 21  * @filetype: The on-disk file type to convert.
 22  *
 23  * This function converts the on-disk file type value (FT_*) to the directory
 24  * entry type (DT_*).
 25  *
 26  * Context: Any context.
 27  * Return:
 28  * * DT_UNKNOWN         - Unknown type
 29  * * DT_FIFO            - FIFO
 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
 36  */
 37 unsigned char fs_ftype_to_dtype(unsigned int filetype)
 38 {
 39         if (filetype >= FT_MAX)
 40                 return DT_UNKNOWN;
 41 
 42         return fs_dtype_by_ftype[filetype];
 43 }
 44 EXPORT_SYMBOL_GPL(fs_ftype_to_dtype);
 45 
 46 /*
 47  * dirent file type to fs on-disk file type conversion
 48  * Values not initialized explicitly are FT_UNKNOWN (0).
 49  */
 50 static const unsigned char fs_ftype_by_dtype[DT_MAX] = {
 51         [DT_REG]        = FT_REG_FILE,
 52         [DT_DIR]        = FT_DIR,
 53         [DT_LNK]        = FT_SYMLINK,
 54         [DT_CHR]        = FT_CHRDEV,
 55         [DT_BLK]        = FT_BLKDEV,
 56         [DT_FIFO]       = FT_FIFO,
 57         [DT_SOCK]       = FT_SOCK,
 58 };
 59 
 60 /**
 61  * fs_umode_to_ftype() - file mode to on-disk file type.
 62  * @mode: The file mode to convert.
 63  *
 64  * This function converts the file mode value to the on-disk file type (FT_*).
 65  *
 66  * Context: Any context.
 67  * Return:
 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
 73  * * FT_FIFO            - FIFO
 74  * * FT_SOCK            - Local-domain socket
 75  * * FT_SYMLINK         - Symbolic link
 76  */
 77 unsigned char fs_umode_to_ftype(umode_t mode)
 78 {
 79         return fs_ftype_by_dtype[S_DT(mode)];
 80 }
 81 EXPORT_SYMBOL_GPL(fs_umode_to_ftype);
 82 
 83 /**
 84  * fs_umode_to_dtype() - file mode to dirent file type.
 85  * @mode: The file mode to convert.
 86  *
 87  * This function converts the file mode value to the directory
 88  * entry type (DT_*).
 89  *
 90  * Context: Any context.
 91  * Return:
 92  * * DT_UNKNOWN         - Unknown type
 93  * * DT_FIFO            - FIFO
 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
100  */
101 unsigned char fs_umode_to_dtype(umode_t mode)
102 {
103         return fs_ftype_to_dtype(fs_umode_to_ftype(mode));
104 }
105 EXPORT_SYMBOL_GPL(fs_umode_to_dtype);
106 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php