ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { struct inode *inode = file->f_dentry->d_inode; ssize_t ret; if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; ret = locks_verify_area(FLOCK_VERIFY_READ, inode, file, *pos, count); if (!ret) { ret = security_file_permission (file, MAY_READ); if (!ret) { if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) dnotify_parent(file->f_dentry, DN_ACCESS); } } return ret; }
/* * ext3301 read: wrapper for the standard file read function. * modifications: handling encryption and immediate files. * original: do_sync_read */ ssize_t ext3301_read(struct file * filp, char __user * buf, size_t len, loff_t * ppos) { struct inode * i = FILP_INODE(filp); ssize_t ret = 0; dbg(KERN_DEBUG "Read: '%s'\n", FILP_NAME(filp)); //Check if the file is immediate (requires special read behaviour) if (I_ISIM(i)) { dbg_im(KERN_DEBUG "- Read-immediate\n"); ret = ext3301_read_immediate(filp, buf, len, ppos); } else { dbg_im(KERN_DEBUG "- Read-regular\n"); ret = do_sync_read(filp, buf, len, ppos); } //Check if the file is in the encryption tree if (ext3301_isencrypted(filp->f_path.dentry)) { //Decrypt the data which was read dbg_cr(KERN_DEBUG "- Encrypting data (%d bytes)\n", (int)len); if (ext3301_cryptbuf(buf, len) < 0) return -EIO; } return ret; }
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; struct super_block *sb = file->f_path.dentry->d_sb; if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; ret = rw_verify_area(READ, file, pos, count); if (ret >= 0) { count = ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); } inc_syscr(current); } if (sb && (!strcmp(sb->s_type->name, "ext4") || !strcmp(sb->s_type->name, "fuse") || !strcmp(sb->s_type->name, "vfat"))) print_io_dump(READ, count); return ret; }
/* * COMP3301 Addition * Use the encryption key to change the content of a buffer * then read the buffer to user */ ssize_t read_encrypt (struct file* flip, const char __user* buf, size_t len, loff_t *ppos) { ssize_t result; struct inode *inode = flip->f_dentry->d_inode; mm_segment_t user_filesystem = get_fs(); char* new_buffer = (char *) kmalloc(sizeof(char) * len, GFP_KERNEL); memset(new_buffer, 0, len); set_fs(get_ds()); if (S_IS_IMMEDIATE(inode->i_mode)) { result = do_immediate_read(flip, new_buffer, len, ppos); } else { result = do_sync_read(flip, new_buffer, len, ppos); } set_fs(user_filesystem); if (is_encrypt_folder(flip)) { decrypt(new_buffer, len); } if (copy_to_user(buf, new_buffer, len)) { kfree(new_buffer); return -1; } kfree(new_buffer); return result; }
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; ret = rw_verify_area(READ, file, pos, count); if (ret >= 0) { count = ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); } inc_syscr(current); } return ret; }
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; ret = rw_verify_area(READ, file, pos, count); if (ret >= 0) { count = ret; ret = security_file_permission (file, MAY_READ); if (!ret) { if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) { fsnotify_access(file->f_dentry); current->rchar += ret; } current->syscr++; } } return ret; }
ssize_t testfs_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos) { int ret = 0; printk(KERN_INFO "testfs: testfs_sync_read\n"); ret = do_sync_read(filp, buf, len, ppos); return ret; }
static ssize_t __do_read(struct file *file, char __user *buf, size_t len, loff_t *ppos) { if (file->f_op->read) return file->f_op->read(file, buf, len, ppos); else return do_sync_read(file, buf, len, ppos); }
static ssize_t svfs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { struct file *filp = iocb->ki_filp; struct file *llfs_filp; struct inode *inode = filp->f_dentry->d_inode; struct svfs_inode *si = SVFS_I(inode); char __user *buf = iov->iov_base; size_t count = iov->iov_len; ssize_t ret = 0, br; int seg; if (si->state & SVFS_STATE_DA) { /* create it now */ ASSERT(!(si->state & SVFS_STATE_CONN)); ret = llfs_create(filp->f_dentry); if (ret) goto out; } if (!(si->state & SVFS_STATE_CONN)) { /* open it? */ ret = llfs_lookup(inode); if (ret) goto out; } llfs_filp = si->llfs_md.llfs_filp; llfs_filp->f_pos = pos; if (!(llfs_filp->f_mode & FMODE_READ)) return -EBADF; if (!llfs_filp->f_op || (!llfs_filp->f_op->read && !llfs_filp->f_op->aio_read)) return -EINVAL; for (seg = 0; seg < nr_segs; seg++) { buf = iov[seg].iov_base; count = iov[seg].iov_len; if (llfs_filp->f_op->read) br = llfs_filp->f_op->read(llfs_filp, buf, count, &llfs_filp->f_pos); else br = do_sync_read(llfs_filp, buf, count, &llfs_filp->f_pos); ret += br; svfs_debug(mdc, "buf %p, len %ld: \n", buf, count); } if (ret > 0) fsnotify_access(llfs_filp->f_dentry); iocb->ki_pos += ret; out: return ret; }
ssize_t new_sync_read_crypt(struct file* filp, char __user* buf, size_t len, loff_t *ppos) { int i = 0; //char* mybuf = (char*)kmalloc(sizeof(char) * len, GFP_KERNEL); ssize_t ret = do_sync_read(filp, buf, len, ppos); for(; i < len; i++) buf[i] = (buf[i] - 25 + 128) % 128; // minus 25 //copy_to_user(buf, mybuf, len); printk("haha decrypt %ld\n", len); return ret; }
ssize_t __vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else if (file->f_op->aio_read) ret = do_sync_read(file, buf, count, pos); else if (file->f_op->read_iter) ret = new_sync_read(file, buf, count, pos); else ret = -EINVAL; return ret; }
ssize_t xixfs_file_read( struct file *filp, char __user *buf, size_t count, loff_t *ppos ) { #if LINUX_VERSION_25_ABOVE struct address_space *mapping = filp->f_mapping; #else struct address_space *mapping = filp->f_dentry->d_inode->i_mapping; #endif struct inode *inode = mapping->host; PXIXFS_LINUX_FCB pFCB = NULL; ssize_t ret = 0; XIXCORE_ASSERT(inode); pFCB = XIXFS_I(inode); XIXFS_ASSERT_FCB(pFCB); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_FCB|DEBUG_TARGET_VFSAPIT), ("ENTER xixfs_file_read (%s).\n", filp->f_dentry->d_name.name)); if(XIXCORE_TEST_FLAGS( pFCB->XixcoreFcb.FCBFlags, XIXCORE_FCB_CHANGE_DELETED )){ DebugTrace(DEBUG_LEVEL_ERROR, DEBUG_TARGET_ALL, ("ERROR DELETED FILE \n")); //printk(KERN_DEBUG "xixfs_file_read ERROR\n"); return -EPERM; } //ret = do_sync_read(filp, buf, count, ppos); #if LINUX_VERSION_2_6_19_REPLACE_INTERFACE ret = do_sync_read(filp, buf, count, ppos); #else ret = generic_file_read(filp, buf, count, ppos); #endif //printk(KERN_DEBUG "xixfs_file_read ret (0x%x)\n", ret); return ret; }
ssize_t ecryptfs_sync_read(struct file *filp, char __user *buf, \ size_t len, loff_t *ppos) { ssize_t result; struct file *lower_file = NULL; if (unlikely(filp->f_flags & O_DIRECT)) { lower_file = ecryptfs_file_to_lower(filp); lower_file->f_flags |= O_DIRECT; lower_file->f_pos = filp->f_pos; result = vfs_read(lower_file, buf, len, ppos); filp->f_pos = lower_file->f_pos; return result; } else { return do_sync_read(filp, buf, len, ppos); } }
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; if (infocoll_data.fs == file->f_vfsmnt->mnt_root) { char data[40] = {0}; loff_t offset = pos ? *pos : 0; ulong inode = file->f_dentry->d_inode->i_ino; ulong size = file->f_dentry->d_inode->i_size; infocoll_write_to_buff(data, inode); infocoll_write_to_buff(data + 8, count); infocoll_write_to_buff(data + 16, offset); infocoll_write_to_buff(data + 24, size); infocoll_send(INFOCOLL_READ, data, NLMSG_DONE); } if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; ret = rw_verify_area(READ, file, pos, count); if (ret >= 0) { count = ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); } inc_syscr(current); } return ret; }
/** * ima_kernel_read - read file content * * This is a function for reading file content instead of kernel_read(). * It does not perform locking checks to ensure it cannot be blocked. * It does not perform security checks because it is irrelevant for IMA. * */ static int ima_kernel_read(struct file *file, loff_t offset, char *addr, unsigned long count) { mm_segment_t old_fs; char __user *buf = addr; ssize_t ret = -EINVAL; if (!(file->f_mode & FMODE_READ)) return -EBADF; old_fs = get_fs(); set_fs(get_ds()); if (file->f_op->read) ret = file->f_op->read(file, buf, count, &offset); else if (file->f_op->aio_read) ret = do_sync_read(file, buf, count, &offset); else if (file->f_op->read_iter) ret = new_sync_read(file, buf, count, &offset); set_fs(old_fs); return ret; }
static ssize_t wrapfs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { int err; struct file *lower_file; struct dentry *dentry = file->f_path.dentry; #ifdef WRAPFS_CRYPTO char nokey[KEY_LENGTH]={0,}; #endif lower_file = wrapfs_lower_file(file); #ifdef DEBUG_SUPPORT if(debug_support(lower_file->f_dentry->d_sb,"file")) UDBG; #endif if(WRAPFS_SB(lower_file->f_path.dentry->d_sb)->mount_options.mmap == 1) { #ifdef WRAPFS_CRYPTO if(!strcmp(WRAPFS_SB(lower_file->f_dentry->d_sb)->key,nokey) || no_key_func(WRAPFS_SB(lower_file->f_dentry->d_sb)->key)) { printk("No Key entered. Encrypt operations cannot be done\n"); return -ENOKEY; } #endif err = do_sync_read(file, buf, count, ppos); } else err = vfs_read(lower_file, buf, count, ppos); /* update our inode atime upon a successful lower read */ if (err >= 0) fsstack_copy_attr_atime(dentry->d_inode, lower_file->f_path.dentry->d_inode); #ifdef DEBUG_SUPPORT if(debug_support(lower_file->f_dentry->d_sb,"file")) UDBGE(err); #endif return err; }
static ssize_t wrapfs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { int err; struct file *lower_file; struct dentry *dentry = file->f_path.dentry; #ifdef WRAPFS_CRYPTO char zero_key[KEYLEN + 1]; memset(zero_key, '0', sizeof(zero_key)); zero_key[KEYLEN] = '\0'; #endif /*printk(KERN_ALERT "In wrapfs_read()\n");*/ lower_file = wrapfs_lower_file(file); if (1 == WRAPFS_SB(file->f_dentry->d_sb)->mount_options.mmap) { /*printk(KERN_ALERT "calling do_sync_read()\n");*/ #ifdef WRAPFS_CRYPTO if (0 == memcmp(&(WRAPFS_SB(file->f_dentry->d_sb)->key), &zero_key, KEYLEN)) return -ENOKEY; #endif err = do_sync_read(file, buf, count, ppos); } else { /*printk(KERN_ALERT "calling vfs_read()\n");*/ err = vfs_read(lower_file, buf, count, ppos); } /* update our inode atime upon a successful lower read */ if (err >= 0) fsstack_copy_attr_atime(dentry->d_inode, lower_file->f_path.dentry->d_inode); return err; }
ssize_t dfs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos) { return do_sync_read(filp, buf, len, ppos); }
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) { ssize_t ret; #if IO_LOGGER_ENABLE unsigned long long time1 = 0,timeoffset = 0; bool add_trace_e = false; const char *mount_point = NULL; char path_c[20]={0}; char *path = NULL; struct mount *mount_data; #endif if (!(file->f_mode & FMODE_READ)) return -EBADF; if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) return -EFAULT; #if IO_LOGGER_ENABLE if(unlikely(en_IOLogger())){ mount_data = real_mount(file->f_path.mnt); mount_point = mount_data->mnt_mountpoint->d_name.name; if (mount_point){ if((!memcmp(mount_point,"data",4))||(!memcmp(mount_point,"system",6))) { path = (char *)file->f_path.dentry->d_name.name; if(strlen(path)>=16){ memcpy(path_c,path,16); path = (char *)path_c; } add_trace_e = true; time1 = sched_clock(); AddIOTrace(IO_LOGGER_MSG_VFS_INTFS,vfs_read,path,(u32)count); } } } #endif ret = rw_verify_area(READ, file, pos, count); if (ret >= 0) { count = ret; if (file->f_op->read) ret = file->f_op->read(file, buf, count, pos); else ret = do_sync_read(file, buf, count, pos); if (ret > 0) { fsnotify_access(file); add_rchar(current, ret); } inc_syscr(current); } #if IO_LOGGER_ENABLE if(unlikely(en_IOLogger()) && add_trace_e){ timeoffset = sched_clock() - time1; add_trace_e = false; if(BEYOND_TRACE_LOG_TIME(timeoffset)) { AddIOTrace(IO_LOGGER_MSG_VFS_INTFS_END,vfs_read,path,ret,timeoffset); if(BEYOND_DUMP_LOG_TIME(timeoffset)) DumpIOTrace(timeoffset); } } #endif return ret; }
static ssize_t ccfs_do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos) { ssize_t res; res = do_sync_read(filp, buf, len, ppos); mdbg(INFO3,"Read file %p [%s] -> Len: %ld, Res: %ld", filp, filp->f_dentry->d_name.name, len, res); return res; }
/* * @brief this function is called by read(2) and related system calls * * @param pfile file structure to read on * @param buf buffer address to be filled * @param len length of buf * @param ppos current file position * * @returns read size */ ssize_t yramfs_file_read(struct file *pfile, char __user *buf, size_t len, loff_t *ppos) { DBG_PRINT("read"); return do_sync_read(pfile, buf, len, ppos); }