1 /* Copyright © 2017-2018 Apple Inc. All rights reserved.
6 * Created by Yakov Ben Zaken on 31/12/2017.
9 #ifndef lf_hfs_common_h
10 #define lf_hfs_common_h
18 #include <sys/errno.h>
19 #include <UserFS/UserVFS.h>
21 #define LF_HFS_CHECK_UNMAPPED 0
22 #define LF_HFS_QOUTA_SUPPORT 0
23 #define LF_HFS_FULL_VNODE_SUPPORT 0
24 #define LF_HFS_NATIVE_SEARCHFS_SUPPORT 0
29 /* pseudo-errors returned inside kernel to modify return to process */
30 #define ERESTART (-1) /* restart syscall */
31 #define EJUSTRETURN (-2) /* don't modify regs, just return */
32 #define ERECYCLE (-5) /* restart lookup under heavy vnode pressure/recycling */
33 #define EREDRIVEOPEN (-6)
34 #define EKEEPLOOKING (-7)
38 int iFD
; // File descriptor as received from usbstoraged
39 unsigned uUnmountHint
; // Unmount hint (passed on in LFHFS_UNMOUNT, cleared on LFHFS_MOUNT)
42 #define VPTOFSRECORD(vp) (vp->sFSParams.vnfs_mp->psHfsmount->hfs_devvp->psFSRecord)
44 #define VNODE_TO_IFD(vp) ((vp->bIsMountVnode)? (vp->psFSRecord->iFD) : ((VPTOFSRECORD(vp))->iFD))
45 #define VNODE_TO_UNMOUNT_HINT(vp) ((vp->bIsMountVnode)? (vp->psFSRecord->uUnmountHint) : ((VPTOFSRECORD(vp))->uUnmountHint))
47 /* Macros to clear/set/test flags. */
48 #define SET(t, f) (t) |= (f)
49 #define CLR(t, f) (t) &= ~(f)
50 #define ISSET(t, f) ((t) & (f))
53 #define ROUND_DOWN(_x, _m) (((_x) / (_m)) * (_m))
56 #define ROUND_UP(_x, _m) ROUND_DOWN((_x) + (_m) - 1, (_m))
59 u_int16_t length
; /* number of unicode characters */
60 u_int16_t unicode
[255]; /* unicode characters */
61 } __attribute__((aligned(2), packed
));
62 typedef struct HFSUniStr255 HFSUniStr255
;
63 typedef const HFSUniStr255
*ConstHFSUniStr255Param
;
67 #define B_LOCKED 0x00000010
69 #define RDONLY 0x00000200 /* lookup with read-only semantics */
70 #define HASBUF 0x00000400 /* has allocated pathname buffer */
71 #define SAVENAME 0x00000800 /* save pathname buffer */
72 #define SAVESTART 0x00001000 /* save starting directory */
73 #define ISDOTDOT 0x00002000 /* current component name is .. */
74 #define MAKEENTRY 0x00004000 /* entry is to be added to name cache */
75 #define ISLASTCN 0x00008000 /* this is last component of pathname */
76 #define ISSYMLINK 0x00010000 /* symlink needs interpretation */
77 #define ISWHITEOUT 0x00020000 /* found whiteout */
78 #define DOWHITEOUT 0x00040000 /* do whiteouts */
79 #define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */
80 #define ISUNICODE 0x00100000 /* current component name is unicode*/
81 #define ISOPEN 0x00200000 /* caller is opening; return a real vnode. */
82 #define NOCROSSMOUNT 0x00400000 /* do not cross mount points */
83 #define NOMACCHECK 0x00800000 /* do not perform MAC checks */
84 #define AUDITVNODE1 0x04000000 /* audit the looked up vnode information */
85 #define AUDITVNODE2 0x08000000 /* audit the looked up vnode information */
86 #define TRAILINGSLASH 0x10000000 /* path ended in a slash */
87 #define NOCAPCHECK 0x20000000 /* do not perform capability checks */
88 #define PARAMASK 0x3ffffe00 /* mask of parameter descriptors */
91 * component name operations (for VNOP_LOOKUP)
93 #define LOOKUP 0 /* perform name lookup only */
94 #define CREATE 1 /* setup for file creation */
95 #define DELETE 2 /* setup for file deletion */
96 #define RENAME 3 /* setup for file renaming */
97 #define OPMASK 3 /* mask for operation */
99 #define ALL_UVFS_MODES (UVFS_FA_MODE_OTH(UVFS_FA_MODE_RWX) | UVFS_FA_MODE_GRP(UVFS_FA_MODE_RWX) | UVFS_FA_MODE_USR(UVFS_FA_MODE_RWX))
101 #define UF_NODUMP 0x00000001 /* do not dump file */
103 #define VALID_NODE_MAGIC (0xC0BEC0BE)
104 #define VALID_NODE_BADMAGIC (0xDEADDABA)
105 #define INVALIDATE_NODE(psNodeRecord) \
107 if ( psNodeRecord != NULL ) { \
108 ((vnode_t)psNodeRecord)->uValidNodeMagic1 = VALID_NODE_BADMAGIC; \
109 ((vnode_t)psNodeRecord)->uValidNodeMagic2 = VALID_NODE_BADMAGIC; \
112 #define SET_NODE_AS_VALID(psNodeRecord) \
114 if ( psNodeRecord != NULL ) { \
115 ((vnode_t)psNodeRecord)->uValidNodeMagic1 = VALID_NODE_MAGIC; \
116 ((vnode_t)psNodeRecord)->uValidNodeMagic2 = VALID_NODE_MAGIC; \
119 #define VERIFY_NODE_IS_VALID(psNodeRecord) \
121 if ((psNodeRecord) && \
122 ((vnode_t)psNodeRecord)->uValidNodeMagic1 == VALID_NODE_BADMAGIC && \
123 ((vnode_t)psNodeRecord)->uValidNodeMagic2 == VALID_NODE_BADMAGIC ) { \
124 LFHFS_LOG( LEVEL_ERROR, "[%s] Got stale node", __FUNCTION__ ); \
127 if ((psNodeRecord == NULL) || \
128 ((vnode_t)psNodeRecord)->uValidNodeMagic1 != VALID_NODE_MAGIC || \
129 ((vnode_t)psNodeRecord)->uValidNodeMagic2 != VALID_NODE_MAGIC ) { \
130 LFHFS_LOG( LEVEL_ERROR, "[%s] Got invalid node", __FUNCTION__ ); \
134 #define VERIFY_NODE_IS_VALID_FOR_RECLAIM(psNodeRecord) \
136 if ((psNodeRecord == NULL) || \
137 ( ((vnode_t)psNodeRecord)->uValidNodeMagic1 != VALID_NODE_MAGIC && \
138 ((vnode_t)psNodeRecord)->uValidNodeMagic1 != VALID_NODE_BADMAGIC ) || \
139 ( ((vnode_t)psNodeRecord)->uValidNodeMagic2 != VALID_NODE_MAGIC && \
140 ((vnode_t)psNodeRecord)->uValidNodeMagic2 != VALID_NODE_BADMAGIC )) { \
141 LFHFS_LOG( LEVEL_ERROR, "Got invalid node for reclaim" ); \
146 #define ALL_UVFS_MODES (UVFS_FA_MODE_OTH(UVFS_FA_MODE_RWX) | UVFS_FA_MODE_GRP(UVFS_FA_MODE_RWX) | UVFS_FA_MODE_USR(UVFS_FA_MODE_RWX))
147 #define UVFS_READ_ONLY (UVFS_FA_MODE_OTH(UVFS_FA_MODE_R | UVFS_FA_MODE_X) | UVFS_FA_MODE_GRP(UVFS_FA_MODE_R | UVFS_FA_MODE_X) | UVFS_FA_MODE_USR(UVFS_FA_MODE_R | UVFS_FA_MODE_X))
150 #endif /* lf_hfs_common_h */