main(int argc, char **argv) { errcode_t retval; char *device_name; ext2_filsys fs; if (argc < 2) { fprintf(stderr, "Usage: %s filesystem\n", argv[0]); exit(1); } device_name = argv[1]; retval = ext2fs_open (device_name, EXT2_FLAG_RW, 0, 0, unix_io_manager, &fs); if (retval) { com_err(argv[0], retval, "while opening %s", device_name); exit(1); } retval = ext2fs_add_journal_inode(fs, 1024, 0); if (retval) { com_err(argv[0], retval, "while adding journal to %s", device_name); exit(1); } retval = ext2fs_flush(fs); if (retval) { printf("Warning, had trouble writing out superblocks.\n"); } ext2fs_close(fs); exit(0); }
int e2fsck_run_ext3_journal(e2fsck_t ctx) { io_manager io_ptr = ctx->fs->io->manager; int blocksize = ctx->fs->blocksize; errcode_t retval, recover_retval; io_stats stats = 0; unsigned long long kbytes_written = 0; printf(_("%s: recovering journal\n"), ctx->device_name); if (ctx->options & E2F_OPT_READONLY) { printf(_("%s: won't do journal recovery while read-only\n"), ctx->device_name); return EXT2_ET_FILE_RO; } if (ctx->fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(ctx->fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(ctx); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ if (ctx->fs->super->s_kbytes_written && ctx->fs->io->manager->get_stats) ctx->fs->io->manager->get_stats(ctx->fs->io, &stats); if (stats && stats->bytes_written) kbytes_written = stats->bytes_written >> 10; ext2fs_mmp_stop(ctx->fs); ext2fs_free(ctx->fs); retval = ext2fs_open(ctx->filesystem_name, EXT2_FLAG_RW, ctx->superblock, blocksize, io_ptr, &ctx->fs); if (retval) { com_err(ctx->program_name, retval, _("while trying to re-open %s"), ctx->device_name); fatal_error(ctx, 0); } ctx->fs->priv_data = ctx; ctx->fs->now = ctx->now; ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; ctx->fs->super->s_kbytes_written += kbytes_written; /* Set the superblock flags */ e2fsck_clear_recover(ctx, recover_retval); /* * Do one last sanity check, and propagate journal->s_errno to * the EXT2_ERROR_FS flag in the fs superblock if needed. */ retval = e2fsck_check_ext3_journal(ctx); return retval ? retval : recover_retval; }
errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp) { ext2_filsys fs = *fsp; io_manager io_ptr = fs->io->manager; errcode_t retval, recover_retval; io_stats stats = 0; unsigned long long kbytes_written = 0; char *fsname; int fsflags; int fsblocksize; if (!(fs->flags & EXT2_FLAG_RW)) return EXT2_ET_FILE_RO; if (fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(fs); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ if (fs->super->s_kbytes_written && fs->io->manager->get_stats) fs->io->manager->get_stats(fs->io, &stats); if (stats && stats->bytes_written) kbytes_written = stats->bytes_written >> 10; ext2fs_mmp_stop(fs); fsname = strdup(fs->device_name); fsflags = fs->flags; fsblocksize = fs->blocksize; ext2fs_free(fs); retval = ext2fs_open(fsname, fsflags, 0, fsblocksize, io_ptr, fsp); free(fsname); if (retval) return retval; fs = *fsp; fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; fs->super->s_kbytes_written += kbytes_written; /* Set the superblock flags */ ext2fs_clear_recover(fs, recover_retval != 0); /* * Do one last sanity check, and propagate journal->s_errno to * the EXT2_ERROR_FS flag in the fs superblock if needed. */ retval = ext2fs_check_ext3_journal(fs); return retval ? retval : recover_retval; }
void swap_filesys(e2fsck_t ctx) { ext2_filsys fs = ctx->fs; #ifdef RESOURCE_TRACK struct resource_track rtrack; init_resource_track(&rtrack); #endif if (!(ctx->options & E2F_OPT_PREEN)) printf(_("Pass 0: Doing byte-swap of filesystem\n")); #ifdef MTRACE mtrace_print("Byte swap"); #endif if (fs->super->s_mnt_count) { fprintf(stderr, _("%s: the filesystem must be freshly " "checked using fsck\n" "and not mounted before trying to " "byte-swap it.\n"), ctx->device_name); ctx->flags |= E2F_FLAG_ABORT; return; } if (fs->flags & EXT2_FLAG_SWAP_BYTES) { fs->flags &= ~(EXT2_FLAG_SWAP_BYTES| EXT2_FLAG_SWAP_BYTES_WRITE); fs->flags |= EXT2_FLAG_SWAP_BYTES_READ; } else { fs->flags &= ~EXT2_FLAG_SWAP_BYTES_READ; fs->flags |= EXT2_FLAG_SWAP_BYTES_WRITE; } swap_inodes(ctx); if (ctx->flags & E2F_FLAG_SIGNAL_MASK) return; if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE) fs->flags |= EXT2_FLAG_SWAP_BYTES; fs->flags &= ~(EXT2_FLAG_SWAP_BYTES_READ| EXT2_FLAG_SWAP_BYTES_WRITE); #ifdef EXT2_BIG_ENDIAN_BITMAPS e2fsck_read_bitmaps(ctx); ext2fs_swap_bitmap(fs->inode_map); ext2fs_swap_bitmap(fs->block_map); fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY; #endif fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; ext2fs_flush(fs); fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; #ifdef RESOURCE_TRACK if (ctx->options & E2F_OPT_TIME2) print_resource_track(_("Byte swap"), &rtrack); #endif }
int op_fsync (const char *path, int datasync, struct fuse_file_info *fi) { errcode_t rc; ext2_filsys e2fs = current_ext2fs(); debugf("enter"); debugf("path = %s (%p)", path, fi); rc = ext2fs_flush(e2fs); if (rc) { return -EIO; } debugf("leave"); return 0; }
errcode_t ext2fs_close(ext2_filsys fs) { errcode_t retval; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); if (fs->flags & EXT2_FLAG_DIRTY) { retval = ext2fs_flush(fs); if (retval) return retval; } if (fs->write_bitmaps) { retval = fs->write_bitmaps(fs); if (retval) return retval; } ext2fs_free(fs); return 0; }
int e2fsck_run_ext3_journal(e2fsck_t ctx) { io_manager io_ptr = ctx->fs->io->manager; int blocksize = ctx->fs->blocksize; errcode_t retval, recover_retval; printf(_("%s: recovering journal\n"), ctx->device_name); if (ctx->options & E2F_OPT_READONLY) { printf(_("%s: won't do journal recovery while read-only\n"), ctx->device_name); return EXT2_ET_FILE_RO; } if (ctx->fs->flags & EXT2_FLAG_DIRTY) ext2fs_flush(ctx->fs); /* Force out any modifications */ recover_retval = recover_ext3_journal(ctx); /* * Reload the filesystem context to get up-to-date data from disk * because journal recovery will change the filesystem under us. */ ext2fs_close(ctx->fs); retval = ext2fs_open(ctx->filesystem_name, EXT2_FLAG_RW, ctx->superblock, blocksize, io_ptr, &ctx->fs); if (retval) { com_err(ctx->program_name, retval, _("while trying to re-open %s"), ctx->device_name); fatal_error(ctx, 0); } ctx->fs->priv_data = ctx; ctx->fs->now = ctx->now; ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; /* Set the superblock flags */ e2fsck_clear_recover(ctx, recover_retval); return recover_retval; }