Commit e151f036 authored by Tigerly's avatar Tigerly
Browse files

init commit

parent 62c692e7
LOCAL_PATH := $(call my-dir)
#########################
# Build the debugfs binary
debugfs_src_files := \
debug_cmds.c \
debugfs.c \
util.c \
ncheck.c\
icheck.c \
ls.c \
lsdel.c \
dump.c \
set_fields.c \
logdump.c \
htree.c \
unused.c \
e2freefrag.c \
filefrag.c \
extent_cmds.c \
extent_inode.c \
zap.c \
create_inode.c \
quota.c \
xattrs.c \
journal.c \
revoke.c \
recovery.c \
do_journal.c
debugfs_shared_libraries := \
libext2fs \
libext2_blkid \
libext2_uuid \
libext2_ss \
libext2_quota \
libext2_com_err \
libext2_e2p
debugfs_system_shared_libraries := libc
debugfs_static_libraries := \
libext2fs \
libext2_blkid \
libext2_uuid_static \
libext2_ss \
libext2_quota \
libext2_com_err \
libext2_e2p
debugfs_system_static_libraries := libc
debugfs_c_includes := \
external/e2fsprogs/e2fsck \
external/e2fsprogs/misc \
external/e2fsprogs/lib
debugfs_cflags := -O2 -g -W -Wall -fno-strict-aliasing -DDEBUGFS
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(debugfs_src_files)
LOCAL_C_INCLUDES := $(debugfs_c_includes)
LOCAL_CFLAGS := $(debugfs_cflags)
LOCAL_SYSTEM_SHARED_LIBRARIES := $(debugfs_system_shared_libraries)
LOCAL_SHARED_LIBRARIES := $(debugfs_shared_libraries)
LOCAL_MODULE := debugfs
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(debugfs_src_files)
LOCAL_C_INCLUDES := $(debugfs_c_includes)
LOCAL_CFLAGS := $(debugfs_cflags)
LOCAL_STATIC_LIBRARIES := $(debugfs_static_libraries) $(debugfs_system_static_libraries)
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE := debugfs_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(debugfs_src_files)
LOCAL_C_INCLUDES := $(debugfs_c_includes)
LOCAL_CFLAGS := $(debugfs_cflags)
LOCAL_SHARED_LIBRARIES := $(addsuffix -host, $(debugfs_shared_libraries))
LOCAL_MODULE := debugfs_host
LOCAL_MODULE_STEM := debugfs
LOCAL_MODULE_TAGS := optional
include $(BUILD_HOST_EXECUTABLE)
This diff is collapsed.
#
# Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
# under the terms of the GNU Public License.
#
command_table debug_cmds;
request do_show_debugfs_params, "Show debugfs parameters",
show_debugfs_params, params;
request do_open_filesys, "Open a filesystem",
open_filesys, open;
request do_close_filesys, "Close the filesystem",
close_filesys, close;
request do_freefrag, "Report free space fragmentation",
freefrag, e2freefrag;
request do_features, "Set/print superblock features",
feature, features;
request do_dirty_filesys, "Mark the filesystem as dirty",
dirty_filesys, dirty;
request do_init_filesys, "Initialize a filesystem (DESTROYS DATA)",
init_filesys;
request do_show_super_stats, "Show superblock statistics",
show_super_stats, stats;
request do_ncheck, "Do inode->name translation",
ncheck;
request do_icheck, "Do block->inode translation",
icheck;
request do_chroot, "Change root directory",
change_root_directory, chroot;
request do_change_working_dir, "Change working directory",
change_working_directory, cd;
request do_list_dir, "List directory",
list_directory, ls;
request do_stat, "Show inode information ",
show_inode_info, stat;
request do_dump_extents, "Dump extents information ",
dump_extents, extents, ex;
request do_blocks, "Dump blocks used by an inode ",
blocks;
request do_filefrag, "Report fragmentation information for an inode",
filefrag;
request do_link, "Create directory link",
link, ln;
request do_unlink, "Delete a directory link",
unlink;
request do_mkdir, "Create a directory",
mkdir;
request do_rmdir, "Remove a directory",
rmdir;
request do_rm, "Remove a file (unlink and kill_file, if appropriate)",
rm;
request do_kill_file, "Deallocate an inode and its blocks",
kill_file;
request do_copy_inode, "Copy the inode structure",
copy_inode;
request do_clri, "Clear an inode's contents",
clri;
request do_freei, "Clear an inode's in-use flag",
freei;
request do_seti, "Set an inode's in-use flag",
seti;
request do_testi, "Test an inode's in-use flag",
testi;
request do_freeb, "Clear a block's in-use flag",
freeb;
request do_setb, "Set a block's in-use flag",
setb;
request do_testb, "Test a block's in-use flag",
testb;
request do_modify_inode, "Modify an inode by structure",
modify_inode, mi;
request do_find_free_block, "Find free block(s)",
find_free_block, ffb;
request do_find_free_inode, "Find free inode(s)",
find_free_inode, ffi;
request do_print_working_directory, "Print current working directory",
print_working_directory, pwd;
request do_expand_dir, "Expand directory",
expand_dir, expand;
request do_mknod, "Create a special file",
mknod;
request do_lsdel, "List deleted inodes",
list_deleted_inodes, lsdel;
request do_undel, "Undelete file",
undelete, undel;
request do_write, "Copy a file from your native filesystem",
write;
request do_dump, "Dump an inode out to a file",
dump_inode, dump;
request do_cat, "Dump an inode out to stdout",
cat;
request do_lcd, "Change the current directory on your native filesystem",
lcd;
request do_rdump, "Recursively dump a directory to the native filesystem",
rdump;
request do_set_super, "Set superblock value",
set_super_value, ssv;
request do_set_inode, "Set inode field",
set_inode_field, sif;
request do_set_block_group_descriptor, "Set block group descriptor field",
set_block_group, set_bg;
request do_logdump, "Dump the contents of the journal",
logdump;
request do_htree_dump, "Dump a hash-indexed directory",
htree_dump, htree;
request do_dx_hash, "Calculate the directory hash of a filename",
dx_hash, hash;
request do_dirsearch, "Search a directory for a particular filename",
dirsearch;
request do_bmap, "Calculate the logical->physical block mapping for an inode",
bmap;
request do_fallocate, "Allocate uninitialized blocks to an inode",
fallocate;
request do_punch, "Punch (or truncate) blocks from an inode by deallocating them",
punch, truncate;
request do_symlink, "Create a symbolic link",
symlink;
request do_imap, "Calculate the location of an inode",
imap;
request do_dump_unused, "Dump unused blocks",
dump_unused;
request do_set_current_time, "Set current time to use when setting filesystem fields",
set_current_time;
request do_supported_features, "Print features supported by this version of e2fsprogs",
supported_features;
request do_dump_mmp, "Dump MMP information",
dump_mmp;
request do_set_mmp_value, "Set MMP value",
set_mmp_value, smmp;
request do_extent_open, "Open inode for extent manipulation",
extent_open, eo;
request do_zap_block, "Zap block: fill with 0, pattern, flip bits etc.",
zap_block, zap;
request do_block_dump, "Dump contents of a block",
block_dump, bdump, bd;
request do_list_xattr, "List extended attributes of an inode",
ea_list;
request do_get_xattr, "Get an extended attribute of an inode",
ea_get;
request do_set_xattr, "Set an extended attribute of an inode",
ea_set;
request do_rm_xattr, "Remove an extended attribute of an inode",
ea_rm;
request do_list_quota, "List quota",
list_quota, lq;
request do_get_quota, "Get quota",
get_quota, gq;
request do_idump, "Dump the inode structure in hex",
inode_dump, idump, id;
request do_journal_open, "Open the journal",
journal_open, jo;
request do_journal_close, "Close the journal",
journal_close, jc;
request do_journal_write, "Write a transaction to the journal",
journal_write, jw;
request do_journal_run, "Recover the journal",
journal_run, jr;
end;
This diff is collapsed.
This diff is collapsed.
/*
* debugfs.h --- header file for the debugfs program
*/
#include "ss/ss.h"
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
#include "../misc/create_inode.h"
#include "support/quotaio.h"
#ifdef __STDC__
#define NOARGS void
#else
#define NOARGS
#define const
#endif
/*
* Flags used by the common argument processing functions
*/
#define CHECK_FS_RW 0x0001
#define CHECK_FS_BITMAPS 0x0002
#define CHECK_FS_NOTOPEN 0x0004
extern ext2_filsys current_fs;
extern quota_ctx_t current_qctx;
extern ext2_ino_t root, cwd;
extern int sci_idx;
extern ss_request_table debug_cmds, extent_cmds;
extern void reset_getopt(void);
extern FILE *open_pager(void);
extern void close_pager(FILE *stream);
extern int check_fs_open(char *name);
extern int check_fs_not_open(char *name);
extern int check_fs_read_write(char *name);
extern int check_fs_bitmaps(char *name);
extern ext2_ino_t string_to_inode(char *str);
extern char *inode_time_to_string(__u32 xtime, __u32 xtime_extra);
extern char *time_to_string(__s64);
extern __s64 string_to_time(const char *);
extern unsigned long parse_ulong(const char *str, const char *cmd,
const char *descr, int *err);
extern unsigned long long parse_ulonglong(const char *str, const char *cmd,
const char *descr, int *err);
extern int strtoblk(const char *cmd, const char *str, const char *errmsg,
blk64_t *ret);
extern int common_args_process(int argc, char *argv[], int min_argc,
int max_argc, const char *cmd,
const char *usage, int flags);
extern int common_inode_args_process(int argc, char *argv[],
ext2_ino_t *inode, int flags);
extern int common_block_args_process(int argc, char *argv[],
blk64_t *block, blk64_t *count);
extern int debugfs_read_inode(ext2_ino_t ino, struct ext2_inode * inode,
const char *cmd);
extern int debugfs_read_inode_full(ext2_ino_t ino, struct ext2_inode * inode,
const char *cmd, int bufsize);
extern int debugfs_write_inode(ext2_ino_t ino, struct ext2_inode * inode,
const char *cmd);
extern int debugfs_write_inode_full(ext2_ino_t ino, struct ext2_inode * inode,
const char *cmd, int bufsize);
extern int debugfs_write_new_inode(ext2_ino_t ino, struct ext2_inode * inode,
const char *cmd);
extern int ext2_file_type(unsigned int mode);
/* ss command functions */
/* dump.c */
extern void do_dump(int argc, char **argv);
extern void do_cat(int argc, char **argv);
extern void do_rdump(int argc, char **argv);
/* extent_inode.c */
extern void do_extent_open(int argc, char **argv);
extern void do_extent_close(int argc, char **argv);
extern void do_current_node(int argc, char **argv);
extern void do_root_node(int argc, char **argv);
extern void do_last_leaf(int argc, char **argv);
extern void do_first_sib(int argc, char **argv);
extern void do_last_sib(int argc, char **argv);
extern void do_next_sib(int argc, char **argv);
extern void do_prev_sib(int argc, char **argv);
extern void do_next_leaf(int argc, char **argv);
extern void do_prev_leaf(int argc, char **argv);
extern void do_next(int argc, char **argv);
extern void do_prev(int argc, char **argv);
extern void do_up(int argc, char **argv);
extern void do_down(int argc, char **argv);
extern void do_delete_node(int argc, char **argv);
extern void do_replace_node(int argc, char **argv);
extern void do_split_node(int argc, char **argv);
extern void do_insert_node(int argc, char **argv);
extern void do_set_bmap(int argc, char **argv);
extern void do_print_all(int argc, char **argv);
extern void do_fix_parents(int argc, char **argv);
extern void do_info(int argc, char **argv);
extern void do_goto_block(int argc, char **argv);
/* htree.c */
extern void do_htree_dump(int argc, char **argv);
extern void do_dx_hash(int argc, char **argv);
extern void do_dirsearch(int argc, char **argv);
/* logdump.c */
extern void do_logdump(int argc, char **argv);
/* lsdel.c */
extern void do_lsdel(int argc, char **argv);
/* icheck.c */
extern void do_icheck(int argc, char **argv);
/* ncheck.c */
extern void do_ncheck(int argc, char **argv);
/* set_fields.c */
extern void do_set_super(int argc, char **);
extern void do_set_inode(int argc, char **);
extern void do_set_block_group_descriptor(int argc, char **);
/* unused.c */
extern void do_dump_unused(int argc, char **argv);
/* debugfs.c */
extern void internal_dump_inode(FILE *, const char *, ext2_ino_t,
struct ext2_inode *, int);
extern void do_dirty_filesys(int argc, char **argv);
extern void do_open_filesys(int argc, char **argv);
extern void do_close_filesys(int argc, char **argv);
extern void do_lcd(int argc, char **argv);
extern void do_init_filesys(int argc, char **argv);
extern void do_show_super_stats(int argc, char **argv);
extern void do_kill_file(int argc, char **argv);
extern void do_rm(int argc, char **argv);
extern void do_link(int argc, char **argv);
extern void do_undel(int argc, char **argv);
extern void do_unlink(int argc, char **argv);
extern void do_find_free_block(int argc, char **argv);
extern void do_find_free_inode(int argc, char **argv);
extern void do_stat(int argc, char **argv);
extern void do_dump_extents(int argc, char **argv);
extern void do_blocks(int argc, char *argv[]);
extern void do_chroot(int argc, char **argv);
extern void do_clri(int argc, char **argv);
extern void do_freei(int argc, char **argv);
extern void do_seti(int argc, char **argv);
extern void do_testi(int argc, char **argv);
extern void do_freeb(int argc, char **argv);
extern void do_setb(int argc, char **argv);
extern void do_testb(int argc, char **argv);
extern void do_modify_inode(int argc, char **argv);
extern void do_list_dir(int argc, char **argv);
extern void do_change_working_dir(int argc, char **argv);
extern void do_print_working_directory(int argc, char **argv);
extern void do_write(int argc, char **argv);
extern void do_mknod(int argc, char **argv);
extern void do_mkdir(int argc, char **argv);
extern void do_rmdir(int argc, char **argv);
extern void do_show_debugfs_params(int argc, char **argv);
extern void do_expand_dir(int argc, char **argv);
extern void do_features(int argc, char **argv);
extern void do_bmap(int argc, char **argv);
extern void do_imap(int argc, char **argv);
extern void do_idump(int argc, char *argv[]);
extern void do_set_current_time(int argc, char **argv);
extern void do_supported_features(int argc, char **argv);
extern void do_punch(int argc, char **argv);
extern void do_fallocate(int argc, char **argv);
extern void do_symlink(int argc, char **argv);
extern void do_dump_mmp(int argc, char **argv);
extern void do_set_mmp_value(int argc, char **argv);
extern void do_freefrag(int argc, char **argv);
extern void do_filefrag(int argc, char *argv[]);
/* do_journal.c */
extern void do_journal_write(int argc, char *argv[]);
extern void do_journal_open(int argc, char *argv[]);
extern void do_journal_close(int argc, char *argv[]);
extern void do_journal_run(int argc, char *argv[]);
/* quota.c */
extern void do_list_quota(int argc, char *argv[]);
extern void do_get_quota(int argc, char *argv[]);
/* util.c */
extern __s64 string_to_time(const char *arg);
errcode_t read_list(char *str, blk64_t **list, size_t *len);
/* xattrs.c */
void dump_inode_attributes(FILE *out, ext2_ino_t ino);
void do_get_xattr(int argc, char **argv);
void do_set_xattr(int argc, char **argv);
void do_rm_xattr(int argc, char **argv);
void do_list_xattr(int argc, char **argv);
/* zap.c */
extern void do_zap_block(int argc, char **argv);
extern void do_block_dump(int argc, char **argv);
extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
This diff is collapsed.
/*
* dump.c --- dump the contents of an inode out to a file
*
* Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
* under the terms of the GNU Public License.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for O_LARGEFILE */
#endif
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utime.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
extern int optind;
extern char *optarg;
#endif
#include "debugfs.h"
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
#endif
/*
* The mode_xlate function translates a linux mode into a native-OS mode_t.
*/
static struct {
__u16 lmask;
mode_t mask;
} mode_table[] = {
{ LINUX_S_IRUSR, S_IRUSR },
{ LINUX_S_IWUSR, S_IWUSR },
{ LINUX_S_IXUSR, S_IXUSR },
{ LINUX_S_IRGRP, S_IRGRP },
{ LINUX_S_IWGRP, S_IWGRP },
{ LINUX_S_IXGRP, S_IXGRP },
{ LINUX_S_IROTH, S_IROTH },
{ LINUX_S_IWOTH, S_IWOTH },
{ LINUX_S_IXOTH, S_IXOTH },
{ 0, 0 }
};
static mode_t mode_xlate(__u16 lmode)
{
mode_t mode = 0;
int i;
for (i=0; mode_table[i].lmask; i++) {
if (lmode & mode_table[i].lmask)
mode |= mode_table[i].mask;
}
return mode;
}
static void fix_perms(const char *cmd, const struct ext2_inode *inode,
int fd, const char *name)
{
struct utimbuf ut;
int i;
if (fd != -1)
i = fchmod(fd, mode_xlate(inode->i_mode));
else
i = chmod(name, mode_xlate(inode->i_mode));
if (i == -1)
com_err(cmd, errno, "while setting permissions of %s", name);
#ifndef HAVE_FCHOWN
i = chown(name, inode->i_uid, inode->i_gid);
#else
if (fd != -1)
i = fchown(fd, inode->i_uid, inode->i_gid);
else
i = chown(name, inode->i_uid, inode->i_gid);
#endif