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