+int
+ubc_setthreadcred(struct vnode *vp, struct proc *p, thread_t thread)
+{
+ struct ubc_info *uip;
+ kauth_cred_t credp;
+ struct uthread *uthread = get_bsdthread_info(thread);
+
+ if (!UBCINFOEXISTS(vp))
+ return (1);
+
+ vnode_lock(vp);
+
+ uip = vp->v_ubcinfo;
+ credp = uip->ui_ucred;
+
+ if (credp == NOCRED) {
+ /* use per-thread cred, if assumed identity, else proc cred */
+ if (uthread == NULL || (uthread->uu_flag & UT_SETUID) == 0) {
+ uip->ui_ucred = kauth_cred_proc_ref(p);
+ } else {
+ uip->ui_ucred = uthread->uu_ucred;
+ kauth_cred_ref(uip->ui_ucred);
+ }
+ }
+ vnode_unlock(vp);
+
+ return (0);
+}
+