/*
- * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <security/mac_framework.h>
#endif
+#if CONFIG_PROTECT
+#include <sys/cprotect.h>
+#endif
+
static int vn_closefile(struct fileglob *fp, vfs_context_t ctx);
static int vn_ioctl(struct fileproc *fp, u_long com, caddr_t data,
}
need_vnop_open = !did_open;
- } else {
+ }
+ else {
if (fmode & O_EXCL)
error = EEXIST;
}
}
+#if CONFIG_PROTECT
+ /*
+ * Perform any content protection access checks prior to calling
+ * into the filesystem, if the raw encrypted mode was not
+ * requested.
+ *
+ * If the va_dataprotect_flags are NOT active, or if they are,
+ * but they do not have the VA_DP_RAWENCRYPTED bit set, then we need
+ * to perform the checks.
+ */
+ if (!(VATTR_IS_ACTIVE (vap, va_dataprotect_flags)) ||
+ ((vap->va_dataprotect_flags & VA_DP_RAWENCRYPTED) == 0)) {
+ error = cp_handle_open (vp, fmode);
+ if (error) {
+ goto bad;
+ }
+ }
+#endif
+
error = VNOP_OPEN(vp, fmode, ctx);
if (error) {
goto bad;
}
#endif
- ioflag = 0;
+ /* This signals to VNOP handlers that this read came from a file table read */
+ ioflag = IO_SYSCALL_DISPATCH;
+
if (fp->f_fglob->fg_flag & FNONBLOCK)
ioflag |= IO_NDELAY;
if ((fp->f_fglob->fg_flag & FNOCACHE) || vnode_isnocache(vp))
- ioflag |= IO_NOCACHE;
+ ioflag |= IO_NOCACHE;
+ if (fp->f_fglob->fg_flag & FENCRYPTED) {
+ ioflag |= IO_ENCRYPTED;
+ }
if (fp->f_fglob->fg_flag & FNORDAHEAD)
- ioflag |= IO_RAOFF;
+ ioflag |= IO_RAOFF;
if ((flags & FOF_OFFSET) == 0)
uio->uio_offset = fp->f_fglob->fg_offset;
}
#endif
- ioflag = IO_UNIT;
+ /*
+ * IO_SYSCALL_DISPATCH signals to VNOP handlers that this write originated
+ * from a file table write.
+ */
+ ioflag = (IO_UNIT | IO_SYSCALL_DISPATCH);
+
if (vp->v_type == VREG && (fp->f_fglob->fg_flag & O_APPEND))
ioflag |= IO_APPEND;
if (fp->f_fglob->fg_flag & FNONBLOCK)
ioflag |= IO_NOCACHE;
if (fp->f_fglob->fg_flag & FNODIRECT)
ioflag |= IO_NODIRECT;
+ if (fp->f_fglob->fg_flag & FSINGLE_WRITER)
+ ioflag |= IO_SINGLE_WRITER;
/*
* Treat synchronous mounts and O_FSYNC on the fd as equivalent.
error = ENXIO;
goto out;
}
- *(int *)data = bdevsw[major(vp->v_rdev)].d_type;
+ *(int *)data = D_TYPEMASK & bdevsw[major(vp->v_rdev)].d_type;
} else if (vp->v_type == VCHR) {
if (major(vp->v_rdev) >= nchrdev) {
error = ENXIO;
goto out;
}
- *(int *)data = cdevsw[major(vp->v_rdev)].d_type;
+ *(int *)data = D_TYPEMASK & cdevsw[major(vp->v_rdev)].d_type;
} else {
error = ENOTTY;
goto out;