Home | History | Annotate | Line # | Download | only in lfs
lfs_itimes.c revision 1.12.44.2
      1  1.12.44.1       tls /*	$NetBSD: lfs_itimes.c,v 1.12.44.2 2017/12/03 11:39:22 jdolecek 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  *
     19        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1  christos  */
     31        1.1  christos #include <sys/cdefs.h>
     32  1.12.44.1       tls __KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.12.44.2 2017/12/03 11:39:22 jdolecek Exp $");
     33        1.1  christos 
     34        1.1  christos #include <sys/param.h>
     35        1.1  christos #include <sys/time.h>
     36        1.1  christos #include <sys/mount.h>
     37        1.1  christos #include <sys/buf.h>
     38        1.1  christos 
     39        1.1  christos #ifndef _KERNEL
     40        1.1  christos #include "bufcache.h"
     41        1.1  christos #include "vnode.h"
     42        1.1  christos #include "lfs_user.h"
     43        1.1  christos #define vnode uvnode
     44        1.1  christos #define buf ubuf
     45        1.2  christos #define panic call_panic
     46        1.1  christos #else
     47  1.12.44.1       tls #include <ufs/lfs/ulfs_inode.h>
     48        1.1  christos #include <ufs/lfs/lfs_extern.h>
     49        1.8  christos #include <sys/kauth.h>
     50        1.1  christos #endif
     51        1.1  christos 
     52        1.1  christos #include <ufs/lfs/lfs.h>
     53  1.12.44.2  jdolecek #include <ufs/lfs/lfs_accessors.h>
     54  1.12.44.1       tls #include <ufs/lfs/lfs_inode.h>
     55        1.1  christos 
     56        1.1  christos void
     57        1.1  christos lfs_itimes(struct inode *ip, const struct timespec *acc,
     58        1.1  christos     const struct timespec *mod, const struct timespec *cre)
     59        1.1  christos {
     60  1.12.44.2  jdolecek 	struct lfs *fs = ip->i_lfs;
     61        1.1  christos #ifdef _KERNEL
     62        1.9    kardel 	struct timespec now;
     63        1.1  christos 
     64  1.12.44.2  jdolecek 	KASSERT(ip->i_state & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
     65        1.9    kardel 
     66       1.10      yamt 	vfs_timestamp(&now);
     67        1.1  christos #endif
     68        1.1  christos 
     69  1.12.44.2  jdolecek 	if (ip->i_state & IN_ACCESS) {
     70        1.1  christos #ifdef _KERNEL
     71        1.1  christos 		if (acc == NULL)
     72        1.9    kardel 			acc = &now;
     73        1.1  christos #endif
     74  1.12.44.2  jdolecek 		lfs_dino_setatime(fs, ip->i_din, acc->tv_sec);
     75  1.12.44.2  jdolecek 		lfs_dino_setatimensec(fs, ip->i_din, acc->tv_nsec);
     76  1.12.44.2  jdolecek 		if (fs->lfs_is64 || lfs_sb_getversion(fs) > 1) {
     77        1.1  christos 			struct buf *ibp;
     78        1.1  christos 			IFILE *ifp;
     79        1.1  christos 
     80  1.12.44.2  jdolecek 			LFS_IENTRY(ifp, fs, ip->i_number, ibp);
     81  1.12.44.2  jdolecek 			lfs_if_setatime_sec(fs, ifp, acc->tv_sec);
     82  1.12.44.2  jdolecek 			lfs_if_setatime_nsec(fs, ifp, acc->tv_nsec);
     83        1.1  christos 			LFS_BWRITE_LOG(ibp);
     84       1.11        ad 			mutex_enter(&lfs_lock);
     85        1.1  christos 			fs->lfs_flags |= LFS_IFDIRTY;
     86       1.11        ad 			mutex_exit(&lfs_lock);
     87        1.1  christos 		} else {
     88       1.11        ad 			mutex_enter(&lfs_lock);
     89        1.1  christos 			LFS_SET_UINO(ip, IN_ACCESSED);
     90       1.11        ad 			mutex_exit(&lfs_lock);
     91        1.1  christos 		}
     92        1.1  christos 	}
     93  1.12.44.2  jdolecek 	if (ip->i_state & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
     94  1.12.44.2  jdolecek 		if (ip->i_state & (IN_UPDATE | IN_MODIFY)) {
     95        1.1  christos #ifdef _KERNEL
     96        1.1  christos 			if (mod == NULL)
     97        1.9    kardel 				mod = &now;
     98        1.1  christos #endif
     99  1.12.44.2  jdolecek 			lfs_dino_setmtime(fs, ip->i_din, mod->tv_sec);
    100  1.12.44.2  jdolecek 			lfs_dino_setmtimensec(fs, ip->i_din, mod->tv_nsec);
    101        1.1  christos 			ip->i_modrev++;
    102        1.1  christos 		}
    103  1.12.44.2  jdolecek 		if (ip->i_state & (IN_CHANGE | IN_MODIFY)) {
    104        1.1  christos #ifdef _KERNEL
    105        1.1  christos 			if (cre == NULL)
    106        1.9    kardel 				cre = &now;
    107        1.1  christos #endif
    108  1.12.44.2  jdolecek 			lfs_dino_setctime(fs, ip->i_din, cre->tv_sec);
    109  1.12.44.2  jdolecek 			lfs_dino_setctimensec(fs, ip->i_din, cre->tv_nsec);
    110        1.1  christos 		}
    111       1.11        ad 		mutex_enter(&lfs_lock);
    112  1.12.44.2  jdolecek 		if (ip->i_state & (IN_CHANGE | IN_UPDATE))
    113        1.1  christos 			LFS_SET_UINO(ip, IN_MODIFIED);
    114  1.12.44.2  jdolecek 		if (ip->i_state & IN_MODIFY)
    115        1.1  christos 			LFS_SET_UINO(ip, IN_ACCESSED);
    116       1.11        ad 		mutex_exit(&lfs_lock);
    117        1.1  christos 	}
    118  1.12.44.2  jdolecek 	ip->i_state &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
    119        1.1  christos }
    120