Commit 0f543980 authored by Tigerly's avatar Tigerly
Browse files

commit_add_analyze_inode_and_superblock

parent 8b8fc1d3
......@@ -16,6 +16,7 @@ request do_close_filesys, "Close the filesystem",
request do_freefrag, "Report free space fragmentation",
freefrag, e2freefrag;
request do_analyze_meta_data, "Analyze all meta data",
analyze_meta_data, features;
......@@ -23,7 +24,6 @@ request do_extract_meta_data, "Extract all meta data",
extract_meta_data, features;
request do_show_super_stats, "Show superblock statistics",
show_super_stats, stats;
......
......@@ -360,7 +360,7 @@ static void print_bg_opts(ext2_filsys fs, dgrp_t group, int mask,
}
}
void do_write_bd(struct ext4_group_desc *buf, FILE *fd) {
static void do_write_bd(struct ext4_group_desc *buf, FILE *fd) {
fprintf(fd," Blocks bitmap block %u \n",buf->bg_block_bitmap);
fprintf(fd," Inodes bitmap block %u \n",buf->bg_inode_bitmap);
fprintf(fd," Inodes table block %u \n",buf->bg_inode_table);
......@@ -386,13 +386,91 @@ void do_write_bd(struct ext4_group_desc *buf, FILE *fd) {
fprintf(fd," reserved %u \n",buf->bg_reserved);
}
static void do_write_sb (struct ext2_super_block *sb, FILE *fd) {
// now just use the existing function
// will modify it and add more features we needed.
list_super2(sb, fd);
/*
fprintf(fd," Inodes count %u \n",buf->s_inodes_count);
fprintf(fd," Blocks count %u \n",buf->s_blocks_count);
fprintf(fd," Reserved blocks count %u \n",buf->s_r_blocks_count);
fprintf(fd," Free blocks count %u \n",buf->s_free_blocks_count);
fprintf(fd," Free inodes count %u \n",buf->s_free_inodes_count);
fprintf(fd," First Data Block %u \n",buf->s_first_data_block);
fprintf(fd," Block size %u \n",buf->s_log_block_size);
fprintf(fd," Allocation cluster size %u \n",buf->s_log_cluster_size);
fprintf(fd," # Blocks per group %u \n",buf->s_blocks_per_group);
fprintf(fd," # Fragments per group %u \n",buf->s_clusters_per_group);
fprintf(fd," # Inodes per group %u \n",buf->s_inodes_per_group);
fprintf(fd," Mount time %u \n",buf->s_mtime);
fprintf(fd," Write time %u \n",buf->s_wtime);
fprintf(fd," Mount count %hu \n",buf->s_mnt_count);
fprintf(fd," Maximal mount count %hd \n",buf->s_max_mnt_count);
fprintf(fd," Magic signature %hu \n",buf->s_magic);
fprintf(fd," File system state %hu \n",buf->s_state);
fprintf(fd," Behaviour when detecting errors %hu \n",buf->s_errors);
fprintf(fd," minor revision level %hu \n",buf->s_minor_rev_level);
fprintf(fd," time of last check %u \n",buf->s_lastcheck);
fprintf(fd," max. time between checks %u \n",buf->s_checkinterval);
fprintf(fd," OS %u \n",buf->s_creator_os);
fprintf(fd," Revision level %u \n",buf->s_rev_level);
fprintf(fd," Default uid for reserved blocks %hu \n",buf->s_def_resuid);
fprintf(fd," Default gid for reserved blocks %hu \n",buf->s_def_resgid);
*/
}
static void do_write_inode(struct ext2_inode *inode, FILE *fd) {
fprintf(fd," File mode %hu \n",inode->i_mode);
fprintf(fd," Low 16 bits of Owner Uid %hu \n",inode->i_uid);
fprintf(fd," Size in bytes %u \n",inode->i_size);
fprintf(fd," Access time %u \n",inode->i_atime);
fprintf(fd," Inode change time %u \n",inode->i_ctime);
fprintf(fd," Modification time %u \n",inode->i_mtime);
fprintf(fd," Deletion Time %u \n",inode->i_dtime);
fprintf(fd," Low 16 bits of Group Id %hu \n",inode->i_gid);
fprintf(fd," Links count %hu \n",inode->i_links_count);
fprintf(fd," Blocks count %u \n",inode->i_blocks);
fprintf(fd," File flags %u \n",inode->i_flags);
fprintf(fd," Version %u \n",inode->osd1.linux1.l_i_version);
fprintf(fd," Translator %u \n",inode->osd1.hurd1.h_i_translator);
fprintf(fd," Pointers to blocks %u \n",inode->i_block[EXT2_N_BLOCKS]);
fprintf(fd," File version (for NFS) %u \n",inode->i_generation);
fprintf(fd," File ACL %u \n",inode->i_file_acl);
fprintf(fd," Formerly i_dir_acl, directory ACL %u \n",inode->i_size_high);
fprintf(fd," Fragment address %u \n",inode->i_faddr);
fprintf(fd, "Block count: %llu\n",
(((unsigned long long)
inode->osd2.linux2.l_i_blocks_hi << 32)) +
inode->i_blocks);
fprintf(fd, "File ACL: %llu",
inode->i_file_acl | ((long long)
(inode->osd2.linux2.l_i_file_acl_high) << 32));
fprintf(fd," these 2 fields %hu \n",inode->osd2.linux2.l_i_uid_high);
fprintf(fd," were reserved2[0] %hu \n",inode->osd2.linux2.l_i_gid_high);
fprintf(fd," crc32c(uuid+inum+inode) %hu \n",inode->osd2.linux2.l_i_checksum_lo);
fprintf(fd," reserved %hu \n",inode->osd2.linux2.l_i_reserved);
fprintf(fd," Fragment number %hu \n",inode->osd2.hurd2.h_i_frag);
fprintf(fd," Fragment size %hu \n",inode->osd2.hurd2.h_i_fsize);
fprintf(fd," mode_high %hu \n",inode->osd2.hurd2.h_i_mode_high);
fprintf(fd," uid_high %hu \n",inode->osd2.hurd2.h_i_uid_high);
fprintf(fd," gid_high %hu \n",inode->osd2.hurd2.h_i_gid_high);
fprintf(fd," author %u \n",inode->osd2.hurd2.h_i_author);
}
void do_analyze_meta_data(int argc, char *argv[]) {
printf("test-----------path = %s\n", argv[1]);
char *path = argv[1];
DIR * dd;
FILE *fd;
FILE *nfd;
struct dirent* dir_ent;
unsigned int *buf = malloc (1024);
size_t size;
unsigned int length;
int bd_loop = 0;
......@@ -437,8 +515,21 @@ void do_analyze_meta_data(int argc, char *argv[]) {
nfd = fopen(dir_ent->d_name, "w");
if (nfd) {
if (bd_loop)
if (bd_loop){
printf("write block!!!\n");
// write block
do_write_bd((struct ext4_group_desc *)buf, nfd);
}
else if(sb_loop){
// write super block
printf("write super block!!!\n");
do_write_sb ((struct ext2_super_block *)buf, nfd);
}
else if(inode_loop){
// write inode
printf("write inode!!!\n");
do_write_inode((struct ext2_inode *)buf, nfd);
}
fclose(nfd);
}
}
......@@ -1311,76 +1402,6 @@ void do_testb(int argc, char *argv[])
}
}
#ifndef READ_ONLY
static void modify_u8(char *com, const char *prompt,
const char *format, __u8 *val)
{
char buf[200];
unsigned long v;
char *tmp;
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
if (!fgets(buf, sizeof(buf), stdin))
return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
return;
v = strtoul(buf, &tmp, 0);
if (*tmp)
com_err(com, 0, "Bad value - %s", buf);
else
*val = v;
}
static void modify_u16(char *com, const char *prompt,
const char *format, __u16 *val)
{
char buf[200];
unsigned long v;
char *tmp;
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
if (!fgets(buf, sizeof(buf), stdin))
return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
return;
v = strtoul(buf, &tmp, 0);
if (*tmp)
com_err(com, 0, "Bad value - %s", buf);
else
*val = v;
}
static void modify_u32(char *com, const char *prompt,
const char *format, __u32 *val)
{
char buf[200];
unsigned long v;
char *tmp;
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
if (!fgets(buf, sizeof(buf), stdin))
return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
return;
v = strtoul(buf, &tmp, 0);
if (*tmp)
com_err(com, 0, "Bad value - %s", buf);
else
*val = v;
}
#endif /* READ_ONLY */
void do_change_working_dir(int argc, char *argv[])
{
ext2_ino_t inode;
......@@ -1433,76 +1454,6 @@ void do_print_working_directory(int argc, char *argv[])
}
#ifndef READ_ONLY
static void make_link(char *sourcename, char *destname)
{
ext2_ino_t ino;
struct ext2_inode inode;
int retval;
ext2_ino_t dir;
char *dest, *cp, *base_name;
/*
* Get the source inode
*/
ino = string_to_inode(sourcename);
if (!ino)
return;
base_name = strrchr(sourcename, '/');
if (base_name)
base_name++;
else
base_name = sourcename;
/*
* Figure out the destination. First see if it exists and is
* a directory.
*/
if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir)))
dest = base_name;
else {
/*
* OK, it doesn't exist. See if it is
* '<dir>/basename' or 'basename'
*/
cp = strrchr(destname, '/');
if (cp) {
*cp = 0;
dir = string_to_inode(destname);
if (!dir)
return;
dest = cp+1;
} else {
dir = cwd;
dest = destname;
}
}
if (debugfs_read_inode(ino, &inode, sourcename))
return;
retval = ext2fs_link(current_fs, dir, dest, ino,
ext2_file_type(inode.i_mode));
if (retval)
com_err("make_link", retval, 0);
return;
}
static int mark_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
blk64_t ref_block EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)),
void *private EXT2FS_ATTR((unused)))
{
blk64_t block;
block = *blocknr;
ext2fs_block_alloc_stats2(fs, block, +1);
return 0;
}
void do_copy_inode(int argc, char *argv[])
{
......@@ -1627,28 +1578,6 @@ void do_find_free_inode(int argc, char *argv[])
#ifndef READ_ONLY
static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
blk64_t ref_block EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)),
void *private EXT2FS_ATTR((unused)))
{
blk64_t block;
block = *blocknr;
ext2fs_block_alloc_stats2(fs, block, -1);
return 0;
}
struct rd_struct {
ext2_ino_t parent;
int empty;
......@@ -1800,48 +1729,6 @@ err:
ext2fs_free_mem(&buf);
}
static int find_supp_feature(__u32 *supp, int feature_type, char *name)
{
int compat, bit, ret;
unsigned int feature_mask;
if (name) {
if (feature_type == E2P_FS_FEATURE)
ret = e2p_string2feature(name, &compat, &feature_mask);
else
ret = e2p_jrnl_string2feature(name, &compat,
&feature_mask);
if (ret)
return ret;
if (!(supp[compat] & feature_mask))
return 1;
} else {
for (compat = 0; compat < 3; compat++) {
for (bit = 0, feature_mask = 1; bit < 32;
bit++, feature_mask <<= 1) {
if (supp[compat] & feature_mask) {
if (feature_type == E2P_FS_FEATURE)
fprintf(stdout, " %s",
e2p_feature2string(compat,
feature_mask));
else
fprintf(stdout, " %s",
e2p_jrnl_feature2string(compat,
feature_mask));
}
}
}
fprintf(stdout, "\n");
}
return 0;
}
#if CONFIG_MMP
void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
{
......
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