lfs_itimes.c revision 1.7 1 /* $NetBSD: lfs_itimes.c,v 1.7 2006/05/15 00:45:57 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.7 2006/05/15 00:45:57 christos Exp $");
40
41 #include <sys/param.h>
42 #include <sys/time.h>
43 #include <sys/mount.h>
44 #include <sys/buf.h>
45
46 #include <ufs/ufs/inode.h>
47
48 #ifndef _KERNEL
49 #include "bufcache.h"
50 #include "vnode.h"
51 #include "lfs_user.h"
52 #define vnode uvnode
53 #define buf ubuf
54 #define panic call_panic
55 #else
56 #include <ufs/lfs/lfs_extern.h>
57 #endif
58
59 #include <ufs/lfs/lfs.h>
60
61 void
62 lfs_itimes(struct inode *ip, const struct timespec *acc,
63 const struct timespec *mod, const struct timespec *cre)
64 {
65 #ifdef _KERNEL
66 struct timespec *ts = NULL, tsb;
67
68 KASSERT(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
69 #endif
70
71 if (ip->i_flag & IN_ACCESS) {
72 #ifdef _KERNEL
73 if (acc == NULL)
74 acc = ts = nanotime(&tsb);
75 #endif
76 ip->i_ffs1_atime = acc->tv_sec;
77 ip->i_ffs1_atimensec = acc->tv_nsec;
78 if (ip->i_lfs->lfs_version > 1) {
79 struct lfs *fs = ip->i_lfs;
80 struct buf *ibp;
81 IFILE *ifp;
82
83 LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);
84 ifp->if_atime_sec = acc->tv_sec;
85 ifp->if_atime_nsec = acc->tv_nsec;
86 LFS_BWRITE_LOG(ibp);
87 simple_lock(&fs->lfs_interlock);
88 fs->lfs_flags |= LFS_IFDIRTY;
89 simple_unlock(&fs->lfs_interlock);
90 } else {
91 LFS_SET_UINO(ip, IN_ACCESSED);
92 }
93 }
94 if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
95 if (ip->i_flag & (IN_UPDATE | IN_MODIFY)) {
96 #ifdef _KERNEL
97 if (mod == NULL)
98 mod = ts == NULL ? (ts = nanotime(&tsb)) : ts;
99 #endif
100 ip->i_ffs1_mtime = mod->tv_sec;
101 ip->i_ffs1_mtimensec = mod->tv_nsec;
102 ip->i_modrev++;
103 }
104 if (ip->i_flag & (IN_CHANGE | IN_MODIFY)) {
105 #ifdef _KERNEL
106 if (cre == NULL)
107 cre = ts == NULL ? (ts = nanotime(&tsb)) : ts;
108 #endif
109 ip->i_ffs1_ctime = cre->tv_sec;
110 ip->i_ffs1_ctimensec = cre->tv_nsec;
111 }
112 if (ip->i_flag & (IN_CHANGE | IN_UPDATE))
113 LFS_SET_UINO(ip, IN_MODIFIED);
114 if (ip->i_flag & IN_MODIFY)
115 LFS_SET_UINO(ip, IN_ACCESSED);
116 }
117 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
118 }
119