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/super.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * The inode cache is used with alloc_inode for both our inode info and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * vfs inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static struct kmem_cache *sdcardfs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * To support the top references, we must track some data separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * An sdcardfs_inode_info always has a reference to its data, and once set up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * also has a reference to its top. The top may be itself, in which case it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * holds two references to its data. When top is changed, it takes a ref to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * new data and then drops the ref to the old data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static struct kmem_cache *sdcardfs_inode_data_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) void data_release(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct sdcardfs_inode_data *data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		container_of(ref, struct sdcardfs_inode_data, refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	kmem_cache_free(sdcardfs_inode_data_cachep, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* final actions when unmounting a file system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static void sdcardfs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct sdcardfs_sb_info *spd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct super_block *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	spd = SDCARDFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (!spd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (spd->obbpath_s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		kfree(spd->obbpath_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		path_put(&spd->obbpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* decrement lower super references */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	s = sdcardfs_lower_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	sdcardfs_set_lower_super(sb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	atomic_dec(&s->s_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	kfree(spd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int sdcardfs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct path lower_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u32 min_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	sdcardfs_get_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	err = vfs_statfs(&lower_path, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	sdcardfs_put_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (sbi->options.reserved_mb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		/* Invalid statfs informations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (buf->f_bsize == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			pr_err("Returned block size is zero.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			return -EINVAL;
^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) 		min_blocks = ((sbi->options.reserved_mb * 1024 * 1024)/buf->f_bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		buf->f_blocks -= min_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (buf->f_bavail > min_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			buf->f_bavail -= min_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			buf->f_bavail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/* Make reserved blocks invisiable to media storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		buf->f_bfree = buf->f_bavail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* set return buf to our f/s to avoid confusing user-level utils */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	buf->f_type = SDCARDFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * @flags: numeric mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * @options: mount options string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int sdcardfs_remount_fs(struct super_block *sb, int *flags, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * The VFS will take care of "ro" and "rw" flags among others.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * can safely accept a few flags (RDONLY, MANDLOCK), and honor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * SILENT, but anything else left over is an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if ((*flags & ~(MS_RDONLY | MS_MANDLOCK | MS_SILENT)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		pr_err("sdcardfs: remount flags 0x%x unsupported\n", *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return err;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * @mnt: mount point we are remounting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * @sb: superblock we are remounting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * @flags: numeric mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * @options: mount options string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int sdcardfs_remount_fs2(struct vfsmount *mnt, struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 						int *flags, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	int err = 0;
^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) 	 * The VFS will take care of "ro" and "rw" flags among others.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 * can safely accept a few flags (RDONLY, MANDLOCK), and honor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * SILENT, but anything else left over is an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if ((*flags & ~(MS_RDONLY | MS_MANDLOCK | MS_SILENT | MS_REMOUNT)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		pr_err("sdcardfs: remount flags 0x%x unsupported\n", *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	pr_info("Remount options were %s for vfsmnt %p.\n", options, mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	err = parse_options_remount(sb, options, *flags & ~MS_SILENT, mnt->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void *sdcardfs_clone_mnt_data(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct sdcardfs_vfsmount_options *opt = kmalloc(sizeof(struct sdcardfs_vfsmount_options), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct sdcardfs_vfsmount_options *old = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (!opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	opt->gid = old->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	opt->mask = old->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void sdcardfs_copy_mnt_data(void *data, void *newdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct sdcardfs_vfsmount_options *old = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct sdcardfs_vfsmount_options *new = newdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	old->gid = new->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	old->mask = new->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * Called by iput() when the inode reference count reached zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * and the inode is not hashed anywhere.  Used to clear anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * that needs to be, before the inode is completely destroyed and put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * on the inode free list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static void sdcardfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct inode *lower_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	truncate_inode_pages(&inode->i_data, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	set_top(SDCARDFS_I(inode), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 * Decrement a reference to a lower_inode, which was incremented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * by our read_inode when it was created initially.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	lower_inode = sdcardfs_lower_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	sdcardfs_set_lower_inode(inode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	iput(lower_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static struct inode *sdcardfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct sdcardfs_inode_info *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct sdcardfs_inode_data *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	i = kmem_cache_alloc(sdcardfs_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* memset everything up to the inode to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	memset(i, 0, offsetof(struct sdcardfs_inode_info, vfs_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	d = kmem_cache_alloc(sdcardfs_inode_data_cachep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 					GFP_KERNEL | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		kmem_cache_free(sdcardfs_inode_cachep, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	i->data = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	kref_init(&d->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	i->top_data = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	spin_lock_init(&i->top_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	kref_get(&d->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	inode_set_iversion(&i->vfs_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return &i->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static void i_callback(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct inode *inode = container_of(head, struct inode, i_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	release_own_data(SDCARDFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	kmem_cache_free(sdcardfs_inode_cachep, SDCARDFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void sdcardfs_destroy_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	call_rcu(&inode->i_rcu, i_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* sdcardfs inode cache constructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static void init_once(void *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct sdcardfs_inode_info *i = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	inode_init_once(&i->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int sdcardfs_init_inode_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	sdcardfs_inode_cachep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		kmem_cache_create("sdcardfs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				  sizeof(struct sdcardfs_inode_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				  SLAB_RECLAIM_ACCOUNT, init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!sdcardfs_inode_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	sdcardfs_inode_data_cachep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		kmem_cache_create("sdcardfs_inode_data_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				  sizeof(struct sdcardfs_inode_data), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				  SLAB_RECLAIM_ACCOUNT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (!sdcardfs_inode_data_cachep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		kmem_cache_destroy(sdcardfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* sdcardfs inode cache destructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void sdcardfs_destroy_inode_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	kmem_cache_destroy(sdcardfs_inode_data_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	kmem_cache_destroy(sdcardfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * Used only in nfs, to kill any pending RPC tasks, so that subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * code can actually succeed and won't leave tasks that need handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static void sdcardfs_umount_begin(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct super_block *lower_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	lower_sb = sdcardfs_lower_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (lower_sb && lower_sb->s_op && lower_sb->s_op->umount_begin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		lower_sb->s_op->umount_begin(lower_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int sdcardfs_show_options(struct vfsmount *mnt, struct seq_file *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct sdcardfs_mount_options *opts = &sbi->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct sdcardfs_vfsmount_options *vfsopts = mnt->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (opts->fs_low_uid != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		seq_printf(m, ",fsuid=%u", opts->fs_low_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (opts->fs_low_gid != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		seq_printf(m, ",fsgid=%u", opts->fs_low_gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (vfsopts->gid != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		seq_printf(m, ",gid=%u", vfsopts->gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (opts->multiuser)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		seq_puts(m, ",multiuser");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (vfsopts->mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		seq_printf(m, ",mask=%u", vfsopts->mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (opts->fs_user_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		seq_printf(m, ",userid=%u", opts->fs_user_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (opts->gid_derivation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		seq_puts(m, ",derive_gid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (opts->default_normal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		seq_puts(m, ",default_normal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (opts->reserved_mb != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		seq_printf(m, ",reserved=%uMB", opts->reserved_mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (opts->nocache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		seq_printf(m, ",nocache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (opts->unshared_obb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		seq_printf(m, ",unshared_obb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int sdcardfs_on_fscrypt_key_removed(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				    unsigned long action, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct sdcardfs_sb_info *sbi = container_of(nb, struct sdcardfs_sb_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 						    fscrypt_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 * Evict any unused sdcardfs dentries (and hence any unused sdcardfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	 * inodes, since sdcardfs doesn't cache unpinned inodes by themselves)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	 * so that the lower filesystem's encrypted inodes can be evicted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	 * This is needed to make the FS_IOC_REMOVE_ENCRYPTION_KEY ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	 * properly "lock" the files underneath the sdcardfs mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	shrink_dcache_sb(sbi->sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) const struct super_operations sdcardfs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	.put_super	= sdcardfs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	.statfs		= sdcardfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.remount_fs	= sdcardfs_remount_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.remount_fs2	= sdcardfs_remount_fs2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	.clone_mnt_data	= sdcardfs_clone_mnt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	.copy_mnt_data	= sdcardfs_copy_mnt_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	.evict_inode	= sdcardfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	.umount_begin	= sdcardfs_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.show_options2	= sdcardfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	.alloc_inode	= sdcardfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	.destroy_inode	= sdcardfs_destroy_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.drop_inode	= generic_delete_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) };