Commit d9e4754e authored by Tigerly's avatar Tigerly
Browse files

usermode_solution

parent eff68e08
......@@ -17,13 +17,14 @@ MANPAGES= debugfs.8
MK_CMDS= _SS_DIR_OVERRIDE=$(srcdir)/../lib/ss ../lib/ss/mk_cmds
DEBUG_OBJS= debug_cmds.o debugfs.o util.o ls.o \
xattrs.o
xattrs.o journal.o revoke.o do_journal.o recovery.o
RO_DEBUG_OBJS= ro_debug_cmds.o ro_debugfs.o util.o ls.o \
xattrs.o
SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \
$(srcdir)/xattrs.c
$(srcdir)/xattrs.c $(srcdir)/journal.c $(srcdir)/../e2fsck/revoke.c \
$(srcdir)/../e2fsck/recovery.c $(srcdir)/do_journal.c
LIBS= $(LIBSUPPORT) $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
$(LIBUUID) $(LIBMAGIC) $(SYSLIBS)
......@@ -78,6 +79,16 @@ ro_debug_cmds.c ro_debug_cmds.h: ro_debug_cmds.ct
ro_debugfs.o: debugfs.c
$(E) " CC $@"
$(Q) $(CC) -c $(ALL_CFLAGS) $< -DREAD_ONLY -o $@
recovery.o: $(srcdir)/../e2fsck/recovery.c
$(E) " CC $@"
$(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) \
$(srcdir)/../e2fsck/recovery.c -o $@
revoke.o: $(srcdir)/../e2fsck/revoke.c
$(E) " CC $@"
$(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) \
$(srcdir)/../e2fsck/revoke.c -o $@
debugfs.8: $(DEP_SUBSTITUTE) $(srcdir)/debugfs.8.in
$(E) " SUBST $@"
......@@ -176,3 +187,40 @@ xattrs.o: $(srcdir)/xattrs.c $(top_builddir)/lib/config.h \
$(srcdir)/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
$(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
$(top_srcdir)/lib/support/quotaio_tree.h
journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/../e2fsck/jfs_user.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
$(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
$(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
$(top_builddir)/lib/ext2fs/ext2_err.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
$(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
$(top_srcdir)/lib/ext2fs/kernel-list.h
revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
$(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
$(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
$(top_builddir)/lib/ext2fs/ext2_err.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
$(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
$(top_srcdir)/lib/ext2fs/kernel-list.h
recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
$(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
$(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
$(top_builddir)/lib/ext2fs/ext2_err.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
$(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
$(top_srcdir)/lib/ext2fs/kernel-list.h
do_journal.o: $(srcdir)/do_journal.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/debugfs.h $(top_srcdir)/lib/ss/ss.h \
$(top_builddir)/lib/ss/ss_err.h $(top_srcdir)/lib/et/com_err.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
$(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
$(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
$(srcdir)/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
$(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
$(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../e2fsck/jfs_user.h \
$(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
$(top_srcdir)/lib/ext2fs/kernel-list.h
......@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <libgen.h>
#ifdef HAVE_GETOPT_H
......@@ -30,6 +31,7 @@ extern char *optarg;
#include "debugfs.h"
#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "journal.h"
#include <ext2fs/ext2_ext_attr.h>
......@@ -484,6 +486,28 @@ static void do_write_bitmap(unsigned int *buf, FILE *fd, long lSize) {
fprintf(fd, "OCCUPIED/TOTAL = %d / %ld \n", count, lSize);
}
static void do_write_journal(struct journal_superblock_s *buf, FILE *fd) {
fprintf(fd, " journal's header \n");
fprintf(fd, " h_magic %u \n", buf->s_header.h_magic);
fprintf(fd, " h_blocktype %u \n", buf->s_header.h_blocktype);
fprintf(fd, " h_sequence %u \n", buf->s_header.h_sequence);
fprintf(fd, " Static information describing the journal \n");
fprintf(fd, " journal device blocksize %u \n",
buf->s_blocksize);
fprintf(fd, " total blocks in journal file %u \n", buf->s_maxlen);
fprintf(fd, " first block of log information %u \n", buf->s_first);
fprintf(fd,
" Dynamic information describing the current state of the log \n");
fprintf(fd, " first commit ID expected in log %u \n", buf->s_sequence);
fprintf(fd, " blocknr of start of log %u \n", buf->s_start);
//jfs_dat.h
}
void do_analyze_meta_data(int argc, char *argv[]) {
char *path = argv[1];
DIR * dd;
......@@ -498,7 +522,7 @@ void do_analyze_meta_data(int argc, char *argv[]) {
unsigned int length;
int bd_loop = 0;
int sb_loop = 0;
int inode_loop = 0;
int journal_loop = 0;
dd = opendir(path);
......@@ -516,10 +540,9 @@ void do_analyze_meta_data(int argc, char *argv[]) {
bd_loop = 1;
else if (strstr(path,"/sb/"))
sb_loop = 1;
/*
else if (strstr(path, "/inode/"))
inode_loop = 1;
*/
else if (strstr(path, "/journal/"))
journal_loop = 1;
while ((dir_ent = readdir(dd)) && dir_ent) {
if (!strcmp (dir_ent->d_name, "."))
continue;
......@@ -575,12 +598,11 @@ void do_analyze_meta_data(int argc, char *argv[]) {
// write super block
do_write_sb ((struct ext2_super_block *)buf, nfd);
}
/*
else if(inode_loop){
// write inode
do_write_inode((struct ext2_inode *)buf, nfd);
else if(journal_loop){
// write journal
do_write_journal((struct journal_superblock_s *)buf, nfd);
}
*/
fclose(nfd);
}
}
......@@ -618,6 +640,9 @@ void do_extract_meta_data(int argc, char *argv[])
int csum_flag;
int check;
static journal_t *journal = NULL;
unsigned long long blocknr;
struct buffer_head *bh;
if (argc < 3) {
printf("Minimum expected arguments are device and path for copying metadata\n");
......@@ -651,6 +676,14 @@ void do_extract_meta_data(int argc, char *argv[])
mkdir(suffix, 0777);
}
suffix[suffix_len] = '\0';
sprintf(suffix, "%s/journal",suffix);
if (stat(suffix, &st) == -1) {
mkdir(suffix, 0777);
}
if (ext2fs_has_feature_meta_bg(current_fs->super))
old_desc_blocks = current_fs->super->s_first_meta_bg;
else
......@@ -690,7 +723,7 @@ void do_extract_meta_data(int argc, char *argv[])
fp = fopen(suffix, "wb");
fwrite(inode_buf, block_nbytes, 1, fp);
fwrite(inode_buf, block_size * current_fs->super->s_reserved_gdt_blocks, 1, fp);
fclose(fp);
}
......@@ -774,6 +807,38 @@ void do_extract_meta_data(int argc, char *argv[])
}
suffix[suffix_len] = '\0';
sprintf(suffix, "%s/journal/journal.bin", suffix);
fp = fopen(suffix, "wb");
retval = ext2fs_open_journal(current_fs, &journal);
if (retval)
goto ret;
for (i = 0; i < journal->j_maxlen; i++) {
retval = journal_bmap(journal, i, &blocknr);
if (retval)
goto ret;
bh = getblk(journal->j_dev, blocknr, journal->j_blocksize);
if (!bh) {
retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
goto ret;
}
mark_buffer_uptodate(bh, 0);
ll_rw_block(READ, 1, &bh);
retval = bh->b_err;
if (retval) {
ext2fs_free_mem(&bh);
goto ret;
}
fwrite(bh->b_data, journal->j_blocksize, 1, fp);
ext2fs_free_mem(&bh);
}
ext2fs_close_journal(current_fs, &journal);
fclose(fp);
suffix[suffix_len] = '\0';
sprintf(suffix, "%s/sb/sb.bin", suffix);
......
This diff is collapsed.
This diff is collapsed.
/*
* journal.h
*
* Copyright (C) 2000 Andreas Dilger
* Copyright (C) 2000 Theodore Ts'o
*
* Parts of the code are based on fs/jfs/journal.c by Stephen C. Tweedie
* Copyright (C) 1999 Red Hat Software
*
* This file may be redistributed under the terms of the
* GNU General Public License version 2 or at your discretion
* any later version.
*/
#include "jfs_user.h"
/* journal.c */
errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j);
errcode_t ext2fs_close_journal(ext2_filsys fs, journal_t **j);
errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
void jbd2_commit_block_csum_set(journal_t *j, struct buffer_head *bh);
void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh);
void jbd2_descr_block_csum_set(journal_t *j, struct buffer_head *bh);
void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
struct buffer_head *bh, __u32 sequence);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment