]> git.saurik.com Git - apple/hfs.git/blob - livefiles_hfs_plugin/lf_hfs_vnode.h
hfs-522.0.9.tar.gz
[apple/hfs.git] / livefiles_hfs_plugin / lf_hfs_vnode.h
1 /* Copyright © 2017-2018 Apple Inc. All rights reserved.
2 *
3 * lf_hfs_vnode.h
4 * livefiles_hfs
5 *
6 * Created by Or Haimovich on 18/3/18.
7 */
8
9 #ifndef lf_hfs_vnode_h
10 #define lf_hfs_vnode_h
11
12 #include <sys/_types/_guid_t.h>
13
14 #include "lf_hfs_common.h"
15
16 /*
17 * Vnode types. VNON means no type.
18 */
19 enum vtype {
20 /* 0 */
21 VNON,
22 /* 1 - 5 */
23 VREG, VDIR, VBLK, VCHR, VLNK,
24 /* 6 - 10 */
25 VSOCK, VFIFO, VBAD, VSTR, VCPLX
26 };
27
28 extern int VTtoUVFS_tab[];
29
30 #define VTTOUVFS(vt) (VTtoUVFS_tab[vt])
31 #define IS_ROOT(vp) (vp->sFSParams.vnfs_markroot)
32 #define IS_DIR(vp) (vp->sFSParams.vnfs_vtype == VDIR)
33 #define IS_LNK(vp) (vp->sFSParams.vnfs_vtype == VLNK)
34
35
36 /*
37 * Convert between vnode types and inode formats (since POSIX.1
38 * defines mode word of stat structure in terms of inode formats).
39 */
40 struct componentname {
41 /*
42 * Arguments to lookup.
43 */
44 uint32_t cn_nameiop; /* lookup operation */
45 uint32_t cn_flags; /* flags (see below) */
46
47 /*
48 * Shared between lookup and commit routines.
49 */
50 char *cn_pnbuf; /* pathname buffer */
51 int cn_pnlen; /* length of allocated buffer */
52 char *cn_nameptr; /* pointer to looked up name */
53 int cn_namelen; /* length of looked up component */
54 uint32_t cn_hash; /* hash value of looked up name */
55 uint32_t cn_consume; /* chars to consume in lookup() */
56 };
57
58 /* The following structure specifies a vnode for creation */
59 struct vnode_fsparam {
60 struct mount *vnfs_mp; /* mount point to which this vnode_t is part of */
61 enum vtype vnfs_vtype; /* vnode type */
62 const char *vnfs_str; /* File system Debug aid */
63 struct vnode *vnfs_dvp; /* The parent vnode */
64 void *vnfs_fsnode; /* inode */
65 // int (**vnfs_vops)(void *); /* vnode dispatch table */
66 int vnfs_markroot; /* is this a root vnode in FS (not a system wide one) */
67 int vnfs_marksystem; /* is a system vnode */
68 dev_t vnfs_rdev; /* dev_t for block or char vnodes */
69 off_t vnfs_filesize; /* that way no need for getattr in UBC */
70 struct componentname *vnfs_cnp; /* component name to add to namecache */
71 uint32_t vnfs_flags; /* flags */
72 };
73
74 typedef struct
75 {
76 uint64_t uDirVersion;
77 } DirData_s;
78
79 typedef struct vnode
80 {
81 uint32_t uValidNodeMagic1;
82
83 struct hfsmount *mount;
84 bool is_rsrc;
85 struct cnode *cnode;
86 struct vnode_fsparam sFSParams;
87 FileSystemRecord_s* psFSRecord;
88 bool bIsMountVnode;
89
90 union
91 {
92 DirData_s sDirData;
93 } sExtraData;
94
95 uint32_t uValidNodeMagic2;
96
97 } *vnode_t;
98
99 typedef struct mount
100 {
101 struct hfsmount* psHfsmount;
102 int mnt_flag;
103 } *mount_t;
104
105 struct vnode_attr {
106 /* bitfields */
107 uint64_t va_supported;
108 uint64_t va_active;
109 /*
110 * Control flags. The low 16 bits are reserved for the
111 * ioflags being passed for truncation operations.
112 */
113 int va_vaflags;
114
115 /* traditional stat(2) parameter fields */
116 dev_t va_rdev; /* device id (device nodes only) */
117 uint64_t va_nlink; /* number of references to this file */
118 uint64_t va_total_size; /* size in bytes of all forks */
119 uint64_t va_total_alloc; /* disk space used by all forks */
120 uint64_t va_data_size; /* size in bytes of the fork managed by current vnode */
121 uint64_t va_data_alloc; /* disk space used by the fork managed by current vnode */
122 uint32_t va_iosize; /* optimal I/O blocksize */
123 /* file security information */
124 uid_t va_uid; /* owner UID */
125 gid_t va_gid; /* owner GID */
126 mode_t va_mode; /* posix permissions */
127 uint32_t va_flags; /* file flags */
128 struct kauth_acl *va_acl; /* access control list */
129 /* timestamps */
130 struct timespec va_create_time; /* time of creation */
131 struct timespec va_access_time; /* time of last access */
132 struct timespec va_modify_time; /* time of last data modification */
133 struct timespec va_change_time; /* time of last metadata change */
134 struct timespec va_backup_time; /* time of last backup */
135
136 /* file parameters */
137 uint64_t va_fileid; /* file unique ID in filesystem */
138 uint64_t va_linkid; /* file link unique ID */
139 uint64_t va_parentid; /* parent ID */
140 uint32_t va_fsid; /* filesystem ID */
141 uint64_t va_filerev; /* file revision counter */ /* XXX */
142 uint32_t va_gen; /* file generation count */ /* XXX - relationship of
143 * these two? */
144 /* misc parameters */
145 uint32_t va_encoding; /* filename encoding script */
146 enum vtype va_type; /* file type */
147 char * va_name; /* Name for ATTR_CMN_NAME; MAXPATHLEN bytes */
148 guid_t va_uuuid; /* file owner UUID */
149 guid_t va_guuid; /* file group UUID */
150
151 /* Meaningful for directories only */
152 uint64_t va_nchildren; /* Number of items in a directory */
153 uint64_t va_dirlinkcount; /* Real references to dir (i.e. excluding "." and ".." refs) */
154
155 struct kauth_acl *va_base_acl;
156
157 struct timespec va_addedtime; /* timestamp when item was added to parent directory */
158
159 /* Data Protection fields */
160 uint32_t va_dataprotect_class; /* class specified for this file if it didn't exist */
161 uint32_t va_dataprotect_flags; /* flags from NP open(2) to the filesystem */
162 /* Document revision tracking */
163 uint32_t va_document_id;
164 /* Fields for Bulk args */
165 uint32_t va_devid; /* devid of filesystem */
166 uint32_t va_objtype; /* type of object */
167 uint32_t va_objtag; /* vnode tag of filesystem */
168 uint32_t va_user_access; /* access for user */
169 uint8_t va_finderinfo[32]; /* Finder Info */
170 uint64_t va_rsrc_length; /* Resource Fork length */
171 uint64_t va_rsrc_alloc; /* Resource Fork allocation size */
172 fsid_t va_fsid64; /* fsid, of the correct type */
173 uint32_t va_write_gencount; /* counter that increments each time the file changes */
174 uint64_t va_private_size; /* If the file were deleted, how many bytes would be freed immediately */
175 /* add new fields here only */
176 };
177
178 /*
179 * Convert between vnode types and inode formats (since POSIX.1
180 * defines mode word of stat structure in terms of inode formats).
181 */
182 extern enum vtype iftovt_tab[];
183 #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
184
185 extern int VTtoUVFS_tab[];
186 extern int uvfsToVtype_tab[];
187 extern mode_t vttoif_tab[];
188
189 #define VTOUVFS(type) (VTtoUVFS_tab[type])
190 #define UVFSTOV(type) (uvfsToVtype_tab[type])
191 #define MAKEIMODE(indx) (vttoif_tab[indx])
192
193 #define VNODE_UPDATE_PARENT 0x01
194 #define VNODE_UPDATE_NAME 0x02
195 #define VNODE_UPDATE_CACHE 0x04
196
197 #define VNODE_REMOVE_NODELETEBUSY 0x0001 /* Don't delete busy files (Carbon) */
198 #define VNODE_REMOVE_SKIP_NAMESPACE_EVENT 0x0002 /* Do not upcall to userland handlers */
199 #define VNODE_REMOVE_NO_AUDIT_PATH 0x0004 /* Do not audit the path */
200
201 #define VNOVAL (-1)
202
203 /*
204 * Flags for ioflag.
205 */
206 #define IO_UNIT 0x0001 /* do I/O as atomic unit */
207 #define IO_APPEND 0x0002 /* append write to end */
208 #define IO_SYNC 0x0004 /* do I/O synchronously */
209 #define IO_NODELOCKED 0x0008 /* underlying node already locked */
210 #define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */
211 #define IO_NOZEROFILL 0x0020 /* F_SETSIZE fcntl uses to prevent zero filling */
212 //#ifdef XNU_KERNEL_PRIVATE
213 #define IO_REVOKE IO_NOZEROFILL /* revoked close for tty, will Not be used in conjunction */
214 //#endif /* XNU_KERNEL_PRIVATE */
215 #define IO_TAILZEROFILL 0x0040 /* zero fills at the tail of write */
216 #define IO_HEADZEROFILL 0x0080 /* zero fills at the head of write */
217 #define IO_NOZEROVALID 0x0100 /* do not zero fill if valid page */
218 #define IO_NOZERODIRTY 0x0200 /* do not zero fill if page is dirty */
219 #define IO_CLOSE 0x0400 /* I/O issued from close path */
220 #define IO_NOCACHE 0x0800 /* same effect as VNOCACHE_DATA, but only for this 1 I/O */
221 #define IO_RAOFF 0x1000 /* same effect as VRAOFF, but only for this 1 I/O */
222 #define IO_DEFWRITE 0x2000 /* defer write if vfs.defwrite is set */
223 #define IO_PASSIVE 0x4000 /* this I/O is marked as background I/O so it won't throttle Throttleable I/O */
224 #define IO_BACKGROUND IO_PASSIVE /* used for backward compatibility. to be removed after IO_BACKGROUND is no longer
225 * used by DiskImages in-kernel mode */
226 #define IO_NOAUTH 0x8000 /* No authorization checks. */
227 #define IO_NODIRECT 0x10000 /* don't use direct synchronous writes if IO_NOCACHE is specified */
228 #define IO_ENCRYPTED 0x20000 /* Retrieve encrypted blocks from the filesystem */
229 #define IO_RETURN_ON_THROTTLE 0x40000
230 #define IO_SINGLE_WRITER 0x80000
231 #define IO_SYSCALL_DISPATCH 0x100000 /* I/O was originated from a file table syscall */
232 #define IO_SWAP_DISPATCH 0x200000 /* I/O was originated from the swap layer */
233 #define IO_SKIP_ENCRYPTION 0x400000 /* Skips en(de)cryption on the IO. Must be initiated from kernel */
234 #define IO_EVTONLY 0x800000 /* the i/o is being done on an fd that's marked O_EVTONLY */
235
236 errno_t vnode_create(uint32_t size, void *data, vnode_t *vpp);
237 errno_t vnode_initialize(uint32_t size, void *data, vnode_t *vpp);
238 void vnode_rele(vnode_t vp);
239 mount_t vnode_mount(vnode_t vp);
240 int vnode_issystem(vnode_t vp);
241 int vnode_isreg(vnode_t vp);
242 int vnode_isdir(vnode_t vp);
243 int vnode_islnk(vnode_t vp);
244 void vnode_update_identity(vnode_t vp, vnode_t dvp, const char *name, int name_len, uint32_t name_hashval, int flags);
245 void vnode_GetAttrInternal (vnode_t vp, UVFSFileAttributes *psOutAttr );
246 #endif /* lf_hfs_vnode_h */