chfs_subr.c revision 1.4 1 1.4 ttoth /* $NetBSD: chfs_subr.c,v 1.4 2012/04/12 15:31:01 ttoth Exp $ */
2 1.1 ahoka
3 1.1 ahoka /*-
4 1.1 ahoka * Copyright (c) 2010 Department of Software Engineering,
5 1.1 ahoka * University of Szeged, Hungary
6 1.1 ahoka * Copyright (C) 2010 Tamas Toth <ttoth (at) inf.u-szeged.hu>
7 1.1 ahoka * Copyright (C) 2010 Adam Hoka <ahoka (at) NetBSD.org>
8 1.1 ahoka * All rights reserved.
9 1.1 ahoka *
10 1.1 ahoka * This code is derived from software contributed to The NetBSD Foundation
11 1.1 ahoka * by the Department of Software Engineering, University of Szeged, Hungary
12 1.1 ahoka *
13 1.1 ahoka * Redistribution and use in source and binary forms, with or without
14 1.1 ahoka * modification, are permitted provided that the following conditions
15 1.1 ahoka * are met:
16 1.1 ahoka * 1. Redistributions of source code must retain the above copyright
17 1.1 ahoka * notice, this list of conditions and the following disclaimer.
18 1.1 ahoka * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 ahoka * notice, this list of conditions and the following disclaimer in the
20 1.1 ahoka * documentation and/or other materials provided with the distribution.
21 1.1 ahoka *
22 1.1 ahoka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 ahoka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ahoka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ahoka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 ahoka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 1.1 ahoka * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 1.1 ahoka * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 1.1 ahoka * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 1.1 ahoka * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 ahoka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 ahoka * SUCH DAMAGE.
33 1.1 ahoka */
34 1.1 ahoka
35 1.1 ahoka /*
36 1.1 ahoka * Efficient memory file system supporting functions.
37 1.1 ahoka */
38 1.1 ahoka
39 1.1 ahoka #include <sys/cdefs.h>
40 1.1 ahoka
41 1.1 ahoka #include <sys/param.h>
42 1.1 ahoka #include <sys/dirent.h>
43 1.1 ahoka #include <sys/event.h>
44 1.1 ahoka #include <sys/kmem.h>
45 1.1 ahoka #include <sys/mount.h>
46 1.1 ahoka #include <sys/namei.h>
47 1.1 ahoka #include <sys/time.h>
48 1.1 ahoka #include <sys/stat.h>
49 1.1 ahoka #include <sys/systm.h>
50 1.1 ahoka #include <sys/swap.h>
51 1.1 ahoka #include <sys/vnode.h>
52 1.1 ahoka #include <sys/kauth.h>
53 1.1 ahoka #include <sys/proc.h>
54 1.1 ahoka #include <sys/atomic.h>
55 1.1 ahoka
56 1.1 ahoka #include <uvm/uvm.h>
57 1.1 ahoka
58 1.1 ahoka #include <miscfs/specfs/specdev.h>
59 1.3 elad #include <miscfs/genfs/genfs.h>
60 1.1 ahoka #include "chfs.h"
61 1.1 ahoka //#include <fs/chfs/chfs_vnops.h>
62 1.1 ahoka //#include </root/xipffs/netbsd.chfs/chfs.h>
63 1.1 ahoka
64 1.1 ahoka /* --------------------------------------------------------------------- */
65 1.1 ahoka
66 1.1 ahoka /*
67 1.1 ahoka * Returns information about the number of available memory pages,
68 1.1 ahoka * including physical and virtual ones.
69 1.1 ahoka *
70 1.1 ahoka * If 'total' is true, the value returned is the total amount of memory
71 1.1 ahoka * pages configured for the system (either in use or free).
72 1.1 ahoka * If it is FALSE, the value returned is the amount of free memory pages.
73 1.1 ahoka *
74 1.1 ahoka * Remember to remove DUMMYFS_PAGES_RESERVED from the returned value to avoid
75 1.1 ahoka * excessive memory usage.
76 1.1 ahoka *
77 1.1 ahoka */
78 1.1 ahoka size_t
79 1.1 ahoka chfs_mem_info(bool total)
80 1.1 ahoka {
81 1.1 ahoka size_t size;
82 1.1 ahoka
83 1.1 ahoka size = 0;
84 1.1 ahoka size += uvmexp.swpgavail;
85 1.1 ahoka if (!total) {
86 1.1 ahoka size -= uvmexp.swpgonly;
87 1.1 ahoka }
88 1.1 ahoka size += uvmexp.free;
89 1.1 ahoka size += uvmexp.filepages;
90 1.1 ahoka if (size > uvmexp.wired) {
91 1.1 ahoka size -= uvmexp.wired;
92 1.1 ahoka } else {
93 1.1 ahoka size = 0;
94 1.1 ahoka }
95 1.1 ahoka
96 1.1 ahoka return size;
97 1.1 ahoka }
98 1.1 ahoka
99 1.1 ahoka
100 1.1 ahoka /* --------------------------------------------------------------------- */
101 1.1 ahoka
102 1.1 ahoka /*
103 1.1 ahoka * Looks for a directory entry in the directory represented by node.
104 1.1 ahoka * 'cnp' describes the name of the entry to look for. Note that the .
105 1.1 ahoka * and .. components are not allowed as they do not physically exist
106 1.1 ahoka * within directories.
107 1.1 ahoka *
108 1.1 ahoka * Returns a pointer to the entry when found, otherwise NULL.
109 1.1 ahoka */
110 1.1 ahoka struct chfs_dirent *
111 1.1 ahoka chfs_dir_lookup(struct chfs_inode *ip, struct componentname *cnp)
112 1.1 ahoka {
113 1.1 ahoka bool found;
114 1.1 ahoka struct chfs_dirent *fd;
115 1.1 ahoka dbg("dir_lookup()\n");
116 1.1 ahoka
117 1.1 ahoka KASSERT(IMPLIES(cnp->cn_namelen == 1, cnp->cn_nameptr[0] != '.'));
118 1.1 ahoka KASSERT(IMPLIES(cnp->cn_namelen == 2, !(cnp->cn_nameptr[0] == '.' &&
119 1.1 ahoka cnp->cn_nameptr[1] == '.')));
120 1.1 ahoka //CHFS_VALIDATE_DIR(node);
121 1.1 ahoka
122 1.1 ahoka //node->chn_status |= CHFS_NODE_ACCESSED;
123 1.1 ahoka
124 1.1 ahoka found = false;
125 1.1 ahoka // fd = ip->dents;
126 1.1 ahoka // while(fd) {
127 1.1 ahoka TAILQ_FOREACH(fd, &ip->dents, fds) {
128 1.1 ahoka KASSERT(cnp->cn_namelen < 0xffff);
129 1.1 ahoka if (fd->vno == 0)
130 1.1 ahoka continue;
131 1.1 ahoka /*dbg("dirent dump:\n");
132 1.1 ahoka dbg(" ->vno: %d\n", fd->vno);
133 1.1 ahoka dbg(" ->version: %ld\n", fd->version);
134 1.1 ahoka dbg(" ->nhash: 0x%x\n", fd->nhash);
135 1.1 ahoka dbg(" ->nsize: %d\n", fd->nsize);
136 1.1 ahoka dbg(" ->name: %s\n", fd->name);
137 1.1 ahoka dbg(" ->type: %d\n", fd->type);*/
138 1.1 ahoka if (fd->nsize == (uint16_t)cnp->cn_namelen &&
139 1.1 ahoka memcmp(fd->name, cnp->cn_nameptr, fd->nsize) == 0) {
140 1.1 ahoka found = true;
141 1.1 ahoka break;
142 1.1 ahoka }
143 1.1 ahoka // fd = fd->next;
144 1.1 ahoka }
145 1.1 ahoka
146 1.1 ahoka return found ? fd : NULL;
147 1.1 ahoka }
148 1.1 ahoka
149 1.1 ahoka /* --------------------------------------------------------------------- */
150 1.1 ahoka
151 1.1 ahoka int
152 1.1 ahoka chfs_filldir(struct uio* uio, ino_t ino, const char *name,
153 1.4 ttoth int namelen, enum chtype type)
154 1.1 ahoka {
155 1.1 ahoka struct dirent dent;
156 1.1 ahoka int error;
157 1.1 ahoka
158 1.1 ahoka memset(&dent, 0, sizeof(dent));
159 1.1 ahoka
160 1.1 ahoka dent.d_fileno = ino;
161 1.1 ahoka switch (type) {
162 1.4 ttoth case CHT_BLK:
163 1.1 ahoka dent.d_type = DT_BLK;
164 1.1 ahoka break;
165 1.1 ahoka
166 1.4 ttoth case CHT_CHR:
167 1.1 ahoka dent.d_type = DT_CHR;
168 1.1 ahoka break;
169 1.1 ahoka
170 1.4 ttoth case CHT_DIR:
171 1.1 ahoka dent.d_type = DT_DIR;
172 1.1 ahoka break;
173 1.1 ahoka
174 1.4 ttoth case CHT_FIFO:
175 1.1 ahoka dent.d_type = DT_FIFO;
176 1.1 ahoka break;
177 1.1 ahoka
178 1.4 ttoth case CHT_LNK:
179 1.1 ahoka dent.d_type = DT_LNK;
180 1.1 ahoka break;
181 1.1 ahoka
182 1.4 ttoth case CHT_REG:
183 1.1 ahoka dent.d_type = DT_REG;
184 1.1 ahoka break;
185 1.1 ahoka
186 1.4 ttoth case CHT_SOCK:
187 1.1 ahoka dent.d_type = DT_SOCK;
188 1.1 ahoka break;
189 1.1 ahoka
190 1.1 ahoka default:
191 1.1 ahoka KASSERT(0);
192 1.1 ahoka }
193 1.1 ahoka dent.d_namlen = namelen;
194 1.1 ahoka (void)memcpy(dent.d_name, name, dent.d_namlen);
195 1.1 ahoka dent.d_reclen = _DIRENT_SIZE(&dent);
196 1.1 ahoka
197 1.1 ahoka if (dent.d_reclen > uio->uio_resid) {
198 1.1 ahoka error = -1;
199 1.1 ahoka } else {
200 1.1 ahoka error = uiomove(&dent, dent.d_reclen, uio);
201 1.1 ahoka }
202 1.1 ahoka
203 1.1 ahoka return error;
204 1.1 ahoka }
205 1.1 ahoka
206 1.1 ahoka
207 1.1 ahoka /* --------------------------------------------------------------------- */
208 1.1 ahoka
209 1.1 ahoka /*
210 1.1 ahoka * Change size of the given vnode.
211 1.1 ahoka * Caller should execute chfs_update on vp after a successful execution.
212 1.1 ahoka * The vnode must be locked on entry and remain locked on exit.
213 1.1 ahoka */
214 1.1 ahoka int
215 1.1 ahoka chfs_chsize(struct vnode *vp, u_quad_t size, kauth_cred_t cred)
216 1.1 ahoka {
217 1.1 ahoka struct chfs_mount *chmp;
218 1.1 ahoka struct chfs_inode *ip;
219 1.1 ahoka struct buf *bp;
220 1.1 ahoka int blknum, append;
221 1.1 ahoka int error = 0;
222 1.1 ahoka char *buf = NULL;
223 1.1 ahoka struct chfs_full_dnode *fd;
224 1.1 ahoka
225 1.1 ahoka ip = VTOI(vp);
226 1.1 ahoka chmp = ip->chmp;
227 1.1 ahoka
228 1.1 ahoka dbg("chfs_chsize\n");
229 1.1 ahoka
230 1.4 ttoth switch (ip->ch_type) {
231 1.4 ttoth case CHT_DIR:
232 1.1 ahoka return EISDIR;
233 1.4 ttoth case CHT_LNK:
234 1.4 ttoth case CHT_REG:
235 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
236 1.1 ahoka return EROFS;
237 1.1 ahoka break;
238 1.4 ttoth case CHT_BLK:
239 1.4 ttoth case CHT_CHR:
240 1.4 ttoth case CHT_FIFO:
241 1.1 ahoka return 0;
242 1.1 ahoka default:
243 1.1 ahoka return EOPNOTSUPP; /* XXX why not ENODEV? */
244 1.1 ahoka }
245 1.1 ahoka
246 1.1 ahoka vflushbuf(vp, 0);
247 1.1 ahoka
248 1.1 ahoka mutex_enter(&chmp->chm_lock_mountfields);
249 1.1 ahoka chfs_flush_pending_wbuf(chmp);
250 1.1 ahoka
251 1.1 ahoka /* handle truncate to zero as a special case */
252 1.1 ahoka if (size == 0) {
253 1.1 ahoka dbg("truncate to zero");
254 1.1 ahoka chfs_truncate_fragtree(ip->chmp,
255 1.1 ahoka &ip->fragtree, size);
256 1.1 ahoka chfs_set_vnode_size(vp, size);
257 1.1 ahoka
258 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
259 1.1 ahoka
260 1.1 ahoka return 0;
261 1.1 ahoka }
262 1.1 ahoka
263 1.1 ahoka
264 1.1 ahoka /* allocate zeros for the new data */
265 1.1 ahoka buf = kmem_zalloc(size, KM_SLEEP);
266 1.1 ahoka bp = getiobuf(vp, true);
267 1.1 ahoka
268 1.1 ahoka if (ip->size != 0) {
269 1.1 ahoka /* read the whole data */
270 1.1 ahoka bp->b_blkno = 0;
271 1.1 ahoka bp->b_bufsize = bp->b_resid = bp->b_bcount = ip->size;
272 1.1 ahoka bp->b_data = kmem_alloc(ip->size, KM_SLEEP);
273 1.1 ahoka
274 1.1 ahoka error = chfs_read_data(chmp, vp, bp);
275 1.1 ahoka if (error) {
276 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
277 1.1 ahoka putiobuf(bp);
278 1.1 ahoka
279 1.1 ahoka return error;
280 1.1 ahoka }
281 1.1 ahoka
282 1.1 ahoka /* create the new data */
283 1.2 agc dbg("create new data vap%llu ip%llu\n",
284 1.2 agc (unsigned long long)size, (unsigned long long)ip->size);
285 1.1 ahoka append = size - ip->size;
286 1.1 ahoka if (append > 0) {
287 1.1 ahoka memcpy(buf, bp->b_data, ip->size);
288 1.1 ahoka } else {
289 1.1 ahoka memcpy(buf, bp->b_data, size);
290 1.1 ahoka chfs_truncate_fragtree(ip->chmp,
291 1.1 ahoka &ip->fragtree, size);
292 1.1 ahoka }
293 1.1 ahoka
294 1.1 ahoka kmem_free(bp->b_data, ip->size);
295 1.1 ahoka
296 1.1 ahoka struct chfs_node_frag *lastfrag = frag_last(&ip->fragtree);
297 1.1 ahoka fd = lastfrag->node;
298 1.1 ahoka chfs_mark_node_obsolete(chmp, fd->nref);
299 1.1 ahoka
300 1.1 ahoka blknum = lastfrag->ofs / PAGE_SIZE;
301 1.1 ahoka lastfrag->size = append > PAGE_SIZE ? PAGE_SIZE : size % PAGE_SIZE;
302 1.1 ahoka } else {
303 1.1 ahoka fd = chfs_alloc_full_dnode();
304 1.1 ahoka blknum = 0;
305 1.1 ahoka }
306 1.1 ahoka
307 1.1 ahoka chfs_set_vnode_size(vp, size);
308 1.1 ahoka
309 1.1 ahoka // write the new data
310 1.1 ahoka for (bp->b_blkno = blknum; bp->b_blkno * PAGE_SIZE < size; bp->b_blkno++) {
311 1.1 ahoka uint64_t writesize = MIN(size - bp->b_blkno * PAGE_SIZE, PAGE_SIZE);
312 1.1 ahoka
313 1.1 ahoka bp->b_bufsize = bp->b_resid = bp->b_bcount = writesize;
314 1.1 ahoka bp->b_data = kmem_alloc(writesize, KM_SLEEP);
315 1.1 ahoka
316 1.1 ahoka memcpy(bp->b_data, buf + (bp->b_blkno * PAGE_SIZE), writesize);
317 1.1 ahoka
318 1.1 ahoka if (bp->b_blkno != blknum) {
319 1.1 ahoka fd = chfs_alloc_full_dnode();
320 1.1 ahoka }
321 1.1 ahoka
322 1.1 ahoka error = chfs_write_flash_dnode(chmp, vp, bp, fd);
323 1.1 ahoka if (error) {
324 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
325 1.1 ahoka kmem_free(bp->b_data, writesize);
326 1.1 ahoka putiobuf(bp);
327 1.1 ahoka
328 1.1 ahoka return error;
329 1.1 ahoka }
330 1.1 ahoka if (bp->b_blkno != blknum) {
331 1.1 ahoka chfs_add_full_dnode_to_inode(chmp, ip, fd);
332 1.1 ahoka }
333 1.1 ahoka kmem_free(bp->b_data, writesize);
334 1.1 ahoka }
335 1.1 ahoka
336 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
337 1.1 ahoka
338 1.1 ahoka kmem_free(buf, size);
339 1.1 ahoka putiobuf(bp);
340 1.1 ahoka
341 1.1 ahoka return 0;
342 1.1 ahoka }
343 1.1 ahoka #if 0
344 1.1 ahoka int error;
345 1.1 ahoka struct chfs_node *node;
346 1.1 ahoka
347 1.1 ahoka KASSERT(VOP_ISLOCKED(vp));
348 1.1 ahoka
349 1.1 ahoka node = VP_TO_CHFS_NODE(vp);
350 1.1 ahoka
351 1.1 ahoka // Decide whether this is a valid operation based on the file type.
352 1.1 ahoka error = 0;
353 1.1 ahoka switch (vp->v_type) {
354 1.1 ahoka case VDIR:
355 1.1 ahoka return EISDIR;
356 1.1 ahoka
357 1.1 ahoka case VREG:
358 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
359 1.1 ahoka return EROFS;
360 1.1 ahoka break;
361 1.1 ahoka
362 1.1 ahoka case VBLK:
363 1.1 ahoka case VCHR:
364 1.1 ahoka case VFIFO:
365 1.1 ahoka // Allow modifications of special files even if in the file
366 1.1 ahoka // system is mounted read-only (we are not modifying the
367 1.1 ahoka // files themselves, but the objects they represent).
368 1.1 ahoka return 0;
369 1.1 ahoka
370 1.1 ahoka default:
371 1.1 ahoka return ENODEV;
372 1.1 ahoka }
373 1.1 ahoka
374 1.1 ahoka // Immutable or append-only files cannot be modified, either.
375 1.1 ahoka if (node->chn_flags & (IMMUTABLE | APPEND))
376 1.1 ahoka return EPERM;
377 1.1 ahoka
378 1.1 ahoka error = chfs_truncate(vp, size);
379 1.1 ahoka // chfs_truncate will raise the NOTE_EXTEND and NOTE_ATTRIB kevents
380 1.1 ahoka // for us, as will update dn_status; no need to do that here.
381 1.1 ahoka
382 1.1 ahoka KASSERT(VOP_ISLOCKED(vp));
383 1.1 ahoka
384 1.1 ahoka return error;
385 1.1 ahoka #endif
386 1.1 ahoka
387 1.1 ahoka /* --------------------------------------------------------------------- */
388 1.1 ahoka
389 1.1 ahoka /*
390 1.1 ahoka * Change flags of the given vnode.
391 1.1 ahoka * Caller should execute chfs_update on vp after a successful execution.
392 1.1 ahoka * The vnode must be locked on entry and remain locked on exit.
393 1.1 ahoka */
394 1.1 ahoka int
395 1.1 ahoka chfs_chflags(struct vnode *vp, int flags, kauth_cred_t cred)
396 1.1 ahoka {
397 1.1 ahoka struct chfs_mount *chmp;
398 1.1 ahoka struct chfs_inode *ip;
399 1.1 ahoka int error = 0;
400 1.3 elad kauth_action_t action = KAUTH_VNODE_WRITE_FLAGS;
401 1.3 elad bool changing_sysflags = false;
402 1.1 ahoka
403 1.1 ahoka ip = VTOI(vp);
404 1.1 ahoka chmp = ip->chmp;
405 1.1 ahoka
406 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
407 1.1 ahoka return EROFS;
408 1.1 ahoka
409 1.3 elad if ((flags & SF_SNAPSHOT) != (ip->flags & SF_SNAPSHOT))
410 1.3 elad return EPERM;
411 1.3 elad
412 1.3 elad /* Indicate we're changing system flags if we are. */
413 1.3 elad if ((ip->flags & SF_SETTABLE) != (flags & SF_SETTABLE) ||
414 1.3 elad (flags & UF_SETTABLE) != flags) {
415 1.3 elad action |= KAUTH_VNODE_WRITE_SYSFLAGS;
416 1.3 elad changing_sysflags = true;
417 1.3 elad }
418 1.3 elad
419 1.3 elad /* Indicate the node has system flags if it does. */
420 1.3 elad if (ip->flags & (SF_IMMUTABLE | SF_APPEND)) {
421 1.3 elad action |= KAUTH_VNODE_HAS_SYSFLAGS;
422 1.3 elad }
423 1.3 elad
424 1.3 elad error = kauth_authorize_vnode(cred, action, vp, NULL,
425 1.4 ttoth genfs_can_chflags(cred, CHTTOVT(ip->ch_type), ip->uid, changing_sysflags));
426 1.3 elad if (error)
427 1.1 ahoka return error;
428 1.1 ahoka
429 1.3 elad if (changing_sysflags) {
430 1.1 ahoka ip->flags = flags;
431 1.1 ahoka } else {
432 1.1 ahoka ip->flags &= SF_SETTABLE;
433 1.1 ahoka ip->flags |= (flags & UF_SETTABLE);
434 1.1 ahoka }
435 1.1 ahoka ip->iflag |= IN_CHANGE;
436 1.1 ahoka error = chfs_update(vp, NULL, NULL, UPDATE_WAIT);
437 1.1 ahoka if (error)
438 1.1 ahoka return error;
439 1.1 ahoka
440 1.1 ahoka if (flags & (IMMUTABLE | APPEND))
441 1.1 ahoka return 0;
442 1.1 ahoka
443 1.1 ahoka return error;
444 1.1 ahoka }
445 1.1 ahoka
446 1.1 ahoka /* --------------------------------------------------------------------- */
447 1.1 ahoka
448 1.1 ahoka void
449 1.1 ahoka chfs_itimes(struct chfs_inode *ip, const struct timespec *acc,
450 1.1 ahoka const struct timespec *mod, const struct timespec *cre)
451 1.1 ahoka {
452 1.1 ahoka //dbg("itimes\n");
453 1.1 ahoka struct timespec now;
454 1.1 ahoka
455 1.1 ahoka if (!(ip->iflag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY))) {
456 1.1 ahoka return;
457 1.1 ahoka }
458 1.1 ahoka
459 1.1 ahoka vfs_timestamp(&now);
460 1.1 ahoka if (ip->iflag & IN_ACCESS) {
461 1.1 ahoka if (acc == NULL)
462 1.1 ahoka acc = &now;
463 1.1 ahoka ip->atime = acc->tv_sec;
464 1.1 ahoka }
465 1.1 ahoka if (ip->iflag & (IN_UPDATE | IN_MODIFY)) {
466 1.1 ahoka if (mod == NULL)
467 1.1 ahoka mod = &now;
468 1.1 ahoka ip->mtime = mod->tv_sec;
469 1.1 ahoka //ip->i_modrev++;
470 1.1 ahoka }
471 1.1 ahoka if (ip->iflag & (IN_CHANGE | IN_MODIFY)) {
472 1.1 ahoka if (cre == NULL)
473 1.1 ahoka cre = &now;
474 1.1 ahoka ip->ctime = cre->tv_sec;
475 1.1 ahoka }
476 1.1 ahoka if (ip->iflag & (IN_ACCESS | IN_MODIFY))
477 1.1 ahoka ip->iflag |= IN_ACCESSED;
478 1.1 ahoka if (ip->iflag & (IN_UPDATE | IN_CHANGE))
479 1.1 ahoka ip->iflag |= IN_MODIFIED;
480 1.1 ahoka ip->iflag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
481 1.1 ahoka }
482 1.1 ahoka
483 1.1 ahoka /* --------------------------------------------------------------------- */
484 1.1 ahoka
485 1.1 ahoka int
486 1.1 ahoka chfs_update(struct vnode *vp, const struct timespec *acc,
487 1.1 ahoka const struct timespec *mod, int flags)
488 1.1 ahoka {
489 1.1 ahoka
490 1.1 ahoka struct chfs_inode *ip;
491 1.1 ahoka
492 1.1 ahoka /* XXX ufs_reclaim calls this function unlocked! */
493 1.1 ahoka // KASSERT(VOP_ISLOCKED(vp));
494 1.1 ahoka
495 1.1 ahoka #if 0
496 1.1 ahoka if (flags & UPDATE_CLOSE)
497 1.1 ahoka ; /* XXX Need to do anything special? */
498 1.1 ahoka #endif
499 1.1 ahoka
500 1.1 ahoka ip = VTOI(vp);
501 1.1 ahoka chfs_itimes(ip, acc, mod, NULL);
502 1.1 ahoka
503 1.1 ahoka // KASSERT(VOP_ISLOCKED(vp));
504 1.1 ahoka return (0);
505 1.1 ahoka }
506 1.1 ahoka
507 1.1 ahoka /* --------------------------------------------------------------------- */
508 1.1 ahoka /*
509 1.1 ahoka int
510 1.1 ahoka chfs_truncate(struct vnode *vp, off_t length)
511 1.1 ahoka {
512 1.1 ahoka bool extended;
513 1.1 ahoka int error;
514 1.1 ahoka struct chfs_node *node;
515 1.1 ahoka printf("CHFS: truncate()\n");
516 1.1 ahoka
517 1.1 ahoka node = VP_TO_CHFS_NODE(vp);
518 1.1 ahoka extended = length > node->chn_size;
519 1.1 ahoka
520 1.1 ahoka if (length < 0) {
521 1.1 ahoka error = EINVAL;
522 1.1 ahoka goto out;
523 1.1 ahoka }
524 1.1 ahoka
525 1.1 ahoka if (node->chn_size == length) {
526 1.1 ahoka error = 0;
527 1.1 ahoka goto out;
528 1.1 ahoka }
529 1.1 ahoka
530 1.1 ahoka error = chfs_reg_resize(vp, length);
531 1.1 ahoka if (error == 0)
532 1.1 ahoka node->chn_status |= CHFS_NODE_CHANGED | CHFS_NODE_MODIFIED;
533 1.1 ahoka
534 1.1 ahoka out:
535 1.1 ahoka chfs_update(vp, NULL, NULL, 0);
536 1.1 ahoka
537 1.1 ahoka return error;
538 1.1 ahoka }*/
539 1.1 ahoka
540 1.1 ahoka
541