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/sdcardfs.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * The sdcardfs v2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   This file system replaces the sdcard daemon on Android
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *   On version 2.0, some of the daemon functions have been ported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   to support the multi-user concepts of Android 4.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (c) 2013 Samsung Electronics Co. Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *               Sunghwan Yun, Sungjong Seo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program has been developed as a stackable file system based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * the WrapFS which written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Copyright (c) 1998-2011 Erez Zadok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Copyright (c) 2009     Shrikar Archak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Copyright (c) 2003-2011 Stony Brook University
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Copyright (c) 2003-2011 The Research Foundation of SUNY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * This file is dual licensed.  It may be redistributed and/or modified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * under the terms of the Apache 2.0 License OR version 2 of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #ifndef _SDCARDFS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define _SDCARDFS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/aio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/fs_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include "multiuser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /* the file system name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define SDCARDFS_NAME "sdcardfs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* sdcardfs root inode number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define SDCARDFS_ROOT_INO     1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /* useful for tracking code reachability */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define UDBG pr_default("DBG:%s:%s:%d\n", __FILE__, __func__, __LINE__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define SDCARDFS_DIRENT_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* temporary static uid settings for development */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define AID_ROOT             0	/* uid for accessing /mnt/sdcard & extSdcard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define AID_MEDIA_RW      1023	/* internal media storage write access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define AID_SDCARD_RW     1015	/* external storage write access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define AID_SDCARD_R      1028	/* external storage read access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define AID_SDCARD_PICS   1033	/* external storage photos access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define AID_SDCARD_AV     1034	/* external storage audio/video access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define AID_SDCARD_ALL    1035	/* access all users external storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define AID_MEDIA_OBB     1059  /* obb files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define AID_SDCARD_IMAGE  1057
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define AID_PACKAGE_INFO  1027
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * Permissions are handled by our permission function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * We don't want anyone who happens to look at our inode value to prematurely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * block access, so store more permissive values. These are probably never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define fixup_tmp_permissions(x)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		(x)->i_uid = make_kuid(&init_user_ns,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				SDCARDFS_I(x)->data->d_uid);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		(x)->i_gid = make_kgid(&init_user_ns, AID_SDCARD_RW);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		(x)->i_mode = ((x)->i_mode & S_IFMT) | 0775;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /* Android 5.0 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /* Permission mode for a specific node. Controls how file permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * are derived for children nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	/* Nothing special; this node should just inherit from its parent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	PERM_INHERIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* This node is one level above a normal root; used for legacy layouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * which use the first level to represent user_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	PERM_PRE_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* This node is "/" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	PERM_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* This node is "/Android" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	PERM_ANDROID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* This node is "/Android/data" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	PERM_ANDROID_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* This node is "/Android/obb" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	PERM_ANDROID_OBB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* This node is "/Android/media" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	PERM_ANDROID_MEDIA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* This node is "/Android/[data|media|obb]/[package]" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	PERM_ANDROID_PACKAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* This node is "/Android/[data|media|obb]/[package]/cache" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	PERM_ANDROID_PACKAGE_CACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) } perm_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct sdcardfs_sb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct sdcardfs_mount_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct sdcardfs_inode_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct sdcardfs_inode_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Do not directly use this function. Use OVERRIDE_CRED() instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) const struct cred *override_fsids(struct sdcardfs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			struct sdcardfs_inode_data *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Do not directly use this function, use REVERT_CRED() instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void revert_fsids(const struct cred *old_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* operations vectors defined in specific files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) extern const struct file_operations sdcardfs_main_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern const struct file_operations sdcardfs_dir_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) extern const struct inode_operations sdcardfs_main_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) extern const struct inode_operations sdcardfs_dir_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) extern const struct inode_operations sdcardfs_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) extern const struct super_operations sdcardfs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern const struct dentry_operations sdcardfs_ci_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern const struct address_space_operations sdcardfs_aops, sdcardfs_dummy_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) extern const struct vm_operations_struct sdcardfs_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) extern int sdcardfs_init_inode_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) extern void sdcardfs_destroy_inode_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) extern int sdcardfs_init_dentry_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern void sdcardfs_destroy_dentry_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) extern int new_dentry_private_data(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) extern void free_dentry_private_data(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) extern struct dentry *sdcardfs_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) extern struct inode *sdcardfs_iget(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				 struct inode *lower_inode, userid_t id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) extern int sdcardfs_interpose(struct dentry *dentry, struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			    struct path *lower_path, userid_t id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern int sdcardfs_on_fscrypt_key_removed(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					   unsigned long action, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* file private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct sdcardfs_file_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct file *lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	const struct vm_operations_struct *lower_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct sdcardfs_inode_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct kref refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	bool abandoned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	perm_t perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	userid_t userid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	uid_t d_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	bool under_android;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bool under_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	bool under_obb;
^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) /* sdcardfs inode data in memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct sdcardfs_inode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct inode *lower_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* state derived based on current position in hierarchy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct sdcardfs_inode_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* top folder for ownership */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	spinlock_t top_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct sdcardfs_inode_data *top_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct inode vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* sdcardfs dentry data in memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct sdcardfs_dentry_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	spinlock_t lock;	/* protects lower_path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct path lower_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct path orig_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct sdcardfs_mount_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	uid_t fs_low_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	gid_t fs_low_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	userid_t fs_user_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	bool multiuser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	bool gid_derivation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	bool default_normal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	bool unshared_obb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	unsigned int reserved_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	bool nocache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct sdcardfs_vfsmount_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	gid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	mode_t mask;
^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) extern int parse_options_remount(struct super_block *sb, char *options, int silent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		struct sdcardfs_vfsmount_options *vfsopts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* sdcardfs super-block data in memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct sdcardfs_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct super_block *lower_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* derived perm policy : some of options have been added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * to sdcardfs_mount_options (Android 4.4 support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct sdcardfs_mount_options options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	spinlock_t lock;	/* protects obbpath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	char *obbpath_s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct path obbpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	void *pkgl_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct notifier_block fscrypt_nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * inode to private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Since we use containers and the struct inode is _inside_ the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * sdcardfs_inode_info structure, SDCARDFS_I will always (given a non-NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * inode pointer), return a valid non-NULL pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static inline struct sdcardfs_inode_info *SDCARDFS_I(const struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return container_of(inode, struct sdcardfs_inode_info, vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* dentry to private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define SDCARDFS_D(dent) ((struct sdcardfs_dentry_info *)(dent)->d_fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* superblock to private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define SDCARDFS_SB(super) ((struct sdcardfs_sb_info *)(super)->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* file to private Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define SDCARDFS_F(file) ((struct sdcardfs_file_info *)((file)->private_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* file to lower file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline struct file *sdcardfs_lower_file(const struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return SDCARDFS_F(f)->lower_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline void sdcardfs_set_lower_file(struct file *f, struct file *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	SDCARDFS_F(f)->lower_file = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* inode to lower inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline struct inode *sdcardfs_lower_inode(const struct inode *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return SDCARDFS_I(i)->lower_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static inline void sdcardfs_set_lower_inode(struct inode *i, struct inode *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	SDCARDFS_I(i)->lower_inode = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* superblock to lower superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static inline struct super_block *sdcardfs_lower_super(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	const struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return SDCARDFS_SB(sb)->lower_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline void sdcardfs_set_lower_super(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 					  struct super_block *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	SDCARDFS_SB(sb)->lower_sb = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* path based (dentry/mnt) macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static inline void pathcpy(struct path *dst, const struct path *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	dst->dentry = src->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	dst->mnt = src->mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* sdcardfs_get_pname functions calls path_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * therefore, the caller must call "proper" path_put functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #define SDCARDFS_DENT_FUNC(pname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline void sdcardfs_get_##pname(const struct dentry *dent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 					struct path *pname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	spin_lock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	pathcpy(pname, &SDCARDFS_D(dent)->pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	path_get(pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	spin_unlock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline void sdcardfs_put_##pname(const struct dentry *dent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 					struct path *pname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	path_put(pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static inline void sdcardfs_set_##pname(const struct dentry *dent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 					struct path *pname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	spin_lock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	pathcpy(&SDCARDFS_D(dent)->pname, pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	spin_unlock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static inline void sdcardfs_reset_##pname(const struct dentry *dent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	spin_lock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	SDCARDFS_D(dent)->pname.dentry = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	SDCARDFS_D(dent)->pname.mnt = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	spin_unlock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	return; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static inline void sdcardfs_put_reset_##pname(const struct dentry *dent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct path pname; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	spin_lock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (SDCARDFS_D(dent)->pname.dentry) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		pathcpy(&pname, &SDCARDFS_D(dent)->pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		SDCARDFS_D(dent)->pname.dentry = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		SDCARDFS_D(dent)->pname.mnt = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		spin_unlock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		path_put(&pname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	} else \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		spin_unlock(&SDCARDFS_D(dent)->lock); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) SDCARDFS_DENT_FUNC(lower_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) SDCARDFS_DENT_FUNC(orig_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static inline bool sbinfo_has_sdcard_magic(struct sdcardfs_sb_info *sbinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	return sbinfo && sbinfo->sb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			&& sbinfo->sb->s_magic == SDCARDFS_SUPER_MAGIC;
^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) static inline struct sdcardfs_inode_data *data_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		struct sdcardfs_inode_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		kref_get(&data->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static inline struct sdcardfs_inode_data *top_data_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		struct sdcardfs_inode_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct sdcardfs_inode_data *top_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	spin_lock(&info->top_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	top_data = data_get(info->top_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	spin_unlock(&info->top_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return top_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) extern void data_release(struct kref *ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline void data_put(struct sdcardfs_inode_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	kref_put(&data->refcount, data_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static inline void release_own_data(struct sdcardfs_inode_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	 * This happens exactly once per inode. At this point, the inode that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	 * originally held this data is about to be freed, and all references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	 * to it are held as a top value, and will likely be released soon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	info->data->abandoned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	data_put(info->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static inline void set_top(struct sdcardfs_inode_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			struct sdcardfs_inode_info *top_owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct sdcardfs_inode_data *old_top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct sdcardfs_inode_data *new_top = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (top_owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		new_top = top_data_get(top_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	spin_lock(&info->top_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	old_top = info->top_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	info->top_data = new_top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (old_top)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		data_put(old_top);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	spin_unlock(&info->top_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static inline int get_gid(struct vfsmount *mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		struct sdcardfs_inode_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	struct sdcardfs_vfsmount_options *vfsopts = mnt->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (vfsopts->gid == AID_SDCARD_RW && !sbi->options.default_normal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		/* As an optimization, certain trusted system components only run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		 * as owner but operate across all users. Since we're now handing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		 * out the sdcard_rw GID only to trusted apps, we're okay relaxing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		 * the user boundary enforcement for the default view. The UIDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		 * assigned to app directories are still multiuser aware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return AID_SDCARD_RW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		return multiuser_get_uid(data->userid, vfsopts->gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static inline int get_mode(struct vfsmount *mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		struct sdcardfs_inode_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		struct sdcardfs_inode_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	int owner_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int filtered_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct sdcardfs_vfsmount_options *opts = mnt->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	int visible_mode = 0775 & ~opts->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (data->perm == PERM_PRE_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		/* Top of multi-user view should always be visible to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		* secondary users can traverse inside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		visible_mode = 0711;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	} else if (data->under_android) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		/* Block "other" access to Android directories, since only apps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		* belonging to a specific user should be in there; we still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		* leave +x open for the default view.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		if (opts->gid == AID_SDCARD_RW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			visible_mode = visible_mode & ~0006;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			visible_mode = visible_mode & ~0007;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	owner_mode = info->lower_inode->i_mode & 0700;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	filtered_mode = visible_mode & (owner_mode | (owner_mode >> 3) | (owner_mode >> 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	return filtered_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static inline int has_graft_path(const struct dentry *dent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	spin_lock(&SDCARDFS_D(dent)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (SDCARDFS_D(dent)->orig_path.dentry != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	spin_unlock(&SDCARDFS_D(dent)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static inline void sdcardfs_get_real_lower(const struct dentry *dent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 						struct path *real_lower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	/* in case of a local obb dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	 * the orig_path should be returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (has_graft_path(dent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		sdcardfs_get_orig_path(dent, real_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		sdcardfs_get_lower_path(dent, real_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static inline void sdcardfs_put_real_lower(const struct dentry *dent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 						struct path *real_lower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (has_graft_path(dent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		sdcardfs_put_orig_path(dent, real_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		sdcardfs_put_lower_path(dent, real_lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) extern struct mutex sdcardfs_super_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) extern struct list_head sdcardfs_super_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* for packagelist.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) extern appid_t get_appid(const char *app_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) extern appid_t get_ext_gid(const char *app_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) extern appid_t is_excluded(const char *app_name, userid_t userid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) extern int check_caller_access_to_name(struct inode *parent_node, const struct qstr *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) extern int packagelist_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) extern void packagelist_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* for derived_perm.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) #define BY_NAME		(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define BY_USERID	(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct limit_search {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	struct qstr name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	userid_t userid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) extern void setup_derived_state(struct inode *inode, perm_t perm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			userid_t userid, uid_t uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) extern void get_derived_permission(struct dentry *parent, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) extern void get_derived_permission_new(struct dentry *parent, struct dentry *dentry, const struct qstr *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) extern void fixup_perms_recursive(struct dentry *dentry, struct limit_search *limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) extern void update_derived_permission_lock(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) void fixup_lower_ownership(struct dentry *dentry, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) extern int need_graft_path(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) extern int is_base_obbpath(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) extern int is_obbpath_invalid(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) extern int setup_obb_dentry(struct dentry *dentry, struct path *lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /* locking helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static inline struct dentry *lock_parent(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	struct dentry *dir = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	return dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static inline void unlock_dir(struct dentry *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	dput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static inline int prepare_dir(const char *path_s, uid_t uid, gid_t gid, mode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	struct dentry *dent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct iattr attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	struct path parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	dent = kern_path_locked(path_s, &parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	if (IS_ERR(dent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		err = PTR_ERR(dent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		if (err == -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	err = vfs_mkdir2(parent.mnt, d_inode(parent.dentry), dent, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (err == -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		goto out_dput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	attrs.ia_uid = make_kuid(&init_user_ns, uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	attrs.ia_gid = make_kgid(&init_user_ns, gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	attrs.ia_valid = ATTR_UID | ATTR_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	inode_lock(d_inode(dent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	notify_change2(parent.mnt, dent, &attrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	inode_unlock(d_inode(dent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) out_dput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	dput(dent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	/* parent dentry locked by lookup_create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	inode_unlock(d_inode(parent.dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	path_put(&parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)  * Return 1, if a disk has enough free space, otherwise 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  * We assume that any files can not be overwritten.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static inline int check_min_free_space(struct dentry *dentry, size_t size, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct path lower_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	struct kstatfs statfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	u64 avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	if (sbi->options.reserved_mb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		/* Get fs stat of lower filesystem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		sdcardfs_get_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		err = vfs_statfs(&lower_path, &statfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		sdcardfs_put_lower_path(dentry, &lower_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		/* Invalid statfs informations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		if (unlikely(statfs.f_bsize == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		/* if you are checking directory, set size to f_bsize. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		if (unlikely(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 			size = statfs.f_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		/* available size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		avail = statfs.f_bavail * statfs.f_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		/* not enough space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		if ((u64)size > avail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		/* enough space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		if ((avail - size) > (sbi->options.reserved_mb * 1024 * 1024))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)  * Copies attrs and maintains sdcardfs managed attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)  * Since our permission check handles all special permissions, set those to be open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) static inline void sdcardfs_copy_and_fix_attrs(struct inode *dest, const struct inode *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	dest->i_mode = (src->i_mode  & S_IFMT) | S_IRWXU | S_IRWXG |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 			S_IROTH | S_IXOTH; /* 0775 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	dest->i_uid = make_kuid(&init_user_ns, SDCARDFS_I(dest)->data->d_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	dest->i_gid = make_kgid(&init_user_ns, AID_SDCARD_RW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	dest->i_rdev = src->i_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	dest->i_atime = src->i_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	dest->i_mtime = src->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	dest->i_ctime = src->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	dest->i_blkbits = src->i_blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	dest->i_flags = src->i_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	set_nlink(dest, src->i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static inline bool str_case_eq(const char *s1, const char *s2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	return !strcasecmp(s1, s2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static inline bool str_n_case_eq(const char *s1, const char *s2, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	return !strncasecmp(s1, s2, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static inline bool qstr_case_eq(const struct qstr *q1, const struct qstr *q2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	return q1->len == q2->len && str_n_case_eq(q1->name, q2->name, q2->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) #define QSTR_LITERAL(string) QSTR_INIT(string, sizeof(string)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) #endif	/* not _SDCARDFS_H_ */