- if ((fp->f_flag & FWRITE) != 0) {
- struct vattr va;
- if ((err =
- VOP_GETATTR(vp, &va,
- p->p_ucred, p)))
- return (err);
- if ((va.va_flags &
- (IMMUTABLE|APPEND)) == 0)
- maxprot |= VM_PROT_WRITE;
- else if (prot & PROT_WRITE)
- return (EPERM);
- } else if ((prot & PROT_WRITE) != 0)
- return (EACCES);
+ if ((fp->f_fglob->fg_flag & FWRITE) != 0) {
+ /*
+ * check for write access
+ *
+ * Note that we already made this check when granting FWRITE
+ * against the file, so it seems redundant here.
+ */
+ error = vnode_authorize(vp, NULL, KAUTH_VNODE_CHECKIMMUTABLE, &context);
+
+ /* if not granted for any reason, but we wanted it, bad */
+ if ((prot & PROT_WRITE) && (error != 0)) {
+ vnode_put(vp);
+ goto bad;
+ }
+
+ /* if writable, remember */
+ if (error == 0)
+ maxprot |= VM_PROT_WRITE;
+
+ } else if ((prot & PROT_WRITE) != 0) {
+ (void)vnode_put(vp);
+ error = EACCES;
+ goto bad;
+ }