2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
34 * $DragonFly: src/sys/vfs/hammer/hammer_vnops.c,v 1.25 2008/02/04 08:33:17 dillon Exp $
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>
46 #include <sys/dirent.h>
47 #include <vm/vm_extern.h>
48 #include <vfs/fifofs/fifo.h>
54 /*static int hammer_vop_vnoperate(struct vop_generic_args *);*/
55 static int hammer_vop_fsync(struct vop_fsync_args *);
56 static int hammer_vop_read(struct vop_read_args *);
57 static int hammer_vop_write(struct vop_write_args *);
58 static int hammer_vop_access(struct vop_access_args *);
59 static int hammer_vop_advlock(struct vop_advlock_args *);
60 static int hammer_vop_close(struct vop_close_args *);
61 static int hammer_vop_ncreate(struct vop_ncreate_args *);
62 static int hammer_vop_getattr(struct vop_getattr_args *);
63 static int hammer_vop_nresolve(struct vop_nresolve_args *);
64 static int hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *);
65 static int hammer_vop_nlink(struct vop_nlink_args *);
66 static int hammer_vop_nmkdir(struct vop_nmkdir_args *);
67 static int hammer_vop_nmknod(struct vop_nmknod_args *);
68 static int hammer_vop_open(struct vop_open_args *);
69 static int hammer_vop_pathconf(struct vop_pathconf_args *);
70 static int hammer_vop_print(struct vop_print_args *);
71 static int hammer_vop_readdir(struct vop_readdir_args *);
72 static int hammer_vop_readlink(struct vop_readlink_args *);
73 static int hammer_vop_nremove(struct vop_nremove_args *);
74 static int hammer_vop_nrename(struct vop_nrename_args *);
75 static int hammer_vop_nrmdir(struct vop_nrmdir_args *);
76 static int hammer_vop_setattr(struct vop_setattr_args *);
77 static int hammer_vop_strategy(struct vop_strategy_args *);
78 static int hammer_vop_nsymlink(struct vop_nsymlink_args *);
79 static int hammer_vop_nwhiteout(struct vop_nwhiteout_args *);
80 static int hammer_vop_ioctl(struct vop_ioctl_args *);
82 static int hammer_vop_fifoclose (struct vop_close_args *);
83 static int hammer_vop_fiforead (struct vop_read_args *);
84 static int hammer_vop_fifowrite (struct vop_write_args *);
86 static int hammer_vop_specclose (struct vop_close_args *);
87 static int hammer_vop_specread (struct vop_read_args *);
88 static int hammer_vop_specwrite (struct vop_write_args *);
90 struct vop_ops hammer_vnode_vops = {
91 .vop_default = vop_defaultop,
92 .vop_fsync = hammer_vop_fsync,
93 .vop_getpages = vop_stdgetpages,
94 .vop_putpages = vop_stdputpages,
95 .vop_read = hammer_vop_read,
96 .vop_write = hammer_vop_write,
97 .vop_access = hammer_vop_access,
98 .vop_advlock = hammer_vop_advlock,
99 .vop_close = hammer_vop_close,
100 .vop_ncreate = hammer_vop_ncreate,
101 .vop_getattr = hammer_vop_getattr,
102 .vop_inactive = hammer_vop_inactive,
103 .vop_reclaim = hammer_vop_reclaim,
104 .vop_nresolve = hammer_vop_nresolve,
105 .vop_nlookupdotdot = hammer_vop_nlookupdotdot,
106 .vop_nlink = hammer_vop_nlink,
107 .vop_nmkdir = hammer_vop_nmkdir,
108 .vop_nmknod = hammer_vop_nmknod,
109 .vop_open = hammer_vop_open,
110 .vop_pathconf = hammer_vop_pathconf,
111 .vop_print = hammer_vop_print,
112 .vop_readdir = hammer_vop_readdir,
113 .vop_readlink = hammer_vop_readlink,
114 .vop_nremove = hammer_vop_nremove,
115 .vop_nrename = hammer_vop_nrename,
116 .vop_nrmdir = hammer_vop_nrmdir,
117 .vop_setattr = hammer_vop_setattr,
118 .vop_strategy = hammer_vop_strategy,
119 .vop_nsymlink = hammer_vop_nsymlink,
120 .vop_nwhiteout = hammer_vop_nwhiteout,
121 .vop_ioctl = hammer_vop_ioctl
124 struct vop_ops hammer_spec_vops = {
125 .vop_default = spec_vnoperate,
126 .vop_fsync = hammer_vop_fsync,
127 .vop_read = hammer_vop_specread,
128 .vop_write = hammer_vop_specwrite,
129 .vop_access = hammer_vop_access,
130 .vop_close = hammer_vop_specclose,
131 .vop_getattr = hammer_vop_getattr,
132 .vop_inactive = hammer_vop_inactive,
133 .vop_reclaim = hammer_vop_reclaim,
134 .vop_setattr = hammer_vop_setattr
137 struct vop_ops hammer_fifo_vops = {
138 .vop_default = fifo_vnoperate,
139 .vop_fsync = hammer_vop_fsync,
140 .vop_read = hammer_vop_fiforead,
141 .vop_write = hammer_vop_fifowrite,
142 .vop_access = hammer_vop_access,
143 .vop_close = hammer_vop_fifoclose,
144 .vop_getattr = hammer_vop_getattr,
145 .vop_inactive = hammer_vop_inactive,
146 .vop_reclaim = hammer_vop_reclaim,
147 .vop_setattr = hammer_vop_setattr
150 static int hammer_dounlink(struct nchandle *nch, struct vnode *dvp,
151 struct ucred *cred, int flags);
152 static int hammer_vop_strategy_read(struct vop_strategy_args *ap);
153 static int hammer_vop_strategy_write(struct vop_strategy_args *ap);
158 hammer_vop_vnoperate(struct vop_generic_args *)
160 return (VOCALL(&hammer_vnode_vops, ap));
165 * hammer_vop_fsync { vp, waitfor }
169 hammer_vop_fsync(struct vop_fsync_args *ap)
175 error = hammer_sync_inode(ip, ap->a_waitfor, 0);
180 * hammer_vop_read { vp, uio, ioflag, cred }
184 hammer_vop_read(struct vop_read_args *ap)
186 struct hammer_transaction trans;
195 if (ap->a_vp->v_type != VREG)
199 seqcount = ap->a_ioflag >> 16;
201 hammer_start_transaction(&trans, ip->hmp);
204 * Access the data in HAMMER_BUFSIZE blocks via the buffer cache.
207 while (uio->uio_resid > 0 && uio->uio_offset < ip->ino_rec.ino_size) {
208 offset = uio->uio_offset & HAMMER_BUFMASK;
210 error = cluster_read(ap->a_vp, ip->ino_rec.ino_size,
211 uio->uio_offset - offset, HAMMER_BUFSIZE,
212 MAXBSIZE, seqcount, &bp);
214 error = bread(ap->a_vp, uio->uio_offset - offset,
215 HAMMER_BUFSIZE, &bp);
220 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
221 n = HAMMER_BUFSIZE - offset;
222 if (n > uio->uio_resid)
224 if (n > ip->ino_rec.ino_size - uio->uio_offset)
225 n = (int)(ip->ino_rec.ino_size - uio->uio_offset);
226 error = uiomove((char *)bp->b_data + offset, n, uio);
231 if ((ip->flags & HAMMER_INODE_RO) == 0) {
232 ip->ino_rec.ino_atime = trans.tid;
233 hammer_modify_inode(&trans, ip, HAMMER_INODE_ITIMES);
237 hammer_commit_transaction(&trans);
242 * hammer_vop_write { vp, uio, ioflag, cred }
246 hammer_vop_write(struct vop_write_args *ap)
248 struct hammer_transaction trans;
249 struct hammer_inode *ip;
257 if (ap->a_vp->v_type != VREG)
262 if (ip->flags & HAMMER_INODE_RO)
266 * Create a transaction to cover the operations we perform.
268 hammer_start_transaction(&trans, ip->hmp);
274 if (ap->a_ioflag & IO_APPEND)
275 uio->uio_offset = ip->ino_rec.ino_size;
278 * Check for illegal write offsets. Valid range is 0...2^63-1
280 if (uio->uio_offset < 0 || uio->uio_offset + uio->uio_resid <= 0) {
281 hammer_commit_transaction(&trans);
286 * Access the data in HAMMER_BUFSIZE blocks via the buffer cache.
288 while (uio->uio_resid > 0) {
291 offset = uio->uio_offset & HAMMER_BUFMASK;
292 n = HAMMER_BUFSIZE - offset;
293 if (n > uio->uio_resid)
295 if (uio->uio_offset + n > ip->ino_rec.ino_size) {
296 vnode_pager_setsize(ap->a_vp, uio->uio_offset + n);
300 if (uio->uio_segflg == UIO_NOCOPY) {
302 * Issuing a write with the same data backing the
303 * buffer. Instantiate the buffer to collect the
304 * backing vm pages, then read-in any missing bits.
306 * This case is used by vop_stdputpages().
308 bp = getblk(ap->a_vp, uio->uio_offset - offset,
309 HAMMER_BUFSIZE, GETBLK_BHEAVY, 0);
310 if ((bp->b_flags & B_CACHE) == 0) {
312 error = bread(ap->a_vp,
313 uio->uio_offset - offset,
314 HAMMER_BUFSIZE, &bp);
316 } else if (offset == 0 && uio->uio_resid >= HAMMER_BUFSIZE) {
318 * entirely overwrite the buffer
320 bp = getblk(ap->a_vp, uio->uio_offset - offset,
321 HAMMER_BUFSIZE, GETBLK_BHEAVY, 0);
322 } else if (offset == 0 && uio->uio_offset >= ip->ino_rec.ino_size) {
326 bp = getblk(ap->a_vp, uio->uio_offset - offset,
327 HAMMER_BUFSIZE, GETBLK_BHEAVY, 0);
331 * Partial overwrite, read in any missing bits then
332 * replace the portion being written.
334 error = bread(ap->a_vp, uio->uio_offset - offset,
335 HAMMER_BUFSIZE, &bp);
340 error = uiomove((char *)bp->b_data + offset, n, uio);
343 * If we screwed up we have to undo any VM size changes we
349 vtruncbuf(ap->a_vp, ip->ino_rec.ino_size,
354 /* bp->b_flags |= B_CLUSTEROK; temporarily disabled */
355 if (ip->ino_rec.ino_size < uio->uio_offset) {
356 ip->ino_rec.ino_size = uio->uio_offset;
357 flags = HAMMER_INODE_RDIRTY;
358 vnode_pager_setsize(ap->a_vp, ip->ino_rec.ino_size);
362 ip->ino_rec.ino_mtime = trans.tid;
363 flags |= HAMMER_INODE_ITIMES | HAMMER_INODE_BUFS;
364 hammer_modify_inode(&trans, ip, flags);
365 if (ap->a_ioflag & IO_SYNC) {
367 } else if (ap->a_ioflag & IO_DIRECT) {
374 hammer_abort_transaction(&trans);
376 hammer_commit_transaction(&trans);
381 * hammer_vop_access { vp, mode, cred }
385 hammer_vop_access(struct vop_access_args *ap)
387 struct hammer_inode *ip = VTOI(ap->a_vp);
392 uid = hammer_to_unix_xid(&ip->ino_data.uid);
393 gid = hammer_to_unix_xid(&ip->ino_data.gid);
395 error = vop_helper_access(ap, uid, gid, ip->ino_data.mode,
396 ip->ino_data.uflags);
401 * hammer_vop_advlock { vp, id, op, fl, flags }
405 hammer_vop_advlock(struct vop_advlock_args *ap)
407 struct hammer_inode *ip = VTOI(ap->a_vp);
409 return (lf_advlock(ap, &ip->advlock, ip->ino_rec.ino_size));
413 * hammer_vop_close { vp, fflag }
417 hammer_vop_close(struct vop_close_args *ap)
419 return (vop_stdclose(ap));
423 * hammer_vop_ncreate { nch, dvp, vpp, cred, vap }
425 * The operating system has already ensured that the directory entry
426 * does not exist and done all appropriate namespace locking.
430 hammer_vop_ncreate(struct vop_ncreate_args *ap)
432 struct hammer_transaction trans;
433 struct hammer_inode *dip;
434 struct hammer_inode *nip;
435 struct nchandle *nch;
439 dip = VTOI(ap->a_dvp);
441 if (dip->flags & HAMMER_INODE_RO)
445 * Create a transaction to cover the operations we perform.
447 hammer_start_transaction(&trans, dip->hmp);
450 * Create a new filesystem object of the requested type. The
451 * returned inode will be referenced but not locked.
454 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
456 kprintf("hammer_create_inode error %d\n", error);
458 hammer_abort_transaction(&trans);
464 * Add the new filesystem object to the directory. This will also
465 * bump the inode's link count.
467 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
469 kprintf("hammer_ip_add_directory error %d\n", error);
475 hammer_rel_inode(nip, 0);
476 hammer_abort_transaction(&trans);
479 hammer_commit_transaction(&trans);
480 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
481 hammer_rel_inode(nip, 0);
483 cache_setunresolved(ap->a_nch);
484 cache_setvp(ap->a_nch, *ap->a_vpp);
491 * hammer_vop_getattr { vp, vap }
495 hammer_vop_getattr(struct vop_getattr_args *ap)
497 struct hammer_inode *ip = VTOI(ap->a_vp);
498 struct vattr *vap = ap->a_vap;
501 if (cache_check_fsmid_vp(ap->a_vp, &ip->fsmid) &&
502 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0 &&
507 hammer_itimes(ap->a_vp);
510 vap->va_fsid = ip->hmp->fsid_udev;
511 vap->va_fileid = ip->ino_rec.base.base.obj_id;
512 vap->va_mode = ip->ino_data.mode;
513 vap->va_nlink = ip->ino_rec.ino_nlinks;
514 vap->va_uid = hammer_to_unix_xid(&ip->ino_data.uid);
515 vap->va_gid = hammer_to_unix_xid(&ip->ino_data.gid);
518 vap->va_size = ip->ino_rec.ino_size;
519 hammer_to_timespec(ip->ino_rec.ino_atime, &vap->va_atime);
520 hammer_to_timespec(ip->ino_rec.ino_mtime, &vap->va_mtime);
521 hammer_to_timespec(ip->ino_data.ctime, &vap->va_ctime);
522 vap->va_flags = ip->ino_data.uflags;
523 vap->va_gen = 1; /* hammer inums are unique for all time */
524 vap->va_blocksize = 32768; /* XXX - extract from root volume */
525 vap->va_bytes = ip->ino_rec.ino_size;
526 vap->va_type = hammer_get_vnode_type(ip->ino_rec.base.base.obj_type);
527 vap->va_filerev = 0; /* XXX */
528 /* mtime uniquely identifies any adjustments made to the file */
529 vap->va_fsmid = ip->ino_rec.ino_mtime;
530 vap->va_uid_uuid = ip->ino_data.uid;
531 vap->va_gid_uuid = ip->ino_data.gid;
532 vap->va_fsid_uuid = ip->hmp->fsid;
533 vap->va_vaflags = VA_UID_UUID_VALID | VA_GID_UUID_VALID |
536 switch (ip->ino_rec.base.base.obj_type) {
537 case HAMMER_OBJTYPE_CDEV:
538 case HAMMER_OBJTYPE_BDEV:
539 vap->va_rmajor = ip->ino_data.rmajor;
540 vap->va_rminor = ip->ino_data.rminor;
550 * hammer_vop_nresolve { nch, dvp, cred }
552 * Locate the requested directory entry.
556 hammer_vop_nresolve(struct vop_nresolve_args *ap)
558 struct namecache *ncp;
562 struct hammer_cursor cursor;
563 union hammer_record_ondisk *rec;
573 * Misc initialization, plus handle as-of name extensions. Look for
574 * the '@@' extension. Note that as-of files and directories cannot
577 dip = VTOI(ap->a_dvp);
578 ncp = ap->a_nch->ncp;
579 asof = dip->obj_asof;
583 for (i = 0; i < nlen; ++i) {
584 if (ncp->nc_name[i] == '@' && ncp->nc_name[i+1] == '@') {
585 asof = hammer_str_to_tid(ncp->nc_name + i + 2);
586 flags |= HAMMER_INODE_RO;
593 * If there is no path component the time extension is relative to
597 ip = hammer_get_inode(dip->hmp, &dip->cache[1], dip->obj_id,
598 asof, flags, &error);
600 error = hammer_get_vnode(ip, LK_EXCLUSIVE, &vp);
601 hammer_rel_inode(ip, 0);
607 cache_setvp(ap->a_nch, vp);
614 * Calculate the namekey and setup the key range for the scan. This
615 * works kinda like a chained hash table where the lower 32 bits
616 * of the namekey synthesize the chain.
618 * The key range is inclusive of both key_beg and key_end.
620 namekey = hammer_directory_namekey(ncp->nc_name, nlen);
622 error = hammer_init_cursor_hmp(&cursor, &dip->cache[0], dip->hmp);
623 cursor.key_beg.obj_id = dip->obj_id;
624 cursor.key_beg.key = namekey;
625 cursor.key_beg.create_tid = 0;
626 cursor.key_beg.delete_tid = 0;
627 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
628 cursor.key_beg.obj_type = 0;
630 cursor.key_end = cursor.key_beg;
631 cursor.key_end.key |= 0xFFFFFFFFULL;
633 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
636 * Scan all matching records (the chain), locate the one matching
637 * the requested path component.
639 * The hammer_ip_*() functions merge in-memory records with on-disk
640 * records for the purposes of the search.
643 error = hammer_ip_first(&cursor, dip);
649 error = hammer_ip_resolve_data(&cursor);
653 if (nlen == rec->entry.base.data_len &&
654 bcmp(ncp->nc_name, cursor.data, nlen) == 0) {
655 obj_id = rec->entry.obj_id;
658 error = hammer_ip_next(&cursor);
660 hammer_done_cursor(&cursor);
662 ip = hammer_get_inode(dip->hmp, &dip->cache[1],
663 obj_id, asof, flags, &error);
665 error = hammer_get_vnode(ip, LK_EXCLUSIVE, &vp);
666 hammer_rel_inode(ip, 0);
672 cache_setvp(ap->a_nch, vp);
675 } else if (error == ENOENT) {
676 cache_setvp(ap->a_nch, NULL);
682 * hammer_vop_nlookupdotdot { dvp, vpp, cred }
684 * Locate the parent directory of a directory vnode.
686 * dvp is referenced but not locked. *vpp must be returned referenced and
687 * locked. A parent_obj_id of 0 does not necessarily indicate that we are
688 * at the root, instead it could indicate that the directory we were in was
693 hammer_vop_nlookupdotdot(struct vop_nlookupdotdot_args *ap)
695 struct hammer_inode *dip;
696 struct hammer_inode *ip;
697 u_int64_t parent_obj_id;
700 dip = VTOI(ap->a_dvp);
701 if ((parent_obj_id = dip->ino_data.parent_obj_id) == 0) {
706 ip = hammer_get_inode(dip->hmp, &dip->cache[1], parent_obj_id,
707 dip->obj_asof, dip->flags, &error);
712 error = hammer_get_vnode(ip, LK_EXCLUSIVE, ap->a_vpp);
713 hammer_rel_inode(ip, 0);
718 * hammer_vop_nlink { nch, dvp, vp, cred }
722 hammer_vop_nlink(struct vop_nlink_args *ap)
724 struct hammer_transaction trans;
725 struct hammer_inode *dip;
726 struct hammer_inode *ip;
727 struct nchandle *nch;
731 dip = VTOI(ap->a_dvp);
734 if (dip->flags & HAMMER_INODE_RO)
736 if (ip->flags & HAMMER_INODE_RO)
740 * Create a transaction to cover the operations we perform.
742 hammer_start_transaction(&trans, dip->hmp);
745 * Add the filesystem object to the directory. Note that neither
746 * dip nor ip are referenced or locked, but their vnodes are
747 * referenced. This function will bump the inode's link count.
749 error = hammer_ip_add_directory(&trans, dip, nch->ncp, ip);
755 hammer_abort_transaction(&trans);
757 cache_setunresolved(nch);
758 cache_setvp(nch, ap->a_vp);
759 hammer_commit_transaction(&trans);
765 * hammer_vop_nmkdir { nch, dvp, vpp, cred, vap }
767 * The operating system has already ensured that the directory entry
768 * does not exist and done all appropriate namespace locking.
772 hammer_vop_nmkdir(struct vop_nmkdir_args *ap)
774 struct hammer_transaction trans;
775 struct hammer_inode *dip;
776 struct hammer_inode *nip;
777 struct nchandle *nch;
781 dip = VTOI(ap->a_dvp);
783 if (dip->flags & HAMMER_INODE_RO)
787 * Create a transaction to cover the operations we perform.
789 hammer_start_transaction(&trans, dip->hmp);
792 * Create a new filesystem object of the requested type. The
793 * returned inode will be referenced but not locked.
795 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
797 kprintf("hammer_mkdir error %d\n", error);
799 hammer_abort_transaction(&trans);
805 * Add the new filesystem object to the directory. This will also
806 * bump the inode's link count.
808 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
810 kprintf("hammer_mkdir (add) error %d\n", error);
816 hammer_rel_inode(nip, 0);
817 hammer_abort_transaction(&trans);
820 hammer_commit_transaction(&trans);
821 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
822 hammer_rel_inode(nip, 0);
824 cache_setunresolved(ap->a_nch);
825 cache_setvp(ap->a_nch, *ap->a_vpp);
832 * hammer_vop_nmknod { nch, dvp, vpp, cred, vap }
834 * The operating system has already ensured that the directory entry
835 * does not exist and done all appropriate namespace locking.
839 hammer_vop_nmknod(struct vop_nmknod_args *ap)
841 struct hammer_transaction trans;
842 struct hammer_inode *dip;
843 struct hammer_inode *nip;
844 struct nchandle *nch;
848 dip = VTOI(ap->a_dvp);
850 if (dip->flags & HAMMER_INODE_RO)
854 * Create a transaction to cover the operations we perform.
856 hammer_start_transaction(&trans, dip->hmp);
859 * Create a new filesystem object of the requested type. The
860 * returned inode will be referenced but not locked.
862 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
864 hammer_abort_transaction(&trans);
870 * Add the new filesystem object to the directory. This will also
871 * bump the inode's link count.
873 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
879 hammer_rel_inode(nip, 0);
880 hammer_abort_transaction(&trans);
883 hammer_commit_transaction(&trans);
884 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
885 hammer_rel_inode(nip, 0);
887 cache_setunresolved(ap->a_nch);
888 cache_setvp(ap->a_nch, *ap->a_vpp);
895 * hammer_vop_open { vp, mode, cred, fp }
899 hammer_vop_open(struct vop_open_args *ap)
901 if ((ap->a_mode & FWRITE) && (VTOI(ap->a_vp)->flags & HAMMER_INODE_RO))
904 return(vop_stdopen(ap));
908 * hammer_vop_pathconf { vp, name, retval }
912 hammer_vop_pathconf(struct vop_pathconf_args *ap)
918 * hammer_vop_print { vp }
922 hammer_vop_print(struct vop_print_args *ap)
928 * hammer_vop_readdir { vp, uio, cred, *eofflag, *ncookies, off_t **cookies }
932 hammer_vop_readdir(struct vop_readdir_args *ap)
934 struct hammer_cursor cursor;
935 struct hammer_inode *ip;
937 hammer_record_ondisk_t rec;
938 hammer_base_elm_t base;
948 saveoff = uio->uio_offset;
950 if (ap->a_ncookies) {
951 ncookies = uio->uio_resid / 16 + 1;
954 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
963 * Handle artificial entries
967 r = vop_write_dirent(&error, uio, ip->obj_id, DT_DIR, 1, ".");
971 cookies[cookie_index] = saveoff;
974 if (cookie_index == ncookies)
978 if (ip->ino_data.parent_obj_id) {
979 r = vop_write_dirent(&error, uio,
980 ip->ino_data.parent_obj_id,
983 r = vop_write_dirent(&error, uio,
984 ip->obj_id, DT_DIR, 2, "..");
989 cookies[cookie_index] = saveoff;
992 if (cookie_index == ncookies)
997 * Key range (begin and end inclusive) to scan. Directory keys
998 * directly translate to a 64 bit 'seek' position.
1000 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
1001 cursor.key_beg.obj_id = ip->obj_id;
1002 cursor.key_beg.create_tid = 0;
1003 cursor.key_beg.delete_tid = 0;
1004 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1005 cursor.key_beg.obj_type = 0;
1006 cursor.key_beg.key = saveoff;
1008 cursor.key_end = cursor.key_beg;
1009 cursor.key_end.key = HAMMER_MAX_KEY;
1010 cursor.asof = ip->obj_asof;
1011 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
1013 error = hammer_ip_first(&cursor, ip);
1015 while (error == 0) {
1016 error = hammer_ip_resolve_data(&cursor);
1019 rec = cursor.record;
1020 base = &rec->base.base;
1021 saveoff = base->key;
1023 if (base->obj_id != ip->obj_id)
1024 panic("readdir: bad record at %p", cursor.node);
1026 r = vop_write_dirent(
1027 &error, uio, rec->entry.obj_id,
1028 hammer_get_dtype(rec->entry.base.base.obj_type),
1029 rec->entry.base.data_len,
1030 (void *)cursor.data);
1035 cookies[cookie_index] = base->key;
1037 if (cookie_index == ncookies)
1039 error = hammer_ip_next(&cursor);
1041 hammer_done_cursor(&cursor);
1045 *ap->a_eofflag = (error == ENOENT);
1046 uio->uio_offset = saveoff;
1047 if (error && cookie_index == 0) {
1048 if (error == ENOENT)
1051 kfree(cookies, M_TEMP);
1052 *ap->a_ncookies = 0;
1053 *ap->a_cookies = NULL;
1056 if (error == ENOENT)
1059 *ap->a_ncookies = cookie_index;
1060 *ap->a_cookies = cookies;
1067 * hammer_vop_readlink { vp, uio, cred }
1071 hammer_vop_readlink(struct vop_readlink_args *ap)
1073 struct hammer_cursor cursor;
1074 struct hammer_inode *ip;
1077 ip = VTOI(ap->a_vp);
1078 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
1081 * Key range (begin and end inclusive) to scan. Directory keys
1082 * directly translate to a 64 bit 'seek' position.
1084 cursor.key_beg.obj_id = ip->obj_id;
1085 cursor.key_beg.create_tid = 0;
1086 cursor.key_beg.delete_tid = 0;
1087 cursor.key_beg.rec_type = HAMMER_RECTYPE_FIX;
1088 cursor.key_beg.obj_type = 0;
1089 cursor.key_beg.key = HAMMER_FIXKEY_SYMLINK;
1090 cursor.asof = ip->obj_asof;
1091 cursor.flags |= HAMMER_CURSOR_ASOF;
1093 error = hammer_ip_lookup(&cursor, ip);
1095 error = hammer_ip_resolve_data(&cursor);
1097 error = uiomove((char *)cursor.data,
1098 cursor.record->generic.base.data_len,
1102 hammer_done_cursor(&cursor);
1107 * hammer_vop_nremove { nch, dvp, cred }
1111 hammer_vop_nremove(struct vop_nremove_args *ap)
1113 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, 0));
1117 * hammer_vop_nrename { fnch, tnch, fdvp, tdvp, cred }
1121 hammer_vop_nrename(struct vop_nrename_args *ap)
1123 struct hammer_transaction trans;
1124 struct namecache *fncp;
1125 struct namecache *tncp;
1126 struct hammer_inode *fdip;
1127 struct hammer_inode *tdip;
1128 struct hammer_inode *ip;
1129 struct hammer_cursor cursor;
1130 union hammer_record_ondisk *rec;
1134 fdip = VTOI(ap->a_fdvp);
1135 tdip = VTOI(ap->a_tdvp);
1136 fncp = ap->a_fnch->ncp;
1137 tncp = ap->a_tnch->ncp;
1138 ip = VTOI(fncp->nc_vp);
1139 KKASSERT(ip != NULL);
1141 if (fdip->flags & HAMMER_INODE_RO)
1143 if (tdip->flags & HAMMER_INODE_RO)
1145 if (ip->flags & HAMMER_INODE_RO)
1148 hammer_start_transaction(&trans, fdip->hmp);
1151 * Remove tncp from the target directory and then link ip as
1152 * tncp. XXX pass trans to dounlink
1154 error = hammer_dounlink(ap->a_tnch, ap->a_tdvp, ap->a_cred, 0);
1155 if (error == 0 || error == ENOENT)
1156 error = hammer_ip_add_directory(&trans, tdip, tncp, ip);
1158 goto failed; /* XXX */
1161 * Locate the record in the originating directory and remove it.
1163 * Calculate the namekey and setup the key range for the scan. This
1164 * works kinda like a chained hash table where the lower 32 bits
1165 * of the namekey synthesize the chain.
1167 * The key range is inclusive of both key_beg and key_end.
1169 namekey = hammer_directory_namekey(fncp->nc_name, fncp->nc_nlen);
1171 hammer_init_cursor_hmp(&cursor, &fdip->cache[0], fdip->hmp);
1172 cursor.key_beg.obj_id = fdip->obj_id;
1173 cursor.key_beg.key = namekey;
1174 cursor.key_beg.create_tid = 0;
1175 cursor.key_beg.delete_tid = 0;
1176 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1177 cursor.key_beg.obj_type = 0;
1179 cursor.key_end = cursor.key_beg;
1180 cursor.key_end.key |= 0xFFFFFFFFULL;
1181 cursor.asof = fdip->obj_asof;
1182 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
1185 * Scan all matching records (the chain), locate the one matching
1186 * the requested path component.
1188 * The hammer_ip_*() functions merge in-memory records with on-disk
1189 * records for the purposes of the search.
1191 error = hammer_ip_first(&cursor, fdip);
1192 while (error == 0) {
1193 if (hammer_ip_resolve_data(&cursor) != 0)
1195 rec = cursor.record;
1196 if (fncp->nc_nlen == rec->entry.base.data_len &&
1197 bcmp(fncp->nc_name, cursor.data, fncp->nc_nlen) == 0) {
1200 error = hammer_ip_next(&cursor);
1204 * If all is ok we have to get the inode so we can adjust nlinks.
1206 * WARNING: hammer_ip_del_directory() may have to terminate the
1207 * cursor to avoid a recursion. It's ok to call hammer_done_cursor()
1211 error = hammer_ip_del_directory(&trans, &cursor, fdip, ip);
1212 hammer_done_cursor(&cursor);
1214 cache_rename(ap->a_fnch, ap->a_tnch);
1215 if (error == EDEADLK)
1219 hammer_commit_transaction(&trans);
1221 hammer_abort_transaction(&trans);
1227 * hammer_vop_nrmdir { nch, dvp, cred }
1231 hammer_vop_nrmdir(struct vop_nrmdir_args *ap)
1233 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, 0));
1237 * hammer_vop_setattr { vp, vap, cred }
1241 hammer_vop_setattr(struct vop_setattr_args *ap)
1243 struct hammer_transaction trans;
1244 struct hammer_cursor *spike = NULL;
1246 struct hammer_inode *ip;
1250 int64_t aligned_size;
1255 ip = ap->a_vp->v_data;
1258 if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
1260 if (ip->flags & HAMMER_INODE_RO)
1263 hammer_start_transaction(&trans, ip->hmp);
1266 if (vap->va_flags != VNOVAL) {
1267 flags = ip->ino_data.uflags;
1268 error = vop_helper_setattr_flags(&flags, vap->va_flags,
1269 hammer_to_unix_xid(&ip->ino_data.uid),
1272 if (ip->ino_data.uflags != flags) {
1273 ip->ino_data.uflags = flags;
1274 modflags |= HAMMER_INODE_DDIRTY;
1276 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1283 if (ip->ino_data.uflags & (IMMUTABLE | APPEND)) {
1287 if (vap->va_uid != (uid_t)VNOVAL) {
1288 hammer_guid_to_uuid(&uuid, vap->va_uid);
1289 if (bcmp(&uuid, &ip->ino_data.uid, sizeof(uuid)) != 0) {
1290 ip->ino_data.uid = uuid;
1291 modflags |= HAMMER_INODE_DDIRTY;
1294 if (vap->va_gid != (uid_t)VNOVAL) {
1295 hammer_guid_to_uuid(&uuid, vap->va_gid);
1296 if (bcmp(&uuid, &ip->ino_data.gid, sizeof(uuid)) != 0) {
1297 ip->ino_data.gid = uuid;
1298 modflags |= HAMMER_INODE_DDIRTY;
1301 while (vap->va_size != VNOVAL && ip->ino_rec.ino_size != vap->va_size) {
1302 switch(ap->a_vp->v_type) {
1304 if (vap->va_size == ip->ino_rec.ino_size)
1306 if (vap->va_size < ip->ino_rec.ino_size) {
1307 vtruncbuf(ap->a_vp, vap->va_size,
1311 vnode_pager_setsize(ap->a_vp, vap->va_size);
1314 ip->ino_rec.ino_size = vap->va_size;
1315 modflags |= HAMMER_INODE_RDIRTY;
1316 aligned_size = (vap->va_size + HAMMER_BUFMASK) &
1317 ~(int64_t)HAMMER_BUFMASK;
1320 error = hammer_ip_delete_range(&trans, ip,
1322 0x7FFFFFFFFFFFFFFFLL,
1326 * If truncating we have to clean out a portion of
1327 * the last block on-disk.
1329 if (truncating && error == 0 &&
1330 vap->va_size < aligned_size) {
1334 offset = vap->va_size & HAMMER_BUFMASK;
1335 error = bread(ap->a_vp,
1336 aligned_size - HAMMER_BUFSIZE,
1337 HAMMER_BUFSIZE, &bp);
1339 bzero(bp->b_data + offset,
1340 HAMMER_BUFSIZE - offset);
1348 error = hammer_ip_delete_range(&trans, ip,
1350 0x7FFFFFFFFFFFFFFFLL,
1352 ip->ino_rec.ino_size = vap->va_size;
1353 modflags |= HAMMER_INODE_RDIRTY;
1359 if (error == ENOSPC) {
1360 error = hammer_spike(&spike);
1364 KKASSERT(spike == NULL);
1367 if (vap->va_atime.tv_sec != VNOVAL) {
1368 ip->ino_rec.ino_atime =
1369 hammer_timespec_to_transid(&vap->va_atime);
1370 modflags |= HAMMER_INODE_ITIMES;
1372 if (vap->va_mtime.tv_sec != VNOVAL) {
1373 ip->ino_rec.ino_mtime =
1374 hammer_timespec_to_transid(&vap->va_mtime);
1375 modflags |= HAMMER_INODE_ITIMES;
1377 if (vap->va_mode != (mode_t)VNOVAL) {
1378 if (ip->ino_data.mode != vap->va_mode) {
1379 ip->ino_data.mode = vap->va_mode;
1380 modflags |= HAMMER_INODE_DDIRTY;
1385 hammer_abort_transaction(&trans);
1387 hammer_modify_inode(&trans, ip, modflags);
1388 hammer_commit_transaction(&trans);
1394 * hammer_vop_nsymlink { nch, dvp, vpp, cred, vap, target }
1398 hammer_vop_nsymlink(struct vop_nsymlink_args *ap)
1400 struct hammer_transaction trans;
1401 struct hammer_inode *dip;
1402 struct hammer_inode *nip;
1403 struct nchandle *nch;
1404 hammer_record_t record;
1408 ap->a_vap->va_type = VLNK;
1411 dip = VTOI(ap->a_dvp);
1413 if (dip->flags & HAMMER_INODE_RO)
1417 * Create a transaction to cover the operations we perform.
1419 hammer_start_transaction(&trans, dip->hmp);
1422 * Create a new filesystem object of the requested type. The
1423 * returned inode will be referenced but not locked.
1426 error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip);
1428 hammer_abort_transaction(&trans);
1434 * Add the new filesystem object to the directory. This will also
1435 * bump the inode's link count.
1437 error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip);
1440 * Add a record representing the symlink. symlink stores the link
1441 * as pure data, not a string, and is no \0 terminated.
1444 record = hammer_alloc_mem_record(nip);
1445 bytes = strlen(ap->a_target);
1447 record->rec.generic.base.base.key = HAMMER_FIXKEY_SYMLINK;
1448 record->rec.generic.base.base.rec_type = HAMMER_RECTYPE_FIX;
1449 record->rec.generic.base.data_len = bytes;
1450 if (bytes <= sizeof(record->rec.generic.filler)) {
1451 record->data = (void *)record->rec.generic.filler;
1452 bcopy(ap->a_target, record->data, bytes);
1454 record->data = (void *)ap->a_target;
1455 /* will be reallocated by routine below */
1457 error = hammer_ip_add_record(&trans, record);
1464 hammer_rel_inode(nip, 0);
1465 hammer_abort_transaction(&trans);
1468 hammer_commit_transaction(&trans);
1469 error = hammer_get_vnode(nip, LK_EXCLUSIVE, ap->a_vpp);
1470 hammer_rel_inode(nip, 0);
1472 cache_setunresolved(ap->a_nch);
1473 cache_setvp(ap->a_nch, *ap->a_vpp);
1480 * hammer_vop_nwhiteout { nch, dvp, cred, flags }
1484 hammer_vop_nwhiteout(struct vop_nwhiteout_args *ap)
1486 return(hammer_dounlink(ap->a_nch, ap->a_dvp, ap->a_cred, ap->a_flags));
1490 * hammer_vop_ioctl { vp, command, data, fflag, cred }
1494 hammer_vop_ioctl(struct vop_ioctl_args *ap)
1496 struct hammer_inode *ip = ap->a_vp->v_data;
1498 return(hammer_ioctl(ip, ap->a_command, ap->a_data,
1499 ap->a_fflag, ap->a_cred));
1503 * hammer_vop_strategy { vp, bio }
1505 * Strategy call, used for regular file read & write only. Note that the
1506 * bp may represent a cluster.
1508 * To simplify operation and allow better optimizations in the future,
1509 * this code does not make any assumptions with regards to buffer alignment
1514 hammer_vop_strategy(struct vop_strategy_args *ap)
1519 bp = ap->a_bio->bio_buf;
1523 error = hammer_vop_strategy_read(ap);
1526 error = hammer_vop_strategy_write(ap);
1532 bp->b_error = error;
1534 bp->b_flags |= B_ERROR;
1540 * Read from a regular file. Iterate the related records and fill in the
1541 * BIO/BUF. Gaps are zero-filled.
1543 * The support code in hammer_object.c should be used to deal with mixed
1544 * in-memory and on-disk records.
1550 hammer_vop_strategy_read(struct vop_strategy_args *ap)
1552 struct hammer_inode *ip = ap->a_vp->v_data;
1553 struct hammer_cursor cursor;
1554 hammer_record_ondisk_t rec;
1555 hammer_base_elm_t base;
1569 hammer_init_cursor_hmp(&cursor, &ip->cache[0], ip->hmp);
1572 * Key range (begin and end inclusive) to scan. Note that the key's
1573 * stored in the actual records represent BASE+LEN, not BASE. The
1574 * first record containing bio_offset will have a key > bio_offset.
1576 cursor.key_beg.obj_id = ip->obj_id;
1577 cursor.key_beg.create_tid = 0;
1578 cursor.key_beg.delete_tid = 0;
1579 cursor.key_beg.obj_type = 0;
1580 cursor.key_beg.key = bio->bio_offset + 1;
1581 cursor.asof = ip->obj_asof;
1582 cursor.flags |= HAMMER_CURSOR_ASOF;
1584 cursor.key_end = cursor.key_beg;
1585 if (ip->ino_rec.base.base.obj_type == HAMMER_OBJTYPE_DBFILE) {
1586 cursor.key_beg.rec_type = HAMMER_RECTYPE_DB;
1587 cursor.key_end.rec_type = HAMMER_RECTYPE_DB;
1588 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
1590 ran_end = bio->bio_offset + bp->b_bufsize;
1591 cursor.key_beg.rec_type = HAMMER_RECTYPE_DATA;
1592 cursor.key_end.rec_type = HAMMER_RECTYPE_DATA;
1593 tmp64 = ran_end + MAXPHYS + 1; /* work-around GCC-4 bug */
1594 if (tmp64 < ran_end)
1595 cursor.key_end.key = 0x7FFFFFFFFFFFFFFFLL;
1597 cursor.key_end.key = ran_end + MAXPHYS + 1;
1599 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE;
1601 error = hammer_ip_first(&cursor, ip);
1604 while (error == 0) {
1605 error = hammer_ip_resolve_data(&cursor);
1608 rec = cursor.record;
1609 base = &rec->base.base;
1611 rec_offset = base->key - rec->data.base.data_len;
1614 * Calculate the gap, if any, and zero-fill it.
1616 n = (int)(rec_offset - (bio->bio_offset + boff));
1618 if (n > bp->b_bufsize - boff)
1619 n = bp->b_bufsize - boff;
1620 bzero((char *)bp->b_data + boff, n);
1626 * Calculate the data offset in the record and the number
1627 * of bytes we can copy.
1629 * Note there is a degenerate case here where boff may
1630 * already be at bp->b_bufsize.
1633 n = rec->data.base.data_len - roff;
1635 if (n > bp->b_bufsize - boff)
1636 n = bp->b_bufsize - boff;
1637 bcopy((char *)cursor.data + roff, (char *)bp->b_data + boff, n);
1639 if (boff == bp->b_bufsize)
1641 error = hammer_ip_next(&cursor);
1643 hammer_done_cursor(&cursor);
1646 * There may have been a gap after the last record
1648 if (error == ENOENT)
1650 if (error == 0 && boff != bp->b_bufsize) {
1651 KKASSERT(boff < bp->b_bufsize);
1652 bzero((char *)bp->b_data + boff, bp->b_bufsize - boff);
1653 /* boff = bp->b_bufsize; */
1660 * Write to a regular file. Iterate the related records and mark for
1661 * deletion. If existing edge records (left and right side) overlap our
1662 * write they have to be marked deleted and new records created, usually
1663 * referencing a portion of the original data. Then add a record to
1664 * represent the buffer.
1666 * The support code in hammer_object.c should be used to deal with mixed
1667 * in-memory and on-disk records.
1671 hammer_vop_strategy_write(struct vop_strategy_args *ap)
1673 struct hammer_transaction trans;
1674 struct hammer_cursor *spike = NULL;
1682 ip = ap->a_vp->v_data;
1684 if (ip->flags & HAMMER_INODE_RO)
1687 hammer_start_transaction(&trans, ip->hmp);
1691 * Delete any records overlapping our range. This function will
1692 * (eventually) properly truncate partial overlaps.
1694 if (ip->ino_rec.base.base.obj_type == HAMMER_OBJTYPE_DBFILE) {
1695 error = hammer_ip_delete_range(&trans, ip, bio->bio_offset,
1696 bio->bio_offset, &spike);
1698 error = hammer_ip_delete_range(&trans, ip, bio->bio_offset,
1705 * Add a single record to cover the write
1708 error = hammer_ip_sync_data(&trans, ip, bio->bio_offset,
1709 bp->b_data, bp->b_bufsize,
1714 * If we ran out of space the spike structure will be filled in
1715 * and we must call hammer_spike with it, then retry.
1717 if (error == ENOSPC) {
1718 error = hammer_spike(&spike);
1722 KKASSERT(spike == NULL);
1725 * If an error occured abort the transaction
1728 /* XXX undo deletion */
1729 hammer_abort_transaction(&trans);
1730 bp->b_resid = bp->b_bufsize;
1732 hammer_commit_transaction(&trans);
1739 * dounlink - disconnect a directory entry
1741 * XXX whiteout support not really in yet
1744 hammer_dounlink(struct nchandle *nch, struct vnode *dvp, struct ucred *cred,
1747 struct hammer_transaction trans;
1748 struct namecache *ncp;
1751 hammer_record_ondisk_t rec;
1752 struct hammer_cursor cursor;
1757 * Calculate the namekey and setup the key range for the scan. This
1758 * works kinda like a chained hash table where the lower 32 bits
1759 * of the namekey synthesize the chain.
1761 * The key range is inclusive of both key_beg and key_end.
1766 if (dip->flags & HAMMER_INODE_RO)
1769 hammer_start_transaction(&trans, dip->hmp);
1771 namekey = hammer_directory_namekey(ncp->nc_name, ncp->nc_nlen);
1773 hammer_init_cursor_hmp(&cursor, &dip->cache[0], dip->hmp);
1774 cursor.key_beg.obj_id = dip->obj_id;
1775 cursor.key_beg.key = namekey;
1776 cursor.key_beg.create_tid = 0;
1777 cursor.key_beg.delete_tid = 0;
1778 cursor.key_beg.rec_type = HAMMER_RECTYPE_DIRENTRY;
1779 cursor.key_beg.obj_type = 0;
1781 cursor.key_end = cursor.key_beg;
1782 cursor.key_end.key |= 0xFFFFFFFFULL;
1783 cursor.asof = dip->obj_asof;
1784 cursor.flags |= HAMMER_CURSOR_END_INCLUSIVE | HAMMER_CURSOR_ASOF;
1787 * Scan all matching records (the chain), locate the one matching
1788 * the requested path component. info->last_error contains the
1789 * error code on search termination and could be 0, ENOENT, or
1792 * The hammer_ip_*() functions merge in-memory records with on-disk
1793 * records for the purposes of the search.
1795 error = hammer_ip_first(&cursor, dip);
1796 while (error == 0) {
1797 error = hammer_ip_resolve_data(&cursor);
1800 rec = cursor.record;
1801 if (ncp->nc_nlen == rec->entry.base.data_len &&
1802 bcmp(ncp->nc_name, cursor.data, ncp->nc_nlen) == 0) {
1805 error = hammer_ip_next(&cursor);
1809 * If all is ok we have to get the inode so we can adjust nlinks.
1811 * If the target is a directory, it must be empty.
1814 ip = hammer_get_inode(dip->hmp, &dip->cache[1],
1816 dip->hmp->asof, 0, &error);
1817 if (error == ENOENT) {
1818 kprintf("obj_id %016llx\n", rec->entry.obj_id);
1819 Debugger("ENOENT unlinking object that should exist, cont to sync");
1820 hammer_sync_hmp(dip->hmp, MNT_NOWAIT);
1821 Debugger("ENOENT - sync done");
1823 if (error == 0 && ip->ino_rec.base.base.obj_type ==
1824 HAMMER_OBJTYPE_DIRECTORY) {
1825 error = hammer_ip_check_directory_empty(&trans, ip);
1828 * WARNING: hammer_ip_del_directory() may have to terminate
1829 * the cursor to avoid a lock recursion. It's ok to call
1830 * hammer_done_cursor() twice.
1833 error = hammer_ip_del_directory(&trans, &cursor, dip, ip);
1835 cache_setunresolved(nch);
1836 cache_setvp(nch, NULL);
1839 cache_inval_vp(ip->vp, CINV_DESTROY);
1841 hammer_rel_inode(ip, 0);
1843 hammer_done_cursor(&cursor);
1844 if (error == EDEADLK)
1848 hammer_commit_transaction(&trans);
1850 hammer_abort_transaction(&trans);
1854 /************************************************************************
1855 * FIFO AND SPECFS OPS *
1856 ************************************************************************
1861 hammer_vop_fifoclose (struct vop_close_args *ap)
1863 /* XXX update itimes */
1864 return (VOCALL(&fifo_vnode_vops, &ap->a_head));
1868 hammer_vop_fiforead (struct vop_read_args *ap)
1872 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
1873 /* XXX update access time */
1878 hammer_vop_fifowrite (struct vop_write_args *ap)
1882 error = VOCALL(&fifo_vnode_vops, &ap->a_head);
1883 /* XXX update access time */
1888 hammer_vop_specclose (struct vop_close_args *ap)
1890 /* XXX update itimes */
1891 return (VOCALL(&spec_vnode_vops, &ap->a_head));
1895 hammer_vop_specread (struct vop_read_args *ap)
1897 /* XXX update access time */
1898 return (VOCALL(&spec_vnode_vops, &ap->a_head));
1902 hammer_vop_specwrite (struct vop_write_args *ap)
1904 /* XXX update last change time */
1905 return (VOCALL(&spec_vnode_vops, &ap->a_head));