aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/super.c')
-rw-r--r--fs/jffs2/super.c194
1 files changed, 19 insertions, 175 deletions
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index e51164a8a8d4..e3c69e659efb 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -19,7 +19,7 @@
19#include <linux/mount.h> 19#include <linux/mount.h>
20#include <linux/jffs2.h> 20#include <linux/jffs2.h>
21#include <linux/pagemap.h> 21#include <linux/pagemap.h>
22#include <linux/mtd/mtd.h> 22#include <linux/mtd/super.h>
23#include <linux/ctype.h> 23#include <linux/ctype.h>
24#include <linux/namei.h> 24#include <linux/namei.h>
25#include "compr.h" 25#include "compr.h"
@@ -78,69 +78,27 @@ static const struct super_operations jffs2_super_operations =
78 .sync_fs = jffs2_sync_fs, 78 .sync_fs = jffs2_sync_fs,
79}; 79};
80 80
81static int jffs2_sb_compare(struct super_block *sb, void *data) 81/*
82{ 82 * fill in the superblock
83 struct jffs2_sb_info *p = data; 83 */
84 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 84static int jffs2_fill_super(struct super_block *sb, void *data, int silent)
85
86 /* The superblocks are considered to be equivalent if the underlying MTD
87 device is the same one */
88 if (c->mtd == p->mtd) {
89 D1(printk(KERN_DEBUG "jffs2_sb_compare: match on device %d (\"%s\")\n", p->mtd->index, p->mtd->name));
90 return 1;
91 } else {
92 D1(printk(KERN_DEBUG "jffs2_sb_compare: No match, device %d (\"%s\"), device %d (\"%s\")\n",
93 c->mtd->index, c->mtd->name, p->mtd->index, p->mtd->name));
94 return 0;
95 }
96}
97
98static int jffs2_sb_set(struct super_block *sb, void *data)
99{
100 struct jffs2_sb_info *p = data;
101
102 /* For persistence of NFS exports etc. we use the same s_dev
103 each time we mount the device, don't just use an anonymous
104 device */
105 sb->s_fs_info = p;
106 p->os_priv = sb;
107 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, p->mtd->index);
108
109 return 0;
110}
111
112static int jffs2_get_sb_mtd(struct file_system_type *fs_type,
113 int flags, const char *dev_name,
114 void *data, struct mtd_info *mtd,
115 struct vfsmount *mnt)
116{ 85{
117 struct super_block *sb;
118 struct jffs2_sb_info *c; 86 struct jffs2_sb_info *c;
119 int ret; 87
88 D1(printk(KERN_DEBUG "jffs2_get_sb_mtd():"
89 " New superblock for device %d (\"%s\")\n",
90 sb->s_mtd->index, sb->s_mtd->name));
120 91
121 c = kzalloc(sizeof(*c), GFP_KERNEL); 92 c = kzalloc(sizeof(*c), GFP_KERNEL);
122 if (!c) 93 if (!c)
123 return -ENOMEM; 94 return -ENOMEM;
124 c->mtd = mtd;
125
126 sb = sget(fs_type, jffs2_sb_compare, jffs2_sb_set, c);
127
128 if (IS_ERR(sb))
129 goto out_error;
130
131 if (sb->s_root) {
132 /* New mountpoint for JFFS2 which is already mounted */
133 D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): Device %d (\"%s\") is already mounted\n",
134 mtd->index, mtd->name));
135 ret = simple_set_mnt(mnt, sb);
136 goto out_put;
137 }
138 95
139 D1(printk(KERN_DEBUG "jffs2_get_sb_mtd(): New superblock for device %d (\"%s\")\n", 96 c->mtd = sb->s_mtd;
140 mtd->index, mtd->name)); 97 c->os_priv = sb;
98 sb->s_fs_info = c;
141 99
142 /* Initialize JFFS2 superblock locks, the further initialization will be 100 /* Initialize JFFS2 superblock locks, the further initialization will
143 * done later */ 101 * be done later */
144 init_MUTEX(&c->alloc_sem); 102 init_MUTEX(&c->alloc_sem);
145 init_MUTEX(&c->erase_free_sem); 103 init_MUTEX(&c->erase_free_sem);
146 init_waitqueue_head(&c->erase_wait); 104 init_waitqueue_head(&c->erase_wait);
@@ -149,133 +107,20 @@ static int jffs2_get_sb_mtd(struct file_system_type *fs_type,
149 spin_lock_init(&c->inocache_lock); 107 spin_lock_init(&c->inocache_lock);
150 108
151 sb->s_op = &jffs2_super_operations; 109 sb->s_op = &jffs2_super_operations;
152 sb->s_flags = flags | MS_NOATIME; 110 sb->s_flags = sb->s_flags | MS_NOATIME;
153 sb->s_xattr = jffs2_xattr_handlers; 111 sb->s_xattr = jffs2_xattr_handlers;
154#ifdef CONFIG_JFFS2_FS_POSIX_ACL 112#ifdef CONFIG_JFFS2_FS_POSIX_ACL
155 sb->s_flags |= MS_POSIXACL; 113 sb->s_flags |= MS_POSIXACL;
156#endif 114#endif
157 ret = jffs2_do_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); 115 return jffs2_do_fill_super(sb, data, silent);
158
159 if (ret) {
160 /* Failure case... */
161 up_write(&sb->s_umount);
162 deactivate_super(sb);
163 return ret;
164 }
165
166 sb->s_flags |= MS_ACTIVE;
167 return simple_set_mnt(mnt, sb);
168
169out_error:
170 ret = PTR_ERR(sb);
171 out_put:
172 kfree(c);
173 put_mtd_device(mtd);
174
175 return ret;
176}
177
178static int jffs2_get_sb_mtdnr(struct file_system_type *fs_type,
179 int flags, const char *dev_name,
180 void *data, int mtdnr,
181 struct vfsmount *mnt)
182{
183 struct mtd_info *mtd;
184
185 mtd = get_mtd_device(NULL, mtdnr);
186 if (IS_ERR(mtd)) {
187 D1(printk(KERN_DEBUG "jffs2: MTD device #%u doesn't appear to exist\n", mtdnr));
188 return PTR_ERR(mtd);
189 }
190
191 return jffs2_get_sb_mtd(fs_type, flags, dev_name, data, mtd, mnt);
192} 116}
193 117
194static int jffs2_get_sb(struct file_system_type *fs_type, 118static int jffs2_get_sb(struct file_system_type *fs_type,
195 int flags, const char *dev_name, 119 int flags, const char *dev_name,
196 void *data, struct vfsmount *mnt) 120 void *data, struct vfsmount *mnt)
197{ 121{
198 int err; 122 return get_sb_mtd(fs_type, flags, dev_name, data, jffs2_fill_super,
199 struct nameidata nd; 123 mnt);
200 int mtdnr;
201
202 if (!dev_name)
203 return -EINVAL;
204
205 D1(printk(KERN_DEBUG "jffs2_get_sb(): dev_name \"%s\"\n", dev_name));
206
207 /* The preferred way of mounting in future; especially when
208 CONFIG_BLK_DEV is implemented - we specify the underlying
209 MTD device by number or by name, so that we don't require
210 block device support to be present in the kernel. */
211
212 /* FIXME: How to do the root fs this way? */
213
214 if (dev_name[0] == 'm' && dev_name[1] == 't' && dev_name[2] == 'd') {
215 /* Probably mounting without the blkdev crap */
216 if (dev_name[3] == ':') {
217 struct mtd_info *mtd;
218
219 /* Mount by MTD device name */
220 D1(printk(KERN_DEBUG "jffs2_get_sb(): mtd:%%s, name \"%s\"\n", dev_name+4));
221 for (mtdnr = 0; mtdnr < MAX_MTD_DEVICES; mtdnr++) {
222 mtd = get_mtd_device(NULL, mtdnr);
223 if (!IS_ERR(mtd)) {
224 if (!strcmp(mtd->name, dev_name+4))
225 return jffs2_get_sb_mtd(fs_type, flags, dev_name, data, mtd, mnt);
226 put_mtd_device(mtd);
227 }
228 }
229 printk(KERN_NOTICE "jffs2_get_sb(): MTD device with name \"%s\" not found.\n", dev_name+4);
230 } else if (isdigit(dev_name[3])) {
231 /* Mount by MTD device number name */
232 char *endptr;
233
234 mtdnr = simple_strtoul(dev_name+3, &endptr, 0);
235 if (!*endptr) {
236 /* It was a valid number */
237 D1(printk(KERN_DEBUG "jffs2_get_sb(): mtd%%d, mtdnr %d\n", mtdnr));
238 return jffs2_get_sb_mtdnr(fs_type, flags, dev_name, data, mtdnr, mnt);
239 }
240 }
241 }
242
243 /* Try the old way - the hack where we allowed users to mount
244 /dev/mtdblock$(n) but didn't actually _use_ the blkdev */
245
246 err = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
247
248 D1(printk(KERN_DEBUG "jffs2_get_sb(): path_lookup() returned %d, inode %p\n",
249 err, nd.dentry->d_inode));
250
251 if (err)
252 return err;
253
254 err = -EINVAL;
255
256 if (!S_ISBLK(nd.dentry->d_inode->i_mode))
257 goto out;
258
259 if (nd.mnt->mnt_flags & MNT_NODEV) {
260 err = -EACCES;
261 goto out;
262 }
263
264 if (imajor(nd.dentry->d_inode) != MTD_BLOCK_MAJOR) {
265 if (!(flags & MS_SILENT))
266 printk(KERN_NOTICE "Attempt to mount non-MTD device \"%s\" as JFFS2\n",
267 dev_name);
268 goto out;
269 }
270
271 mtdnr = iminor(nd.dentry->d_inode);
272 path_release(&nd);
273
274 return jffs2_get_sb_mtdnr(fs_type, flags, dev_name, data, mtdnr, mnt);
275
276out:
277 path_release(&nd);
278 return err;
279} 124}
280 125
281static void jffs2_put_super (struct super_block *sb) 126static void jffs2_put_super (struct super_block *sb)
@@ -310,8 +155,7 @@ static void jffs2_kill_sb(struct super_block *sb)
310 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 155 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
311 if (!(sb->s_flags & MS_RDONLY)) 156 if (!(sb->s_flags & MS_RDONLY))
312 jffs2_stop_garbage_collect_thread(c); 157 jffs2_stop_garbage_collect_thread(c);
313 generic_shutdown_super(sb); 158 kill_mtd_super(sb);
314 put_mtd_device(c->mtd);
315 kfree(c); 159 kfree(c);
316} 160}
317 161