Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/sdcardfs/packagelist.c |
| 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 | |
| 21 | #include "sdcardfs.h" |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 22 | #include <linux/hashtable.h> |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 25 | |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/slab.h> |
| 29 | |
| 30 | #include <linux/configfs.h> |
| 31 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 32 | #define STRING_BUF_SIZE (512) |
| 33 | |
| 34 | struct hashtable_entry { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 35 | struct hlist_node hlist; |
| 36 | void *key; |
Daniel Campello | 5d3b416 | 2015-07-20 16:33:46 -0700 | [diff] [blame] | 37 | unsigned int value; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 40 | struct sb_list { |
| 41 | struct super_block *sb; |
| 42 | struct list_head list; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 45 | struct packagelist_data { |
| 46 | DECLARE_HASHTABLE(package_to_appid,8); |
| 47 | struct mutex hashtable_lock; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 48 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static struct packagelist_data *pkgl_data_all; |
| 52 | |
| 53 | static struct kmem_cache *hashtable_entry_cachep; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 54 | |
Daniel Campello | 5d3b416 | 2015-07-20 16:33:46 -0700 | [diff] [blame] | 55 | static unsigned int str_hash(const char *key) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 56 | int i; |
| 57 | unsigned int h = strlen(key); |
| 58 | char *data = (char *)key; |
| 59 | |
| 60 | for (i = 0; i < strlen(key); i++) { |
| 61 | h = h * 31 + *data; |
| 62 | data++; |
| 63 | } |
| 64 | return h; |
| 65 | } |
| 66 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 67 | appid_t get_appid(void *pkgl_id, const char *app_name) |
| 68 | { |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 69 | struct packagelist_data *pkgl_dat = pkgl_data_all; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 70 | struct hashtable_entry *hash_cur; |
Daniel Campello | 5d3b416 | 2015-07-20 16:33:46 -0700 | [diff] [blame] | 71 | unsigned int hash = str_hash(app_name); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 72 | appid_t ret_id; |
| 73 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 74 | mutex_lock(&pkgl_dat->hashtable_lock); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 75 | hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 76 | if (!strcasecmp(app_name, hash_cur->key)) { |
| 77 | ret_id = (appid_t)hash_cur->value; |
| 78 | mutex_unlock(&pkgl_dat->hashtable_lock); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 79 | return ret_id; |
| 80 | } |
| 81 | } |
| 82 | mutex_unlock(&pkgl_dat->hashtable_lock); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | /* Kernel has already enforced everything we returned through |
| 87 | * derive_permissions_locked(), so this is used to lock down access |
| 88 | * even further, such as enforcing that apps hold sdcard_rw. */ |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 89 | int check_caller_access_to_name(struct inode *parent_node, const char* name) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 90 | |
| 91 | /* Always block security-sensitive files at root */ |
| 92 | if (parent_node && SDCARDFS_I(parent_node)->perm == PERM_ROOT) { |
| 93 | if (!strcasecmp(name, "autorun.inf") |
| 94 | || !strcasecmp(name, ".android_secure") |
| 95 | || !strcasecmp(name, "android_secure")) { |
| 96 | return 0; |
| 97 | } |
| 98 | } |
| 99 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 100 | /* Root always has access; access for any other UIDs should always |
| 101 | * be controlled through packages.list. */ |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 102 | if (from_kuid(&init_user_ns, current_fsuid()) == 0) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 103 | return 1; |
| 104 | } |
| 105 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 106 | /* No extra permissions to enforce */ |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | /* This function is used when file opening. The open flags must be |
| 111 | * checked before calling check_caller_access_to_name() */ |
| 112 | int open_flags_to_access_mode(int open_flags) { |
| 113 | if((open_flags & O_ACCMODE) == O_RDONLY) { |
| 114 | return 0; /* R_OK */ |
| 115 | } else if ((open_flags & O_ACCMODE) == O_WRONLY) { |
| 116 | return 1; /* W_OK */ |
| 117 | } else { |
| 118 | /* Probably O_RDRW, but treat as default to be safe */ |
| 119 | return 1; /* R_OK | W_OK */ |
| 120 | } |
| 121 | } |
| 122 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 123 | static int insert_str_to_int_lock(struct packagelist_data *pkgl_dat, char *key, |
Daniel Campello | 5d3b416 | 2015-07-20 16:33:46 -0700 | [diff] [blame] | 124 | unsigned int value) |
| 125 | { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 126 | struct hashtable_entry *hash_cur; |
| 127 | struct hashtable_entry *new_entry; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 128 | unsigned int hash = str_hash(key); |
| 129 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 130 | hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 131 | if (!strcasecmp(key, hash_cur->key)) { |
| 132 | hash_cur->value = value; |
| 133 | return 0; |
| 134 | } |
| 135 | } |
| 136 | new_entry = kmem_cache_alloc(hashtable_entry_cachep, GFP_KERNEL); |
| 137 | if (!new_entry) |
| 138 | return -ENOMEM; |
| 139 | new_entry->key = kstrdup(key, GFP_KERNEL); |
| 140 | new_entry->value = value; |
| 141 | hash_add(pkgl_dat->package_to_appid, &new_entry->hlist, hash); |
| 142 | return 0; |
| 143 | } |
| 144 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 145 | static void fixup_perms(struct super_block *sb) { |
| 146 | if (sb && sb->s_magic == SDCARDFS_SUPER_MAGIC) { |
| 147 | mutex_lock(&sb->s_root->d_inode->i_mutex); |
| 148 | get_derive_permissions_recursive(sb->s_root); |
| 149 | mutex_unlock(&sb->s_root->d_inode->i_mutex); |
| 150 | } |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 153 | static int insert_str_to_int(struct packagelist_data *pkgl_dat, char *key, |
| 154 | unsigned int value) { |
| 155 | int ret; |
| 156 | struct sdcardfs_sb_info *sbinfo; |
| 157 | mutex_lock(&sdcardfs_super_list_lock); |
| 158 | mutex_lock(&pkgl_dat->hashtable_lock); |
| 159 | ret = insert_str_to_int_lock(pkgl_dat, key, value); |
| 160 | mutex_unlock(&pkgl_dat->hashtable_lock); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 161 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 162 | list_for_each_entry(sbinfo, &sdcardfs_super_list, list) { |
| 163 | if (sbinfo) { |
| 164 | fixup_perms(sbinfo->sb); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 167 | mutex_unlock(&sdcardfs_super_list_lock); |
| 168 | return ret; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 171 | static void remove_str_to_int_lock(struct hashtable_entry *h_entry) { |
| 172 | kfree(h_entry->key); |
| 173 | hash_del(&h_entry->hlist); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 174 | kmem_cache_free(hashtable_entry_cachep, h_entry); |
| 175 | } |
| 176 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 177 | static void remove_str_to_int(struct packagelist_data *pkgl_dat, const char *key) |
| 178 | { |
| 179 | struct sdcardfs_sb_info *sbinfo; |
| 180 | struct hashtable_entry *hash_cur; |
| 181 | unsigned int hash = str_hash(key); |
| 182 | mutex_lock(&sdcardfs_super_list_lock); |
| 183 | mutex_lock(&pkgl_dat->hashtable_lock); |
| 184 | hash_for_each_possible(pkgl_dat->package_to_appid, hash_cur, hlist, hash) { |
| 185 | if (!strcasecmp(key, hash_cur->key)) { |
| 186 | remove_str_to_int_lock(hash_cur); |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | mutex_unlock(&pkgl_dat->hashtable_lock); |
| 191 | list_for_each_entry(sbinfo, &sdcardfs_super_list, list) { |
| 192 | if (sbinfo) { |
| 193 | fixup_perms(sbinfo->sb); |
| 194 | } |
| 195 | } |
| 196 | mutex_unlock(&sdcardfs_super_list_lock); |
| 197 | return; |
| 198 | } |
| 199 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 200 | static void remove_all_hashentrys(struct packagelist_data *pkgl_dat) |
| 201 | { |
| 202 | struct hashtable_entry *hash_cur; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 203 | struct hlist_node *h_t; |
| 204 | int i; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 205 | mutex_lock(&pkgl_dat->hashtable_lock); |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 206 | hash_for_each_safe(pkgl_dat->package_to_appid, i, h_t, hash_cur, hlist) |
| 207 | remove_str_to_int_lock(hash_cur); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 208 | mutex_unlock(&pkgl_dat->hashtable_lock); |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 209 | hash_init(pkgl_dat->package_to_appid); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 212 | static struct packagelist_data * packagelist_create(void) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 213 | { |
| 214 | struct packagelist_data *pkgl_dat; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 215 | |
| 216 | pkgl_dat = kmalloc(sizeof(*pkgl_dat), GFP_KERNEL | __GFP_ZERO); |
| 217 | if (!pkgl_dat) { |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 218 | printk(KERN_ERR "sdcardfs: Failed to create hash\n"); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 219 | return ERR_PTR(-ENOMEM); |
| 220 | } |
| 221 | |
| 222 | mutex_init(&pkgl_dat->hashtable_lock); |
| 223 | hash_init(pkgl_dat->package_to_appid); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 224 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 225 | return pkgl_dat; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 228 | static void packagelist_destroy(struct packagelist_data *pkgl_dat) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 229 | { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 230 | remove_all_hashentrys(pkgl_dat); |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 231 | printk(KERN_INFO "sdcardfs: destroyed packagelist pkgld\n"); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 232 | kfree(pkgl_dat); |
| 233 | } |
| 234 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 235 | struct package_appid { |
| 236 | struct config_item item; |
| 237 | int add_pid; |
| 238 | }; |
| 239 | |
| 240 | static inline struct package_appid *to_package_appid(struct config_item *item) |
| 241 | { |
| 242 | return item ? container_of(item, struct package_appid, item) : NULL; |
| 243 | } |
| 244 | |
| 245 | static ssize_t package_appid_attr_show(struct config_item *item, |
| 246 | char *page) |
| 247 | { |
| 248 | ssize_t count; |
| 249 | count = sprintf(page, "%d\n", get_appid(pkgl_data_all, item->ci_name)); |
| 250 | return count; |
| 251 | } |
| 252 | |
| 253 | static ssize_t package_appid_attr_store(struct config_item *item, |
| 254 | const char *page, size_t count) |
| 255 | { |
| 256 | struct package_appid *package_appid = to_package_appid(item); |
| 257 | unsigned long tmp; |
| 258 | char *p = (char *) page; |
| 259 | int ret; |
| 260 | |
| 261 | tmp = simple_strtoul(p, &p, 10); |
| 262 | if (!p || (*p && (*p != '\n'))) |
| 263 | return -EINVAL; |
| 264 | |
| 265 | if (tmp > INT_MAX) |
| 266 | return -ERANGE; |
| 267 | ret = insert_str_to_int(pkgl_data_all, item->ci_name, (unsigned int)tmp); |
| 268 | package_appid->add_pid = tmp; |
| 269 | if (ret) |
| 270 | return ret; |
| 271 | |
| 272 | return count; |
| 273 | } |
| 274 | |
| 275 | static struct configfs_attribute package_appid_attr_add_pid = { |
| 276 | .ca_owner = THIS_MODULE, |
| 277 | .ca_name = "appid", |
| 278 | .ca_mode = S_IRUGO | S_IWUGO, |
| 279 | .show = package_appid_attr_show, |
| 280 | .store = package_appid_attr_store, |
| 281 | }; |
| 282 | |
| 283 | static struct configfs_attribute *package_appid_attrs[] = { |
| 284 | &package_appid_attr_add_pid, |
| 285 | NULL, |
| 286 | }; |
| 287 | |
| 288 | static void package_appid_release(struct config_item *item) |
| 289 | { |
| 290 | printk(KERN_INFO "sdcardfs: removing %s\n", item->ci_dentry->d_name.name); |
| 291 | /* item->ci_name is freed already, so we rely on the dentry */ |
| 292 | remove_str_to_int(pkgl_data_all, item->ci_dentry->d_name.name); |
| 293 | kfree(to_package_appid(item)); |
| 294 | } |
| 295 | |
| 296 | static struct configfs_item_operations package_appid_item_ops = { |
| 297 | .release = package_appid_release, |
| 298 | }; |
| 299 | |
| 300 | static struct config_item_type package_appid_type = { |
| 301 | .ct_item_ops = &package_appid_item_ops, |
| 302 | .ct_attrs = package_appid_attrs, |
| 303 | .ct_owner = THIS_MODULE, |
| 304 | }; |
| 305 | |
| 306 | |
| 307 | struct sdcardfs_packages { |
| 308 | struct config_group group; |
| 309 | }; |
| 310 | |
| 311 | static inline struct sdcardfs_packages *to_sdcardfs_packages(struct config_item *item) |
| 312 | { |
| 313 | return item ? container_of(to_config_group(item), struct sdcardfs_packages, group) : NULL; |
| 314 | } |
| 315 | |
| 316 | static struct config_item *sdcardfs_packages_make_item(struct config_group *group, const char *name) |
| 317 | { |
| 318 | struct package_appid *package_appid; |
| 319 | |
| 320 | package_appid = kzalloc(sizeof(struct package_appid), GFP_KERNEL); |
| 321 | if (!package_appid) |
| 322 | return ERR_PTR(-ENOMEM); |
| 323 | |
| 324 | config_item_init_type_name(&package_appid->item, name, |
| 325 | &package_appid_type); |
| 326 | |
| 327 | package_appid->add_pid = 0; |
| 328 | |
| 329 | return &package_appid->item; |
| 330 | } |
| 331 | |
| 332 | static ssize_t packages_attr_show(struct config_item *item, |
| 333 | char *page) |
| 334 | { |
| 335 | struct hashtable_entry *hash_cur; |
| 336 | struct hlist_node *h_t; |
| 337 | int i; |
Daniel Rosenberg | 0de3b4c | 2016-07-08 14:15:14 -0700 | [diff] [blame^] | 338 | int count = 0, written = 0; |
| 339 | char errormsg[] = "<truncated>\n"; |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 340 | |
Daniel Rosenberg | 0de3b4c | 2016-07-08 14:15:14 -0700 | [diff] [blame^] | 341 | mutex_lock(&pkgl_data_all->hashtable_lock); |
| 342 | hash_for_each_safe(pkgl_data_all->package_to_appid, i, h_t, hash_cur, hlist) { |
| 343 | written = scnprintf(page + count, PAGE_SIZE - sizeof(errormsg) - count, "%s %d\n", (char *)hash_cur->key, hash_cur->value); |
| 344 | if (count + written == PAGE_SIZE - sizeof(errormsg)) { |
| 345 | count += scnprintf(page + count, PAGE_SIZE - count, errormsg); |
| 346 | break; |
| 347 | } |
| 348 | count += written; |
| 349 | } |
| 350 | mutex_unlock(&pkgl_data_all->hashtable_lock); |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 351 | |
| 352 | return count; |
| 353 | } |
| 354 | |
| 355 | static struct configfs_attribute sdcardfs_packages_attr_description = { |
| 356 | .ca_owner = THIS_MODULE, |
| 357 | .ca_name = "packages_gid.list", |
| 358 | .ca_mode = S_IRUGO, |
| 359 | .show = packages_attr_show, |
| 360 | }; |
| 361 | |
| 362 | static struct configfs_attribute *sdcardfs_packages_attrs[] = { |
| 363 | &sdcardfs_packages_attr_description, |
| 364 | NULL, |
| 365 | }; |
| 366 | |
| 367 | static void sdcardfs_packages_release(struct config_item *item) |
| 368 | { |
| 369 | |
| 370 | printk(KERN_INFO "sdcardfs: destroyed something?\n"); |
| 371 | kfree(to_sdcardfs_packages(item)); |
| 372 | } |
| 373 | |
| 374 | static struct configfs_item_operations sdcardfs_packages_item_ops = { |
| 375 | .release = sdcardfs_packages_release, |
| 376 | }; |
| 377 | |
| 378 | /* |
| 379 | * Note that, since no extra work is required on ->drop_item(), |
| 380 | * no ->drop_item() is provided. |
| 381 | */ |
| 382 | static struct configfs_group_operations sdcardfs_packages_group_ops = { |
| 383 | .make_item = sdcardfs_packages_make_item, |
| 384 | }; |
| 385 | |
| 386 | static struct config_item_type sdcardfs_packages_type = { |
| 387 | .ct_item_ops = &sdcardfs_packages_item_ops, |
| 388 | .ct_group_ops = &sdcardfs_packages_group_ops, |
| 389 | .ct_attrs = sdcardfs_packages_attrs, |
| 390 | .ct_owner = THIS_MODULE, |
| 391 | }; |
| 392 | |
| 393 | static struct configfs_subsystem sdcardfs_packages_subsys = { |
| 394 | .su_group = { |
| 395 | .cg_item = { |
| 396 | .ci_namebuf = "sdcardfs", |
| 397 | .ci_type = &sdcardfs_packages_type, |
| 398 | }, |
| 399 | }, |
| 400 | }; |
| 401 | |
Daniel Rosenberg | cfdb665 | 2016-03-28 16:00:34 -0700 | [diff] [blame] | 402 | static int configfs_sdcardfs_init(void) |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 403 | { |
| 404 | int ret; |
| 405 | struct configfs_subsystem *subsys = &sdcardfs_packages_subsys; |
| 406 | |
| 407 | config_group_init(&subsys->su_group); |
| 408 | mutex_init(&subsys->su_mutex); |
| 409 | ret = configfs_register_subsystem(subsys); |
| 410 | if (ret) { |
| 411 | printk(KERN_ERR "Error %d while registering subsystem %s\n", |
| 412 | ret, |
| 413 | subsys->su_group.cg_item.ci_namebuf); |
| 414 | } |
| 415 | return ret; |
| 416 | } |
| 417 | |
Daniel Rosenberg | cfdb665 | 2016-03-28 16:00:34 -0700 | [diff] [blame] | 418 | static void configfs_sdcardfs_exit(void) |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 419 | { |
| 420 | configfs_unregister_subsystem(&sdcardfs_packages_subsys); |
| 421 | } |
| 422 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 423 | int packagelist_init(void) |
| 424 | { |
| 425 | hashtable_entry_cachep = |
| 426 | kmem_cache_create("packagelist_hashtable_entry", |
| 427 | sizeof(struct hashtable_entry), 0, 0, NULL); |
| 428 | if (!hashtable_entry_cachep) { |
| 429 | printk(KERN_ERR "sdcardfs: failed creating pkgl_hashtable entry slab cache\n"); |
| 430 | return -ENOMEM; |
| 431 | } |
| 432 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 433 | pkgl_data_all = packagelist_create(); |
| 434 | configfs_sdcardfs_init(); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | void packagelist_exit(void) |
| 439 | { |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 440 | configfs_sdcardfs_exit(); |
| 441 | packagelist_destroy(pkgl_data_all); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 442 | if (hashtable_entry_cachep) |
| 443 | kmem_cache_destroy(hashtable_entry_cachep); |
| 444 | } |