]>
git.saurik.com Git - apple/hfs.git/blob - livefiles_hfs_plugin/lf_hfs_vnode.c
1 /* Copyright © 2017-2018 Apple Inc. All rights reserved.
6 * Created by Or Haimovich on 20/3/18.
9 #include "lf_hfs_vnode.h"
10 #include "lf_hfs_utils.h"
11 #include "lf_hfs_vfsutils.h"
12 #include "lf_hfs_generic_buf.h"
13 #include "lf_hfs_fileops_handler.h"
14 #include "lf_hfs_xattr.h"
15 #include <System/sys/decmpfs.h>
17 int VTtoUVFS_tab
[16] =
21 UVFS_FA_TYPE_FILE
, UVFS_FA_TYPE_DIR
, VNON
, VNON
, UVFS_FA_TYPE_SYMLINK
,
23 VNON
, VNON
, VNON
, VNON
, VNON
26 enum vtype iftovt_tab
[16] =
28 VNON
, VFIFO
, VCHR
, VNON
, VDIR
, VNON
, VBLK
, VNON
,
29 VREG
, VNON
, VLNK
, VNON
, VSOCK
, VNON
, VNON
, VBAD
,
32 int uvfsToVtype_tab
[4] =
37 mode_t vttoif_tab
[9] =
39 0, S_IFREG
, S_IFDIR
, S_IFBLK
, S_IFCHR
, S_IFLNK
,
40 S_IFSOCK
, S_IFIFO
, S_IFMT
,
43 errno_t
vnode_initialize(uint32_t size
, void *data
, vnode_t
*vpp
)
45 memset(*vpp
,0,sizeof(struct vnode
));
47 assert(size
== sizeof((*vpp
)->sFSParams
));
48 memcpy((void *) &(*vpp
)->sFSParams
,data
,size
);
50 if ((*vpp
)->sFSParams
.vnfs_vtype
== VDIR
)
52 (*vpp
)->sExtraData
.sDirData
.uDirVersion
= 1;
57 errno_t
vnode_create(uint32_t size
, void *data
, vnode_t
*vpp
)
59 *vpp
= hfs_malloc(sizeof(struct vnode
));
65 return (vnode_initialize(size
, data
, vpp
));
68 void vnode_rele(vnode_t vp
)
71 lf_hfs_generic_buf_cache_LockBufCache();
72 lf_hfs_generic_buf_cache_remove_vnode(vp
);
73 lf_hfs_generic_buf_cache_UnLockBufCache();
79 mount_t
vnode_mount(vnode_t vp
)
81 return (vp
->sFSParams
.vnfs_mp
);
84 int vnode_issystem(vnode_t vp
)
86 return (vp
->sFSParams
.vnfs_marksystem
);
89 int vnode_isreg(vnode_t vp
)
91 return (vp
->sFSParams
.vnfs_vtype
== VREG
);
94 int vnode_isdir(vnode_t vp
)
96 return (vp
->sFSParams
.vnfs_vtype
== VDIR
);
99 int vnode_islnk(vnode_t vp
)
101 return (vp
->sFSParams
.vnfs_vtype
== VLNK
);
105 @function vnode_update_identity
107 VNODE_UPDATE_PARENT: set parent.
108 VNODE_UPDATE_NAME: set name.
109 VNODE_UPDATE_CACHE: flush cache entries for hard links associated with this file.
113 void vnode_update_identity(vnode_t vp
, vnode_t dvp
, const char *name
, int name_len
, uint32_t name_hashval
, int flags
)
115 if (flags
& VNODE_UPDATE_PARENT
)
117 vp
->sFSParams
.vnfs_dvp
= dvp
;
120 if (flags
& VNODE_UPDATE_NAME
)
122 if (!vp
->sFSParams
.vnfs_cnp
) {
123 vp
->sFSParams
.vnfs_cnp
= hfs_malloc(sizeof(struct componentname
));
124 if (vp
->sFSParams
.vnfs_cnp
== NULL
) {
125 LFHFS_LOG(LEVEL_ERROR
, "vnode_update_identity: failed to malloc vnfs_cnp\n");
128 bzero(vp
->sFSParams
.vnfs_cnp
, sizeof(struct componentname
));
130 vp
->sFSParams
.vnfs_cnp
->cn_namelen
= name_len
;
131 if (vp
->sFSParams
.vnfs_cnp
->cn_nameptr
) {
132 hfs_free(vp
->sFSParams
.vnfs_cnp
->cn_nameptr
);
133 vp
->sFSParams
.vnfs_cnp
->cn_nameptr
= NULL
;
135 vp
->sFSParams
.vnfs_cnp
->cn_nameptr
= lf_hfs_utils_allocate_and_copy_string( (char*) name
, name_len
);
136 vp
->sFSParams
.vnfs_cnp
->cn_hash
= name_hashval
;
140 void vnode_GetAttrInternal (vnode_t vp
, UVFSFileAttributes
*psOutAttr
)
142 struct cnode
*cp
= VTOC(vp
);
145 memset( psOutAttr
, 0, sizeof(UVFSFileAttributes
) );
147 psOutAttr
->fa_validmask
= VALID_OUT_ATTR_MASK
;
149 psOutAttr
->fa_gid
= cp
->c_gid
;
150 psOutAttr
->fa_uid
= cp
->c_uid
;
151 psOutAttr
->fa_mode
= cp
->c_mode
& ALL_UVFS_MODES
;
153 v_type
= vp
->sFSParams
.vnfs_vtype
;
154 psOutAttr
->fa_type
= VTOUVFS(v_type
);
156 psOutAttr
->fa_atime
.tv_sec
= cp
->c_atime
;
157 psOutAttr
->fa_ctime
.tv_sec
= cp
->c_ctime
;
158 psOutAttr
->fa_mtime
.tv_sec
= cp
->c_mtime
;
159 psOutAttr
->fa_birthtime
.tv_sec
= cp
->c_btime
;
161 psOutAttr
->fa_fileid
= cp
->c_fileid
;
162 psOutAttr
->fa_parentid
= cp
->c_parentcnid
;
163 psOutAttr
->fa_bsd_flags
= cp
->c_bsdflags
;
167 psOutAttr
->fa_allocsize
= 0;
168 psOutAttr
->fa_size
= (cp
->c_entries
+ 2) * AVERAGE_HFSDIRENTRY_SIZE
;
169 psOutAttr
->fa_nlink
= cp
->c_entries
+ 2;
173 if (psOutAttr
->fa_bsd_flags
& UF_COMPRESSED
)
175 if (VNODE_IS_RSRC(vp
))
177 psOutAttr
->fa_allocsize
= VTOF(vp
)->ff_blocks
* VTOHFS(vp
)->blockSize
;
178 psOutAttr
->fa_size
= VTOF(vp
)->ff_size
;
182 hfs_unlock(VTOC(vp
));
185 int iErr
= hfs_vnop_getxattr(vp
, "com.apple.decmpfs", NULL
, 0, &attr_size
);
190 if (attr_size
< sizeof(decmpfs_disk_header
) || attr_size
> MAX_DECMPFS_XATTR_SIZE
) {
194 /* allocation includes space for the extra attr_size field of a compressed_header */
195 data
= (char *) malloc(attr_size
);
201 /* read the xattr into our buffer, skipping over the attr_size field at the beginning */
203 iErr
= hfs_vnop_getxattr(vp
, "com.apple.decmpfs", data
, attr_size
, &read_size
);
207 if (read_size
!= attr_size
) {
213 Hdr
.attr_size
= (uint32_t) attr_size
;
214 Hdr
.compression_magic
= *((uint32_t*)data
);
215 Hdr
.compression_type
= *((uint32_t*)(data
+ sizeof(uint32_t)));
216 Hdr
.uncompressed_size
= *((uint32_t*)(data
+ sizeof(uint64_t)));
221 psOutAttr
->fa_allocsize
= VCTOF(vp
, cp
)->ff_blocks
* VTOHFS(vp
)->blockSize
;
222 psOutAttr
->fa_size
= VCTOF(vp
, cp
)->ff_size
;
226 psOutAttr
->fa_allocsize
= ROUND_UP(Hdr
.uncompressed_size
,VTOHFS(vp
)->blockSize
);
227 psOutAttr
->fa_size
= Hdr
.uncompressed_size
;
230 if (data
) free(data
);
231 hfs_lock(VTOC(vp
), 0, 0);
236 psOutAttr
->fa_allocsize
= VCTOF(vp
, cp
)->ff_blocks
* VTOHFS(vp
)->blockSize
;
237 psOutAttr
->fa_size
= VCTOF(vp
, cp
)->ff_size
;
239 psOutAttr
->fa_nlink
= (cp
->c_flag
& C_HARDLINK
)? cp
->c_linkcount
: 1;