(void) do_ioctl(p1, p2, _DKIOCCSUNPINEXTENT, (caddr_t)&pin);
}
- while (offset < end)
+ for (; offset < end; offset += filechunk)
{
if (ref->vp->v_type == VREG)
{
if (filechunk > (size_t)(end - offset))
filechunk = (size_t)(end - offset);
error = VNOP_BLOCKMAP(ref->vp, offset, filechunk, &blkno,
- &filechunk, NULL, VNODE_WRITE, NULL);
- if (error) break;
+ &filechunk, NULL, VNODE_WRITE | VNODE_BLOCKMAP_NO_TRACK, NULL);
+ if (error) break;
+ if (-1LL == blkno) continue;
fileblk = blkno * ref->blksize;
}
else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR))
else error = EINVAL;
if (error) break;
- offset += filechunk;
}
return (error);
}
bzero(ref, sizeof(*ref));
p = kernproc;
- ref->ctx = vfs_context_create(vfs_context_kernel());
+ ref->ctx = vfs_context_kernel();
fmode = (create_file) ? (O_CREAT | FWRITE) : FWRITE;
cmode = S_IRUSR | S_IWUSR;
VATTR_SET(&va, va_mode, cmode);
VATTR_SET(&va, va_dataprotect_flags, VA_DP_RAWENCRYPTED);
VATTR_SET(&va, va_dataprotect_class, PROTECTION_CLASS_D);
- if ((error = vn_open_auth(&nd, &fmode, &va))) goto out;
+ if ((error = vn_open_auth(&nd, &fmode, &va))) {
+ kprintf("vn_open_auth(fmode: %d, cmode: %d) failed with error: %d\n", fmode, cmode, error);
+ goto out;
+ }
ref->vp = nd.ni_vp;
if (ref->vp->v_type == VREG)
if (write_file_addr && write_file_len)
{
- if ((error = kern_write_file(ref, write_file_offset, write_file_addr, write_file_len, 0))) goto out;
+ if ((error = kern_write_file(ref, write_file_offset, write_file_addr, write_file_len, IO_SKIP_ENCRYPTION))) {
+ kprintf("kern_write_file() failed with error: %d\n", error);
+ goto out;
+ }
}
VATTR_INIT(&va);
VATTR_WANTED(&va, va_rdev);
VATTR_WANTED(&va, va_fsid);
+ VATTR_WANTED(&va, va_devid);
VATTR_WANTED(&va, va_data_size);
VATTR_WANTED(&va, va_data_alloc);
VATTR_WANTED(&va, va_nlink);
/* Don't dump files with links. */
if (va.va_nlink != 1) goto out;
- device = va.va_fsid;
+ device = (VATTR_IS_SUPPORTED(&va, va_devid)) ? va.va_devid : va.va_fsid;
ref->filelength = va.va_data_size;
p1 = &device;
locked = TRUE;
f_offset = 0;
- while (f_offset < ref->filelength)
+ for (; f_offset < ref->filelength; f_offset += filechunk)
{
if (ref->vp->v_type == VREG)
{
daddr64_t blkno;
error = VNOP_BLOCKMAP(ref->vp, f_offset, filechunk, &blkno,
- &filechunk, NULL, VNODE_WRITE, NULL);
+ &filechunk, NULL, VNODE_WRITE | VNODE_BLOCKMAP_NO_TRACK, NULL);
if (error) goto out;
-
+ if (-1LL == blkno) continue;
fileblk = blkno * ref->blksize;
}
else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR))
#endif
physoffset += getphysreq.length;
}
- f_offset += filechunk;
}
callback(callback_ref, 0ULL, 0ULL);
{
vnode_close(ref->vp, FWRITE, ref->ctx);
ref->vp = NULLVP;
- vfs_context_rele(ref->ctx);
ref->ctx = NULL;
}
out:
- printf("kern_open_file_for_direct_io(%d)\n", error);
+ printf("kern_open_file_for_direct_io(%p, %d)\n", ref, error);
+
if (error && locked)
{
vnode_close(ref->vp, FWRITE, ref->ctx);
ref->vp = NULLVP;
}
- vfs_context_rele(ref->ctx);
+ ref->ctx = NULL;
kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
ref = NULL;
}
off_t discard_offset, off_t discard_end)
{
int error;
- kprintf("kern_close_file_for_direct_io\n");
+ printf("kern_close_file_for_direct_io(%p)\n", ref);
if (!ref) return;
if (addr && write_length)
{
- (void) kern_write_file(ref, write_offset, addr, write_length, 0);
+ (void) kern_write_file(ref, write_offset, addr, write_length, IO_SKIP_ENCRYPTION);
}
error = vnode_close(ref->vp, FWRITE, ref->ctx);
ref->vp = NULLVP;
kprintf("vnode_close(%d)\n", error);
+
}
- if (ref->ctx)
- {
- vfs_context_rele(ref->ctx);
- ref->ctx = NULL;
- }
+
+ ref->ctx = NULL;
+
kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
}