Home | History | Annotate | Line # | Download | only in lfs
lfs_itimes.c revision 1.1
      1 /*	$NetBSD: lfs_itimes.c,v 1.1 2005/09/13 04:13:26 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.1 2005/09/13 04:13:26 christos Exp $");
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/time.h>
     44 #include <sys/ucred.h>
     45 #include <sys/mount.h>
     46 #include <sys/buf.h>
     47 
     48 #include <ufs/ufs/inode.h>
     49 
     50 #ifndef _KERNEL
     51 #include "bufcache.h"
     52 #include "vnode.h"
     53 #include "lfs_user.h"
     54 #define vnode uvnode
     55 #define buf ubuf
     56 #else
     57 #include <ufs/lfs/lfs_extern.h>
     58 #endif
     59 
     60 #include <ufs/lfs/lfs.h>
     61 
     62 void
     63 lfs_itimes(struct inode *ip, const struct timespec *acc,
     64     const struct timespec *mod, const struct timespec *cre)
     65 {
     66 #ifdef _KERNEL
     67 	struct timespec *ts = NULL, tsb;
     68 
     69 	KASSERT(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
     70 #endif
     71 
     72 	if (ip->i_flag & IN_ACCESS) {
     73 #ifdef _KERNEL
     74 		if (acc == NULL)
     75 			acc = ts == NULL ? (ts = nanotime(&tsb)) : ts;
     76 #endif
     77 		ip->i_ffs1_atime = acc->tv_sec;
     78 		ip->i_ffs1_atimensec = acc->tv_nsec;
     79 		if (ip->i_lfs->lfs_version > 1) {
     80 			struct lfs *fs = ip->i_lfs;
     81 			struct buf *ibp;
     82 			IFILE *ifp;
     83 
     84 			LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);
     85 			ifp->if_atime_sec = acc->tv_sec;
     86 			ifp->if_atime_nsec = acc->tv_nsec;
     87 			LFS_BWRITE_LOG(ibp);
     88 			simple_lock(&fs->lfs_interlock);
     89 			fs->lfs_flags |= LFS_IFDIRTY;
     90 			simple_unlock(&fs->lfs_interlock);
     91 		} else {
     92 			LFS_SET_UINO(ip, IN_ACCESSED);
     93 		}
     94 	}
     95 	if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
     96 		if (ip->i_flag & (IN_UPDATE | IN_MODIFY)) {
     97 #ifdef _KERNEL
     98 			if (mod == NULL)
     99 				mod = ts == NULL ? (ts = nanotime(&tsb)) : ts;
    100 #endif
    101 			ip->i_ffs1_mtime = mod->tv_sec;
    102 			ip->i_ffs1_mtimensec = mod->tv_nsec;
    103 			ip->i_modrev++;
    104 		}
    105 		if (ip->i_flag & (IN_CHANGE | IN_MODIFY)) {
    106 #ifdef _KERNEL
    107 			if (cre == NULL)
    108 				cre = ts == NULL ? (ts = nanotime(&tsb)) : ts;
    109 #endif
    110 			ip->i_ffs1_ctime = cre->tv_sec;
    111 			ip->i_ffs1_ctimensec = cre->tv_nsec;
    112 		}
    113 		if (ip->i_flag & (IN_CHANGE | IN_UPDATE))
    114 			LFS_SET_UINO(ip, IN_MODIFIED);
    115 		if (ip->i_flag & IN_MODIFY)
    116 			LFS_SET_UINO(ip, IN_ACCESSED);
    117 	}
    118 	ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
    119 }
    120