Whamcloud - gitweb
ext2fs: rename "s_overhead_blocks" to "s_overhead_clusters"
[tools/e2fsprogs.git] / debugfs / do_journal.c
index b8c1e59..48b2149 100644 (file)
@@ -85,10 +85,10 @@ static errcode_t journal_commit_trans(journal_transaction_t *trans)
 
        /* write the descriptor block header */
        commit = (struct commit_header *)bh->b_data;
-       commit->h_magic = ext2fs_cpu_to_be32(JFS_MAGIC_NUMBER);
-       commit->h_blocktype = ext2fs_cpu_to_be32(JFS_COMMIT_BLOCK);
+       commit->h_magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER);
+       commit->h_blocktype = ext2fs_cpu_to_be32(JBD2_COMMIT_BLOCK);
        commit->h_sequence = ext2fs_cpu_to_be32(trans->tid);
-       if (jfs_has_feature_checksum(trans->journal)) {
+       if (jbd2_has_feature_checksum(trans->journal)) {
                __u32 csum_v1 = ~0;
                blk64_t cblk;
 
@@ -100,12 +100,12 @@ static errcode_t journal_commit_trans(journal_transaction_t *trans)
                }
 
                for (cblk = trans->start; cblk < trans->block; cblk++) {
-                       err = journal_bmap(trans->journal, cblk,
-                                          &cbh->b_blocknr);
+                       err = jbd2_journal_bmap(trans->journal, cblk,
+                                               &cbh->b_blocknr);
                        if (err)
                                goto error;
                        mark_buffer_uptodate(cbh, 0);
-                       ll_rw_block(READ, 1, &cbh);
+                       ll_rw_block(REQ_OP_READ, 0, 1, &cbh);
                        err = cbh->b_err;
                        if (err)
                                goto error;
@@ -114,8 +114,8 @@ static errcode_t journal_commit_trans(journal_transaction_t *trans)
                                        cbh->b_size);
                }
 
-               commit->h_chksum_type = JFS_CRC32_CHKSUM;
-               commit->h_chksum_size = JFS_CRC32_CHKSUM_SIZE;
+               commit->h_chksum_type = JBD2_CRC32_CHKSUM;
+               commit->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
                commit->h_chksum[0] = ext2fs_cpu_to_be32(csum_v1);
        } else {
                commit->h_chksum_type = 0;
@@ -133,14 +133,14 @@ static errcode_t journal_commit_trans(journal_transaction_t *trans)
 
        /* Write block */
        jbd2_commit_block_csum_set(trans->journal, bh);
-       err = journal_bmap(trans->journal, trans->block, &bh->b_blocknr);
+       err = jbd2_journal_bmap(trans->journal, trans->block, &bh->b_blocknr);
        if (err)
                goto error;
 
        dbg_printf("Writing commit block at %llu:%llu\n", trans->block,
                   bh->b_blocknr);
        mark_buffer_dirty(bh);
-       ll_rw_block(WRITE, 1, &bh);
+       ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
        err = bh->b_err;
        if (err)
                goto error;
@@ -161,11 +161,12 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
                                             blk64_t *revoke_list,
                                             size_t revoke_len)
 {
-       journal_revoke_header_t *jrb;
+       jbd2_journal_revoke_header_t *jrb;
        void *buf;
        size_t i, offset;
        blk64_t curr_blk;
-       int sz, csum_size = 0;
+       unsigned int sz;
+       unsigned csum_size = 0;
        struct buffer_head *bh;
        errcode_t err;
 
@@ -179,8 +180,8 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
                return 0;
 
        /* Do we need to leave space at the end for a checksum? */
-       if (journal_has_csum_v2or3(trans->journal))
-               csum_size = sizeof(struct journal_revoke_tail);
+       if (jbd2_journal_has_csum_v2or3(trans->journal))
+               csum_size = sizeof(struct jbd2_journal_block_tail);
 
        curr_blk = trans->block;
 
@@ -189,12 +190,12 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
        if (bh == NULL)
                return ENOMEM;
        jrb = buf = bh->b_data;
-       jrb->r_header.h_magic = ext2fs_cpu_to_be32(JFS_MAGIC_NUMBER);
-       jrb->r_header.h_blocktype = ext2fs_cpu_to_be32(JFS_REVOKE_BLOCK);
+       jrb->r_header.h_magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER);
+       jrb->r_header.h_blocktype = ext2fs_cpu_to_be32(JBD2_REVOKE_BLOCK);
        jrb->r_header.h_sequence = ext2fs_cpu_to_be32(trans->tid);
        offset = sizeof(*jrb);
 
-       if (jfs_has_feature_64bit(trans->journal))
+       if (jbd2_has_feature_64bit(trans->journal))
                sz = 8;
        else
                sz = 4;
@@ -205,14 +206,14 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
                        jrb->r_count = ext2fs_cpu_to_be32(offset);
                        jbd2_revoke_csum_set(trans->journal, bh);
 
-                       err = journal_bmap(trans->journal, curr_blk,
-                                          &bh->b_blocknr);
+                       err = jbd2_journal_bmap(trans->journal, curr_blk,
+                                               &bh->b_blocknr);
                        if (err)
                                goto error;
                        dbg_printf("Writing revoke block at %llu:%llu\n",
                                   curr_blk, bh->b_blocknr);
                        mark_buffer_dirty(bh);
-                       ll_rw_block(WRITE, 1, &bh);
+                       ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
                        err = bh->b_err;
                        if (err)
                                goto error;
@@ -227,7 +228,7 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
                        goto error;
                }
 
-               if (jfs_has_feature_64bit(trans->journal))
+               if (jbd2_has_feature_64bit(trans->journal))
                        *((__u64 *)(&((char *)buf)[offset])) =
                                ext2fs_cpu_to_be64(revoke_list[i]);
                else
@@ -240,13 +241,14 @@ static errcode_t journal_add_revoke_to_trans(journal_transaction_t *trans,
                jrb->r_count = ext2fs_cpu_to_be32(offset);
                jbd2_revoke_csum_set(trans->journal, bh);
 
-               err = journal_bmap(trans->journal, curr_blk, &bh->b_blocknr);
+               err = jbd2_journal_bmap(trans->journal, curr_blk,
+                                       &bh->b_blocknr);
                if (err)
                        goto error;
                dbg_printf("Writing revoke block at %llu:%llu\n",
                           curr_blk, bh->b_blocknr);
                mark_buffer_dirty(bh);
-               ll_rw_block(WRITE, 1, &bh);
+               ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
                err = bh->b_err;
                if (err)
                        goto error;
@@ -283,8 +285,8 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
                return 0;
 
        /* Do we need to leave space at the end for a checksum? */
-       if (journal_has_csum_v2or3(trans->journal))
-               csum_size = sizeof(struct journal_block_tail);
+       if (jbd2_journal_has_csum_v2or3(trans->journal))
+               csum_size = sizeof(struct jbd2_journal_block_tail);
 
        curr_blk = jdb_blk = trans->block;
 
@@ -302,8 +304,8 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
                goto error;
        }
        jdb = jdb_buf = bh->b_data;
-       jdb->h_magic = ext2fs_cpu_to_be32(JFS_MAGIC_NUMBER);
-       jdb->h_blocktype = ext2fs_cpu_to_be32(JFS_DESCRIPTOR_BLOCK);
+       jdb->h_magic = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER);
+       jdb->h_blocktype = ext2fs_cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
        jdb->h_sequence = ext2fs_cpu_to_be32(trans->tid);
        jdbt = (journal_block_tag_t *)(jdb + 1);
 
@@ -321,14 +323,14 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
                if ((char *)jdbt + tag_bytes >
                    (char *)jdb_buf + trans->journal->j_blocksize - csum_size) {
                        jbd2_descr_block_csum_set(trans->journal, bh);
-                       err = journal_bmap(trans->journal, jdb_blk,
+                       err = jbd2_journal_bmap(trans->journal, jdb_blk,
                                           &bh->b_blocknr);
                        if (err)
                                goto error;
                        dbg_printf("Writing descriptor block at %llu:%llu\n",
                                   jdb_blk, bh->b_blocknr);
                        mark_buffer_dirty(bh);
-                       ll_rw_block(WRITE, 1, &bh);
+                       ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
                        err = bh->b_err;
                        if (err)
                                goto error;
@@ -348,7 +350,7 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
                jdbt->t_blocknr = ext2fs_cpu_to_be32(block_list[i] & 0xFFFFFFFF);
                jdbt->t_flags = 0;
                if (jdbt != (journal_block_tag_t *)(jdb + 1))
-                       jdbt->t_flags |= ext2fs_cpu_to_be16(JFS_FLAG_SAME_UUID);
+                       jdbt->t_flags |= ext2fs_cpu_to_be16(JBD2_FLAG_SAME_UUID);
                else {
                        memcpy(jdbt + tag_bytes,
                               trans->journal->j_superblock->s_uuid,
@@ -356,26 +358,26 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
                        tag_bytes += 16;
                }
                if (i == block_len - 1)
-                       jdbt->t_flags |= ext2fs_cpu_to_be16(JFS_FLAG_LAST_TAG);
-               if (*((__u32 *)buf) == ext2fs_cpu_to_be32(JFS_MAGIC_NUMBER)) {
+                       jdbt->t_flags |= ext2fs_cpu_to_be16(JBD2_FLAG_LAST_TAG);
+               if (*((__u32 *)buf) == ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER)) {
                        *((__u32 *)buf) = 0;
-                       jdbt->t_flags |= ext2fs_cpu_to_be16(JFS_FLAG_ESCAPE);
+                       jdbt->t_flags |= ext2fs_cpu_to_be16(JBD2_FLAG_ESCAPE);
                }
-               if (jfs_has_feature_64bit(trans->journal))
+               if (jbd2_has_feature_64bit(trans->journal))
                        jdbt->t_blocknr_high = ext2fs_cpu_to_be32(block_list[i] >> 32);
                jbd2_block_tag_csum_set(trans->journal, jdbt, data_bh,
                                        trans->tid);
 
                /* Write the data block */
-               err = journal_bmap(trans->journal, curr_blk,
-                                  &data_bh->b_blocknr);
+               err = jbd2_journal_bmap(trans->journal, curr_blk,
+                                       &data_bh->b_blocknr);
                if (err)
                        goto error;
                dbg_printf("Writing data block %llu at %llu:%llu tag %d\n",
                           block_list[i], curr_blk, data_bh->b_blocknr,
                           tag_bytes);
                mark_buffer_dirty(data_bh);
-               ll_rw_block(WRITE, 1, &data_bh);
+               ll_rw_block(REQ_OP_WRITE, 0, 1, &data_bh);
                err = data_bh->b_err;
                if (err)
                        goto error;
@@ -387,13 +389,14 @@ static errcode_t journal_add_blocks_to_trans(journal_transaction_t *trans,
        /* Write out the last descriptor block */
        if (jdbt != (journal_block_tag_t *)(jdb + 1)) {
                jbd2_descr_block_csum_set(trans->journal, bh);
-               err = journal_bmap(trans->journal, jdb_blk, &bh->b_blocknr);
+               err = jbd2_journal_bmap(trans->journal, jdb_blk,
+                                       &bh->b_blocknr);
                if (err)
                        goto error;
                dbg_printf("Writing descriptor block at %llu:%llu\n",
                           jdb_blk, bh->b_blocknr);
                mark_buffer_dirty(bh);
-               ll_rw_block(WRITE, 1, &bh);
+               ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
                err = bh->b_err;
                if (err)
                        goto error;
@@ -415,15 +418,15 @@ static blk64_t journal_guess_blocks(journal_t *journal, blk64_t data_blocks,
 
        /* Estimate # of revoke blocks */
        bs = journal->j_blocksize;
-       if (journal_has_csum_v2or3(journal))
-               bs -= sizeof(struct journal_revoke_tail);
-       sz = jfs_has_feature_64bit(journal) ? sizeof(__u64) : sizeof(__u32);
+       if (jbd2_journal_has_csum_v2or3(journal))
+               bs -= sizeof(struct jbd2_journal_block_tail);
+       sz = jbd2_has_feature_64bit(journal) ? sizeof(__u64) : sizeof(__u32);
        ret += revoke_blocks * sz / bs;
 
        /* Estimate # of data blocks */
        bs = journal->j_blocksize - 16;
-       if (journal_has_csum_v2or3(journal))
-               bs -= sizeof(struct journal_block_tail);
+       if (jbd2_journal_has_csum_v2or3(journal))
+               bs -= sizeof(struct jbd2_journal_block_tail);
        sz = journal_tag_bytes(journal);
        ret += data_blocks * sz / bs;
 
@@ -503,7 +506,7 @@ static errcode_t journal_write(journal_t *journal,
        errcode_t err;
 
        if (revoke_len > 0) {
-               jfs_set_feature_revoke(journal);
+               jbd2_set_feature_revoke(journal);
                mark_buffer_dirty(journal->j_sb_buffer);
        }
 
@@ -533,7 +536,8 @@ error:
        return err;
 }
 
-void do_journal_write(int argc, char *argv[])
+void do_journal_write(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
+                     void *infop EXT2FS_ATTR((unused)))
 {
        blk64_t *blist = NULL, *rlist = NULL;
        size_t bn = 0, rn = 0;
@@ -622,8 +626,8 @@ static int count_tags(journal_t *journal, char *buf)
        int                     nr = 0, size = journal->j_blocksize;
        int                     tag_bytes = journal_tag_bytes(journal);
 
-       if (journal_has_csum_v2or3(journal))
-               size -= sizeof(struct journal_block_tail);
+       if (jbd2_journal_has_csum_v2or3(journal))
+               size -= sizeof(struct jbd2_journal_block_tail);
 
        tagp = buf + sizeof(journal_header_t);
 
@@ -632,10 +636,10 @@ static int count_tags(journal_t *journal, char *buf)
 
                nr++;
                tagp += tag_bytes;
-               if (!(tag->t_flags & ext2fs_cpu_to_be16(JFS_FLAG_SAME_UUID)))
+               if (!(tag->t_flags & ext2fs_cpu_to_be16(JBD2_FLAG_SAME_UUID)))
                        tagp += 16;
 
-               if (tag->t_flags & ext2fs_cpu_to_be16(JFS_FLAG_LAST_TAG))
+               if (tag->t_flags & ext2fs_cpu_to_be16(JBD2_FLAG_LAST_TAG))
                        break;
        }
 
@@ -685,11 +689,12 @@ static errcode_t journal_find_head(journal_t *journal)
                /* Skip over each chunk of the transaction looking
                 * either the next descriptor block or the final commit
                 * record. */
-               err = journal_bmap(journal, next_log_block, &bh->b_blocknr);
+               err = jbd2_journal_bmap(journal, next_log_block,
+                                       &bh->b_blocknr);
                if (err)
                        goto err;
                mark_buffer_uptodate(bh, 0);
-               ll_rw_block(READ, 1, &bh);
+               ll_rw_block(REQ_OP_READ, 0, 1, &bh);
                err = bh->b_err;
                if (err)
                        goto err;
@@ -705,7 +710,7 @@ static errcode_t journal_find_head(journal_t *journal)
 
                tmp = (journal_header_t *)bh->b_data;
 
-               if (tmp->h_magic != ext2fs_cpu_to_be32(JFS_MAGIC_NUMBER)) {
+               if (tmp->h_magic != ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER)) {
                        dbg_printf("JBD2: wrong magic 0x%x\n", tmp->h_magic);
                        goto err;
                }
@@ -726,17 +731,17 @@ static errcode_t journal_find_head(journal_t *journal)
                 * to do with it?  That depends on the pass... */
 
                switch (blocktype) {
-               case JFS_DESCRIPTOR_BLOCK:
+               case JBD2_DESCRIPTOR_BLOCK:
                        next_log_block += count_tags(journal, bh->b_data);
                        wrap(journal, next_log_block);
                        continue;
 
-               case JFS_COMMIT_BLOCK:
+               case JBD2_COMMIT_BLOCK:
                        head_block = next_log_block;
                        next_commit_ID++;
                        continue;
 
-               case JFS_REVOKE_BLOCK:
+               case JBD2_REVOKE_BLOCK:
                        continue;
 
                default:
@@ -778,14 +783,14 @@ static void update_journal_csum(journal_t *journal, int ver)
                printf("Setting csum v%d\n", ver);
                switch (ver) {
                case 2:
-                       jfs_clear_feature_csum3(journal);
-                       jfs_set_feature_csum2(journal);
-                       jfs_clear_feature_checksum(journal);
+                       jbd2_clear_feature_csum3(journal);
+                       jbd2_set_feature_csum2(journal);
+                       jbd2_clear_feature_checksum(journal);
                        break;
                case 3:
-                       jfs_set_feature_csum3(journal);
-                       jfs_clear_feature_csum2(journal);
-                       jfs_clear_feature_checksum(journal);
+                       jbd2_set_feature_csum3(journal);
+                       jbd2_clear_feature_csum2(journal);
+                       jbd2_clear_feature_checksum(journal);
                        break;
                default:
                        printf("Unknown checksum v%d\n", ver);
@@ -795,9 +800,9 @@ static void update_journal_csum(journal_t *journal, int ver)
                journal->j_csum_seed = jbd2_chksum(journal, ~0, jsb->s_uuid,
                                                   sizeof(jsb->s_uuid));
        } else {
-               jfs_clear_feature_csum3(journal);
-               jfs_clear_feature_csum2(journal);
-               jfs_set_feature_checksum(journal);
+               jbd2_clear_feature_csum3(journal);
+               jbd2_clear_feature_csum2(journal);
+               jbd2_set_feature_checksum(journal);
        }
 }
 
@@ -819,7 +824,7 @@ static void update_uuid(journal_t *journal)
        if (!ext2fs_has_feature_64bit(fs->super))
                return;
 
-       if (jfs_has_feature_64bit(journal) &&
+       if (jbd2_has_feature_64bit(journal) &&
            ext2fs_has_feature_64bit(fs->super))
                return;
 
@@ -841,7 +846,7 @@ static void update_64bit_flag(journal_t *journal)
        if (!ext2fs_has_feature_64bit(journal->j_fs_dev->k_fs->super))
                return;
 
-       if (jfs_has_feature_64bit(journal) &&
+       if (jbd2_has_feature_64bit(journal) &&
            ext2fs_has_feature_64bit(journal->j_fs_dev->k_fs->super))
                return;
 
@@ -852,10 +857,11 @@ static void update_64bit_flag(journal_t *journal)
                return;
        }
 
-       jfs_set_feature_64bit(journal);
+       jbd2_set_feature_64bit(journal);
 }
 
-void do_journal_open(int argc, char *argv[])
+void do_journal_open(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
+                    void *infop EXT2FS_ATTR((unused)))
 {
        int opt, enable_csum = 0, csum_ver = 3;
        journal_t *journal;
@@ -898,7 +904,7 @@ void do_journal_open(int argc, char *argv[])
                        printf("%s: [-c] [-v ver] [-f ext_jnl]\n", argv[0]);
                        printf("-c: Enable journal checksumming.\n");
                        printf("-v: Use this version checksum format.\n");
-                       printf("-j: Load this external journal.\n");
+                       printf("-f: Load this external journal.\n");
                }
        }
 
@@ -925,7 +931,9 @@ void do_journal_open(int argc, char *argv[])
 }
 
 void do_journal_close(int argc EXT2FS_ATTR((unused)),
-                     char *argv[] EXT2FS_ATTR((unused)))
+                     char *argv[] EXT2FS_ATTR((unused)),
+                     int sci_idx EXT2FS_ATTR((unused)),
+                     void *infop EXT2FS_ATTR((unused)))
 {
        if (current_journal == NULL) {
                printf("Journal not open.\n");
@@ -935,7 +943,9 @@ void do_journal_close(int argc EXT2FS_ATTR((unused)),
        ext2fs_close_journal(current_fs, &current_journal);
 }
 
-void do_journal_run(int argc EXT2FS_ATTR((unused)), char *argv[])
+void do_journal_run(int argc EXT2FS_ATTR((unused)), char *argv[],
+                   int sci_idx EXT2FS_ATTR((unused)),
+                   void *infop EXT2FS_ATTR((unused)))
 {
        errcode_t err;