blob: ba52af8644cc89b73c1149502f646f5ce15741d5 [file] [log] [blame]
Daniel Campello35c9e242015-07-20 16:23:50 -07001/*
2 * fs/sdcardfs/main.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"
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/parser.h>
25
26enum {
Daniel Rosenberg497ac902016-02-03 21:08:21 -080027 Opt_fsuid,
28 Opt_fsgid,
Daniel Campello35c9e242015-07-20 16:23:50 -070029 Opt_gid,
Daniel Campello35c9e242015-07-20 16:23:50 -070030 Opt_debug,
Daniel Rosenberg497ac902016-02-03 21:08:21 -080031 Opt_mask,
Daniel Rosenbergd64126c2017-03-16 19:33:35 -070032 Opt_multiuser,
Daniel Rosenberg497ac902016-02-03 21:08:21 -080033 Opt_userid,
Daniel Campello35c9e242015-07-20 16:23:50 -070034 Opt_reserved_mb,
Daniel Rosenberg7d10e432017-07-19 17:25:07 -070035 Opt_gid_derivation,
Daniel Rosenberg173c52e2018-01-02 14:44:49 -080036 Opt_default_normal,
Daniel Rosenberg80af4332018-07-06 16:24:27 -070037 Opt_nocache,
Daniel Campello35c9e242015-07-20 16:23:50 -070038 Opt_err,
39};
40
41static const match_table_t sdcardfs_tokens = {
Daniel Rosenberg497ac902016-02-03 21:08:21 -080042 {Opt_fsuid, "fsuid=%u"},
43 {Opt_fsgid, "fsgid=%u"},
Daniel Campello35c9e242015-07-20 16:23:50 -070044 {Opt_gid, "gid=%u"},
Daniel Campello35c9e242015-07-20 16:23:50 -070045 {Opt_debug, "debug"},
Daniel Rosenberg497ac902016-02-03 21:08:21 -080046 {Opt_mask, "mask=%u"},
47 {Opt_userid, "userid=%d"},
48 {Opt_multiuser, "multiuser"},
Daniel Rosenberg7d10e432017-07-19 17:25:07 -070049 {Opt_gid_derivation, "derive_gid"},
Daniel Rosenberg173c52e2018-01-02 14:44:49 -080050 {Opt_default_normal, "default_normal"},
Daniel Campello35c9e242015-07-20 16:23:50 -070051 {Opt_reserved_mb, "reserved_mb=%u"},
Daniel Rosenberg80af4332018-07-06 16:24:27 -070052 {Opt_nocache, "nocache"},
Daniel Campello35c9e242015-07-20 16:23:50 -070053 {Opt_err, NULL}
54};
55
56static int parse_options(struct super_block *sb, char *options, int silent,
Daniel Rosenberg317e7702016-10-26 17:36:05 -070057 int *debug, struct sdcardfs_vfsmount_options *vfsopts,
58 struct sdcardfs_mount_options *opts)
Daniel Campello35c9e242015-07-20 16:23:50 -070059{
60 char *p;
61 substring_t args[MAX_OPT_ARGS];
62 int option;
Daniel Campello35c9e242015-07-20 16:23:50 -070063
64 /* by default, we use AID_MEDIA_RW as uid, gid */
65 opts->fs_low_uid = AID_MEDIA_RW;
66 opts->fs_low_gid = AID_MEDIA_RW;
Daniel Rosenberg317e7702016-10-26 17:36:05 -070067 vfsopts->mask = 0;
Daniel Rosenberg497ac902016-02-03 21:08:21 -080068 opts->multiuser = false;
69 opts->fs_user_id = 0;
Daniel Rosenberg317e7702016-10-26 17:36:05 -070070 vfsopts->gid = 0;
Daniel Campello35c9e242015-07-20 16:23:50 -070071 /* by default, 0MB is reserved */
72 opts->reserved_mb = 0;
Daniel Rosenberg7d10e432017-07-19 17:25:07 -070073 /* by default, gid derivation is off */
74 opts->gid_derivation = false;
Daniel Rosenberge12a9c42018-01-18 16:17:16 -080075 opts->default_normal = false;
Daniel Rosenberg80af4332018-07-06 16:24:27 -070076 opts->nocache = false;
Daniel Campello35c9e242015-07-20 16:23:50 -070077
78 *debug = 0;
79
80 if (!options)
81 return 0;
82
83 while ((p = strsep(&options, ",")) != NULL) {
84 int token;
Daniel Rosenberg5e024f62017-03-16 17:42:58 -070085
Daniel Campello35c9e242015-07-20 16:23:50 -070086 if (!*p)
87 continue;
88
89 token = match_token(p, sdcardfs_tokens, args);
90
91 switch (token) {
92 case Opt_debug:
93 *debug = 1;
94 break;
Daniel Rosenberg497ac902016-02-03 21:08:21 -080095 case Opt_fsuid:
Daniel Campello35c9e242015-07-20 16:23:50 -070096 if (match_int(&args[0], &option))
97 return 0;
98 opts->fs_low_uid = option;
99 break;
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800100 case Opt_fsgid:
Daniel Campello35c9e242015-07-20 16:23:50 -0700101 if (match_int(&args[0], &option))
102 return 0;
103 opts->fs_low_gid = option;
104 break;
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800105 case Opt_gid:
Daniel Campello35c9e242015-07-20 16:23:50 -0700106 if (match_int(&args[0], &option))
107 return 0;
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700108 vfsopts->gid = option;
Daniel Campello35c9e242015-07-20 16:23:50 -0700109 break;
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800110 case Opt_userid:
111 if (match_int(&args[0], &option))
112 return 0;
113 opts->fs_user_id = option;
Daniel Campello35c9e242015-07-20 16:23:50 -0700114 break;
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800115 case Opt_mask:
116 if (match_int(&args[0], &option))
117 return 0;
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700118 vfsopts->mask = option;
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800119 break;
120 case Opt_multiuser:
121 opts->multiuser = true;
Daniel Campello35c9e242015-07-20 16:23:50 -0700122 break;
Daniel Campello35c9e242015-07-20 16:23:50 -0700123 case Opt_reserved_mb:
124 if (match_int(&args[0], &option))
125 return 0;
126 opts->reserved_mb = option;
127 break;
Daniel Rosenberg7d10e432017-07-19 17:25:07 -0700128 case Opt_gid_derivation:
129 opts->gid_derivation = true;
Daniel Rosenberg93babeb2017-09-08 17:20:06 -0700130 break;
Daniel Rosenberg173c52e2018-01-02 14:44:49 -0800131 case Opt_default_normal:
Daniel Rosenberge12a9c42018-01-18 16:17:16 -0800132 opts->default_normal = true;
Daniel Rosenberg14dbf602018-01-08 13:57:36 -0800133 break;
Daniel Rosenberg80af4332018-07-06 16:24:27 -0700134 case Opt_nocache:
135 opts->nocache = true;
136 break;
Daniel Campello35c9e242015-07-20 16:23:50 -0700137 /* unknown option */
138 default:
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700139 if (!silent)
140 pr_err("Unrecognized mount option \"%s\" or missing value", p);
Daniel Campello35c9e242015-07-20 16:23:50 -0700141 return -EINVAL;
142 }
143 }
144
145 if (*debug) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700146 pr_info("sdcardfs : options - debug:%d\n", *debug);
147 pr_info("sdcardfs : options - uid:%d\n",
Daniel Campello35c9e242015-07-20 16:23:50 -0700148 opts->fs_low_uid);
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700149 pr_info("sdcardfs : options - gid:%d\n",
Daniel Campello35c9e242015-07-20 16:23:50 -0700150 opts->fs_low_gid);
151 }
152
153 return 0;
154}
155
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700156int parse_options_remount(struct super_block *sb, char *options, int silent,
157 struct sdcardfs_vfsmount_options *vfsopts)
158{
159 char *p;
160 substring_t args[MAX_OPT_ARGS];
161 int option;
162 int debug;
163
164 if (!options)
165 return 0;
166
167 while ((p = strsep(&options, ",")) != NULL) {
168 int token;
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700169
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700170 if (!*p)
171 continue;
172
173 token = match_token(p, sdcardfs_tokens, args);
174
175 switch (token) {
176 case Opt_debug:
177 debug = 1;
178 break;
179 case Opt_gid:
180 if (match_int(&args[0], &option))
181 return 0;
182 vfsopts->gid = option;
183
184 break;
185 case Opt_mask:
186 if (match_int(&args[0], &option))
187 return 0;
188 vfsopts->mask = option;
189 break;
Daniel Rosenberg173c52e2018-01-02 14:44:49 -0800190 case Opt_default_normal:
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700191 case Opt_multiuser:
192 case Opt_userid:
193 case Opt_fsuid:
194 case Opt_fsgid:
195 case Opt_reserved_mb:
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700196 pr_warn("Option \"%s\" can't be changed during remount\n", p);
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700197 break;
198 /* unknown option */
199 default:
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700200 if (!silent)
201 pr_err("Unrecognized mount option \"%s\" or missing value", p);
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700202 return -EINVAL;
203 }
204 }
205
206 if (debug) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700207 pr_info("sdcardfs : options - debug:%d\n", debug);
208 pr_info("sdcardfs : options - gid:%d\n", vfsopts->gid);
209 pr_info("sdcardfs : options - mask:%d\n", vfsopts->mask);
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700210 }
211
212 return 0;
213}
214
Daniel Campellod1d080c2015-07-20 16:27:37 -0700215#if 0
Daniel Campello35c9e242015-07-20 16:23:50 -0700216/*
217 * our custom d_alloc_root work-alike
218 *
219 * we can't use d_alloc_root if we want to use our own interpose function
220 * unchanged, so we simply call our own "fake" d_alloc_root
221 */
222static struct dentry *sdcardfs_d_alloc_root(struct super_block *sb)
223{
224 struct dentry *ret = NULL;
225
226 if (sb) {
227 static const struct qstr name = {
228 .name = "/",
229 .len = 1
230 };
231
232 ret = d_alloc(NULL, &name);
233 if (ret) {
234 d_set_d_op(ret, &sdcardfs_ci_dops);
235 ret->d_sb = sb;
236 ret->d_parent = ret;
237 }
238 }
239 return ret;
240}
Daniel Campellod1d080c2015-07-20 16:27:37 -0700241#endif
Daniel Campello35c9e242015-07-20 16:23:50 -0700242
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800243DEFINE_MUTEX(sdcardfs_super_list_lock);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800244EXPORT_SYMBOL_GPL(sdcardfs_super_list_lock);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700245LIST_HEAD(sdcardfs_super_list);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800246EXPORT_SYMBOL_GPL(sdcardfs_super_list);
247
Daniel Campello35c9e242015-07-20 16:23:50 -0700248/*
249 * There is no need to lock the sdcardfs_super_info's rwsem as there is no
250 * way anyone can have a reference to the superblock at this point in time.
251 */
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700252static int sdcardfs_read_super(struct vfsmount *mnt, struct super_block *sb,
253 const char *dev_name, void *raw_data, int silent)
Daniel Campello35c9e242015-07-20 16:23:50 -0700254{
255 int err = 0;
256 int debug;
257 struct super_block *lower_sb;
258 struct path lower_path;
259 struct sdcardfs_sb_info *sb_info;
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700260 struct sdcardfs_vfsmount_options *mnt_opt = mnt->data;
Daniel Campellod1d080c2015-07-20 16:27:37 -0700261 struct inode *inode;
Daniel Campello35c9e242015-07-20 16:23:50 -0700262
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700263 pr_info("sdcardfs version 2.0\n");
Daniel Campello35c9e242015-07-20 16:23:50 -0700264
265 if (!dev_name) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700266 pr_err("sdcardfs: read_super: missing dev_name argument\n");
Daniel Campello35c9e242015-07-20 16:23:50 -0700267 err = -EINVAL;
268 goto out;
269 }
270
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700271 pr_info("sdcardfs: dev_name -> %s\n", dev_name);
272 pr_info("sdcardfs: options -> %s\n", (char *)raw_data);
273 pr_info("sdcardfs: mnt -> %p\n", mnt);
Daniel Campello35c9e242015-07-20 16:23:50 -0700274
275 /* parse lower path */
276 err = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
277 &lower_path);
278 if (err) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700279 pr_err("sdcardfs: error accessing lower directory '%s'\n", dev_name);
Daniel Campello35c9e242015-07-20 16:23:50 -0700280 goto out;
281 }
282
283 /* allocate superblock private data */
284 sb->s_fs_info = kzalloc(sizeof(struct sdcardfs_sb_info), GFP_KERNEL);
285 if (!SDCARDFS_SB(sb)) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700286 pr_crit("sdcardfs: read_super: out of memory\n");
Daniel Campello35c9e242015-07-20 16:23:50 -0700287 err = -ENOMEM;
288 goto out_free;
289 }
290
291 sb_info = sb->s_fs_info;
Daniel Campello35c9e242015-07-20 16:23:50 -0700292 /* parse options */
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700293 err = parse_options(sb, raw_data, silent, &debug, mnt_opt, &sb_info->options);
Daniel Campello35c9e242015-07-20 16:23:50 -0700294 if (err) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700295 pr_err("sdcardfs: invalid options\n");
Daniel Campello35c9e242015-07-20 16:23:50 -0700296 goto out_freesbi;
297 }
298
Daniel Campello35c9e242015-07-20 16:23:50 -0700299 /* set the lower superblock field of upper superblock */
300 lower_sb = lower_path.dentry->d_sb;
301 atomic_inc(&lower_sb->s_active);
302 sdcardfs_set_lower_super(sb, lower_sb);
303
Daniel Rosenberg99055912018-07-26 16:32:09 -0700304 sb->s_stack_depth = lower_sb->s_stack_depth + 1;
305 if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
306 pr_err("sdcardfs: maximum fs stacking depth exceeded\n");
307 err = -EINVAL;
308 goto out_sput;
309 }
310
Daniel Campello35c9e242015-07-20 16:23:50 -0700311 /* inherit maxbytes from lower file system */
312 sb->s_maxbytes = lower_sb->s_maxbytes;
313
314 /*
315 * Our c/m/atime granularity is 1 ns because we may stack on file
316 * systems whose granularity is as good.
317 */
318 sb->s_time_gran = 1;
319
320 sb->s_magic = SDCARDFS_SUPER_MAGIC;
321 sb->s_op = &sdcardfs_sops;
322
Daniel Campellod1d080c2015-07-20 16:27:37 -0700323 /* get a new inode and allocate our root dentry */
Daniel Rosenberg63d20762016-12-01 14:36:29 -0800324 inode = sdcardfs_iget(sb, d_inode(lower_path.dentry), 0);
Daniel Campellod1d080c2015-07-20 16:27:37 -0700325 if (IS_ERR(inode)) {
326 err = PTR_ERR(inode);
Daniel Campello35c9e242015-07-20 16:23:50 -0700327 goto out_sput;
328 }
Daniel Campellod1d080c2015-07-20 16:27:37 -0700329 sb->s_root = d_make_root(inode);
330 if (!sb->s_root) {
331 err = -ENOMEM;
Daniel Rosenberg8442aee2018-04-11 16:24:51 -0700332 goto out_sput;
Daniel Campellod1d080c2015-07-20 16:27:37 -0700333 }
334 d_set_d_op(sb->s_root, &sdcardfs_ci_dops);
Daniel Campello35c9e242015-07-20 16:23:50 -0700335
336 /* link the upper and lower dentries */
337 sb->s_root->d_fsdata = NULL;
338 err = new_dentry_private_data(sb->s_root);
339 if (err)
340 goto out_freeroot;
341
342 /* set the lower dentries for s_root */
343 sdcardfs_set_lower_path(sb->s_root, &lower_path);
344
Daniel Campellod1d080c2015-07-20 16:27:37 -0700345 /*
346 * No need to call interpose because we already have a positive
347 * dentry, which was instantiated by d_make_root. Just need to
348 * d_rehash it.
349 */
350 d_rehash(sb->s_root);
351
352 /* setup permission policy */
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800353 sb_info->obbpath_s = kzalloc(PATH_MAX, GFP_KERNEL);
354 mutex_lock(&sdcardfs_super_list_lock);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700355 if (sb_info->options.multiuser) {
356 setup_derived_state(d_inode(sb->s_root), PERM_PRE_ROOT,
Daniel Rosenberg47af77b2018-02-01 16:52:22 -0800357 sb_info->options.fs_user_id, AID_ROOT);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800358 snprintf(sb_info->obbpath_s, PATH_MAX, "%s/obb", dev_name);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800359 } else {
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700360 setup_derived_state(d_inode(sb->s_root), PERM_ROOT,
Daniel Rosenberg47af77b2018-02-01 16:52:22 -0800361 sb_info->options.fs_user_id, AID_ROOT);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800362 snprintf(sb_info->obbpath_s, PATH_MAX, "%s/Android/obb", dev_name);
Daniel Campello35c9e242015-07-20 16:23:50 -0700363 }
Daniel Rosenberg90219272016-10-26 20:27:20 -0700364 fixup_tmp_permissions(d_inode(sb->s_root));
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800365 sb_info->sb = sb;
366 list_add(&sb_info->list, &sdcardfs_super_list);
367 mutex_unlock(&sdcardfs_super_list_lock);
Daniel Campello35c9e242015-07-20 16:23:50 -0700368
Daniel Campellod1d080c2015-07-20 16:27:37 -0700369 if (!silent)
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700370 pr_info("sdcardfs: mounted on top of %s type %s\n",
Daniel Campellod1d080c2015-07-20 16:27:37 -0700371 dev_name, lower_sb->s_type->name);
372 goto out; /* all is well */
373
374 /* no longer needed: free_dentry_private_data(sb->s_root); */
Daniel Campello35c9e242015-07-20 16:23:50 -0700375out_freeroot:
376 dput(sb->s_root);
Daniel Rosenberg132f0972018-04-11 18:39:43 -0700377 sb->s_root = NULL;
Daniel Campello35c9e242015-07-20 16:23:50 -0700378out_sput:
379 /* drop refs we took earlier */
380 atomic_dec(&lower_sb->s_active);
Daniel Campello35c9e242015-07-20 16:23:50 -0700381out_freesbi:
382 kfree(SDCARDFS_SB(sb));
383 sb->s_fs_info = NULL;
384out_free:
385 path_put(&lower_path);
386
387out:
388 return err;
389}
390
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800391struct sdcardfs_mount_private {
392 struct vfsmount *mnt;
393 const char *dev_name;
394 void *raw_data;
395};
Daniel Campello35c9e242015-07-20 16:23:50 -0700396
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800397static int __sdcardfs_fill_super(
398 struct super_block *sb,
399 void *_priv, int silent)
Daniel Campello35c9e242015-07-20 16:23:50 -0700400{
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800401 struct sdcardfs_mount_private *priv = _priv;
Daniel Campello35c9e242015-07-20 16:23:50 -0700402
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800403 return sdcardfs_read_super(priv->mnt,
404 sb, priv->dev_name, priv->raw_data, silent);
Daniel Campello35c9e242015-07-20 16:23:50 -0700405}
406
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700407static struct dentry *sdcardfs_mount(struct vfsmount *mnt,
408 struct file_system_type *fs_type, int flags,
Daniel Campello35c9e242015-07-20 16:23:50 -0700409 const char *dev_name, void *raw_data)
410{
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800411 struct sdcardfs_mount_private priv = {
412 .mnt = mnt,
413 .dev_name = dev_name,
414 .raw_data = raw_data
415 };
416
417 return mount_nodev(fs_type, flags,
418 &priv, __sdcardfs_fill_super);
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700419}
420
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700421static struct dentry *sdcardfs_mount_wrn(struct file_system_type *fs_type,
422 int flags, const char *dev_name, void *raw_data)
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700423{
424 WARN(1, "sdcardfs does not support mount. Use mount2.\n");
425 return ERR_PTR(-EINVAL);
426}
427
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700428void *sdcardfs_alloc_mnt_data(void)
429{
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700430 return kmalloc(sizeof(struct sdcardfs_vfsmount_options), GFP_KERNEL);
Daniel Campello35c9e242015-07-20 16:23:50 -0700431}
432
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700433void sdcardfs_kill_sb(struct super_block *sb)
434{
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800435 struct sdcardfs_sb_info *sbi;
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700436
Daniel Rosenberga0838172018-04-11 16:19:10 -0700437 if (sb->s_magic == SDCARDFS_SUPER_MAGIC && sb->s_fs_info) {
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800438 sbi = SDCARDFS_SB(sb);
439 mutex_lock(&sdcardfs_super_list_lock);
440 list_del(&sbi->list);
441 mutex_unlock(&sdcardfs_super_list_lock);
442 }
Gao Xiangb2ac1fd2017-05-09 12:30:56 +0800443 kill_anon_super(sb);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800444}
445
Daniel Campello35c9e242015-07-20 16:23:50 -0700446static struct file_system_type sdcardfs_fs_type = {
447 .owner = THIS_MODULE,
448 .name = SDCARDFS_NAME,
Daniel Rosenberg317e7702016-10-26 17:36:05 -0700449 .mount = sdcardfs_mount_wrn,
450 .mount2 = sdcardfs_mount,
451 .alloc_mnt_data = sdcardfs_alloc_mnt_data,
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800452 .kill_sb = sdcardfs_kill_sb,
Daniel Campellod1d080c2015-07-20 16:27:37 -0700453 .fs_flags = 0,
Daniel Campello35c9e242015-07-20 16:23:50 -0700454};
Daniel Rosenberg35ba5f62017-03-09 20:59:18 -0800455MODULE_ALIAS_FS(SDCARDFS_NAME);
Daniel Campello35c9e242015-07-20 16:23:50 -0700456
457static int __init init_sdcardfs_fs(void)
458{
459 int err;
460
461 pr_info("Registering sdcardfs " SDCARDFS_VERSION "\n");
462
463 err = sdcardfs_init_inode_cache();
464 if (err)
465 goto out;
466 err = sdcardfs_init_dentry_cache();
467 if (err)
468 goto out;
469 err = packagelist_init();
470 if (err)
471 goto out;
472 err = register_filesystem(&sdcardfs_fs_type);
473out:
474 if (err) {
475 sdcardfs_destroy_inode_cache();
476 sdcardfs_destroy_dentry_cache();
477 packagelist_exit();
478 }
479 return err;
480}
481
482static void __exit exit_sdcardfs_fs(void)
483{
484 sdcardfs_destroy_inode_cache();
485 sdcardfs_destroy_dentry_cache();
486 packagelist_exit();
487 unregister_filesystem(&sdcardfs_fs_type);
488 pr_info("Completed sdcardfs module unload\n");
489}
490
Daniel Rosenberg75665df2017-03-09 20:56:05 -0800491/* Original wrapfs authors */
492MODULE_AUTHOR("Erez Zadok, Filesystems and Storage Lab, Stony Brook University (http://www.fsl.cs.sunysb.edu/)");
493
494/* Original sdcardfs authors */
495MODULE_AUTHOR("Woojoong Lee, Daeho Jeong, Kitae Lee, Yeongjin Gil System Memory Lab., Samsung Electronics");
496
497/* Current maintainer */
498MODULE_AUTHOR("Daniel Rosenberg, Google");
499MODULE_DESCRIPTION("Sdcardfs " SDCARDFS_VERSION);
Daniel Campello35c9e242015-07-20 16:23:50 -0700500MODULE_LICENSE("GPL");
501
502module_init(init_sdcardfs_fs);
503module_exit(exit_sdcardfs_fs);