4 * Copyright (c) 2013 Samsung Electronics Co. Ltd
5 * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
6 * Sunghwan Yun, Sungjong Seo
8 * This program has been developed as a stackable file system based on
9 * the WrapFS which written by
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
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.
24 * The inode cache is used with alloc_inode for both our inode info and the
27 static struct kmem_cache *sdcardfs_inode_cachep;
29 /* final actions when unmounting a file system */
30 static void sdcardfs_put_super(struct super_block *sb)
32 struct sdcardfs_sb_info *spd;
33 struct super_block *s;
35 spd = SDCARDFS_SB(sb);
40 kfree(spd->obbpath_s);
41 path_put(&spd->obbpath);
44 /* decrement lower super references */
45 s = sdcardfs_lower_super(sb);
46 sdcardfs_set_lower_super(sb, NULL);
47 atomic_dec(&s->s_active);
50 packagelist_destroy(spd->pkgl_id);
56 static int sdcardfs_statfs(struct dentry *dentry, struct kstatfs *buf)
59 struct path lower_path;
61 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
63 sdcardfs_get_lower_path(dentry, &lower_path);
64 err = vfs_statfs(&lower_path, buf);
65 sdcardfs_put_lower_path(dentry, &lower_path);
67 if (sbi->options.reserved_mb) {
68 /* Invalid statfs informations. */
69 if (buf->f_bsize == 0) {
70 printk(KERN_ERR "Returned block size is zero.\n");
74 min_blocks = ((sbi->options.reserved_mb * 1024 * 1024)/buf->f_bsize);
75 buf->f_blocks -= min_blocks;
77 if (buf->f_bavail > min_blocks)
78 buf->f_bavail -= min_blocks;
82 /* Make reserved blocks invisiable to media storage */
83 buf->f_bfree = buf->f_bavail;
86 /* set return buf to our f/s to avoid confusing user-level utils */
87 buf->f_type = SDCARDFS_SUPER_MAGIC;
93 * @flags: numeric mount options
94 * @options: mount options string
96 static int sdcardfs_remount_fs(struct super_block *sb, int *flags, char *options)
101 * The VFS will take care of "ro" and "rw" flags among others. We
102 * can safely accept a few flags (RDONLY, MANDLOCK), and honor
103 * SILENT, but anything else left over is an error.
105 if ((*flags & ~(MS_RDONLY | MS_MANDLOCK | MS_SILENT)) != 0) {
107 "sdcardfs: remount flags 0x%x unsupported\n", *flags);
115 * Called by iput() when the inode reference count reached zero
116 * and the inode is not hashed anywhere. Used to clear anything
117 * that needs to be, before the inode is completely destroyed and put
118 * on the inode free list.
120 static void sdcardfs_evict_inode(struct inode *inode)
122 struct inode *lower_inode;
124 truncate_inode_pages(&inode->i_data, 0);
127 * Decrement a reference to a lower_inode, which was incremented
128 * by our read_inode when it was created initially.
130 lower_inode = sdcardfs_lower_inode(inode);
131 sdcardfs_set_lower_inode(inode, NULL);
135 static struct inode *sdcardfs_alloc_inode(struct super_block *sb)
137 struct sdcardfs_inode_info *i;
139 i = kmem_cache_alloc(sdcardfs_inode_cachep, GFP_KERNEL);
143 /* memset everything up to the inode to 0 */
144 memset(i, 0, offsetof(struct sdcardfs_inode_info, vfs_inode));
146 i->vfs_inode.i_version = 1;
147 return &i->vfs_inode;
150 static void sdcardfs_destroy_inode(struct inode *inode)
152 kmem_cache_free(sdcardfs_inode_cachep, SDCARDFS_I(inode));
155 /* sdcardfs inode cache constructor */
156 static void init_once(void *obj)
158 struct sdcardfs_inode_info *i = obj;
160 inode_init_once(&i->vfs_inode);
163 int sdcardfs_init_inode_cache(void)
167 sdcardfs_inode_cachep =
168 kmem_cache_create("sdcardfs_inode_cache",
169 sizeof(struct sdcardfs_inode_info), 0,
170 SLAB_RECLAIM_ACCOUNT, init_once);
171 if (!sdcardfs_inode_cachep)
176 /* sdcardfs inode cache destructor */
177 void sdcardfs_destroy_inode_cache(void)
179 if (sdcardfs_inode_cachep)
180 kmem_cache_destroy(sdcardfs_inode_cachep);
184 * Used only in nfs, to kill any pending RPC tasks, so that subsequent
185 * code can actually succeed and won't leave tasks that need handling.
187 static void sdcardfs_umount_begin(struct super_block *sb)
189 struct super_block *lower_sb;
191 lower_sb = sdcardfs_lower_super(sb);
192 if (lower_sb && lower_sb->s_op && lower_sb->s_op->umount_begin)
193 lower_sb->s_op->umount_begin(lower_sb);
196 static int sdcardfs_show_options(struct seq_file *m, struct dentry *root)
198 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(root->d_sb);
199 struct sdcardfs_mount_options *opts = &sbi->options;
201 if (opts->fs_low_uid != 0)
202 seq_printf(m, ",uid=%u", opts->fs_low_uid);
203 if (opts->fs_low_gid != 0)
204 seq_printf(m, ",gid=%u", opts->fs_low_gid);
206 if (opts->derive == DERIVE_NONE)
207 seq_printf(m, ",derive=none");
208 else if (opts->derive == DERIVE_LEGACY)
209 seq_printf(m, ",derive=legacy");
210 else if (opts->derive == DERIVE_UNIFIED)
211 seq_printf(m, ",derive=unified");
213 if (opts->reserved_mb != 0)
214 seq_printf(m, ",reserved=%uMB", opts->reserved_mb);
219 const struct super_operations sdcardfs_sops = {
220 .put_super = sdcardfs_put_super,
221 .statfs = sdcardfs_statfs,
222 .remount_fs = sdcardfs_remount_fs,
223 .evict_inode = sdcardfs_evict_inode,
224 .umount_begin = sdcardfs_umount_begin,
225 .show_options = sdcardfs_show_options,
226 .alloc_inode = sdcardfs_alloc_inode,
227 .destroy_inode = sdcardfs_destroy_inode,
228 .drop_inode = generic_delete_inode,