lfs_itimes.c revision 1.2 1 /* $NetBSD: lfs_itimes.c,v 1.2 2005/09/13 04:40:42 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.2 2005/09/13 04:40:42 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 #define panic call_panic
57 #else
58 #include <ufs/lfs/lfs_extern.h>
59 #endif
60
61 #include <ufs/lfs/lfs.h>
62
63 void
64 lfs_itimes(struct inode *ip, const struct timespec *acc,
65 const struct timespec *mod, const struct timespec *cre)
66 {
67 #ifdef _KERNEL
68 struct timespec *ts = NULL, tsb;
69
70 KASSERT(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY));
71 #endif
72
73 if (ip->i_flag & IN_ACCESS) {
74 #ifdef _KERNEL
75 if (acc == NULL)
76 acc = ts == NULL ? (ts = nanotime(&tsb)) : ts;
77 #endif
78 ip->i_ffs1_atime = acc->tv_sec;
79 ip->i_ffs1_atimensec = acc->tv_nsec;
80 if (ip->i_lfs->lfs_version > 1) {
81 struct lfs *fs = ip->i_lfs;
82 struct buf *ibp;
83 IFILE *ifp;
84
85 LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);
86 ifp->if_atime_sec = acc->tv_sec;
87 ifp->if_atime_nsec = acc->tv_nsec;
88 LFS_BWRITE_LOG(ibp);
89 simple_lock(&fs->lfs_interlock);
90 fs->lfs_flags |= LFS_IFDIRTY;
91 simple_unlock(&fs->lfs_interlock);
92 } else {
93 LFS_SET_UINO(ip, IN_ACCESSED);
94 }
95 }
96 if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFY)) {
97 if (ip->i_flag & (IN_UPDATE | IN_MODIFY)) {
98 #ifdef _KERNEL
99 if (mod == NULL)
100 mod = ts == NULL ? (ts = nanotime(&tsb)) : ts;
101 #endif
102 ip->i_ffs1_mtime = mod->tv_sec;
103 ip->i_ffs1_mtimensec = mod->tv_nsec;
104 ip->i_modrev++;
105 }
106 if (ip->i_flag & (IN_CHANGE | IN_MODIFY)) {
107 #ifdef _KERNEL
108 if (cre == NULL)
109 cre = ts == NULL ? (ts = nanotime(&tsb)) : ts;
110 #endif
111 ip->i_ffs1_ctime = cre->tv_sec;
112 ip->i_ffs1_ctimensec = cre->tv_nsec;
113 }
114 if (ip->i_flag & (IN_CHANGE | IN_UPDATE))
115 LFS_SET_UINO(ip, IN_MODIFIED);
116 if (ip->i_flag & IN_MODIFY)
117 LFS_SET_UINO(ip, IN_ACCESSED);
118 }
119 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
120 }
121