chfs_subr.c revision 1.1 1 1.1 ahoka /* $NetBSD: chfs_subr.c,v 1.1 2011/11/24 15:51:31 ahoka 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.1 ahoka #include "chfs.h"
60 1.1 ahoka //#include <fs/chfs/chfs_vnops.h>
61 1.1 ahoka //#include </root/xipffs/netbsd.chfs/chfs.h>
62 1.1 ahoka
63 1.1 ahoka /* --------------------------------------------------------------------- */
64 1.1 ahoka
65 1.1 ahoka /*
66 1.1 ahoka * Returns information about the number of available memory pages,
67 1.1 ahoka * including physical and virtual ones.
68 1.1 ahoka *
69 1.1 ahoka * If 'total' is true, the value returned is the total amount of memory
70 1.1 ahoka * pages configured for the system (either in use or free).
71 1.1 ahoka * If it is FALSE, the value returned is the amount of free memory pages.
72 1.1 ahoka *
73 1.1 ahoka * Remember to remove DUMMYFS_PAGES_RESERVED from the returned value to avoid
74 1.1 ahoka * excessive memory usage.
75 1.1 ahoka *
76 1.1 ahoka */
77 1.1 ahoka size_t
78 1.1 ahoka chfs_mem_info(bool total)
79 1.1 ahoka {
80 1.1 ahoka size_t size;
81 1.1 ahoka
82 1.1 ahoka size = 0;
83 1.1 ahoka size += uvmexp.swpgavail;
84 1.1 ahoka if (!total) {
85 1.1 ahoka size -= uvmexp.swpgonly;
86 1.1 ahoka }
87 1.1 ahoka size += uvmexp.free;
88 1.1 ahoka size += uvmexp.filepages;
89 1.1 ahoka if (size > uvmexp.wired) {
90 1.1 ahoka size -= uvmexp.wired;
91 1.1 ahoka } else {
92 1.1 ahoka size = 0;
93 1.1 ahoka }
94 1.1 ahoka
95 1.1 ahoka return size;
96 1.1 ahoka }
97 1.1 ahoka
98 1.1 ahoka
99 1.1 ahoka /* --------------------------------------------------------------------- */
100 1.1 ahoka
101 1.1 ahoka /*
102 1.1 ahoka * Looks for a directory entry in the directory represented by node.
103 1.1 ahoka * 'cnp' describes the name of the entry to look for. Note that the .
104 1.1 ahoka * and .. components are not allowed as they do not physically exist
105 1.1 ahoka * within directories.
106 1.1 ahoka *
107 1.1 ahoka * Returns a pointer to the entry when found, otherwise NULL.
108 1.1 ahoka */
109 1.1 ahoka struct chfs_dirent *
110 1.1 ahoka chfs_dir_lookup(struct chfs_inode *ip, struct componentname *cnp)
111 1.1 ahoka {
112 1.1 ahoka bool found;
113 1.1 ahoka struct chfs_dirent *fd;
114 1.1 ahoka dbg("dir_lookup()\n");
115 1.1 ahoka
116 1.1 ahoka KASSERT(IMPLIES(cnp->cn_namelen == 1, cnp->cn_nameptr[0] != '.'));
117 1.1 ahoka KASSERT(IMPLIES(cnp->cn_namelen == 2, !(cnp->cn_nameptr[0] == '.' &&
118 1.1 ahoka cnp->cn_nameptr[1] == '.')));
119 1.1 ahoka //CHFS_VALIDATE_DIR(node);
120 1.1 ahoka
121 1.1 ahoka //node->chn_status |= CHFS_NODE_ACCESSED;
122 1.1 ahoka
123 1.1 ahoka found = false;
124 1.1 ahoka // fd = ip->dents;
125 1.1 ahoka // while(fd) {
126 1.1 ahoka TAILQ_FOREACH(fd, &ip->dents, fds) {
127 1.1 ahoka KASSERT(cnp->cn_namelen < 0xffff);
128 1.1 ahoka if (fd->vno == 0)
129 1.1 ahoka continue;
130 1.1 ahoka /*dbg("dirent dump:\n");
131 1.1 ahoka dbg(" ->vno: %d\n", fd->vno);
132 1.1 ahoka dbg(" ->version: %ld\n", fd->version);
133 1.1 ahoka dbg(" ->nhash: 0x%x\n", fd->nhash);
134 1.1 ahoka dbg(" ->nsize: %d\n", fd->nsize);
135 1.1 ahoka dbg(" ->name: %s\n", fd->name);
136 1.1 ahoka dbg(" ->type: %d\n", fd->type);*/
137 1.1 ahoka if (fd->nsize == (uint16_t)cnp->cn_namelen &&
138 1.1 ahoka memcmp(fd->name, cnp->cn_nameptr, fd->nsize) == 0) {
139 1.1 ahoka found = true;
140 1.1 ahoka break;
141 1.1 ahoka }
142 1.1 ahoka // fd = fd->next;
143 1.1 ahoka }
144 1.1 ahoka
145 1.1 ahoka return found ? fd : NULL;
146 1.1 ahoka }
147 1.1 ahoka
148 1.1 ahoka /* --------------------------------------------------------------------- */
149 1.1 ahoka
150 1.1 ahoka int
151 1.1 ahoka chfs_filldir(struct uio* uio, ino_t ino, const char *name,
152 1.1 ahoka int namelen, enum vtype type)
153 1.1 ahoka {
154 1.1 ahoka struct dirent dent;
155 1.1 ahoka int error;
156 1.1 ahoka
157 1.1 ahoka memset(&dent, 0, sizeof(dent));
158 1.1 ahoka
159 1.1 ahoka dent.d_fileno = ino;
160 1.1 ahoka switch (type) {
161 1.1 ahoka case VBLK:
162 1.1 ahoka dent.d_type = DT_BLK;
163 1.1 ahoka break;
164 1.1 ahoka
165 1.1 ahoka case VCHR:
166 1.1 ahoka dent.d_type = DT_CHR;
167 1.1 ahoka break;
168 1.1 ahoka
169 1.1 ahoka case VDIR:
170 1.1 ahoka dent.d_type = DT_DIR;
171 1.1 ahoka break;
172 1.1 ahoka
173 1.1 ahoka case VFIFO:
174 1.1 ahoka dent.d_type = DT_FIFO;
175 1.1 ahoka break;
176 1.1 ahoka
177 1.1 ahoka case VLNK:
178 1.1 ahoka dent.d_type = DT_LNK;
179 1.1 ahoka break;
180 1.1 ahoka
181 1.1 ahoka case VREG:
182 1.1 ahoka dent.d_type = DT_REG;
183 1.1 ahoka break;
184 1.1 ahoka
185 1.1 ahoka case VSOCK:
186 1.1 ahoka dent.d_type = DT_SOCK;
187 1.1 ahoka break;
188 1.1 ahoka
189 1.1 ahoka default:
190 1.1 ahoka KASSERT(0);
191 1.1 ahoka }
192 1.1 ahoka dent.d_namlen = namelen;
193 1.1 ahoka (void)memcpy(dent.d_name, name, dent.d_namlen);
194 1.1 ahoka dent.d_reclen = _DIRENT_SIZE(&dent);
195 1.1 ahoka
196 1.1 ahoka if (dent.d_reclen > uio->uio_resid) {
197 1.1 ahoka error = -1;
198 1.1 ahoka } else {
199 1.1 ahoka error = uiomove(&dent, dent.d_reclen, uio);
200 1.1 ahoka }
201 1.1 ahoka
202 1.1 ahoka return error;
203 1.1 ahoka }
204 1.1 ahoka
205 1.1 ahoka
206 1.1 ahoka /* --------------------------------------------------------------------- */
207 1.1 ahoka
208 1.1 ahoka /*
209 1.1 ahoka * Change size of the given vnode.
210 1.1 ahoka * Caller should execute chfs_update on vp after a successful execution.
211 1.1 ahoka * The vnode must be locked on entry and remain locked on exit.
212 1.1 ahoka */
213 1.1 ahoka int
214 1.1 ahoka chfs_chsize(struct vnode *vp, u_quad_t size, kauth_cred_t cred)
215 1.1 ahoka {
216 1.1 ahoka struct chfs_mount *chmp;
217 1.1 ahoka struct chfs_inode *ip;
218 1.1 ahoka struct buf *bp;
219 1.1 ahoka int blknum, append;
220 1.1 ahoka int error = 0;
221 1.1 ahoka char *buf = NULL;
222 1.1 ahoka struct chfs_full_dnode *fd;
223 1.1 ahoka
224 1.1 ahoka ip = VTOI(vp);
225 1.1 ahoka chmp = ip->chmp;
226 1.1 ahoka
227 1.1 ahoka dbg("chfs_chsize\n");
228 1.1 ahoka
229 1.1 ahoka switch (vp->v_type) {
230 1.1 ahoka case VDIR:
231 1.1 ahoka return EISDIR;
232 1.1 ahoka case VLNK:
233 1.1 ahoka case VREG:
234 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
235 1.1 ahoka return EROFS;
236 1.1 ahoka break;
237 1.1 ahoka case VBLK:
238 1.1 ahoka case VCHR:
239 1.1 ahoka case VFIFO:
240 1.1 ahoka return 0;
241 1.1 ahoka default:
242 1.1 ahoka return EOPNOTSUPP; /* XXX why not ENODEV? */
243 1.1 ahoka }
244 1.1 ahoka
245 1.1 ahoka vflushbuf(vp, 0);
246 1.1 ahoka
247 1.1 ahoka mutex_enter(&chmp->chm_lock_mountfields);
248 1.1 ahoka chfs_flush_pending_wbuf(chmp);
249 1.1 ahoka
250 1.1 ahoka /* handle truncate to zero as a special case */
251 1.1 ahoka if (size == 0) {
252 1.1 ahoka dbg("truncate to zero");
253 1.1 ahoka chfs_truncate_fragtree(ip->chmp,
254 1.1 ahoka &ip->fragtree, size);
255 1.1 ahoka chfs_set_vnode_size(vp, size);
256 1.1 ahoka
257 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
258 1.1 ahoka
259 1.1 ahoka return 0;
260 1.1 ahoka }
261 1.1 ahoka
262 1.1 ahoka
263 1.1 ahoka /* allocate zeros for the new data */
264 1.1 ahoka buf = kmem_zalloc(size, KM_SLEEP);
265 1.1 ahoka bp = getiobuf(vp, true);
266 1.1 ahoka
267 1.1 ahoka if (ip->size != 0) {
268 1.1 ahoka /* read the whole data */
269 1.1 ahoka bp->b_blkno = 0;
270 1.1 ahoka bp->b_bufsize = bp->b_resid = bp->b_bcount = ip->size;
271 1.1 ahoka bp->b_data = kmem_alloc(ip->size, KM_SLEEP);
272 1.1 ahoka
273 1.1 ahoka error = chfs_read_data(chmp, vp, bp);
274 1.1 ahoka if (error) {
275 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
276 1.1 ahoka putiobuf(bp);
277 1.1 ahoka
278 1.1 ahoka return error;
279 1.1 ahoka }
280 1.1 ahoka
281 1.1 ahoka /* create the new data */
282 1.1 ahoka dbg("create new data vap%llu ip%llu\n", size, ip->size);
283 1.1 ahoka append = size - ip->size;
284 1.1 ahoka if (append > 0) {
285 1.1 ahoka memcpy(buf, bp->b_data, ip->size);
286 1.1 ahoka } else {
287 1.1 ahoka memcpy(buf, bp->b_data, size);
288 1.1 ahoka chfs_truncate_fragtree(ip->chmp,
289 1.1 ahoka &ip->fragtree, size);
290 1.1 ahoka }
291 1.1 ahoka
292 1.1 ahoka kmem_free(bp->b_data, ip->size);
293 1.1 ahoka
294 1.1 ahoka struct chfs_node_frag *lastfrag = frag_last(&ip->fragtree);
295 1.1 ahoka fd = lastfrag->node;
296 1.1 ahoka chfs_mark_node_obsolete(chmp, fd->nref);
297 1.1 ahoka
298 1.1 ahoka blknum = lastfrag->ofs / PAGE_SIZE;
299 1.1 ahoka lastfrag->size = append > PAGE_SIZE ? PAGE_SIZE : size % PAGE_SIZE;
300 1.1 ahoka } else {
301 1.1 ahoka fd = chfs_alloc_full_dnode();
302 1.1 ahoka blknum = 0;
303 1.1 ahoka }
304 1.1 ahoka
305 1.1 ahoka chfs_set_vnode_size(vp, size);
306 1.1 ahoka
307 1.1 ahoka // write the new data
308 1.1 ahoka for (bp->b_blkno = blknum; bp->b_blkno * PAGE_SIZE < size; bp->b_blkno++) {
309 1.1 ahoka uint64_t writesize = MIN(size - bp->b_blkno * PAGE_SIZE, PAGE_SIZE);
310 1.1 ahoka
311 1.1 ahoka bp->b_bufsize = bp->b_resid = bp->b_bcount = writesize;
312 1.1 ahoka bp->b_data = kmem_alloc(writesize, KM_SLEEP);
313 1.1 ahoka
314 1.1 ahoka memcpy(bp->b_data, buf + (bp->b_blkno * PAGE_SIZE), writesize);
315 1.1 ahoka
316 1.1 ahoka if (bp->b_blkno != blknum) {
317 1.1 ahoka fd = chfs_alloc_full_dnode();
318 1.1 ahoka }
319 1.1 ahoka
320 1.1 ahoka error = chfs_write_flash_dnode(chmp, vp, bp, fd);
321 1.1 ahoka if (error) {
322 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
323 1.1 ahoka kmem_free(bp->b_data, writesize);
324 1.1 ahoka putiobuf(bp);
325 1.1 ahoka
326 1.1 ahoka return error;
327 1.1 ahoka }
328 1.1 ahoka if (bp->b_blkno != blknum) {
329 1.1 ahoka chfs_add_full_dnode_to_inode(chmp, ip, fd);
330 1.1 ahoka }
331 1.1 ahoka kmem_free(bp->b_data, writesize);
332 1.1 ahoka }
333 1.1 ahoka
334 1.1 ahoka mutex_exit(&chmp->chm_lock_mountfields);
335 1.1 ahoka
336 1.1 ahoka kmem_free(buf, size);
337 1.1 ahoka putiobuf(bp);
338 1.1 ahoka
339 1.1 ahoka return 0;
340 1.1 ahoka }
341 1.1 ahoka #if 0
342 1.1 ahoka int error;
343 1.1 ahoka struct chfs_node *node;
344 1.1 ahoka
345 1.1 ahoka KASSERT(VOP_ISLOCKED(vp));
346 1.1 ahoka
347 1.1 ahoka node = VP_TO_CHFS_NODE(vp);
348 1.1 ahoka
349 1.1 ahoka // Decide whether this is a valid operation based on the file type.
350 1.1 ahoka error = 0;
351 1.1 ahoka switch (vp->v_type) {
352 1.1 ahoka case VDIR:
353 1.1 ahoka return EISDIR;
354 1.1 ahoka
355 1.1 ahoka case VREG:
356 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
357 1.1 ahoka return EROFS;
358 1.1 ahoka break;
359 1.1 ahoka
360 1.1 ahoka case VBLK:
361 1.1 ahoka case VCHR:
362 1.1 ahoka case VFIFO:
363 1.1 ahoka // Allow modifications of special files even if in the file
364 1.1 ahoka // system is mounted read-only (we are not modifying the
365 1.1 ahoka // files themselves, but the objects they represent).
366 1.1 ahoka return 0;
367 1.1 ahoka
368 1.1 ahoka default:
369 1.1 ahoka return ENODEV;
370 1.1 ahoka }
371 1.1 ahoka
372 1.1 ahoka // Immutable or append-only files cannot be modified, either.
373 1.1 ahoka if (node->chn_flags & (IMMUTABLE | APPEND))
374 1.1 ahoka return EPERM;
375 1.1 ahoka
376 1.1 ahoka error = chfs_truncate(vp, size);
377 1.1 ahoka // chfs_truncate will raise the NOTE_EXTEND and NOTE_ATTRIB kevents
378 1.1 ahoka // for us, as will update dn_status; no need to do that here.
379 1.1 ahoka
380 1.1 ahoka KASSERT(VOP_ISLOCKED(vp));
381 1.1 ahoka
382 1.1 ahoka return error;
383 1.1 ahoka #endif
384 1.1 ahoka
385 1.1 ahoka /* --------------------------------------------------------------------- */
386 1.1 ahoka
387 1.1 ahoka /*
388 1.1 ahoka * Change flags of the given vnode.
389 1.1 ahoka * Caller should execute chfs_update on vp after a successful execution.
390 1.1 ahoka * The vnode must be locked on entry and remain locked on exit.
391 1.1 ahoka */
392 1.1 ahoka int
393 1.1 ahoka chfs_chflags(struct vnode *vp, int flags, kauth_cred_t cred)
394 1.1 ahoka {
395 1.1 ahoka struct chfs_mount *chmp;
396 1.1 ahoka struct chfs_inode *ip;
397 1.1 ahoka int error = 0;
398 1.1 ahoka
399 1.1 ahoka ip = VTOI(vp);
400 1.1 ahoka chmp = ip->chmp;
401 1.1 ahoka
402 1.1 ahoka if (vp->v_mount->mnt_flag & MNT_RDONLY)
403 1.1 ahoka return EROFS;
404 1.1 ahoka
405 1.1 ahoka if (kauth_cred_geteuid(cred) != ip->uid &&
406 1.1 ahoka (error = kauth_authorize_generic(cred,
407 1.1 ahoka KAUTH_GENERIC_ISSUSER, NULL)))
408 1.1 ahoka return error;
409 1.1 ahoka
410 1.1 ahoka if (kauth_authorize_generic(cred, KAUTH_GENERIC_ISSUSER,
411 1.1 ahoka NULL) == 0) {
412 1.1 ahoka if ((ip->flags & (SF_IMMUTABLE | SF_APPEND)) &&
413 1.1 ahoka kauth_authorize_system(curlwp->l_cred,
414 1.1 ahoka KAUTH_SYSTEM_CHSYSFLAGS, 0, NULL, NULL, NULL))
415 1.1 ahoka return EPERM;
416 1.1 ahoka
417 1.1 ahoka if ((flags & SF_SNAPSHOT) !=
418 1.1 ahoka (ip->flags & SF_SNAPSHOT))
419 1.1 ahoka return EPERM;
420 1.1 ahoka
421 1.1 ahoka ip->flags = flags;
422 1.1 ahoka } else {
423 1.1 ahoka if ((ip->flags & (SF_IMMUTABLE | SF_APPEND)) ||
424 1.1 ahoka (flags & UF_SETTABLE) != flags)
425 1.1 ahoka return EPERM;
426 1.1 ahoka
427 1.1 ahoka if ((ip->flags & SF_SETTABLE) !=
428 1.1 ahoka (flags & SF_SETTABLE))
429 1.1 ahoka return EPERM;
430 1.1 ahoka
431 1.1 ahoka ip->flags &= SF_SETTABLE;
432 1.1 ahoka ip->flags |= (flags & UF_SETTABLE);
433 1.1 ahoka }
434 1.1 ahoka ip->iflag |= IN_CHANGE;
435 1.1 ahoka error = chfs_update(vp, NULL, NULL, UPDATE_WAIT);
436 1.1 ahoka if (error)
437 1.1 ahoka return error;
438 1.1 ahoka
439 1.1 ahoka if (flags & (IMMUTABLE | APPEND))
440 1.1 ahoka return 0;
441 1.1 ahoka
442 1.1 ahoka return error;
443 1.1 ahoka }
444 1.1 ahoka
445 1.1 ahoka /* --------------------------------------------------------------------- */
446 1.1 ahoka
447 1.1 ahoka void
448 1.1 ahoka chfs_itimes(struct chfs_inode *ip, const struct timespec *acc,
449 1.1 ahoka const struct timespec *mod, const struct timespec *cre)
450 1.1 ahoka {
451 1.1 ahoka //dbg("itimes\n");
452 1.1 ahoka struct timespec now;
453 1.1 ahoka
454 1.1 ahoka if (!(ip->iflag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY))) {
455 1.1 ahoka return;
456 1.1 ahoka }
457 1.1 ahoka
458 1.1 ahoka vfs_timestamp(&now);
459 1.1 ahoka if (ip->iflag & IN_ACCESS) {
460 1.1 ahoka if (acc == NULL)
461 1.1 ahoka acc = &now;
462 1.1 ahoka ip->atime = acc->tv_sec;
463 1.1 ahoka }
464 1.1 ahoka if (ip->iflag & (IN_UPDATE | IN_MODIFY)) {
465 1.1 ahoka if (mod == NULL)
466 1.1 ahoka mod = &now;
467 1.1 ahoka ip->mtime = mod->tv_sec;
468 1.1 ahoka //ip->i_modrev++;
469 1.1 ahoka }
470 1.1 ahoka if (ip->iflag & (IN_CHANGE | IN_MODIFY)) {
471 1.1 ahoka if (cre == NULL)
472 1.1 ahoka cre = &now;
473 1.1 ahoka ip->ctime = cre->tv_sec;
474 1.1 ahoka }
475 1.1 ahoka if (ip->iflag & (IN_ACCESS | IN_MODIFY))
476 1.1 ahoka ip->iflag |= IN_ACCESSED;
477 1.1 ahoka if (ip->iflag & (IN_UPDATE | IN_CHANGE))
478 1.1 ahoka ip->iflag |= IN_MODIFIED;
479 1.1 ahoka ip->iflag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY);
480 1.1 ahoka }
481 1.1 ahoka
482 1.1 ahoka /* --------------------------------------------------------------------- */
483 1.1 ahoka
484 1.1 ahoka int
485 1.1 ahoka chfs_update(struct vnode *vp, const struct timespec *acc,
486 1.1 ahoka const struct timespec *mod, int flags)
487 1.1 ahoka {
488 1.1 ahoka
489 1.1 ahoka struct chfs_inode *ip;
490 1.1 ahoka
491 1.1 ahoka /* XXX ufs_reclaim calls this function unlocked! */
492 1.1 ahoka // KASSERT(VOP_ISLOCKED(vp));
493 1.1 ahoka
494 1.1 ahoka #if 0
495 1.1 ahoka if (flags & UPDATE_CLOSE)
496 1.1 ahoka ; /* XXX Need to do anything special? */
497 1.1 ahoka #endif
498 1.1 ahoka
499 1.1 ahoka ip = VTOI(vp);
500 1.1 ahoka chfs_itimes(ip, acc, mod, NULL);
501 1.1 ahoka
502 1.1 ahoka // KASSERT(VOP_ISLOCKED(vp));
503 1.1 ahoka return (0);
504 1.1 ahoka }
505 1.1 ahoka
506 1.1 ahoka /* --------------------------------------------------------------------- */
507 1.1 ahoka /*
508 1.1 ahoka int
509 1.1 ahoka chfs_truncate(struct vnode *vp, off_t length)
510 1.1 ahoka {
511 1.1 ahoka bool extended;
512 1.1 ahoka int error;
513 1.1 ahoka struct chfs_node *node;
514 1.1 ahoka printf("CHFS: truncate()\n");
515 1.1 ahoka
516 1.1 ahoka node = VP_TO_CHFS_NODE(vp);
517 1.1 ahoka extended = length > node->chn_size;
518 1.1 ahoka
519 1.1 ahoka if (length < 0) {
520 1.1 ahoka error = EINVAL;
521 1.1 ahoka goto out;
522 1.1 ahoka }
523 1.1 ahoka
524 1.1 ahoka if (node->chn_size == length) {
525 1.1 ahoka error = 0;
526 1.1 ahoka goto out;
527 1.1 ahoka }
528 1.1 ahoka
529 1.1 ahoka error = chfs_reg_resize(vp, length);
530 1.1 ahoka if (error == 0)
531 1.1 ahoka node->chn_status |= CHFS_NODE_CHANGED | CHFS_NODE_MODIFIED;
532 1.1 ahoka
533 1.1 ahoka out:
534 1.1 ahoka chfs_update(vp, NULL, NULL, 0);
535 1.1 ahoka
536 1.1 ahoka return error;
537 1.1 ahoka }*/
538 1.1 ahoka
539 1.1 ahoka
540