Index: lib/libc/sys/stat.2 =================================================================== RCS file: /home/dcvs/src/lib/libc/sys/stat.2,v retrieving revision 1.5 diff -u -r1.5 stat.2 --- lib/libc/sys/stat.2 1 May 2008 23:36:43 -0000 1.5 +++ lib/libc/sys/stat.2 27 May 2008 19:33:00 -0000 @@ -123,10 +123,12 @@ .It st_atime Time when file data last accessed. Changed by the +.Xr execve 2 , .Xr mknod 2 , -.Xr utimes 2 -and +.Xr mmap 2 , .Xr read 2 +and +.Xr utimes 2 system calls. .It st_mtime Time when file data last modified. Index: sys/kern/kern_exec.c =================================================================== RCS file: /home/dcvs/src/sys/kern/kern_exec.c,v retrieving revision 1.63 diff -u -r1.63 kern_exec.c --- sys/kern/kern_exec.c 6 Jan 2008 16:55:51 -0000 1.63 +++ sys/kern/kern_exec.c 27 May 2008 19:33:00 -0000 @@ -465,6 +465,9 @@ exec_setregs(imgp->entry_addr, (u_long)(uintptr_t)stack_base, imgp->ps_strings); + /* Set the access time on the vnode */ + vn_mark_atime(imgp->vp, td); + /* Free any previous argument cache */ if (p->p_args && --p->p_args->ar_ref == 0) FREE(p->p_args, M_PARGS); Index: sys/kern/vfs_subr.c =================================================================== RCS file: /home/dcvs/src/sys/kern/vfs_subr.c,v retrieving revision 1.114 diff -u -r1.114 vfs_subr.c --- sys/kern/vfs_subr.c 18 May 2008 05:54:25 -0000 1.114 +++ sys/kern/vfs_subr.c 27 May 2008 19:33:00 -0000 @@ -2114,3 +2114,16 @@ return(0); } +void +vn_mark_atime(struct vnode *vp, struct thread *td) +{ + struct timespec atime; + struct proc *p = td->td_proc; + struct ucred *cred = p ? p->p_ucred : proc0.p_ucred; + + if ((vp->v_mount->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0) { + vfs_timestamp(&atime); + VOP_MARKATIME(vp, &atime, cred); + } +} + Index: sys/kern/vfs_vopops.c =================================================================== RCS file: /home/dcvs/src/sys/kern/vfs_vopops.c,v retrieving revision 1.38 diff -u -r1.38 vfs_vopops.c --- sys/kern/vfs_vopops.c 9 May 2008 17:52:17 -0000 1.38 +++ sys/kern/vfs_vopops.c 27 May 2008 19:33:00 -0000 @@ -127,6 +127,7 @@ VNODEOP_DESC_INIT(getextattr); VNODEOP_DESC_INIT(setextattr); VNODEOP_DESC_INIT(mountctl); +VNODEOP_DESC_INIT(markatime); VNODEOP_DESC_INIT(nresolve); VNODEOP_DESC_INIT(nlookupdotdot); @@ -901,7 +902,7 @@ int vop_mountctl(struct vop_ops *ops, int op, struct file *fp, - const void *ctl, int ctllen, void *buf, int buflen, int *res) + const void *ctl, int ctllen, void *buf, int buflen, int *res) { struct vop_mountctl_args ap; int error; @@ -920,6 +921,23 @@ return(error); } +int +vop_markatime(struct vop_ops *ops, struct vnode *vp, struct timespec *tsp, + struct ucred *cred) +{ + struct vop_markatime_args ap; + int error; + + ap.a_head.a_desc = &vop_markatime_desc; + ap.a_head.a_ops = ops; + ap.a_vp = vp; + ap.a_tsp = tsp; + ap.a_cred = cred; + + DO_OPS(ops, error, &ap, vop_markatime); + return(error); +} + /* * NEW API FUNCTIONS * @@ -1605,6 +1623,15 @@ } int +vop_markatime_ap(struct vop_markatime_args *ap) +{ + int error; + + DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime); + return(error); +} + +int vop_nresolve_ap(struct vop_nresolve_args *ap) { int error; Index: sys/sys/vfsops.h =================================================================== RCS file: /home/dcvs/src/sys/sys/vfsops.h,v retrieving revision 1.31 diff -u -r1.31 vfsops.h --- sys/sys/vfsops.h 6 Feb 2008 00:27:26 -0000 1.31 +++ sys/sys/vfsops.h 27 May 2008 19:33:00 -0000 @@ -413,6 +413,14 @@ int *a_res; }; +struct vop_markatime_args { + struct vop_generic_args a_head; + int a_op; + struct vnode *a_vp; + struct timespec *a_tsp; + struct ucred *a_cred; +}; + /* * NEW API */ @@ -617,6 +625,7 @@ int (*vop_unused07)(void *); int (*vop_unused08)(void *); int (*vop_mountctl)(struct vop_mountctl_args *); + int (*vop_markatime)(struct vop_markatime_args *); int (*vop_nresolve)(struct vop_nresolve_args *); int (*vop_nlookupdotdot)(struct vop_nlookupdotdot_args *); @@ -689,6 +698,7 @@ struct vop_getextattr_args vu_getextattr; struct vop_setextattr_args vu_setextattr; struct vop_mountctl_args vu_mountctl; + struct vop_markatime_args vu_markatime; struct vop_nresolve_args vu_nresolve; struct vop_nlookupdotdot_args vu_nlookupdotdot; @@ -798,6 +808,8 @@ struct uio *uio, struct ucred *cred); int vop_mountctl(struct vop_ops *ops, int op, struct file *fp, const void *ctl, int ctllen, void *buf, int buflen, int *res); +int vop_markatime(struct vop_ops *ops, struct vnode *vp, struct timespec *tsp, + struct ucred *cred); int vop_nresolve(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp, struct ucred *cred); int vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp, @@ -879,6 +891,7 @@ int vop_getextattr_ap(struct vop_getextattr_args *ap); int vop_setextattr_ap(struct vop_setextattr_args *ap); int vop_mountctl_ap(struct vop_mountctl_args *ap); +int vop_markatime_ap(struct vop_markatime_args *ap); int vop_nresolve_ap(struct vop_nresolve_args *ap); int vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap); @@ -941,6 +954,7 @@ extern struct syslink_desc vop_getextattr_desc; extern struct syslink_desc vop_setextattr_desc; extern struct syslink_desc vop_mountctl_desc; +extern struct syslink_desc vop_markatime_desc; extern struct syslink_desc vop_nresolve_desc; extern struct syslink_desc vop_nlookupdotdot_desc; @@ -1022,6 +1036,8 @@ vop_getextattr(*(vp)->v_ops, vp, name, uio, cred) #define VOP_SETEXTATTR(vp, name, uio, cred) \ vop_setextattr(*(vp)->v_ops, vp, name, uio, cred) +#define VOP_MARKATIME(vp, tsp, cred) \ + vop_markatime(*(vp)->v_ops, vp, tsp, cred) /* no VOP_VFSSET() */ /* VOP_STRATEGY - does not exist, use vn_strategy() */ Index: sys/sys/vnode.h =================================================================== RCS file: /home/dcvs/src/sys/sys/vnode.h,v retrieving revision 1.80 diff -u -r1.80 vnode.h --- sys/sys/vnode.h 18 May 2008 21:47:05 -0000 1.80 +++ sys/sys/vnode.h 27 May 2008 19:33:00 -0000 @@ -520,6 +520,7 @@ int vn_stat (struct vnode *vp, struct stat *sb, struct ucred *cred); cdev_t vn_todev (struct vnode *vp); void vfs_timestamp (struct timespec *); +void vn_mark_atime(struct vnode *vp, struct thread *td); int vn_writechk (struct vnode *vp, struct nchandle *nch); int ncp_writechk(struct nchandle *nch); int vop_stdopen (struct vop_open_args *ap); Index: sys/vfs/ufs/ufs_vnops.c =================================================================== RCS file: /home/dcvs/src/sys/vfs/ufs/ufs_vnops.c,v retrieving revision 1.63 diff -u -r1.63 ufs_vnops.c --- sys/vfs/ufs/ufs_vnops.c 20 Nov 2007 21:03:51 -0000 1.63 +++ sys/vfs/ufs/ufs_vnops.c 27 May 2008 19:48:25 -0000 @@ -88,6 +88,7 @@ static int ufs_getattr (struct vop_getattr_args *); static int ufs_link (struct vop_old_link_args *); static int ufs_makeinode (int mode, struct vnode *, struct vnode **, struct componentname *); +static int ufs_markatime (struct vop_markatime_args *); static int ufs_missingop (struct vop_generic_args *ap); static int ufs_mkdir (struct vop_old_mkdir_args *); static int ufs_mknod (struct vop_old_mknod_args *); @@ -440,6 +441,38 @@ return (0); } +static +int +ufs_markatime(struct vop_markatime_args *ap) +{ + struct vnode *vp = ap->a_vp; + struct inode *ip = VTOI(vp); + struct timespec *tsp = ap->a_tsp; + struct ucred *cred = ap->a_cred; + int error; + + if (vp->v_mount->mnt_flag & MNT_RDONLY) + return (EROFS); + if (cred->cr_uid != ip->i_uid && + (error = suser_cred(cred, PRISON_ROOT)) && + (error = VOP_ACCESS(vp, VWRITE, cred))) + return (error); + ip->i_flag |= IN_ACCESS; + ip->i_atime = tsp->tv_sec; + ip->i_atimensec = tsp->tv_nsec; + error = ffs_update(vp, 0); + if (error) + return (error); + + /* + * XXX I didn't notify attribute modification using KNOTE, + * but that would go here if you wanted to. + * + * VN_KNOTE(vp, NOTE_ATTRIB); + */ + return (error); +} + /* * Set attribute vnode op. called from several syscalls * @@ -2382,8 +2415,8 @@ .vop_getattr = ufs_getattr, .vop_inactive = ufs_inactive, .vop_old_link = ufs_link, - .vop_old_mkdir = ufs_mkdir, - .vop_old_mknod = ufs_mknod, + .vop_old_mkdir = ufs_mkdir, + .vop_old_mknod = ufs_mknod, .vop_mmap = ufs_mmap, .vop_open = ufs_open, .vop_pathconf = ufs_pathconf, @@ -2397,6 +2430,7 @@ .vop_old_rename = ufs_rename, .vop_old_rmdir = ufs_rmdir, .vop_setattr = ufs_setattr, + .vop_markatime = ufs_markatime, .vop_strategy = ufs_strategy, .vop_old_symlink = ufs_symlink, .vop_old_whiteout = ufs_whiteout @@ -2413,6 +2447,7 @@ .vop_read = ufsspec_read, .vop_reclaim = ufs_reclaim, .vop_setattr = ufs_setattr, + .vop_markatime = ufs_markatime, .vop_write = ufsspec_write }; @@ -2428,6 +2463,7 @@ .vop_read = ufsfifo_read, .vop_reclaim = ufs_reclaim, .vop_setattr = ufs_setattr, + .vop_markatime = ufs_markatime, .vop_write = ufsfifo_write }; Index: sys/vm/vm_mmap.c =================================================================== RCS file: /home/dcvs/src/sys/vm/vm_mmap.c,v retrieving revision 1.39 diff -u -r1.39 vm_mmap.c --- sys/vm/vm_mmap.c 30 Apr 2007 07:18:57 -0000 1.39 +++ sys/vm/vm_mmap.c 27 May 2008 19:33:00 -0000 @@ -983,6 +983,7 @@ boolean_t fitit; vm_object_t object; struct vnode *vp = NULL; + struct thread *td = curthread; struct proc *p; objtype_t type; int rv = KERN_SUCCESS; @@ -1128,6 +1129,13 @@ goto out; } } + + /* + * Set the access time on the vnode + */ + if (handle != NULL) { + vn_mark_atime(handle, td); + } out: switch (rv) { case KERN_SUCCESS: