* Common implementation code for utimes(), lutimes(), futimes(), futimens(), * and utimensat(). */
| 3121 | * and utimensat(). |
| 3122 | */ |
| 3123 | static int |
| 3124 | setutimes(struct thread *td, struct vnode *vp, const struct timespec *ts, |
| 3125 | int numtimes, int nullflag) |
| 3126 | { |
| 3127 | struct mount *mp; |
| 3128 | struct vattr vattr; |
| 3129 | int error, setbirthtime; |
| 3130 | |
| 3131 | if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) |
| 3132 | return (error); |
| 3133 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
| 3134 | setbirthtime = 0; |
| 3135 | if (numtimes < 3 && !VOP_GETATTR(vp, &vattr, td->td_ucred) && |
| 3136 | timespeccmp(&ts[1], &vattr.va_birthtime, < )) |
| 3137 | setbirthtime = 1; |
| 3138 | VATTR_NULL(&vattr); |
| 3139 | vattr.va_atime = ts[0]; |
| 3140 | vattr.va_mtime = ts[1]; |
| 3141 | if (setbirthtime) |
| 3142 | vattr.va_birthtime = ts[1]; |
| 3143 | if (numtimes > 2) |
| 3144 | vattr.va_birthtime = ts[2]; |
| 3145 | if (nullflag) |
| 3146 | vattr.va_vaflags |= VA_UTIMES_NULL; |
| 3147 | #ifdef MAC |
| 3148 | error = mac_vnode_check_setutimes(td->td_ucred, vp, vattr.va_atime, |
| 3149 | vattr.va_mtime); |
| 3150 | #endif |
| 3151 | if (error == 0) |
| 3152 | error = VOP_SETATTR(vp, &vattr, td->td_ucred); |
| 3153 | VOP_UNLOCK(vp); |
| 3154 | vn_finished_write(mp); |
| 3155 | return (error); |
| 3156 | } |
| 3157 | |
| 3158 | /* |
| 3159 | * Set the access and modification times of a file. |
no test coverage detected