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