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