sdcardfs.h 18 KB

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