]> git.saurik.com Git - apple/hfs.git/blob - livefiles_hfs_plugin/lf_hfs_common.h
hfs-556.41.1.tar.gz
[apple/hfs.git] / livefiles_hfs_plugin / lf_hfs_common.h
1 /* Copyright © 2017-2018 Apple Inc. All rights reserved.
2 *
3 * lf_hfs_common.h
4 * livefiles_hfs
5 *
6 * Created by Yakov Ben Zaken on 31/12/2017.
7 */
8
9 #ifndef lf_hfs_common_h
10 #define lf_hfs_common_h
11
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <stdio.h>
16 #import <os/log.h>
17 #include <err.h>
18 #include <sys/errno.h>
19 #include <UserFS/UserVFS.h>
20
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
25
26 #define min MIN
27 #define max MAX
28
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)
35
36 typedef struct
37 {
38 int iFD; // File descriptor as received from usbstoraged
39 unsigned uUnmountHint; // Unmount hint (passed on in LFHFS_UNMOUNT, cleared on LFHFS_MOUNT)
40 } FileSystemRecord_s;
41
42 #define VPTOFSRECORD(vp) (vp->sFSParams.vnfs_mp->psHfsmount->hfs_devvp->psFSRecord)
43
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))
46
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))
51
52 #undef ROUND_DOWN
53 #define ROUND_DOWN(_x, _m) (((_x) / (_m)) * (_m))
54
55 #undef ROUND_UP
56 #define ROUND_UP(_x, _m) ROUND_DOWN((_x) + (_m) - 1, (_m))
57
58 struct HFSUniStr255 {
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;
64
65 struct hfsmount;
66
67 #define B_LOCKED 0x00000010
68
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 */
89
90 /*
91 * component name operations (for VNOP_LOOKUP)
92 */
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 */
98
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))
100
101 #define UF_NODUMP 0x00000001 /* do not dump file */
102
103 #define VALID_NODE_MAGIC (0xC0BEC0BE)
104 #define VALID_NODE_BADMAGIC (0xDEADDABA)
105 #define INVALIDATE_NODE(psNodeRecord) \
106 do { \
107 if ( psNodeRecord != NULL ) { \
108 ((vnode_t)psNodeRecord)->uValidNodeMagic1 = VALID_NODE_BADMAGIC; \
109 ((vnode_t)psNodeRecord)->uValidNodeMagic2 = VALID_NODE_BADMAGIC; \
110 } \
111 } while(0)
112 #define SET_NODE_AS_VALID(psNodeRecord) \
113 do { \
114 if ( psNodeRecord != NULL ) { \
115 ((vnode_t)psNodeRecord)->uValidNodeMagic1 = VALID_NODE_MAGIC; \
116 ((vnode_t)psNodeRecord)->uValidNodeMagic2 = VALID_NODE_MAGIC; \
117 } \
118 } while(0)
119 #define VERIFY_NODE_IS_VALID(psNodeRecord) \
120 do { \
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__ ); \
125 return ESTALE; \
126 } \
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__ ); \
131 return EINVAL; \
132 } \
133 } while(0)
134 #define VERIFY_NODE_IS_VALID_FOR_RECLAIM(psNodeRecord) \
135 do { \
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" ); \
142 return EINVAL; \
143 } \
144 } while(0)
145
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))
148
149
150 #endif /* lf_hfs_common_h */