Nuke staled code
[dragonfly.git] / sys / vfs / hammer / hammer_vnops.c
CommitLineData
427e5fc6
MD
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
fe7678ee 34 * $DragonFly: src/sys/vfs/hammer/hammer_vnops.c,v 1.21 2008/01/17 05:06:09 dillon Exp $
427e5fc6
MD
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/fcntl.h>
41#include <sys/namecache.h>
42#include <sys/vnode.h>
43#include <sys/lockf.h>
44#include <sys/event.h>
45#include <sys/stat.h>
b3deaf57 46#include <sys/dirent.h>
c0ade690 47#include <vm/vm_extern.h>
7a04d74f 48#include <vfs/fifofs/fifo.h>
427e5fc6
MD
49#include "hammer.h"
50
51/*
52 * USERFS VNOPS
53 */
54/*static int hammer_vop_vnoperate(struct vop_generic_args *);*/
66325755
MD
55static int hammer_vop_fsync(struct vop_fsync_args *);
56static int hammer_vop_read(struct vop_read_args *);
57static int hammer_vop_write(struct vop_write_args *);
58static int hammer_vop_access(struct vop_access_args *);
59static int hammer_vop_advlock(struct vop_advlock_args *);
60static int hammer_vop_close(struct vop_close_args *);
61static int hammer_vop_ncreate(struct vop_ncreate_args *);
62static int hammer_vop_getattr(struct vop_getattr_args *);
63static int hammer_vop_nresolve(struct vop_nresolve_args *);
64static int hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *);
65static int hammer_vop_nlink(struct vop_nlink_args *);
66static int hammer_vop_nmkdir(struct vop_nmkdir_args *);
67static int hammer_vop_nmknod(struct vop_nmknod_args *);
68static int hammer_vop_open(struct vop_open_args *);
69static int hammer_vop_pathconf(struct vop_pathconf_args *);
70static int hammer_vop_print(struct vop_print_args *);
71static int hammer_vop_readdir(struct vop_readdir_args *);
72static int hammer_vop_readlink(struct vop_readlink_args *);
73static int hammer_vop_nremove(struct vop_nremove_args *);
74static int hammer_vop_nrename(struct vop_nrename_args *);
75static int hammer_vop_nrmdir(struct vop_nrmdir_args *);
76static int hammer_vop_setattr(struct vop_setattr_args *);
77static int hammer_vop_strategy(struct vop_strategy_args *);
78static int hammer_vop_nsymlink(struct vop_nsymlink_args *);
79static int hammer_vop_nwhiteout(struct vop_nwhiteout_args *);
427e5fc6 80
7a04d74f
MD
81static int hammer_vop_fifoclose (struct vop_close_args *);
82static int hammer_vop_fiforead (struct vop_read_args *);
83static int hammer_vop_fifowrite (struct vop_write_args *);
84
85static int hammer_vop_specclose (struct vop_close_args *);
86static int hammer_vop_specread (struct vop_read_args *);
87static int hammer_vop_specwrite (struct vop_write_args *);
88
427e5fc6
MD
89struct vop_ops hammer_vnode_vops = {
90 .vop_default = vop_defaultop,
91 .vop_fsync = hammer_vop_fsync,
c0ade690
MD
92 .vop_getpages = vop_stdgetpages,
93 .vop_putpages = vop_stdputpages,
427e5fc6
MD
94 .vop_read = hammer_vop_read,
95 .vop_write = hammer_vop_write,
96 .vop_access = hammer_vop_access,
97 .vop_advlock = hammer_vop_advlock,
98 .vop_close = hammer_vop_close,
99 .vop_ncreate = hammer_vop_ncreate,
100 .vop_getattr = hammer_vop_getattr,
101 .vop_inactive = hammer_vop_inactive,
102 .vop_reclaim = hammer_vop_reclaim,
103 .vop_nresolve = hammer_vop_nresolve,
104 .vop_nlookupdotdot = hammer_vop_nlookupdotdot,
105 .vop_nlink = hammer_vop_nlink,
106 .vop_nmkdir = hammer_vop_nmkdir,
107 .vop_nmknod = hammer_vop_nmknod,
108 .vop_open = hammer_vop_open,
109 .vop_pathconf = hammer_vop_pathconf,
110 .vop_print = hammer_vop_print,
111 .vop_readdir = hammer_vop_readdir,
112 .vop_readlink = hammer_vop_readlink,
113 .vop_nremove = hammer_vop_nremove,
114 .vop_nrename = hammer_vop_nrename,
115 .vop_nrmdir = hammer_vop_nrmdir,
116 .vop_setattr = hammer_vop_setattr,
117 .vop_strategy = hammer_vop_strategy,
118 .vop_nsymlink = hammer_vop_nsymlink,
119 .vop_nwhiteout = hammer_vop_nwhiteout
120};
121
7a04d74f
MD
122struct vop_ops hammer_spec_vops = {
123 .vop_default = spec_vnoperate,
124 .vop_fsync = hammer_vop_fsync,
125 .vop_read = hammer_vop_specread,
126 .vop_write = hammer_vop_specwrite,
127 .vop_access = hammer_vop_access,
128 .vop_close = hammer_vop_specclose,
129 .vop_getattr = hammer_vop_getattr,
130 .vop_inactive = hammer_vop_inactive,
131 .vop_reclaim = hammer_vop_reclaim,
132 .vop_setattr = hammer_vop_setattr
133};
134
135struct vop_ops hammer_fifo_vops = {
136 .vop_default = fifo_vnoperate,
137 .vop_fsync = hammer_vop_fsync,
138 .vop_read = hammer_vop_fiforead,
139 .vop_write = hammer_vop_fifowrite,
140 .vop_access = hammer_vop_access,
141 .vop_close = hammer_vop_fifoclose,
142 .vop_getattr = hammer_vop_getattr,
143 .vop_inactive = hammer_vop_inactive,
144 .vop_reclaim = hammer_vop_reclaim,
145 .vop_setattr = hammer_vop_setattr
146};
147
8cd0a023
MD
148static int hammer_dounlink(struct nchandle *nch, struct vnode *dvp,
149 struct ucred *cred, int flags);
150static int hammer_vop_strategy_read(struct vop_strategy_args *ap);
151static int hammer_vop_strategy_write(struct vop_strategy_args *ap);
152
427e5fc6
MD
153#if 0
154static
155int
156hammer_vop_vnoperate(struct vop_generic_args *)
157{
158 return (VOCALL(&hammer_vnode_vops, ap));
159}
160#endif
161
66325755
MD
162/*
163 * hammer_vop_fsync { vp, waitfor }
164 */
427e5fc6
MD
165static
166int
66325755 167hammer_vop_fsync(struct vop_fsync_args *ap)
427e5fc6 168{
c0ade690
MD
169 hammer_inode_t ip;
170 int error;
171
172 ip = VTOI(ap->a_vp);
173 error = hammer_sync_inode(ip, ap->a_waitfor, 0);
174 return (error);
427e5fc6
MD
175}
176
66325755
MD
177/*
178 * hammer_vop_read { vp, uio, ioflag, cred }
179 */
427e5fc6
MD
180static
181int
66325755 182hammer_vop_read(struct vop_read_args *ap)
427e5fc6 183{
66325755 184 struct hammer_transaction trans;
c0ade690 185 hammer_inode_t ip;
66325755
MD
186 off_t offset;
187 struct buf *bp;
188 struct uio *uio;
189 int error;
190 int n;
8cd0a023 191 int seqcount;
66325755
MD
192
193 if (ap->a_vp->v_type != VREG)
194 return (EINVAL);
195 ip = VTOI(ap->a_vp);
196 error = 0;
8cd0a023 197 seqcount = ap->a_ioflag >> 16;
66325755 198
8cd0a023 199 hammer_start_transaction(&trans, ip->hmp);
66325755
MD
200
201 /*
202 * Access the data in HAMMER_BUFSIZE blocks via the buffer cache.
203 */
204 uio = ap->a_uio;
205 while (uio->uio_resid > 0 && uio->uio_offset < ip->ino_rec.ino_size) {
206 offset = uio->uio_offset & HAMMER_BUFMASK;
c0ade690 207#if 0
8cd0a023
MD
208 error = cluster_read(ap->a_vp, ip->ino_rec.ino_size,
209 uio->uio_offset - offset, HAMMER_BUFSIZE,
210 MAXBSIZE, seqcount, &bp);
c0ade690
MD
211#endif
212 error = bread(ap->a_vp, uio->uio_offset - offset,
213 HAMMER_BUFSIZE, &bp);
66325755
MD
214 if (error) {
215 brelse(bp);
216 break;
217 }
c0ade690 218 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
66325755
MD
219 n = HAMMER_BUFSIZE - offset;
220 if (n > uio->uio_resid)
221 n = uio->uio_resid;
222 if (n > ip->ino_rec.ino_size - uio->uio_offset)
223 n = (int)(ip->ino_rec.ino_size - uio->uio_offset);
224 error = uiomove((char *)bp->b_data + offset, n, uio);
225 if (error) {
8cd0a023 226 bqrelse(bp);
66325755
MD
227 break;
228 }
d113fda1
MD
229 if ((ip->flags & HAMMER_INODE_RO) == 0) {
230 ip->ino_rec.ino_atime = trans.tid;
231 hammer_modify_inode(&trans, ip, HAMMER_INODE_ITIMES);
232 }
66325755
MD
233 bqrelse(bp);
234 }
235 hammer_commit_transaction(&trans);
236 return (error);
427e5fc6
MD
237}
238
66325755
MD
239/*
240 * hammer_vop_write { vp, uio, ioflag, cred }
241 */
427e5fc6
MD
242static
243int
66325755 244hammer_vop_write(struct vop_write_args *ap)
427e5fc6 245{
66325755
MD
246 struct hammer_transaction trans;
247 struct hammer_inode *ip;
248 struct uio *uio;
249 off_t offset;
250 struct buf *bp;
251 int error;
252 int n;
c0ade690 253 int flags;
66325755
MD
254
255 if (ap->a_vp->v_type != VREG)
256 return (EINVAL);
257 ip = VTOI(ap->a_vp);
258 error = 0;
259
d113fda1
MD
260 if (ip->flags & HAMMER_INODE_RO)
261 return (EROFS);
262
66325755
MD
263 /*
264 * Create a transaction to cover the operations we perform.
265 */
8cd0a023 266 hammer_start_transaction(&trans, ip->hmp);
66325755
MD
267 uio = ap->a_uio;
268
269 /*
270 * Check append mode
271 */
272 if (ap->a_ioflag & IO_APPEND)
273 uio->uio_offset = ip->ino_rec.ino_size;
274
275 /*
276 * Check for illegal write offsets. Valid range is 0...2^63-1
277 */
9c448776
MD
278 if (uio->uio_offset < 0 || uio->uio_offset + uio->uio_resid <= 0) {
279 hammer_commit_transaction(&trans);
66325755 280 return (EFBIG);
9c448776 281 }
66325755
MD
282
283 /*
284 * Access the data in HAMMER_BUFSIZE blocks via the buffer cache.
285 */
286 while (uio->uio_resid > 0) {
287 offset = uio->uio_offset & HAMMER_BUFMASK;
c0ade690
MD
288 if (uio->uio_segflg == UIO_NOCOPY) {
289 /*
290 * Issuing a write with the same data backing the
291 * buffer. Instantiate the buffer to collect the
292 * backing vm pages, then read-in any missing bits.
293 *
294 * This case is used by vop_stdputpages().
295 */
296 bp = getblk(ap->a_vp, uio->uio_offset, HAMMER_BUFSIZE,
055f5ff8 297 GETBLK_BHEAVY, 0);
c0ade690
MD
298 if ((bp->b_flags & B_CACHE) == 0) {
299 bqrelse(bp);
300 error = bread(ap->a_vp,
301 uio->uio_offset - offset,
302 HAMMER_BUFSIZE, &bp);
303 if (error) {
304 brelse(bp);
305 break;
306 }
307 }
308 } else if (offset == 0 && uio->uio_resid >= HAMMER_BUFSIZE) {
309 /*
310 * entirely overwrite the buffer
311 */
66325755 312 bp = getblk(ap->a_vp, uio->uio_offset, HAMMER_BUFSIZE,
055f5ff8 313 GETBLK_BHEAVY, 0);
66325755 314 } else if (offset == 0 && uio->uio_offset >= ip->ino_rec.ino_size) {
c0ade690
MD
315 /*
316 * XXX
317 */
66325755 318 bp = getblk(ap->a_vp, uio->uio_offset, HAMMER_BUFSIZE,
055f5ff8 319 GETBLK_BHEAVY, 0);
66325755
MD
320 vfs_bio_clrbuf(bp);
321 } else {
c0ade690
MD
322 /*
323 * Partial overwrite, read in any missing bits then
324 * replace the portion being written.
325 */
66325755
MD
326 error = bread(ap->a_vp, uio->uio_offset - offset,
327 HAMMER_BUFSIZE, &bp);
328 if (error) {
329 brelse(bp);
330 break;
331 }
055f5ff8 332 bheavy(bp);
66325755
MD
333 }
334 n = HAMMER_BUFSIZE - offset;
335 if (n > uio->uio_resid)
336 n = uio->uio_resid;
337 error = uiomove((char *)bp->b_data + offset, n, uio);
338 if (error) {
339 brelse(bp);
340 break;
341 }
c0ade690 342 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
66325755
MD
343 if (ip->ino_rec.ino_size < uio->uio_offset) {
344 ip->ino_rec.ino_size = uio->uio_offset;
d113fda1 345 flags = HAMMER_INODE_RDIRTY;
c0ade690
MD
346 vnode_pager_setsize(ap->a_vp, ip->ino_rec.ino_size);
347 } else {
d113fda1 348 flags = 0;
66325755 349 }
d113fda1 350 ip->ino_rec.ino_mtime = trans.tid;
f3b0f382 351 flags |= HAMMER_INODE_ITIMES | HAMMER_INODE_BUFS;
c0ade690 352 hammer_modify_inode(&trans, ip, flags);
66325755
MD
353 if (ap->a_ioflag & IO_SYNC) {
354 bwrite(bp);
355 } else if (ap->a_ioflag & IO_DIRECT) {
66325755
MD
356 bawrite(bp);
357 } else {
66325755
MD
358 bdwrite(bp);
359 }
360 }
361 if (error)
362 hammer_abort_transaction(&trans);
363 else
364 hammer_commit_transaction(&trans);
365 return (error);
427e5fc6
MD
366}
367
66325755
MD
368/*
369 * hammer_vop_access { vp, mode, cred }
370 */
427e5fc6
MD
371static
372int
66325755 373hammer_vop_access(struct vop_access_args *ap)
427e5fc6 374{
66325755
MD
375 struct hammer_inode *ip = VTOI(ap->a_vp);
376 uid_t uid;
377 gid_t gid;
378 int error;
379
380 uid = hammer_to_unix_xid(&ip->ino_data.uid);
381 gid = hammer_to_unix_xid(&ip->ino_data.gid);
382
383 error = vop_helper_access(ap, uid, gid, ip->ino_data.mode,
384 ip->ino_data.uflags);
385 return (error);
427e5fc6
MD
386}
387
66325755
MD
388/*
389 * hammer_vop_advlock { vp, id, op, fl, flags }
390 */
427e5fc6
MD
391static
392int
66325755 393hammer_vop_advlock(struct vop_advlock_args *ap)
427e5fc6 394{
66325755
MD
395 struct hammer_inode *ip = VTOI(ap->a_vp);
396
397 return (lf_advlock(ap, &ip->advlock, ip->ino_rec.ino_size));
427e5fc6
MD
398}
399
66325755
MD
400/*
401 * hammer_vop_close { vp, fflag }
402 */
427e5fc6
MD
403static
404int
66325755 405hammer_vop_close(struct vop_close_args *ap)
427e5fc6 406{
a89aec1b 407 return (vop_stdclose(ap));
427e5fc6
MD
408}
409
66325755
MD
410/*
411 * hammer_vop_ncreate { nch, dvp, vpp, cred, vap }
412 *
413 * The operating system has already ensured that the directory entry
414 * does not exist and done all appropriate namespace locking.
415 */
427e5fc6
MD
416static
417int
66325755 418hammer_vop_ncreate(struct vop_ncreate_args *ap)
427e5fc6 419{
66325755
MD
420 struct hammer_transaction trans;
421 struct hammer_inode *dip;
422 struct hammer_inode *nip;
423 struct nchandle *nch;
424 int error;
425
426 nch = ap->a_nch;
427 dip = VTOI(ap->a_dvp);
428
d113fda1
MD
429 if (dip->flags & HAMMER_INODE_RO)
430 return (EROFS);
431
66325755
MD
432 /*
433 * Create a transaction to cover the operations we perform.
434 */
8cd0a023 435 hammer_start_transaction(&trans, dip->hmp);
66325755
MD
436
437 /*
438 * Create a new filesystem object of the requested type. The
7a04d74f 439 * returned inode will be referenced but not locked.
66325755 440 */
8cd0a023
MD
441
442 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
0b075555
MD
443 if (error)
444 kprintf("hammer_create_inode error %d\n", error);
66325755
MD
445 if (error) {
446 hammer_abort_transaction(&trans);
447 *ap->a_vpp = NULL;
448 return (error);
449 }
66325755
MD
450
451 /*
452 * Add the new filesystem object to the directory. This will also
453 * bump the inode's link count.
454 */
a89aec1b 455 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
0b075555
MD
456 if (error)
457 kprintf("hammer_ip_add_directory error %d\n", error);
66325755
MD
458
459 /*
460 * Finish up.
461 */
462 if (error) {
a89aec1b 463 hammer_rel_inode(nip, 0);
66325755
MD
464 hammer_abort_transaction(&trans);
465 *ap->a_vpp = NULL;
466 } else {
467 hammer_commit_transaction(&trans);
468 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
a89aec1b
MD
469 hammer_rel_inode(nip, 0);
470 if (error == 0) {
471 cache_setunresolved(ap->a_nch);
472 cache_setvp(ap->a_nch, *ap->a_vpp);
473 }
66325755
MD
474 }
475 return (error);
427e5fc6
MD
476}
477
66325755
MD
478/*
479 * hammer_vop_getattr { vp, vap }
480 */
427e5fc6
MD
481static
482int
66325755 483hammer_vop_getattr(struct vop_getattr_args *ap)
427e5fc6 484{
66325755
MD
485 struct hammer_inode *ip = VTOI(ap->a_vp);
486 struct vattr *vap = ap->a_vap;
487
488#if 0
489 if (cache_check_fsmid_vp(ap->a_vp, &ip->fsmid) &&
490 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0 &&
7f7c1f84 491 ip->obj_asof == XXX
66325755
MD
492 ) {
493 /* LAZYMOD XXX */
494 }
495 hammer_itimes(ap->a_vp);
496#endif
497
498 vap->va_fsid = ip->hmp->fsid_udev;
499 vap->va_fileid = ip->ino_rec.base.base.obj_id;
500 vap->va_mode = ip->ino_data.mode;
501 vap->va_nlink = ip->ino_rec.ino_nlinks;
502 vap->va_uid = hammer_to_unix_xid(&ip->ino_data.uid);
503 vap->va_gid = hammer_to_unix_xid(&ip->ino_data.gid);
504 vap->va_rmajor = 0;
505 vap->va_rminor = 0;
506 vap->va_size = ip->ino_rec.ino_size;
507 hammer_to_timespec(ip->ino_rec.ino_atime, &vap->va_atime);
508 hammer_to_timespec(ip->ino_rec.ino_mtime, &vap->va_mtime);
509 hammer_to_timespec(ip->ino_data.ctime, &vap->va_ctime);
510 vap->va_flags = ip->ino_data.uflags;
511 vap->va_gen = 1; /* hammer inums are unique for all time */
512 vap->va_blocksize = 32768; /* XXX - extract from root volume */
513 vap->va_bytes = ip->ino_rec.ino_size;
514 vap->va_type = hammer_get_vnode_type(ip->ino_rec.base.base.obj_type);
515 vap->va_filerev = 0; /* XXX */
516 /* mtime uniquely identifies any adjustments made to the file */
517 vap->va_fsmid = ip->ino_rec.ino_mtime;
518 vap->va_uid_uuid = ip->ino_data.uid;
519 vap->va_gid_uuid = ip->ino_data.gid;
520 vap->va_fsid_uuid = ip->hmp->fsid;
521 vap->va_vaflags = VA_UID_UUID_VALID | VA_GID_UUID_VALID |
522 VA_FSID_UUID_VALID;
7a04d74f
MD
523
524 switch (ip->ino_rec.base.base.obj_type) {
525 case HAMMER_OBJTYPE_CDEV:
526 case HAMMER_OBJTYPE_BDEV:
527 vap->va_rmajor = ip->ino_data.rmajor;
528 vap->va_rminor = ip->ino_data.rminor;
529 break;
530 default:
531 break;
532 }
533
66325755 534 return(0);
427e5fc6
MD
535}
536
66325755
MD
537/*
538 * hammer_vop_nresolve { nch, dvp, cred }
539 *
540 * Locate the requested directory entry.
541 */
427e5fc6
MD
542static
543int
66325755 544hammer_vop_nresolve(struct vop_nresolve_args *ap)
427e5fc6 545{
66325755 546 struct namecache *ncp;
7f7c1f84
MD
547 hammer_inode_t dip;
548 hammer_inode_t ip;
549 hammer_tid_t asof;
8cd0a023
MD
550 struct hammer_cursor cursor;
551 union hammer_record_ondisk *rec;
66325755
MD
552 struct vnode *vp;
553 int64_t namekey;
554 int error;
7f7c1f84
MD
555 int i;
556 int nlen;
d113fda1 557 int flags;
7f7c1f84
MD
558
559 /*
560 * Misc initialization, plus handle as-of name extensions. Look for
561 * the '@@' extension. Note that as-of files and directories cannot
562 * be modified.
7f7c1f84
MD
563 */
564 dip = VTOI(ap->a_dvp);
565 ncp = ap->a_nch->ncp;
566 asof = dip->obj_asof;
567 nlen = ncp->nc_nlen;
d113fda1 568 flags = dip->flags;
7f7c1f84
MD
569
570 for (i = 0; i < nlen; ++i) {
571 if (ncp->nc_name[i] == '@' && ncp->nc_name[i+1] == '@') {
d113fda1 572 asof = hammer_str_to_tid(ncp->nc_name + i + 2);
7f7c1f84 573 kprintf("ASOF %016llx\n", asof);
d113fda1 574 flags |= HAMMER_INODE_RO;
7f7c1f84
MD
575 break;
576 }
577 }
578 nlen = i;
66325755 579
d113fda1
MD
580 /*
581 * If there is no path component the time extension is relative to
582 * dip.
583 */
584 if (nlen == 0) {
61aeeb33
MD
585 ip = hammer_get_inode(dip->hmp, &dip->cache[1], dip->obj_id,
586 asof, flags, &error);
d113fda1
MD
587 if (error == 0) {
588 error = hammer_get_vnode(ip, LK_EXCLUSIVE, &vp);
589 hammer_rel_inode(ip, 0);
590 } else {
591 vp = NULL;
592 }
593 if (error == 0) {
594 vn_unlock(vp);
595 cache_setvp(ap->a_nch, vp);
596 vrele(vp);
597 }
598 return(error);
599 }
600
8cd0a023
MD
601 /*
602 * Calculate the namekey and setup the key range for the scan. This
603 * works kinda like a chained hash table where the lower 32 bits
604 * of the namekey synthesize the chain.
605 *
606 * The key range is inclusive of both key_beg and key_end.
607 */
7f7c1f84 608 namekey = hammer_directory_namekey(ncp->nc_name, nlen);
66325755 609
61aeeb33 610 hammer_init_cursor_hmp(&cursor, &dip->cache[0], dip->hmp);
8cd0a023
MD
611 cursor.key_beg.obj_id = dip->obj_id;
612 cursor.key_beg.key = namekey;
d5530d22 613 cursor.key_beg.create_tid = 0;
8cd0a023
MD
614 cursor.key_beg.delete_tid = 0;
615 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
616 cursor.key_beg.obj_type = 0;
66325755 617
8cd0a023
MD
618 cursor.key_end = cursor.key_beg;
619 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
620 cursor.asof = asof;
621 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
66325755
MD
622
623 /*
8cd0a023 624 * Scan all matching records (the chain), locate the one matching
a89aec1b 625 * the requested path component.
8cd0a023
MD
626 *
627 * The hammer_ip_*() functions merge in-memory records with on-disk
628 * records for the purposes of the search.
66325755 629 */
a89aec1b 630 error = hammer_ip_first(&cursor, dip);
0b075555 631 rec = NULL;
a89aec1b
MD
632 while (error == 0) {
633 error = hammer_ip_resolve_data(&cursor);
634 if (error)
66325755 635 break;
a89aec1b 636 rec = cursor.record;
7f7c1f84
MD
637 if (nlen == rec->entry.base.data_len &&
638 bcmp(ncp->nc_name, cursor.data, nlen) == 0) {
66325755
MD
639 break;
640 }
a89aec1b 641 error = hammer_ip_next(&cursor);
66325755
MD
642 }
643 if (error == 0) {
61aeeb33
MD
644 ip = hammer_get_inode(dip->hmp, &dip->cache[1],
645 rec->entry.obj_id, asof,
d113fda1 646 flags, &error);
7f7c1f84
MD
647 if (error == 0) {
648 error = hammer_get_vnode(ip, LK_EXCLUSIVE, &vp);
649 hammer_rel_inode(ip, 0);
650 } else {
651 vp = NULL;
652 }
66325755
MD
653 if (error == 0) {
654 vn_unlock(vp);
655 cache_setvp(ap->a_nch, vp);
656 vrele(vp);
657 }
658 } else if (error == ENOENT) {
659 cache_setvp(ap->a_nch, NULL);
660 }
8cd0a023 661 hammer_done_cursor(&cursor);
66325755 662 return (error);
427e5fc6
MD
663}
664
66325755
MD
665/*
666 * hammer_vop_nlookupdotdot { dvp, vpp, cred }
667 *
668 * Locate the parent directory of a directory vnode.
669 *
670 * dvp is referenced but not locked. *vpp must be returned referenced and
671 * locked. A parent_obj_id of 0 does not necessarily indicate that we are
672 * at the root, instead it could indicate that the directory we were in was
673 * removed.
674 */
427e5fc6
MD
675static
676int
66325755 677hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
427e5fc6 678{
66325755 679 struct hammer_inode *dip;
d113fda1 680 struct hammer_inode *ip;
66325755 681 u_int64_t parent_obj_id;
d113fda1 682 int error;
66325755
MD
683
684 dip = VTOI(ap->a_dvp);
685 if ((parent_obj_id = dip->ino_data.parent_obj_id) == 0) {
686 *ap->a_vpp = NULL;
687 return ENOENT;
688 }
d113fda1 689
61aeeb33
MD
690 ip = hammer_get_inode(dip->hmp, &dip->cache[1], parent_obj_id,
691 dip->obj_asof, dip->flags, &error);
d113fda1
MD
692 if (ip == NULL) {
693 *ap->a_vpp = NULL;
694 return(error);
695 }
696 error = hammer_get_vnode(ip, LK_EXCLUSIVE, ap->a_vpp);
697 hammer_rel_inode(ip, 0);
698 return (error);
427e5fc6
MD
699}
700
66325755
MD
701/*
702 * hammer_vop_nlink { nch, dvp, vp, cred }
703 */
427e5fc6
MD
704static
705int
66325755 706hammer_vop_nlink(struct vop_nlink_args *ap)
427e5fc6 707{
66325755
MD
708 struct hammer_transaction trans;
709 struct hammer_inode *dip;
710 struct hammer_inode *ip;
711 struct nchandle *nch;
712 int error;
713
714 nch = ap->a_nch;
715 dip = VTOI(ap->a_dvp);
716 ip = VTOI(ap->a_vp);
717
d113fda1
MD
718 if (dip->flags & HAMMER_INODE_RO)
719 return (EROFS);
720 if (ip->flags & HAMMER_INODE_RO)
721 return (EROFS);
722
66325755
MD
723 /*
724 * Create a transaction to cover the operations we perform.
725 */
8cd0a023 726 hammer_start_transaction(&trans, dip->hmp);
66325755
MD
727
728 /*
729 * Add the filesystem object to the directory. Note that neither
730 * dip nor ip are referenced or locked, but their vnodes are
731 * referenced. This function will bump the inode's link count.
732 */
a89aec1b 733 error = hammer_ip_add_directory(&trans, dip, nch->ncp, ip);
66325755
MD
734
735 /*
736 * Finish up.
737 */
738 if (error) {
739 hammer_abort_transaction(&trans);
740 } else {
6b4f890b
MD
741 cache_setunresolved(nch);
742 cache_setvp(nch, ap->a_vp);
66325755
MD
743 hammer_commit_transaction(&trans);
744 }
745 return (error);
427e5fc6
MD
746}
747
66325755
MD
748/*
749 * hammer_vop_nmkdir { nch, dvp, vpp, cred, vap }
750 *
751 * The operating system has already ensured that the directory entry
752 * does not exist and done all appropriate namespace locking.
753 */
427e5fc6
MD
754static
755int
66325755 756hammer_vop_nmkdir(struct vop_nmkdir_args *ap)
427e5fc6 757{
66325755
MD
758 struct hammer_transaction trans;
759 struct hammer_inode *dip;
760 struct hammer_inode *nip;
761 struct nchandle *nch;
762 int error;
763
764 nch = ap->a_nch;
765 dip = VTOI(ap->a_dvp);
766
d113fda1
MD
767 if (dip->flags & HAMMER_INODE_RO)
768 return (EROFS);
769
66325755
MD
770 /*
771 * Create a transaction to cover the operations we perform.
772 */
8cd0a023 773 hammer_start_transaction(&trans, dip->hmp);
66325755
MD
774
775 /*
776 * Create a new filesystem object of the requested type. The
8cd0a023 777 * returned inode will be referenced but not locked.
66325755 778 */
8cd0a023 779 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
0b075555
MD
780 if (error)
781 kprintf("hammer_mkdir error %d\n", error);
66325755
MD
782 if (error) {
783 hammer_abort_transaction(&trans);
784 *ap->a_vpp = NULL;
785 return (error);
786 }
66325755
MD
787
788 /*
789 * Add the new filesystem object to the directory. This will also
790 * bump the inode's link count.
791 */
a89aec1b 792 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
0b075555
MD
793 if (error)
794 kprintf("hammer_mkdir (add) error %d\n", error);
66325755
MD
795
796 /*
797 * Finish up.
798 */
799 if (error) {
a89aec1b 800 hammer_rel_inode(nip, 0);
66325755
MD
801 hammer_abort_transaction(&trans);
802 *ap->a_vpp = NULL;
803 } else {
804 hammer_commit_transaction(&trans);
805 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
a89aec1b
MD
806 hammer_rel_inode(nip, 0);
807 if (error == 0) {
808 cache_setunresolved(ap->a_nch);
809 cache_setvp(ap->a_nch, *ap->a_vpp);
810 }
66325755
MD
811 }
812 return (error);
427e5fc6
MD
813}
814
66325755
MD
815/*
816 * hammer_vop_nmknod { nch, dvp, vpp, cred, vap }
817 *
818 * The operating system has already ensured that the directory entry
819 * does not exist and done all appropriate namespace locking.
820 */
427e5fc6
MD
821static
822int
66325755 823hammer_vop_nmknod(struct vop_nmknod_args *ap)
427e5fc6 824{
66325755
MD
825 struct hammer_transaction trans;
826 struct hammer_inode *dip;
827 struct hammer_inode *nip;
828 struct nchandle *nch;
829 int error;
830
831 nch = ap->a_nch;
832 dip = VTOI(ap->a_dvp);
833
d113fda1
MD
834 if (dip->flags & HAMMER_INODE_RO)
835 return (EROFS);
836
66325755
MD
837 /*
838 * Create a transaction to cover the operations we perform.
839 */
8cd0a023 840 hammer_start_transaction(&trans, dip->hmp);
66325755
MD
841
842 /*
843 * Create a new filesystem object of the requested type. The
8cd0a023 844 * returned inode will be referenced but not locked.
66325755 845 */
8cd0a023 846 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
66325755
MD
847 if (error) {
848 hammer_abort_transaction(&trans);
849 *ap->a_vpp = NULL;
850 return (error);
851 }
66325755
MD
852
853 /*
854 * Add the new filesystem object to the directory. This will also
855 * bump the inode's link count.
856 */
a89aec1b 857 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
66325755
MD
858
859 /*
860 * Finish up.
861 */
862 if (error) {
a89aec1b 863 hammer_rel_inode(nip, 0);
66325755
MD
864 hammer_abort_transaction(&trans);
865 *ap->a_vpp = NULL;
866 } else {
867 hammer_commit_transaction(&trans);
868 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
a89aec1b
MD
869 hammer_rel_inode(nip, 0);
870 if (error == 0) {
871 cache_setunresolved(ap->a_nch);
872 cache_setvp(ap->a_nch, *ap->a_vpp);
873 }
66325755
MD
874 }
875 return (error);
427e5fc6
MD
876}
877
66325755
MD
878/*
879 * hammer_vop_open { vp, mode, cred, fp }
880 */
427e5fc6
MD
881static
882int
66325755 883hammer_vop_open(struct vop_open_args *ap)
427e5fc6 884{
d113fda1
MD
885 if ((ap->a_mode & FWRITE) && (VTOI(ap->a_vp)->flags & HAMMER_INODE_RO))
886 return (EROFS);
887
a89aec1b 888 return(vop_stdopen(ap));
427e5fc6
MD
889}
890
66325755
MD
891/*
892 * hammer_vop_pathconf { vp, name, retval }
893 */
427e5fc6
MD
894static
895int
66325755 896hammer_vop_pathconf(struct vop_pathconf_args *ap)
427e5fc6
MD
897{
898 return EOPNOTSUPP;
899}
900
66325755
MD
901/*
902 * hammer_vop_print { vp }
903 */
427e5fc6
MD
904static
905int
66325755 906hammer_vop_print(struct vop_print_args *ap)
427e5fc6
MD
907{
908 return EOPNOTSUPP;
909}
910
66325755 911/*
6b4f890b 912 * hammer_vop_readdir { vp, uio, cred, *eofflag, *ncookies, off_t **cookies }
66325755 913 */
427e5fc6
MD
914static
915int
66325755 916hammer_vop_readdir(struct vop_readdir_args *ap)
427e5fc6 917{
6b4f890b
MD
918 struct hammer_cursor cursor;
919 struct hammer_inode *ip;
920 struct uio *uio;
921 hammer_record_ondisk_t rec;
922 hammer_base_elm_t base;
923 int error;
924 int cookie_index;
925 int ncookies;
926 off_t *cookies;
927 off_t saveoff;
928 int r;
929
930 ip = VTOI(ap->a_vp);
931 uio = ap->a_uio;
b3deaf57
MD
932 saveoff = uio->uio_offset;
933
934 if (ap->a_ncookies) {
935 ncookies = uio->uio_resid / 16 + 1;
936 if (ncookies > 1024)
937 ncookies = 1024;
938 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
939 cookie_index = 0;
940 } else {
941 ncookies = -1;
942 cookies = NULL;
943 cookie_index = 0;
944 }
945
946 /*
947 * Handle artificial entries
948 */
949 error = 0;
950 if (saveoff == 0) {
951 r = vop_write_dirent(&error, uio, ip->obj_id, DT_DIR, 1, ".");
952 if (r)
953 goto done;
954 if (cookies)
955 cookies[cookie_index] = saveoff;
956 ++saveoff;
957 ++cookie_index;
958 if (cookie_index == ncookies)
959 goto done;
960 }
961 if (saveoff == 1) {
962 if (ip->ino_data.parent_obj_id) {
963 r = vop_write_dirent(&error, uio,
964 ip->ino_data.parent_obj_id,
965 DT_DIR, 2, "..");
966 } else {
967 r = vop_write_dirent(&error, uio,
968 ip->obj_id, DT_DIR, 2, "..");
969 }
970 if (r)
971 goto done;
972 if (cookies)
973 cookies[cookie_index] = saveoff;
974 ++saveoff;
975 ++cookie_index;
976 if (cookie_index == ncookies)
977 goto done;
978 }
6b4f890b
MD
979
980 /*
981 * Key range (begin and end inclusive) to scan. Directory keys
982 * directly translate to a 64 bit 'seek' position.
983 */
61aeeb33 984 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
6b4f890b 985 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 986 cursor.key_beg.create_tid = 0;
6b4f890b
MD
987 cursor.key_beg.delete_tid = 0;
988 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
989 cursor.key_beg.obj_type = 0;
b3deaf57 990 cursor.key_beg.key = saveoff;
6b4f890b
MD
991
992 cursor.key_end = cursor.key_beg;
993 cursor.key_end.key = HAMMER_MAX_KEY;
d5530d22
MD
994 cursor.asof = ip->obj_asof;
995 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
6b4f890b 996
6b4f890b
MD
997 error = hammer_ip_first(&cursor, ip);
998
999 while (error == 0) {
1000 error = hammer_ip_resolve_data(&cursor);
1001 if (error)
1002 break;
1003 rec = cursor.record;
1004 base = &rec->base.base;
1005 saveoff = base->key;
1006
7a04d74f
MD
1007 if (base->obj_id != ip->obj_id)
1008 panic("readdir: bad record at %p", cursor.node);
1009
6b4f890b
MD
1010 r = vop_write_dirent(
1011 &error, uio, rec->entry.obj_id,
6b4f890b 1012 hammer_get_dtype(rec->entry.base.base.obj_type),
7a04d74f 1013 rec->entry.base.data_len,
6b4f890b
MD
1014 (void *)cursor.data);
1015 if (r)
1016 break;
1017 ++saveoff;
1018 if (cookies)
1019 cookies[cookie_index] = base->key;
1020 ++cookie_index;
1021 if (cookie_index == ncookies)
1022 break;
1023 error = hammer_ip_next(&cursor);
1024 }
1025 hammer_done_cursor(&cursor);
1026
b3deaf57 1027done:
6b4f890b
MD
1028 if (ap->a_eofflag)
1029 *ap->a_eofflag = (error == ENOENT);
6b4f890b
MD
1030 uio->uio_offset = saveoff;
1031 if (error && cookie_index == 0) {
b3deaf57
MD
1032 if (error == ENOENT)
1033 error = 0;
6b4f890b
MD
1034 if (cookies) {
1035 kfree(cookies, M_TEMP);
1036 *ap->a_ncookies = 0;
1037 *ap->a_cookies = NULL;
1038 }
1039 } else {
7a04d74f
MD
1040 if (error == ENOENT)
1041 error = 0;
6b4f890b
MD
1042 if (cookies) {
1043 *ap->a_ncookies = cookie_index;
1044 *ap->a_cookies = cookies;
1045 }
1046 }
1047 return(error);
427e5fc6
MD
1048}
1049
66325755
MD
1050/*
1051 * hammer_vop_readlink { vp, uio, cred }
1052 */
427e5fc6
MD
1053static
1054int
66325755 1055hammer_vop_readlink(struct vop_readlink_args *ap)
427e5fc6 1056{
7a04d74f
MD
1057 struct hammer_cursor cursor;
1058 struct hammer_inode *ip;
1059 int error;
1060
1061 ip = VTOI(ap->a_vp);
61aeeb33 1062 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
7a04d74f
MD
1063
1064 /*
1065 * Key range (begin and end inclusive) to scan. Directory keys
1066 * directly translate to a 64 bit 'seek' position.
1067 */
1068 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 1069 cursor.key_beg.create_tid = 0;
7a04d74f
MD
1070 cursor.key_beg.delete_tid = 0;
1071 cursor.key_beg.rec_type = HAMMER_RECTYPE_FIX;
1072 cursor.key_beg.obj_type = 0;
1073 cursor.key_beg.key = HAMMER_FIXKEY_SYMLINK;
d5530d22
MD
1074 cursor.asof = ip->obj_asof;
1075 cursor.flags |= HAMMER_CURSOR_ASOF;
7a04d74f
MD
1076
1077 error = hammer_ip_lookup(&cursor, ip);
1078 if (error == 0) {
1079 error = hammer_ip_resolve_data(&cursor);
1080 if (error == 0) {
1081 error = uiomove((char *)cursor.data,
1082 cursor.record->generic.base.data_len,
1083 ap->a_uio);
1084 }
1085 }
1086 hammer_done_cursor(&cursor);
1087 return(error);
427e5fc6
MD
1088}
1089
66325755
MD
1090/*
1091 * hammer_vop_nremove { nch, dvp, cred }
1092 */
427e5fc6
MD
1093static
1094int
66325755 1095hammer_vop_nremove(struct vop_nremove_args *ap)
427e5fc6 1096{
8cd0a023 1097 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, 0));
427e5fc6
MD
1098}
1099
66325755
MD
1100/*
1101 * hammer_vop_nrename { fnch, tnch, fdvp, tdvp, cred }
1102 */
427e5fc6
MD
1103static
1104int
66325755 1105hammer_vop_nrename(struct vop_nrename_args *ap)
427e5fc6 1106{
8cd0a023
MD
1107 struct hammer_transaction trans;
1108 struct namecache *fncp;
1109 struct namecache *tncp;
1110 struct hammer_inode *fdip;
1111 struct hammer_inode *tdip;
1112 struct hammer_inode *ip;
1113 struct hammer_cursor cursor;
1114 union hammer_record_ondisk *rec;
1115 int64_t namekey;
1116 int error;
1117
1118 fdip = VTOI(ap->a_fdvp);
1119 tdip = VTOI(ap->a_tdvp);
1120 fncp = ap->a_fnch->ncp;
1121 tncp = ap->a_tnch->ncp;
b3deaf57
MD
1122 ip = VTOI(fncp->nc_vp);
1123 KKASSERT(ip != NULL);
d113fda1
MD
1124
1125 if (fdip->flags & HAMMER_INODE_RO)
1126 return (EROFS);
1127 if (tdip->flags & HAMMER_INODE_RO)
1128 return (EROFS);
1129 if (ip->flags & HAMMER_INODE_RO)
1130 return (EROFS);
1131
8cd0a023
MD
1132 hammer_start_transaction(&trans, fdip->hmp);
1133
1134 /*
b3deaf57
MD
1135 * Remove tncp from the target directory and then link ip as
1136 * tncp. XXX pass trans to dounlink
8cd0a023 1137 */
b3deaf57
MD
1138 error = hammer_dounlink(ap->a_tnch, ap->a_tdvp, ap->a_cred, 0);
1139 if (error == 0 || error == ENOENT)
1140 error = hammer_ip_add_directory(&trans, tdip, tncp, ip);
1141 if (error)
1142 goto failed; /* XXX */
8cd0a023
MD
1143
1144 /*
1145 * Locate the record in the originating directory and remove it.
1146 *
1147 * Calculate the namekey and setup the key range for the scan. This
1148 * works kinda like a chained hash table where the lower 32 bits
1149 * of the namekey synthesize the chain.
1150 *
1151 * The key range is inclusive of both key_beg and key_end.
1152 */
1153 namekey = hammer_directory_namekey(fncp->nc_name, fncp->nc_nlen);
1154
61aeeb33 1155 hammer_init_cursor_hmp(&cursor, &fdip->cache[0], fdip->hmp);
8cd0a023
MD
1156 cursor.key_beg.obj_id = fdip->obj_id;
1157 cursor.key_beg.key = namekey;
d5530d22 1158 cursor.key_beg.create_tid = 0;
8cd0a023
MD
1159 cursor.key_beg.delete_tid = 0;
1160 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1161 cursor.key_beg.obj_type = 0;
1162
1163 cursor.key_end = cursor.key_beg;
1164 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
1165 cursor.asof = fdip->obj_asof;
1166 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
8cd0a023
MD
1167
1168 /*
1169 * Scan all matching records (the chain), locate the one matching
a89aec1b 1170 * the requested path component.
8cd0a023
MD
1171 *
1172 * The hammer_ip_*() functions merge in-memory records with on-disk
1173 * records for the purposes of the search.
1174 */
a89aec1b
MD
1175 error = hammer_ip_first(&cursor, fdip);
1176 while (error == 0) {
8cd0a023
MD
1177 if (hammer_ip_resolve_data(&cursor) != 0)
1178 break;
a89aec1b 1179 rec = cursor.record;
8cd0a023
MD
1180 if (fncp->nc_nlen == rec->entry.base.data_len &&
1181 bcmp(fncp->nc_name, cursor.data, fncp->nc_nlen) == 0) {
1182 break;
1183 }
a89aec1b 1184 error = hammer_ip_next(&cursor);
8cd0a023 1185 }
8cd0a023
MD
1186
1187 /*
1188 * If all is ok we have to get the inode so we can adjust nlinks.
1189 */
1190 if (error)
1191 goto done;
a89aec1b 1192 error = hammer_ip_del_directory(&trans, &cursor, fdip, ip);
b3deaf57 1193
9944ae54 1194 if (error == 0)
8cd0a023 1195 cache_rename(ap->a_fnch, ap->a_tnch);
8cd0a023 1196done:
c0ade690 1197 hammer_done_cursor(&cursor);
b3deaf57 1198failed:
8cd0a023
MD
1199 if (error == 0) {
1200 hammer_commit_transaction(&trans);
1201 } else {
1202 hammer_abort_transaction(&trans);
1203 }
8cd0a023 1204 return (error);
427e5fc6
MD
1205}
1206
66325755
MD
1207/*
1208 * hammer_vop_nrmdir { nch, dvp, cred }
1209 */
427e5fc6
MD
1210static
1211int
66325755 1212hammer_vop_nrmdir(struct vop_nrmdir_args *ap)
427e5fc6 1213{
8cd0a023 1214 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, 0));
427e5fc6
MD
1215}
1216
66325755
MD
1217/*
1218 * hammer_vop_setattr { vp, vap, cred }
1219 */
427e5fc6
MD
1220static
1221int
66325755 1222hammer_vop_setattr(struct vop_setattr_args *ap)
427e5fc6 1223{
8cd0a023 1224 struct hammer_transaction trans;
d26d0ae9 1225 struct hammer_cursor *spike = NULL;
8cd0a023
MD
1226 struct vattr *vap;
1227 struct hammer_inode *ip;
1228 int modflags;
1229 int error;
76376933 1230 int64_t aligned_size;
8cd0a023
MD
1231 u_int32_t flags;
1232 uuid_t uuid;
1233
1234 vap = ap->a_vap;
1235 ip = ap->a_vp->v_data;
1236 modflags = 0;
1237
1238 if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
1239 return(EROFS);
d113fda1
MD
1240 if (ip->flags & HAMMER_INODE_RO)
1241 return (EROFS);
8cd0a023
MD
1242
1243 hammer_start_transaction(&trans, ip->hmp);
1244 error = 0;
1245
1246 if (vap->va_flags != VNOVAL) {
1247 flags = ip->ino_data.uflags;
1248 error = vop_helper_setattr_flags(&flags, vap->va_flags,
1249 hammer_to_unix_xid(&ip->ino_data.uid),
1250 ap->a_cred);
1251 if (error == 0) {
1252 if (ip->ino_data.uflags != flags) {
1253 ip->ino_data.uflags = flags;
1254 modflags |= HAMMER_INODE_DDIRTY;
1255 }
1256 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1257 error = 0;
1258 goto done;
1259 }
1260 }
1261 goto done;
1262 }
1263 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1264 error = EPERM;
1265 goto done;
1266 }
1267 if (vap->va_uid != (uid_t)VNOVAL) {
1268 hammer_guid_to_uuid(&uuid, vap->va_uid);
6b4f890b 1269 if (bcmp(&uuid, &ip->ino_data.uid, sizeof(uuid)) != 0) {
8cd0a023
MD
1270 ip->ino_data.uid = uuid;
1271 modflags |= HAMMER_INODE_DDIRTY;
1272 }
1273 }
1274 if (vap->va_gid != (uid_t)VNOVAL) {
6b4f890b
MD
1275 hammer_guid_to_uuid(&uuid, vap->va_gid);
1276 if (bcmp(&uuid, &ip->ino_data.gid, sizeof(uuid)) != 0) {
8cd0a023
MD
1277 ip->ino_data.gid = uuid;
1278 modflags |= HAMMER_INODE_DDIRTY;
1279 }
1280 }
d26d0ae9 1281 while (vap->va_size != VNOVAL && ip->ino_rec.ino_size != vap->va_size) {
8cd0a023
MD
1282 switch(ap->a_vp->v_type) {
1283 case VREG:
c0ade690
MD
1284 if (vap->va_size < ip->ino_rec.ino_size) {
1285 vtruncbuf(ap->a_vp, vap->va_size,
1286 HAMMER_BUFSIZE);
1287 } else if (vap->va_size > ip->ino_rec.ino_size) {
1288 vnode_pager_setsize(ap->a_vp, vap->va_size);
1289 }
76376933
MD
1290 aligned_size = (vap->va_size + HAMMER_BUFMASK) &
1291 ~(int64_t)HAMMER_BUFMASK;
1292 error = hammer_ip_delete_range(&trans, ip,
1293 aligned_size,
d26d0ae9
MD
1294 0x7FFFFFFFFFFFFFFFLL,
1295 &spike);
76376933
MD
1296 ip->ino_rec.ino_size = vap->va_size;
1297 modflags |= HAMMER_INODE_RDIRTY;
1298 break;
8cd0a023 1299 case VDATABASE:
a89aec1b 1300 error = hammer_ip_delete_range(&trans, ip,
8cd0a023 1301 vap->va_size,
d26d0ae9
MD
1302 0x7FFFFFFFFFFFFFFFLL,
1303 &spike);
c0ade690
MD
1304 ip->ino_rec.ino_size = vap->va_size;
1305 modflags |= HAMMER_INODE_RDIRTY;
8cd0a023
MD
1306 break;
1307 default:
1308 error = EINVAL;
1309 goto done;
1310 }
d26d0ae9
MD
1311 if (error == ENOSPC) {
1312 error = hammer_spike(&spike);
1313 if (error == 0)
1314 continue;
1315 }
1316 KKASSERT(spike == NULL);
1317 break;
8cd0a023
MD
1318 }
1319 if (vap->va_atime.tv_sec != VNOVAL) {
1320 ip->ino_rec.ino_atime =
1321 hammer_timespec_to_transid(&vap->va_atime);
1322 modflags |= HAMMER_INODE_ITIMES;
1323 }
1324 if (vap->va_mtime.tv_sec != VNOVAL) {
1325 ip->ino_rec.ino_mtime =
1326 hammer_timespec_to_transid(&vap->va_mtime);
1327 modflags |= HAMMER_INODE_ITIMES;
1328 }
1329 if (vap->va_mode != (mode_t)VNOVAL) {
1330 if (ip->ino_data.mode != vap->va_mode) {
1331 ip->ino_data.mode = vap->va_mode;
1332 modflags |= HAMMER_INODE_DDIRTY;
1333 }
1334 }
1335done:
1336 if (error) {
1337 hammer_abort_transaction(&trans);
1338 } else {
c0ade690 1339 hammer_modify_inode(&trans, ip, modflags);
8cd0a023
MD
1340 hammer_commit_transaction(&trans);
1341 }
1342 return (error);
427e5fc6
MD
1343}
1344
66325755
MD
1345/*
1346 * hammer_vop_nsymlink { nch, dvp, vpp, cred, vap, target }
1347 */
427e5fc6
MD
1348static
1349int
66325755 1350hammer_vop_nsymlink(struct vop_nsymlink_args *ap)
427e5fc6 1351{
7a04d74f
MD
1352 struct hammer_transaction trans;
1353 struct hammer_inode *dip;
1354 struct hammer_inode *nip;
1355 struct nchandle *nch;
1356 hammer_record_t record;
1357 int error;
1358 int bytes;
1359
1360 ap->a_vap->va_type = VLNK;
1361
1362 nch = ap->a_nch;
1363 dip = VTOI(ap->a_dvp);
1364
d113fda1
MD
1365 if (dip->flags & HAMMER_INODE_RO)
1366 return (EROFS);
1367
7a04d74f
MD
1368 /*
1369 * Create a transaction to cover the operations we perform.
1370 */
1371 hammer_start_transaction(&trans, dip->hmp);
1372
1373 /*
1374 * Create a new filesystem object of the requested type. The
1375 * returned inode will be referenced but not locked.
1376 */
1377
1378 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
1379 if (error) {
1380 hammer_abort_transaction(&trans);
1381 *ap->a_vpp = NULL;
1382 return (error);
1383 }
1384
1385 /*
1386 * Add the new filesystem object to the directory. This will also
1387 * bump the inode's link count.
1388 */
1389 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
1390
1391 /*
1392 * Add a record representing the symlink. symlink stores the link
1393 * as pure data, not a string, and is no \0 terminated.
1394 */
1395 if (error == 0) {
1396 record = hammer_alloc_mem_record(nip);
1397 bytes = strlen(ap->a_target);
1398
1399 record->rec.generic.base.base.key = HAMMER_FIXKEY_SYMLINK;
1400 record->rec.generic.base.base.rec_type = HAMMER_RECTYPE_FIX;
1401 record->rec.generic.base.data_len = bytes;
1402 if (bytes <= sizeof(record->rec.generic.filler)) {
1403 record->data = (void *)record->rec.generic.filler;
1404 bcopy(ap->a_target, record->data, bytes);
1405 } else {
1406 record->data = (void *)ap->a_target;
1407 /* will be reallocated by routine below */
1408 }
1409 error = hammer_ip_add_record(&trans, record);
1410 }
1411
1412 /*
1413 * Finish up.
1414 */
1415 if (error) {
1416 hammer_rel_inode(nip, 0);
1417 hammer_abort_transaction(&trans);
1418 *ap->a_vpp = NULL;
1419 } else {
1420 hammer_commit_transaction(&trans);
1421 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
1422 hammer_rel_inode(nip, 0);
1423 if (error == 0) {
1424 cache_setunresolved(ap->a_nch);
1425 cache_setvp(ap->a_nch, *ap->a_vpp);
1426 }
1427 }
1428 return (error);
427e5fc6
MD
1429}
1430
66325755
MD
1431/*
1432 * hammer_vop_nwhiteout { nch, dvp, cred, flags }
1433 */
427e5fc6
MD
1434static
1435int
66325755 1436hammer_vop_nwhiteout(struct vop_nwhiteout_args *ap)
427e5fc6 1437{
8cd0a023 1438 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, ap->a_flags));
427e5fc6
MD
1439}
1440
66325755
MD
1441/*
1442 * hammer_vop_strategy { vp, bio }
8cd0a023
MD
1443 *
1444 * Strategy call, used for regular file read & write only. Note that the
1445 * bp may represent a cluster.
1446 *
1447 * To simplify operation and allow better optimizations in the future,
1448 * this code does not make any assumptions with regards to buffer alignment
1449 * or size.
66325755 1450 */
427e5fc6
MD
1451static
1452int
66325755 1453hammer_vop_strategy(struct vop_strategy_args *ap)
427e5fc6 1454{
8cd0a023
MD
1455 struct buf *bp;
1456 int error;
1457
1458 bp = ap->a_bio->bio_buf;
1459
1460 switch(bp->b_cmd) {
1461 case BUF_CMD_READ:
1462 error = hammer_vop_strategy_read(ap);
1463 break;
1464 case BUF_CMD_WRITE:
1465 error = hammer_vop_strategy_write(ap);
1466 break;
1467 default:
1468 error = EINVAL;
1469 break;
1470 }
1471 bp->b_error = error;
1472 if (error)
1473 bp->b_flags |= B_ERROR;
1474 biodone(ap->a_bio);
1475 return (error);
427e5fc6
MD
1476}
1477
8cd0a023
MD
1478/*
1479 * Read from a regular file. Iterate the related records and fill in the
1480 * BIO/BUF. Gaps are zero-filled.
1481 *
1482 * The support code in hammer_object.c should be used to deal with mixed
1483 * in-memory and on-disk records.
1484 *
1485 * XXX atime update
1486 */
1487static
1488int
1489hammer_vop_strategy_read(struct vop_strategy_args *ap)
1490{
1491 struct hammer_inode *ip = ap->a_vp->v_data;
1492 struct hammer_cursor cursor;
1493 hammer_record_ondisk_t rec;
1494 hammer_base_elm_t base;
1495 struct bio *bio;
1496 struct buf *bp;
1497 int64_t rec_offset;
a89aec1b 1498 int64_t ran_end;
195c19a1 1499 int64_t tmp64;
8cd0a023
MD
1500 int error;
1501 int boff;
1502 int roff;
1503 int n;
1504
1505 bio = ap->a_bio;
1506 bp = bio->bio_buf;
1507
61aeeb33 1508 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
8cd0a023
MD
1509
1510 /*
1511 * Key range (begin and end inclusive) to scan. Note that the key's
c0ade690
MD
1512 * stored in the actual records represent BASE+LEN, not BASE. The
1513 * first record containing bio_offset will have a key > bio_offset.
8cd0a023
MD
1514 */
1515 cursor.key_beg.obj_id = ip->obj_id;
d5530d22 1516 cursor.key_beg.create_tid = 0;
8cd0a023 1517 cursor.key_beg.delete_tid = 0;
8cd0a023 1518 cursor.key_beg.obj_type = 0;
c0ade690 1519 cursor.key_beg.key = bio->bio_offset + 1;
d5530d22
MD
1520 cursor.asof = ip->obj_asof;
1521 cursor.flags |= HAMMER_CURSOR_ASOF;
8cd0a023
MD
1522
1523 cursor.key_end = cursor.key_beg;
a89aec1b
MD
1524 if (ip->ino_rec.base.base.obj_type == HAMMER_OBJTYPE_DBFILE) {
1525 cursor.key_beg.rec_type = HAMMER_RECTYPE_DB;
1526 cursor.key_end.rec_type = HAMMER_RECTYPE_DB;
1527 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
1528 } else {
c0ade690 1529 ran_end = bio->bio_offset + bp->b_bufsize;
a89aec1b
MD
1530 cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA;
1531 cursor.key_end.rec_type = HAMMER_RECTYPE_DATA;
195c19a1
MD
1532 tmp64 = ran_end + MAXPHYS + 1; /* work-around GCC-4 bug */
1533 if (tmp64 < ran_end)
a89aec1b
MD
1534 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
1535 else
7f7c1f84 1536 cursor.key_end.key = ran_end + MAXPHYS + 1;
a89aec1b 1537 }
d26d0ae9 1538 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE;
8cd0a023 1539
a89aec1b 1540 error = hammer_ip_first(&cursor, ip);
8cd0a023
MD
1541 boff = 0;
1542
a89aec1b
MD
1543 while (error == 0) {
1544 error = hammer_ip_resolve_data(&cursor);
1545 if (error)
66325755 1546 break;
a89aec1b 1547 rec = cursor.record;
8cd0a023
MD
1548 base = &rec->base.base;
1549
c0ade690 1550 rec_offset = base->key - rec->data.base.data_len;
8cd0a023 1551
66325755 1552 /*
a89aec1b 1553 * Calculate the gap, if any, and zero-fill it.
66325755 1554 */
8cd0a023
MD
1555 n = (int)(rec_offset - (bio->bio_offset + boff));
1556 if (n > 0) {
a89aec1b
MD
1557 if (n > bp->b_bufsize - boff)
1558 n = bp->b_bufsize - boff;
8cd0a023
MD
1559 kprintf("zfill %d bytes\n", n);
1560 bzero((char *)bp->b_data + boff, n);
1561 boff += n;
1562 n = 0;
66325755 1563 }
8cd0a023
MD
1564
1565 /*
1566 * Calculate the data offset in the record and the number
1567 * of bytes we can copy.
a89aec1b
MD
1568 *
1569 * Note there is a degenerate case here where boff may
1570 * already be at bp->b_bufsize.
8cd0a023
MD
1571 */
1572 roff = -n;
1573 n = rec->data.base.data_len - roff;
1574 KKASSERT(n > 0);
1575 if (n > bp->b_bufsize - boff)
1576 n = bp->b_bufsize - boff;
1577 bcopy((char *)cursor.data + roff, (char *)bp->b_data + boff, n);
1578 boff += n;
1579 if (boff == bp->b_bufsize)
66325755 1580 break;
a89aec1b 1581 error = hammer_ip_next(&cursor);
66325755 1582 }
8cd0a023 1583 hammer_done_cursor(&cursor);
66325755
MD
1584
1585 /*
8cd0a023 1586 * There may have been a gap after the last record
66325755 1587 */
8cd0a023
MD
1588 if (error == ENOENT)
1589 error = 0;
1590 if (error == 0 && boff != bp->b_bufsize) {
7f7c1f84 1591 KKASSERT(boff < bp->b_bufsize);
8cd0a023
MD
1592 bzero((char *)bp->b_data + boff, bp->b_bufsize - boff);
1593 /* boff = bp->b_bufsize; */
1594 }
1595 bp->b_resid = 0;
1596 return(error);
1597}
1598
1599/*
1600 * Write to a regular file. Iterate the related records and mark for
1601 * deletion. If existing edge records (left and right side) overlap our
1602 * write they have to be marked deleted and new records created, usually
1603 * referencing a portion of the original data. Then add a record to
1604 * represent the buffer.
1605 *
1606 * The support code in hammer_object.c should be used to deal with mixed
1607 * in-memory and on-disk records.
1608 */
1609static
1610int
1611hammer_vop_strategy_write(struct vop_strategy_args *ap)
1612{
1613 struct hammer_transaction trans;
d26d0ae9 1614 struct hammer_cursor *spike = NULL;
8cd0a023
MD
1615 hammer_inode_t ip;
1616 struct bio *bio;
1617 struct buf *bp;
1618 int error;
1619
1620 bio = ap->a_bio;
1621 bp = bio->bio_buf;
1622 ip = ap->a_vp->v_data;
d113fda1
MD
1623
1624 if (ip->flags & HAMMER_INODE_RO)
1625 return (EROFS);
1626
8cd0a023
MD
1627 hammer_start_transaction(&trans, ip->hmp);
1628
d26d0ae9 1629retry:
8cd0a023
MD
1630 /*
1631 * Delete any records overlapping our range. This function will
d26d0ae9 1632 * (eventually) properly truncate partial overlaps.
8cd0a023 1633 */
a89aec1b
MD
1634 if (ip->ino_rec.base.base.obj_type == HAMMER_OBJTYPE_DBFILE) {
1635 error = hammer_ip_delete_range(&trans, ip, bio->bio_offset,
d26d0ae9 1636 bio->bio_offset, &spike);
a89aec1b
MD
1637 } else {
1638 error = hammer_ip_delete_range(&trans, ip, bio->bio_offset,
d26d0ae9
MD
1639 bio->bio_offset +
1640 bp->b_bufsize - 1,
1641 &spike);
a89aec1b 1642 }
8cd0a023
MD
1643
1644 /*
1645 * Add a single record to cover the write
1646 */
1647 if (error == 0) {
c0ade690 1648 error = hammer_ip_sync_data(&trans, ip, bio->bio_offset,
d26d0ae9
MD
1649 bp->b_data, bp->b_bufsize,
1650 &spike);
1651 }
1652
1653 /*
1654 * If we ran out of space the spike structure will be filled in
1655 * and we must call hammer_spike with it, then retry.
1656 */
1657 if (error == ENOSPC) {
1658 error = hammer_spike(&spike);
1659 if (error == 0)
1660 goto retry;
66325755 1661 }
d26d0ae9 1662 KKASSERT(spike == NULL);
66325755
MD
1663
1664 /*
8cd0a023 1665 * If an error occured abort the transaction
66325755 1666 */
8cd0a023
MD
1667 if (error) {
1668 /* XXX undo deletion */
1669 hammer_abort_transaction(&trans);
1670 bp->b_resid = bp->b_bufsize;
1671 } else {
1672 hammer_commit_transaction(&trans);
1673 bp->b_resid = 0;
1674 }
1675 return(error);
1676}
1677
1678/*
1679 * dounlink - disconnect a directory entry
1680 *
1681 * XXX whiteout support not really in yet
1682 */
1683static int
1684hammer_dounlink(struct nchandle *nch, struct vnode *dvp, struct ucred *cred,
1685 int flags)
1686{
1687 struct hammer_transaction trans;
1688 struct namecache *ncp;
1689 hammer_inode_t dip;
1690 hammer_inode_t ip;
1691 hammer_record_ondisk_t rec;
1692 struct hammer_cursor cursor;
8cd0a023
MD
1693 int64_t namekey;
1694 int error;
1695
1696 /*
1697 * Calculate the namekey and setup the key range for the scan. This
1698 * works kinda like a chained hash table where the lower 32 bits
1699 * of the namekey synthesize the chain.
1700 *
1701 * The key range is inclusive of both key_beg and key_end.
1702 */
1703 dip = VTOI(dvp);
1704 ncp = nch->ncp;
d113fda1
MD
1705
1706 if (dip->flags & HAMMER_INODE_RO)
1707 return (EROFS);
1708
8cd0a023
MD
1709 namekey = hammer_directory_namekey(ncp->nc_name, ncp->nc_nlen);
1710
61aeeb33 1711 hammer_init_cursor_hmp(&cursor, &dip->cache[0], dip->hmp);
8cd0a023
MD
1712 cursor.key_beg.obj_id = dip->obj_id;
1713 cursor.key_beg.key = namekey;
d5530d22 1714 cursor.key_beg.create_tid = 0;
8cd0a023
MD
1715 cursor.key_beg.delete_tid = 0;
1716 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1717 cursor.key_beg.obj_type = 0;
1718
1719 cursor.key_end = cursor.key_beg;
1720 cursor.key_end.key |= 0xFFFFFFFFULL;
d5530d22
MD
1721 cursor.asof = dip->obj_asof;
1722 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
8cd0a023
MD
1723
1724 hammer_start_transaction(&trans, dip->hmp);
1725
1726 /*
1727 * Scan all matching records (the chain), locate the one matching
1728 * the requested path component. info->last_error contains the
1729 * error code on search termination and could be 0, ENOENT, or
1730 * something else.
1731 *
1732 * The hammer_ip_*() functions merge in-memory records with on-disk
1733 * records for the purposes of the search.
1734 */
a89aec1b
MD
1735 error = hammer_ip_first(&cursor, dip);
1736 while (error == 0) {
1737 error = hammer_ip_resolve_data(&cursor);
1738 if (error)
66325755 1739 break;
a89aec1b 1740 rec = cursor.record;
8cd0a023
MD
1741 if (ncp->nc_nlen == rec->entry.base.data_len &&
1742 bcmp(ncp->nc_name, cursor.data, ncp->nc_nlen) == 0) {
66325755
MD
1743 break;
1744 }
a89aec1b 1745 error = hammer_ip_next(&cursor);
66325755 1746 }
8cd0a023
MD
1747
1748 /*
1749 * If all is ok we have to get the inode so we can adjust nlinks.
b3deaf57
MD
1750 *
1751 * If the target is a directory, it must be empty.
8cd0a023 1752 */
66325755 1753 if (error == 0) {
61aeeb33
MD
1754 ip = hammer_get_inode(dip->hmp, &dip->cache[1],
1755 rec->entry.obj_id,
d113fda1 1756 dip->hmp->asof, 0, &error);
fe7678ee 1757 KKASSERT(error != ENOENT);
b3deaf57
MD
1758 if (error == 0 && ip->ino_rec.base.base.obj_type ==
1759 HAMMER_OBJTYPE_DIRECTORY) {
1760 error = hammer_ip_check_directory_empty(&trans, ip);
1761 }
8cd0a023 1762 if (error == 0)
a89aec1b 1763 error = hammer_ip_del_directory(&trans, &cursor, dip, ip);
8cd0a023
MD
1764 if (error == 0) {
1765 cache_setunresolved(nch);
1766 cache_setvp(nch, NULL);
1767 /* XXX locking */
1768 if (ip->vp)
1769 cache_inval_vp(ip->vp, CINV_DESTROY);
1770 }
a89aec1b 1771 hammer_rel_inode(ip, 0);
66325755 1772 }
9c448776
MD
1773
1774 if (error == 0)
1775 hammer_commit_transaction(&trans);
1776 else
1777 hammer_abort_transaction(&trans);
8cd0a023 1778 hammer_done_cursor(&cursor);
66325755 1779 return (error);
66325755
MD
1780}
1781
7a04d74f
MD
1782/************************************************************************
1783 * FIFO AND SPECFS OPS *
1784 ************************************************************************
1785 *
1786 */
1787
1788static int
1789hammer_vop_fifoclose (struct vop_close_args *ap)
1790{
1791 /* XXX update itimes */
1792 return (VOCALL(&fifo_vnode_vops, &ap->a_head));
1793}
1794
1795static int
1796hammer_vop_fiforead (struct vop_read_args *ap)
1797{
1798 int error;
1799
1800 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
1801 /* XXX update access time */
1802 return (error);
1803}
1804
1805static int
1806hammer_vop_fifowrite (struct vop_write_args *ap)
1807{
1808 int error;
1809
1810 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
1811 /* XXX update access time */
1812 return (error);
1813}
1814
1815static int
1816hammer_vop_specclose (struct vop_close_args *ap)
1817{
1818 /* XXX update itimes */
1819 return (VOCALL(&spec_vnode_vops, &ap->a_head));
1820}
1821
1822static int
1823hammer_vop_specread (struct vop_read_args *ap)
1824{
1825 /* XXX update access time */
1826 return (VOCALL(&spec_vnode_vops, &ap->a_head));
1827}
1828
1829static int
1830hammer_vop_specwrite (struct vop_write_args *ap)
1831{
1832 /* XXX update last change time */
1833 return (VOCALL(&spec_vnode_vops, &ap->a_head));
1834}
1835