static ssize_t HgfsWrite(struct file *file, // IN: File to write to const char __user *buf, // IN: User buffer where the data is size_t count, // IN: Number of bytes to write loff_t *offset) // IN: Offset to begin writing at { int result; ASSERT(file); ASSERT(file->f_dentry); ASSERT(file->f_dentry->d_inode); ASSERT(buf); ASSERT(offset); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsWrite: write %Zu bytes to fh %u " "at offset %Lu\n", count, FILE_GET_FI_P(file)->handle, *offset)); result = HgfsRevalidate(file->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsWrite: invalid dentry\n")); goto out; } result = generic_file_write(file, buf, count, offset); out: return result; }
static loff_t HgfsSeek(struct file *file, // IN: File to seek loff_t offset, // IN: Number of bytes to seek int origin) // IN: Position to seek from { loff_t result = -1; ASSERT(file); ASSERT(file->f_dentry); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsSeek: seek to %Lu bytes from fh %u " "from position %d\n", offset, FILE_GET_FI_P(file)->handle, origin)); result = (loff_t) HgfsRevalidate(file->f_dentry); if (result) { LOG(6, (KERN_DEBUG "VMware hgfs: HgfsSeek: invalid dentry\n")); goto out; } result = generic_file_llseek(file, offset, origin); out: return result; }
static ssize_t HgfsRead(struct file *file, // IN: File to read from char __user *buf, // OUT: User buffer to copy data into size_t count, // IN: Number of bytes to read loff_t *offset) // IN: Offset at which to read { int result; ASSERT(file); ASSERT(file->f_dentry); ASSERT(buf); ASSERT(offset); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsRead: read %Zu bytes from fh %u " "at offset %Lu\n", count, FILE_GET_FI_P(file)->handle, *offset)); result = HgfsRevalidate(file->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsRead: invalid dentry\n")); goto out; } result = generic_file_read(file, buf, count, offset); out: return result; }
static ssize_t HgfsAioWrite(struct kiocb *iocb, // IN: I/O control block const struct iovec *iov, // IN: Array of I/O buffers unsigned long numSegs, // IN: Number of buffers loff_t offset) // IN: Offset at which to read { int result; ASSERT(iocb); ASSERT(iocb->ki_filp); ASSERT(iocb->ki_filp->f_dentry); ASSERT(iov); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsAioWrite: was called\n")); result = HgfsRevalidate(iocb->ki_filp->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsAioWrite: invalid dentry\n")); goto out; } result = generic_file_aio_write(iocb, iov, numSegs, offset); out: return result; }
static ssize_t HgfsSpliceRead(struct file *file, // IN: File to read from loff_t *offset, // IN/OUT: Where to start reading struct pipe_inode_info *pipe, // IN: Pipe where to write data size_t len, // IN: How much to read unsigned int flags) // IN: Various flags { ssize_t result; ASSERT(file); ASSERT(file->f_dentry); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsSpliceRead: was called\n")); result = HgfsRevalidate(file->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsSpliceRead: invalid dentry\n")); goto out; } result = generic_file_splice_read(file, offset, pipe, len, flags); out: return result; }
static ssize_t HgfsSendfile(struct file *file, // IN: File to read from loff_t *offset, // IN/OUT: Where to start reading size_t count, // IN: How much to read read_actor_t actor, // IN: Routine to send a page of data void *target) // IN: Destination file/socket #endif { ssize_t result; ASSERT(file); ASSERT(file->f_dentry); ASSERT(target); ASSERT(offset); ASSERT(actor); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsSendfile: was called\n")); result = HgfsRevalidate(file->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsSendfile: invalid dentry\n")); goto out; } result = generic_file_sendfile (file, offset, count, actor, target); out: return result; }
static int HgfsDentryRevalidate(struct dentry *dentry, // IN: Dentry to revalidate #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) unsigned int flags // IN: Lookup flags & intent #else struct nameidata *nd // IN: Lookup flags & intent #endif ) { int error; LOG(6, (KERN_DEBUG "VMware hgfs: HgfsDentryRevalidate: calling " "HgfsRevalidate\n")); ASSERT(dentry); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) if (flags & LOOKUP_RCU) { return -ECHILD; } #elif defined(LOOKUP_RCU) /* Introduced in 2.6.38 */ if (nd && (nd->flags & LOOKUP_RCU)) { return -ECHILD; } #endif /* Just call HgfsRevaliate, which does the right thing. */ error = HgfsRevalidate(dentry); if (error) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsDentryRevalidate: invalid\n")); if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) { shrink_dcache_parent(dentry); } d_drop(dentry); return 0; } LOG(6, (KERN_DEBUG "VMware hgfs: HgfsDentryRevalidate: valid\n")); return 1; }
static int HgfsMmap(struct file *file, // IN: File we operate on struct vm_area_struct *vma) // IN/OUT: VM area information { int result; ASSERT(file); ASSERT(vma); ASSERT(file->f_dentry); LOG(6, (KERN_DEBUG "VMware hgfs: HgfsMmap: was called\n")); result = HgfsRevalidate(file->f_dentry); if (result) { LOG(4, (KERN_DEBUG "VMware hgfs: HgfsMmap: invalid dentry\n")); goto out; } result = generic_file_mmap(file, vma); out: return result; }