Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * fs/sdcardfs/file.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2013 Samsung Electronics Co. Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *               Sunghwan Yun, Sungjong Seo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This program has been developed as a stackable file system based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * the WrapFS which written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (c) 1998-2011 Erez Zadok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Copyright (c) 2009     Shrikar Archak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Copyright (c) 2003-2011 Stony Brook University
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Copyright (c) 2003-2011 The Research Foundation of SUNY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * This file is dual licensed.  It may be redistributed and/or modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * under the terms of the Apache 2.0 License OR version 2 of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "sdcardfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #ifdef CONFIG_SDCARD_FS_FADV_NOACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static ssize_t sdcardfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			   size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #ifdef CONFIG_SDCARD_FS_FADV_NOACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct backing_dev_info *bdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #ifdef CONFIG_SDCARD_FS_FADV_NOACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (file->f_mode & FMODE_NOACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (!(lower_file->f_mode & FMODE_NOACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			bdi = lower_file->f_mapping->backing_dev_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			lower_file->f_ra.ra_pages = bdi->ra_pages * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			spin_lock(&lower_file->f_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			lower_file->f_mode |= FMODE_NOACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			spin_unlock(&lower_file->f_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	err = vfs_read(lower_file, buf, count, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* update our inode atime upon a successful lower read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		fsstack_copy_attr_atime(d_inode(dentry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 					file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static ssize_t sdcardfs_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			    size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/* check disk space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!check_min_free_space(dentry, count, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		pr_err("No minimum free space.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	err = vfs_write(lower_file, buf, count, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* update our inode times+sizes upon a successful lower write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (err >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (sizeof(loff_t) > sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		fsstack_copy_inode_size(inode, file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		fsstack_copy_attr_times(inode, file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (sizeof(loff_t) > sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int sdcardfs_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct file *lower_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	lower_file->f_pos = file->f_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	err = iterate_dir(lower_file, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	file->f_pos = lower_file->f_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (err >= 0)		/* copy the atime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		fsstack_copy_attr_atime(d_inode(dentry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 					file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static long sdcardfs_unlocked_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				  unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	long err = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	const struct cred *saved_cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* XXX: use vfs_ioctl if/when VFS exports it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!lower_file || !lower_file->f_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* save current_cred and override it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	saved_cred = override_fsids(sbi, SDCARDFS_I(file_inode(file))->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!saved_cred) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (lower_file->f_op->unlocked_ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		err = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* some ioctls can change inode attributes (EXT2_IOC_SETFLAGS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		sdcardfs_copy_and_fix_attrs(file_inode(file),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				      file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	revert_fsids(saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static long sdcardfs_compat_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	long err = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	const struct cred *saved_cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* XXX: use vfs_ioctl if/when VFS exports it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!lower_file || !lower_file->f_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* save current_cred and override it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	saved_cred = override_fsids(sbi, SDCARDFS_I(file_inode(file))->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!saved_cred) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (lower_file->f_op->compat_ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		err = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	revert_fsids(saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int sdcardfs_mmap(struct file *file, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	bool willwrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	const struct vm_operations_struct *saved_vm_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* this might be deferred to mmap's writepage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	willwrite = ((vma->vm_flags | VM_SHARED | VM_WRITE) == vma->vm_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * File systems which do not implement ->writepage may use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * generic_file_readonly_mmap as their ->mmap op.  If you call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * generic_file_readonly_mmap with VM_WRITE, you'd get an -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * But we cannot call the lower ->mmap op, so we can't tell that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * writeable mappings won't work.  Therefore, our only choice is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * check if the lower file system supports the ->writepage, and if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * not, return EINVAL (the same error that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 * generic_file_readonly_mmap returns in that case).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (willwrite && !lower_file->f_mapping->a_ops->writepage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		pr_err("sdcardfs: lower file system does not support writeable mmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * find and save lower vm_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * XXX: the VFS should have a cleaner way of finding the lower vm_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!SDCARDFS_F(file)->lower_vm_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		err = lower_file->f_op->mmap(lower_file, vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			pr_err("sdcardfs: lower mmap failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		saved_vm_ops = vma->vm_ops; /* save: came from lower ->mmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * Next 3 lines are all I need from generic_file_mmap.  I definitely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * don't want its test for ->readpage which returns -ENOEXEC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	file_accessed(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	vma->vm_ops = &sdcardfs_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	file->f_mapping->a_ops = &sdcardfs_aops; /* set our aops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!SDCARDFS_F(file)->lower_vm_ops) /* save for our ->fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		SDCARDFS_F(file)->lower_vm_ops = saved_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	vma->vm_private_data = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	get_file(lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	vma->vm_file = lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int sdcardfs_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct file *lower_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct path lower_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct dentry *parent = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	const struct cred *saved_cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* don't open unhashed/deleted files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (d_unhashed(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (!check_caller_access_to_name(d_inode(parent), &dentry->d_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		err = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* save current_cred and override it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	saved_cred = override_fsids(sbi, SDCARDFS_I(inode)->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!saved_cred) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	file->private_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		kzalloc(sizeof(struct sdcardfs_file_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (!SDCARDFS_F(file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		goto out_revert_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	/* open lower object and link sdcardfs's file struct to lower's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	sdcardfs_get_lower_path(file->f_path.dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	lower_file = dentry_open(&lower_path, file->f_flags, current_cred());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	path_put(&lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (IS_ERR(lower_file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		err = PTR_ERR(lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (lower_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			sdcardfs_set_lower_file(file, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			fput(lower_file); /* fput calls dput for lower_dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		sdcardfs_set_lower_file(file, lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		kfree(SDCARDFS_F(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		sdcardfs_copy_and_fix_attrs(inode, sdcardfs_lower_inode(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) out_revert_cred:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	revert_fsids(saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int sdcardfs_flush(struct file *file, fl_owner_t id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	struct file *lower_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (lower_file && lower_file->f_op && lower_file->f_op->flush) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		filemap_write_and_wait(file->f_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		err = lower_file->f_op->flush(lower_file, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* release all lower object references & free the file info structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static int sdcardfs_file_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (lower_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		sdcardfs_set_lower_file(file, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		fput(lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	kfree(SDCARDFS_F(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int sdcardfs_fsync(struct file *file, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct path lower_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	err = __generic_file_fsync(file, start, end, datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	sdcardfs_get_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	err = vfs_fsync_range(lower_file, start, end, datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	sdcardfs_put_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int sdcardfs_fasync(int fd, struct file *file, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct file *lower_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (lower_file->f_op && lower_file->f_op->fasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		err = lower_file->f_op->fasync(fd, lower_file, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * Sdcardfs cannot use generic_file_llseek as ->llseek, because it would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * only set the offset of the upper file.  So we have to implement our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * own method to set both the upper and lower file offsets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * consistently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static loff_t sdcardfs_file_llseek(struct file *file, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	err = generic_file_llseek(file, offset, whence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	err = generic_file_llseek(lower_file, offset, whence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  * Sdcardfs read_iter, redirect modified iocb to lower read_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ssize_t sdcardfs_read_iter(struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct file *file = iocb->ki_filp, *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (!lower_file->f_op->read_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	get_file(lower_file); /* prevent lower_file from being released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	iocb->ki_filp = lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	err = lower_file->f_op->read_iter(iocb, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	iocb->ki_filp = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	fput(lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	/* update upper inode atime as needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (err >= 0 || err == -EIOCBQUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		fsstack_copy_attr_atime(file->f_path.dentry->d_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 					file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * Sdcardfs write_iter, redirect modified iocb to lower write_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ssize_t sdcardfs_write_iter(struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct file *file = iocb->ki_filp, *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct inode *inode = file->f_path.dentry->d_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	lower_file = sdcardfs_lower_file(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (!lower_file->f_op->write_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	get_file(lower_file); /* prevent lower_file from being released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	iocb->ki_filp = lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	err = lower_file->f_op->write_iter(iocb, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	iocb->ki_filp = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	fput(lower_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	/* update upper inode times/sizes as needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (err >= 0 || err == -EIOCBQUEUED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (sizeof(loff_t) > sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		fsstack_copy_inode_size(inode, file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		fsstack_copy_attr_times(inode, file_inode(lower_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		if (sizeof(loff_t) > sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) const struct file_operations sdcardfs_main_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	.read		= sdcardfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.write		= sdcardfs_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	.unlocked_ioctl	= sdcardfs_unlocked_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.compat_ioctl	= sdcardfs_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	.mmap		= sdcardfs_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	.open		= sdcardfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	.flush		= sdcardfs_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	.release	= sdcardfs_file_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.fsync		= sdcardfs_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.fasync		= sdcardfs_fasync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	.read_iter	= sdcardfs_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	.write_iter	= sdcardfs_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* trimmed directory options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) const struct file_operations sdcardfs_dir_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	.llseek		= sdcardfs_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.read		= generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.iterate	= sdcardfs_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.unlocked_ioctl	= sdcardfs_unlocked_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.compat_ioctl	= sdcardfs_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	.open		= sdcardfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	.release	= sdcardfs_file_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	.flush		= sdcardfs_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	.fsync		= sdcardfs_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.fasync		= sdcardfs_fasync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) };