int journal_wipe(journal_t *journal, int write) { journal_superblock_t *sb; int err = 0; J_ASSERT (!(journal->j_flags & JFS_LOADED)); err = load_superblock(journal); if (err) return err; sb = journal->j_superblock; if (!journal->j_tail) goto no_recovery; printk (KERN_WARNING "JBD: %s recovery information on journal\n", write ? "Clearing" : "Ignoring"); err = journal_skip_recovery(journal); if (write) journal_update_superblock(journal, 1); no_recovery: return err; }
void ext2_init_fs() { load_superblock(); load_bgdt(); // Read the root inode, just for fun Ext2_inode root_inode; read_inode(&root_inode, ROOT_INODE); term_printf(" / creation time = %d\n", root_inode.creation_time); term_printf(" / uid = %d\n", root_inode.uid); term_printf(" / type & perms = 0x%X\n", root_inode.type_and_permissions); term_printf(" / size = %d\n", root_inode.size); // Enumerate the files in it term_puts(" / files:"); Ext2_file file; ext2_open_inode(ROOT_INODE, &file); Ext2_dirent dirent; while (ext2_next_dirent(&file, &dirent)) { term_printf(" inode %d, name `%s'\n", dirent.inode_num, dirent.name); } kfree(file.buf); // Look for a file term_putsn(" looking for file `/bar/baz/quux'..."); uint32_t inode = ext2_look_up_path("/bar/baz/quux"); if (inode == 0) term_puts(" not found"); else term_printf(" found: inode = %d\n", inode); }
/** * int journal_load() - Read journal from disk. * @journal: Journal to act on. * * Given a journal_t structure which tells us which disk blocks contain * a journal, read the journal from disk to initialise the in-memory * structures. */ int journal_load(journal_t *journal) { int err; journal_superblock_t *sb; err = load_superblock(journal); if (err) return err; sb = journal->j_superblock; /* If this is a V2 superblock, then we have to check the * features flags on it. */ if (journal->j_format_version >= 2) { if ((sb->s_feature_ro_compat & ~cpu_to_be32(JFS_KNOWN_ROCOMPAT_FEATURES)) || (sb->s_feature_incompat & ~cpu_to_be32(JFS_KNOWN_INCOMPAT_FEATURES))) { printk (KERN_WARNING "JBD: Unrecognised features on journal\n"); return -EINVAL; } } /* Let the recovery code check whether it needs to recover any * data from the journal. */ if (journal_recover(journal)) goto recovery_error; /* OK, we've finished with the dynamic journal bits: * reinitialise the dynamic contents of the superblock in memory * and reset them on disk. */ if (journal_reset(journal)) goto recovery_error; journal->j_flags &= ~JFS_ABORT; journal->j_flags |= JFS_LOADED; return 0; recovery_error: printk (KERN_WARNING "JBD: recovery failed\n"); return -EIO; }