1 /* 2 * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com. 3 * Copyright 2001-2009, Axel Dörfler, axeld@pinc-software.de. 4 * This file may be used under the terms of the MIT License. 5 */ 6 #ifndef UTILITY_H 7 #define UTILITY_H 8 9 10 #include "btrfs.h" 11 12 13 enum inode_type { 14 S_DIRECTORY = S_IFDIR, 15 S_FILE = S_IFREG, 16 S_SYMLINK = S_IFLNK, 17 18 S_INDEX_TYPES = (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX 19 | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX 20 | S_FLOAT_INDEX | S_DOUBLE_INDEX), 21 22 S_EXTENDED_TYPES = (S_ATTR_DIR | S_ATTR | S_INDEX_DIR) 23 }; 24 25 26 inline uint8 27 get_filetype(int32 mode) 28 { 29 mode &= S_IFMT; 30 switch (mode) 31 { 32 case S_IFSOCK: 33 return BTRFS_FILETYPE_SOCKET; 34 case S_IFLNK: 35 return BTRFS_FILETYPE_SYMLINK; 36 case S_IFREG: 37 return BTRFS_FILETYPE_REGULAR; 38 case S_IFBLK: 39 return BTRFS_FILETYPE_BLKDEV; 40 case S_IFDIR: 41 return BTRFS_FILETYPE_DIRECTORY; 42 case S_IFCHR: 43 return BTRFS_FILETYPE_CHRDEV; 44 case S_IFIFO: 45 return BTRFS_FILETYPE_FIFO; 46 default: 47 return BTRFS_FILETYPE_UNKNOWN; 48 } 49 } 50 51 52 /*! Converts the open mode, the open flags given to bfs_open(), into 53 access modes, e.g. since O_RDONLY requires read access to the 54 file, it will be converted to R_OK. 55 */ 56 inline int 57 open_mode_to_access(int openMode) 58 { 59 openMode &= O_RWMASK; 60 if (openMode == O_RDONLY) 61 return R_OK; 62 if (openMode == O_WRONLY) 63 return W_OK; 64 65 return R_OK | W_OK; 66 } 67 68 69 #endif // UTILITY_H 70