- if ((error = vnode_open(name, (O_CREAT | FWRITE), (0), 0, &ref->vp, ref->ctx)))
- goto out;
+ fmode = (create_file) ? (O_CREAT | FWRITE) : FWRITE;
+ cmode = S_IRUSR | S_IWUSR;
+ ndflags = NOFOLLOW;
+ NDINIT(&nd, LOOKUP, OP_OPEN, ndflags, UIO_SYSSPACE, CAST_USER_ADDR_T(name), ref->ctx);
+ VATTR_INIT(&va);
+ VATTR_SET(&va, va_mode, cmode);
+ VATTR_SET(&va, va_dataprotect_flags, VA_DP_RAWENCRYPTED);
+ VATTR_SET(&va, va_dataprotect_class, PROTECTION_CLASS_D);
+ if ((error = vn_open_auth(&nd, &fmode, &va))) {
+ kprintf("vn_open_auth(fmode: %d, cmode: %d) failed with error: %d\n", fmode, cmode, error);
+ goto out;
+ }