14 #include <linux/slab.h>
16 #include <linux/module.h>
22 static struct page *emergency_page;
43 return emergency_page;
48 if (page == emergency_page)
60 for (segno = 0; segno < super->
s_no_segs; segno++) {
64 if (++segno < super->s_no_segs) {
69 if (++segno < super->s_no_segs) {
74 if (++segno < super->s_no_segs) {
113 static int logfs_sb_set(
struct super_block *sb,
void *_super)
122 sb->
s_bdi = &bdev_get_queue(sb->
s_bdev)->backing_dev_info;
131 static int logfs_sb_test(
struct super_block *sb,
void *_super)
136 if (mtd && sb->
s_mtd == mtd)
162 memset(ds, 0,
sizeof(*ds));
163 set_segment_header(sh,
SEG_SUPER, 0, segno, ec);
181 ds->ds_journal_seg[i] =
cpu_to_be32(super->s_journal_seg[i]);
183 ds->ds_crc = logfs_crc32(ds,
sizeof(*ds),
198 page = find_sb(sb, &ofs);
202 segno = seg_no(sb, ofs);
207 logfs_write_ds(sb, ds, segno, ec);
208 err = super->
s_devops->write_sb(sb, page);
219 err = write_one_sb(sb, super->
s_devops->find_first_sb);
224 err = write_one_sb(sb, super->
s_devops->find_last_sb);
230 static int ds_cmp(
const void *ds0,
const void *ds1)
238 return memcmp(ds0, ds1, len);
241 static int logfs_recover_sb(
struct super_block *sb)
246 int err, valid0, valid1;
259 if (!valid0 && valid1) {
261 return write_one_sb(sb, super->
s_devops->find_first_sb);
263 if (valid0 && !valid1) {
265 return write_one_sb(sb, super->
s_devops->find_last_sb);
267 if (valid0 && valid1 && ds_cmp(ds0, ds1)) {
273 BUG_ON(!valid0 && !valid1);
277 static int logfs_make_writeable(
struct super_block *sb)
286 err = logfs_recover_sb(sb);
307 static int logfs_get_sb_final(
struct super_block *sb)
310 struct inode *rootdir;
329 err = logfs_make_writeable(sb);
351 if (sh->
crc != logfs_crc32(sh, LOGFS_SEGMENT_HEADERSIZE, 4))
353 if (ds->
ds_crc != logfs_crc32(ds,
sizeof(*ds),
354 LOGFS_SEGMENT_HEADERSIZE + 12))
359 static struct page *find_super_block(
struct super_block *sb)
365 if (!first || IS_ERR(first))
368 if (!last || IS_ERR(last)) {
397 page = find_super_block(sb);
426 super->s_total_levels = super->s_ifile_levels + super->s_iblock_levels
427 + super->s_data_levels;
450 ret = __logfs_read_sb(sb);
509 log_super(
"LogFS: Finished unmounting\n");
517 static int mount_count;
519 log_super(
"LogFS: Start mount %x\n", mount_count++);
522 sb =
sget(type, logfs_sb_test, logfs_sb_set, flags |
MS_NOATIME, super);
551 err = logfs_get_sb_final(sb);
568 const char *devname,
void *
data)
584 else if (
strncmp(devname,
"mtd", 3))
600 return logfs_get_sb_device(super, type, flags);
606 .mount = logfs_mount,
607 .kill_sb = logfs_kill_sb,
612 static int __init logfs_init(
void)
639 static void __exit logfs_exit(
void)