Daniel Campello | 819e203 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/sdcardfs/multiuser.h |
| 3 | * |
| 4 | * Copyright (c) 2013 Samsung Electronics Co. Ltd |
| 5 | * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun, |
| 6 | * Sunghwan Yun, Sungjong Seo |
| 7 | * |
| 8 | * This program has been developed as a stackable file system based on |
| 9 | * the WrapFS which written by |
| 10 | * |
| 11 | * Copyright (c) 1998-2011 Erez Zadok |
| 12 | * Copyright (c) 2009 Shrikar Archak |
| 13 | * Copyright (c) 2003-2011 Stony Brook University |
| 14 | * Copyright (c) 2003-2011 The Research Foundation of SUNY |
| 15 | * |
| 16 | * This file is dual licensed. It may be redistributed and/or modified |
| 17 | * under the terms of the Apache 2.0 License OR version 2 of the GNU |
| 18 | * General Public License. |
| 19 | */ |
| 20 | |
Daniel Rosenberg | 0edc9bf | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 21 | #define AID_USER_OFFSET 100000 /* offset for uid ranges for each user */ |
| 22 | #define AID_APP_START 10000 /* first app user */ |
| 23 | #define AID_APP_END 19999 /* last app user */ |
| 24 | #define AID_CACHE_GID_START 20000 /* start of gids for apps to mark cached data */ |
| 25 | #define AID_EXT_GID_START 30000 /* start of gids for apps to mark external data */ |
Daniel Rosenberg | 5686635 | 2017-04-17 17:11:38 -0700 | [diff] [blame] | 26 | #define AID_EXT_CACHE_GID_START 40000 /* start of gids for apps to mark external cached data */ |
| 27 | #define AID_EXT_CACHE_GID_END 49999 /* end of gids for apps to mark external cached data */ |
Daniel Rosenberg | 0edc9bf | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 28 | #define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */ |
Daniel Campello | 819e203 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 29 | |
| 30 | typedef uid_t userid_t; |
| 31 | typedef uid_t appid_t; |
| 32 | |
Daniel Rosenberg | 0edc9bf | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 33 | static inline uid_t multiuser_get_uid(userid_t user_id, appid_t app_id) |
| 34 | { |
| 35 | return (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET); |
Daniel Campello | 819e203 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Daniel Rosenberg | 70472b2 | 2017-04-24 16:11:03 -0700 | [diff] [blame] | 38 | static inline bool uid_is_app(uid_t uid) |
| 39 | { |
| 40 | appid_t appid = uid % AID_USER_OFFSET; |
| 41 | |
| 42 | return appid >= AID_APP_START && appid <= AID_APP_END; |
| 43 | } |
| 44 | |
Daniel Rosenberg | 5686635 | 2017-04-17 17:11:38 -0700 | [diff] [blame] | 45 | static inline gid_t multiuser_get_ext_cache_gid(uid_t uid) |
Daniel Rosenberg | 0edc9bf | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 46 | { |
Daniel Rosenberg | 5686635 | 2017-04-17 17:11:38 -0700 | [diff] [blame] | 47 | return uid - AID_APP_START + AID_EXT_CACHE_GID_START; |
Daniel Campello | 819e203 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Daniel Rosenberg | d4299b0 | 2017-03-13 15:34:03 -0700 | [diff] [blame] | 50 | static inline gid_t multiuser_get_ext_gid(uid_t uid) |
Daniel Rosenberg | 0edc9bf | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 51 | { |
Daniel Rosenberg | d4299b0 | 2017-03-13 15:34:03 -0700 | [diff] [blame] | 52 | return uid - AID_APP_START + AID_EXT_GID_START; |
Daniel Campello | 819e203 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 53 | } |