-static int
-nspace_materialization_is_prevented(void)
-{
- proc_t p = current_proc();
- uthread_t ut = (uthread_t)get_bsdthread_info(current_thread());
- vfs_context_t ctx = vfs_context_current();
-
- /*
- * Kernel context ==> return EDEADLK, as we would with any random
- * process decorated as no-materialize.
- */
- if (ctx == vfs_context_kernel()) {
- return EDEADLK;
- }
-
- /*
- * If the process has the dataless-manipulation entitlement,
- * materialization is prevented, and depending on the kind
- * of file system operation, things get to proceed as if the
- * object is not dataless.
- */
- if (vfs_context_is_dataless_manipulator(ctx)) {
- return EJUSTRETURN;
- }
-
- /*
- * Per-thread decorations override any process-wide decorations.
- * (Foundation uses this, and this overrides even the dataless-
- * manipulation entitlement so as to make API contracts consistent.)
- */
- if (ut != NULL) {
- if (ut->uu_flag & UT_NSPACE_NODATALESSFAULTS) {
- return EDEADLK;
- }
- if (ut->uu_flag & UT_NSPACE_FORCEDATALESSFAULTS) {
- return 0;
- }
- }
-
- /*
- * If the process's iopolicy specifies that dataless files
- * can be materialized, then we let it go ahead.
- */
- if (p->p_vfs_iopolicy & P_VFS_IOPOLICY_MATERIALIZE_DATALESS_FILES) {
- return 0;
- }
-
- /*
- * The default behavior is to not materialize dataless files;
- * return to the caller that deadlock was detected.
- */
- return EDEADLK;
-}
-