^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * fs/sdcardfs/multiuser.h
^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) #define AID_USER_OFFSET 100000 /* offset for uid ranges for each user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define AID_APP_START 10000 /* first app user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define AID_APP_END 19999 /* last app user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define AID_CACHE_GID_START 20000 /* start of gids for apps to mark cached data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define AID_EXT_GID_START 30000 /* start of gids for apps to mark external data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define AID_EXT_CACHE_GID_START 40000 /* start of gids for apps to mark external cached data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define AID_EXT_CACHE_GID_END 49999 /* end of gids for apps to mark external cached data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) typedef uid_t userid_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) typedef uid_t appid_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static inline uid_t multiuser_get_uid(userid_t user_id, appid_t app_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static inline bool uid_is_app(uid_t uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) appid_t appid = uid % AID_USER_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return appid >= AID_APP_START && appid <= AID_APP_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static inline gid_t multiuser_get_ext_cache_gid(uid_t uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return uid - AID_APP_START + AID_EXT_CACHE_GID_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static inline gid_t multiuser_get_ext_gid(uid_t uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return uid - AID_APP_START + AID_EXT_GID_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }