Lines Matching defs:ref

100 kern_ioctl_file_extents(struct kern_direct_file_io_ref_t * ref, u_long theIoctl, off_t offset, off_t end)
115 if (ref->vp->v_type == VREG)
117 p1 = &ref->device;
124 p1 = ref->vp;
125 p2 = ref->ctx;
130 if (ref->vp->v_type == VREG)
136 error = VNOP_BLOCKMAP(ref->vp, offset, filechunk, &blkno, &filechunk, NULL, 0, NULL);
138 fileblk = blkno * ref->blksize;
140 else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR))
143 filechunk = ref->filelength;
176 kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
192 struct kern_direct_file_io_ref_t * ref;
215 ref = (struct kern_direct_file_io_ref_t *) kalloc(sizeof(struct kern_direct_file_io_ref_t));
216 if (!ref)
222 bzero(ref, sizeof(*ref));
224 ref->ctx = vfs_context_create(vfs_context_current());
226 if ((error = vnode_open(name, (O_CREAT | FWRITE), (0), 0, &ref->vp, ref->ctx)))
231 if ((error = kern_write_file(ref, write_file_offset, write_file_addr, write_file_len)))
241 if (vnode_getattr(ref->vp, &va, ref->ctx))
248 if (ref->vp->v_type == VREG)
255 ref->filelength = va.va_data_size;
265 error = VNOP_ALLOCATE(ref->vp, set_file_size, alloc_flags,
267 ref->ctx);
269 if (!error) error = vnode_setsize(ref->vp, set_file_size, IO_NOZEROFILL, ref->ctx);
271 ref->filelength = bytesallocated;
274 else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR))
279 p1 = ref->vp;
280 p2 = ref->ctx;
289 ref->device = device;
293 error = do_ioctl(p1, p2, DKIOCGETBLOCKSIZE, (caddr_t) &ref->blksize);
297 if (ref->vp->v_type != VREG)
302 ref->filelength = fileblk * ref->blksize;
307 error = kern_ioctl_file_extents(ref, _DKIOCCSPINEXTENT, 0, ref->filelength);
309 ref->pinned = (error == 0);
319 while (f_offset < ref->filelength)
321 if (ref->vp->v_type == VREG)
326 error = VNOP_BLOCKMAP(ref->vp, f_offset, filechunk, &blkno, &filechunk, NULL, 0, NULL);
330 fileblk = blkno * ref->blksize;
332 else if ((ref->vp->v_type == VBLK) || (ref->vp->v_type == VCHR))
335 filechunk = f_offset ? 0 : ref->filelength;
365 if (ref->vp->v_type == VREG)
444 if (error && ref)
446 if (ref->vp)
448 vnode_close(ref->vp, FWRITE, ref->ctx);
449 ref->vp = NULLVP;
451 vfs_context_rele(ref->ctx);
452 kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
453 ref = NULL;
456 return(ref);
460 kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len)
462 return (vn_rdwr(UIO_WRITE, ref->vp,
465 vfs_context_ucred(ref->ctx), (int *) 0,
466 vfs_context_proc(ref->ctx)));
471 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
478 if (!ref) return;
480 if (ref->vp)
486 if (ref->vp->v_type == VREG)
488 p1 = &ref->device;
495 p1 = ref->vp;
496 p2 = ref->ctx;
503 (void) kern_write_file(ref, write_offset, addr, write_length);
505 if (discard_offset && discard_end && !ref->pinned)
507 (void) kern_ioctl_file_extents(ref, DKIOCUNMAP, discard_offset, discard_end);
510 error = vnode_close(ref->vp, FWRITE, ref->ctx);
512 ref->vp = NULLVP;
515 vfs_context_rele(ref->ctx);
516 ref->ctx = NULL;
517 kfree(ref, sizeof(struct kern_direct_file_io_ref_t));