Hi, The below set of patches add debug-btrfs command to btrfs-progs package. The new command depends on the libss.a library provided e2fsprogs. To build one have to set E2FSPRGS_BUILD_DIR to point to the e2fsprogs build directory. Once we get e2fsprogs to create a proper libss package we should be able to remove the above export. Currently supported list of commands are listed below. It should be really easy to add new commands debug-btrfs: ? Available debug-btrfs requests: show_debugfs_params, params Show btrfs_debug parameters open_filesys, open Open the file system dump_tree Show full btrfs tree dump_root_tree Show root tree dump_chunk_tree Show btrfs chunk tree print_inode Print inode details help Display info on command or topic. list_requests, lr, ? List available commands. quit, q Leave the subsystem. You should be able to get the patches with --no-renames at http://www.kernel.org/pub/linux/kernel/people/kvaneesh/debug-btrfs/ -aneesh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Build libbtrfs.a and link against that for the commands Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- Makefile | 72 +++---------------- lib/Makefile | 47 ++++++++++++ bit-radix.c => lib/bit-radix.c | 0 bit-radix.h => lib/bit-radix.h | 0 crc32c.c => lib/crc32c.c | 0 crc32c.h => lib/crc32c.h | 0 ctree.c => lib/ctree.c | 0 ctree.h => lib/ctree.h | 0 dir-item.c => lib/dir-item.c | 0 disk-io.c => lib/disk-io.c | 0 disk-io.h => lib/disk-io.h | 0 extent-cache.c => lib/extent-cache.c | 0 extent-cache.h => lib/extent-cache.h | 0 extent-tree.c => lib/extent-tree.c | 0 extent_io.c => lib/extent_io.c | 0 extent_io.h => lib/extent_io.h | 0 file-item.c => lib/file-item.c | 0 hash.h => lib/hash.h | 0 inode-item.c => lib/inode-item.c | 0 inode-map.c => lib/inode-map.c | 0 ioctl.h => lib/ioctl.h | 0 kerncompat.h => lib/kerncompat.h | 0 list.h => lib/list.h | 0 print-tree.c => lib/print-tree.c | 0 print-tree.h => lib/print-tree.h | 0 radix-tree.c => lib/radix-tree.c | 0 radix-tree.h => lib/radix-tree.h | 0 rbtree.c => lib/rbtree.c | 0 rbtree.h => lib/rbtree.h | 0 root-tree.c => lib/root-tree.c | 0 transaction.h => lib/transaction.h | 0 utils.c => lib/utils.c | 0 utils.h => lib/utils.h | 0 volumes.c => lib/volumes.c | 0 volumes.h => lib/volumes.h | 0 misc/Makefile | 79 ++++++++++++++++++++ bcp => misc/bcp | 0 btrfs-image.c => misc/btrfs-image.c | 0 btrfs-map-logical.c => misc/btrfs-map-logical.c | 0 btrfs-show.c => misc/btrfs-show.c | 0 btrfs-vol.c => misc/btrfs-vol.c | 0 btrfsck.c => misc/btrfsck.c | 0 btrfsctl.c => misc/btrfsctl.c | 0 btrfstune.c => misc/btrfstune.c | 0 convert.c => misc/convert.c | 0 debug-tree.c => misc/debug-tree.c | 0 mkfs.c => misc/mkfs.c | 0 version.sh => misc/version.sh | 0 tests/Makefile | 88 +++++++++++++++++++++++ dir-test.c => tests/dir-test.c | 0 hasher.c => tests/hasher.c | 0 quick-test.c => tests/quick-test.c | 0 random-test.c => tests/random-test.c | 0 show-blocks => tests/show-blocks | 0 54 files changed, 223 insertions(+), 63 deletions(-) create mode 100644 lib/Makefile rename bit-radix.c => lib/bit-radix.c (100%) rename bit-radix.h => lib/bit-radix.h (100%) rename crc32c.c => lib/crc32c.c (100%) rename crc32c.h => lib/crc32c.h (100%) rename ctree.c => lib/ctree.c (100%) rename ctree.h => lib/ctree.h (100%) rename dir-item.c => lib/dir-item.c (100%) rename disk-io.c => lib/disk-io.c (100%) rename disk-io.h => lib/disk-io.h (100%) rename extent-cache.c => lib/extent-cache.c (100%) rename extent-cache.h => lib/extent-cache.h (100%) rename extent-tree.c => lib/extent-tree.c (100%) rename extent_io.c => lib/extent_io.c (100%) rename extent_io.h => lib/extent_io.h (100%) rename file-item.c => lib/file-item.c (100%) rename hash.h => lib/hash.h (100%) rename inode-item.c => lib/inode-item.c (100%) rename inode-map.c => lib/inode-map.c (100%) rename ioctl.h => lib/ioctl.h (100%) rename kerncompat.h => lib/kerncompat.h (100%) rename list.h => lib/list.h (100%) rename print-tree.c => lib/print-tree.c (100%) rename print-tree.h => lib/print-tree.h (100%) rename radix-tree.c => lib/radix-tree.c (100%) rename radix-tree.h => lib/radix-tree.h (100%) rename rbtree.c => lib/rbtree.c (100%) rename rbtree.h => lib/rbtree.h (100%) rename root-tree.c => lib/root-tree.c (100%) rename transaction.h => lib/transaction.h (100%) rename utils.c => lib/utils.c (100%) rename utils.h => lib/utils.h (100%) rename volumes.c => lib/volumes.c (100%) rename volumes.h => lib/volumes.h (100%) create mode 100644 misc/Makefile rename bcp => misc/bcp (100%) mode change 100755 => 100644 rename btrfs-image.c => misc/btrfs-image.c (100%) rename btrfs-map-logical.c => misc/btrfs-map-logical.c (100%) rename btrfs-show.c => misc/btrfs-show.c (100%) rename btrfs-vol.c => misc/btrfs-vol.c (100%) rename btrfsck.c => misc/btrfsck.c (100%) rename btrfsctl.c => misc/btrfsctl.c (100%) rename btrfstune.c => misc/btrfstune.c (100%) rename convert.c => misc/convert.c (100%) rename debug-tree.c => misc/debug-tree.c (100%) rename mkfs.c => misc/mkfs.c (100%) rename version.sh => misc/version.sh (100%) create mode 100644 tests/Makefile rename dir-test.c => tests/dir-test.c (100%) rename hasher.c => tests/hasher.c (100%) rename quick-test.c => tests/quick-test.c (100%) rename random-test.c => tests/random-test.c (100%) rename show-blocks => tests/show-blocks (100%) mode change 100755 => 100644 diff --git a/Makefile b/Makefile index 02f881e..a30c212 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,6 @@ CC=gcc AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 CFLAGS = -g -Werror -Os -objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ - root-tree.o dir-item.o file-item.o inode-item.o \ - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ - volumes.o utils.o - # CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef @@ -16,8 +11,7 @@ prefix ?= /usr/local bindir = $(prefix)/bin LIBS=-luuid -progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ - btrfs-map-logical +SUBDIRS=lib misc man # make C=1 to enable sparse ifdef C @@ -31,60 +25,12 @@ endif $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< -all: version $(progs) manpages - -version: - bash version.sh - -btrfsctl: $(objects) btrfsctl.o - gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-vol: $(objects) btrfs-vol.o - gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-show: $(objects) btrfs-show.o - gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS) - -btrfsck: $(objects) btrfsck.o - gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS) - -mkfs.btrfs: $(objects) mkfs.o - gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) - -btrfs-debug-tree: $(objects) debug-tree.o - gcc $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS) - -btrfstune: $(objects) btrfstune.o - gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS) - -btrfs-map-logical: $(objects) btrfs-map-logical.o - gcc $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS) - -btrfs-image: $(objects) btrfs-image.o - gcc $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS) - -dir-test: $(objects) dir-test.o - gcc $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS) - -quick-test: $(objects) quick-test.o - gcc $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS) - -convert: $(objects) convert.o - gcc $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs $(LDFLAGS) $(LIBS) - -manpages: - cd man; make - -install-man: - cd man; make install - -clean : - rm -f $(progs) cscope.out *.o .*.d btrfs-convert - cd man; make clean - -install: $(progs) install-man - $(INSTALL) -m755 -d $(DESTDIR)$(bindir) - $(INSTALL) $(progs) $(DESTDIR)$(bindir) - if [ -e btrfs-convert ]; then $(INSTALL) btrfs-convert $(DESTDIR)$(bindir); fi +all clean install: + @for subdir in $(SUBDIRS); do \ + if test -d $$subdir ; then \ + target=`echo $@`; \ + echo making $$target in $$subdir; \ + (cd $$subdir && $(MAKE) $$target) || exit 1; \ + fi ; \ + done --include .*.d diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..7ece415 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,47 @@ +CC=gcc +AR = ar +ARGEN = $(AR) rc +RANLIB = ranlib +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g -Werror -Os +objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ + root-tree.o dir-item.o file-item.o inode-item.o \ + inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ + volumes.o utils.o + +# +CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ + -Wuninitialized -Wshadow -Wundef +DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ + +INSTALL= install +prefix ?= /usr/local +libdir = $(prefix)/lib/ + + +# make C=1 to enable sparse +ifdef C + check=sparse $(CHECKFLAGS) +else + check=ls +endif + +.c.o: + $(check) $< + $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< + +all: libbtrfs.a + +libbtrfs.a: $(objects) + $(ARGEN) $@ $(objects) + $(RANLIB) $@ + +clean : + rm -f $(progs) *.o .*.d + rm -f libbtrfs.a + +install: $(progs) + $(INSTALL) -m755 -d $(DESTDIR)$(libdir) + $(INSTALL) libbtrfs.a $(DESTDIR)$(libdir) + +-include .*.d diff --git a/bit-radix.c b/lib/bit-radix.c similarity index 100% rename from bit-radix.c rename to lib/bit-radix.c diff --git a/bit-radix.h b/lib/bit-radix.h similarity index 100% rename from bit-radix.h rename to lib/bit-radix.h diff --git a/crc32c.c b/lib/crc32c.c similarity index 100% rename from crc32c.c rename to lib/crc32c.c diff --git a/crc32c.h b/lib/crc32c.h similarity index 100% rename from crc32c.h rename to lib/crc32c.h diff --git a/ctree.c b/lib/ctree.c similarity index 100% rename from ctree.c rename to lib/ctree.c diff --git a/ctree.h b/lib/ctree.h similarity index 100% rename from ctree.h rename to lib/ctree.h diff --git a/dir-item.c b/lib/dir-item.c similarity index 100% rename from dir-item.c rename to lib/dir-item.c diff --git a/disk-io.c b/lib/disk-io.c similarity index 100% rename from disk-io.c rename to lib/disk-io.c diff --git a/disk-io.h b/lib/disk-io.h similarity index 100% rename from disk-io.h rename to lib/disk-io.h diff --git a/extent-cache.c b/lib/extent-cache.c similarity index 100% rename from extent-cache.c rename to lib/extent-cache.c diff --git a/extent-cache.h b/lib/extent-cache.h similarity index 100% rename from extent-cache.h rename to lib/extent-cache.h diff --git a/extent-tree.c b/lib/extent-tree.c similarity index 100% rename from extent-tree.c rename to lib/extent-tree.c diff --git a/extent_io.c b/lib/extent_io.c similarity index 100% rename from extent_io.c rename to lib/extent_io.c diff --git a/extent_io.h b/lib/extent_io.h similarity index 100% rename from extent_io.h rename to lib/extent_io.h diff --git a/file-item.c b/lib/file-item.c similarity index 100% rename from file-item.c rename to lib/file-item.c diff --git a/hash.h b/lib/hash.h similarity index 100% rename from hash.h rename to lib/hash.h diff --git a/inode-item.c b/lib/inode-item.c similarity index 100% rename from inode-item.c rename to lib/inode-item.c diff --git a/inode-map.c b/lib/inode-map.c similarity index 100% rename from inode-map.c rename to lib/inode-map.c diff --git a/ioctl.h b/lib/ioctl.h similarity index 100% rename from ioctl.h rename to lib/ioctl.h diff --git a/kerncompat.h b/lib/kerncompat.h similarity index 100% rename from kerncompat.h rename to lib/kerncompat.h diff --git a/list.h b/lib/list.h similarity index 100% rename from list.h rename to lib/list.h diff --git a/print-tree.c b/lib/print-tree.c similarity index 100% rename from print-tree.c rename to lib/print-tree.c diff --git a/print-tree.h b/lib/print-tree.h similarity index 100% rename from print-tree.h rename to lib/print-tree.h diff --git a/radix-tree.c b/lib/radix-tree.c similarity index 100% rename from radix-tree.c rename to lib/radix-tree.c diff --git a/radix-tree.h b/lib/radix-tree.h similarity index 100% rename from radix-tree.h rename to lib/radix-tree.h diff --git a/rbtree.c b/lib/rbtree.c similarity index 100% rename from rbtree.c rename to lib/rbtree.c diff --git a/rbtree.h b/lib/rbtree.h similarity index 100% rename from rbtree.h rename to lib/rbtree.h diff --git a/root-tree.c b/lib/root-tree.c similarity index 100% rename from root-tree.c rename to lib/root-tree.c diff --git a/transaction.h b/lib/transaction.h similarity index 100% rename from transaction.h rename to lib/transaction.h diff --git a/utils.c b/lib/utils.c similarity index 100% rename from utils.c rename to lib/utils.c diff --git a/utils.h b/lib/utils.h similarity index 100% rename from utils.h rename to lib/utils.h diff --git a/volumes.c b/lib/volumes.c similarity index 100% rename from volumes.c rename to lib/volumes.c diff --git a/volumes.h b/lib/volumes.h similarity index 100% rename from volumes.h rename to lib/volumes.h diff --git a/misc/Makefile b/misc/Makefile new file mode 100644 index 0000000..4a39c80 --- /dev/null +++ b/misc/Makefile @@ -0,0 +1,79 @@ +CC=gcc +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g -Werror -Os -I../lib/ +# +CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ + -Wuninitialized -Wshadow -Wundef +DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ + +INSTALL= install +prefix ?= /usr/local +bindir = $(prefix)/bin +LIBS=-luuid +TOPDIR=../ + +progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ + btrfs-map-logical + +# make C=1 to enable sparse +ifdef C + check=sparse $(CHECKFLAGS) +else + check=ls +endif + +.c.o: + $(check) $< + $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< + +all: version $(progs) + +version: + bash version.sh + +btrfsctl: $(TOPDIR)/lib/libbtrfs.a btrfsctl.o + gcc $(CFLAGS) -static -o btrfsctl btrfsctl.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfs-vol: $(TOPDIR)/lib/libbtrfs.a btrfs-vol.o + gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfs-show: $(TOPDIR)/lib/libbtrfs.a btrfs-show.o + gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfsck: $(TOPDIR)/lib/libbtrfs.a btrfsck.o + gcc $(CFLAGS) -o btrfsck btrfsck.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +mkfs.btrfs: $(TOPDIR)/lib/libbtrfs.a mkfs.o + gcc $(CFLAGS) -o mkfs.btrfs mkfs.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfs-debug-tree: $(TOPDIR)/lib/libbtrfs.a debug-tree.o + gcc $(CFLAGS) -o btrfs-debug-tree debug-tree.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfstune: $(TOPDIR)/lib/libbtrfs.a btrfstune.o + gcc $(CFLAGS) -o btrfstune btrfstune.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfs-map-logical: $(TOPDIR)/lib/libbtrfs.a btrfs-map-logical.o + gcc $(CFLAGS) -o btrfs-map-logical btrfs-map-logical.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +btrfs-image: $(TOPDIR)/lib/libbtrfs.a btrfs-image.o + gcc $(CFLAGS) -o btrfs-image btrfs-image.o $(TOPDIR)/lib/libbtrfs.a -lpthread -lz $(LDFLAGS) $(LIBS) + +dir-test: $(TOPDIR)/lib/libbtrfs.a dir-test.o + gcc $(CFLAGS) -o dir-test dir-test.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +quick-test: $(TOPDIR)/lib/libbtrfs.a quick-test.o + gcc $(CFLAGS) -o quick-test quick-test.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +convert: $(TOPDIR)/lib/libbtrfs.a convert.o + gcc $(CFLAGS) -o btrfs-convert convert.o $(TOPDIR)/lib/libbtrfs.a -lext2fs $(LDFLAGS) $(LIBS) + +clean : + rm -f $(progs) cscope.out *.o .*.d btrfs-convert + rm -f version.h + +install: $(progs) install-man + $(INSTALL) -m755 -d $(DESTDIR)$(bindir) + $(INSTALL) $(progs) $(DESTDIR)$(bindir) + if [ -e btrfs-convert ]; then $(INSTALL) btrfs-convert $(DESTDIR)$(bindir); fi + +-include .*.d diff --git a/bcp b/misc/bcp old mode 100755 new mode 100644 similarity index 100% rename from bcp rename to misc/bcp diff --git a/btrfs-image.c b/misc/btrfs-image.c similarity index 100% rename from btrfs-image.c rename to misc/btrfs-image.c diff --git a/btrfs-map-logical.c b/misc/btrfs-map-logical.c similarity index 100% rename from btrfs-map-logical.c rename to misc/btrfs-map-logical.c diff --git a/btrfs-show.c b/misc/btrfs-show.c similarity index 100% rename from btrfs-show.c rename to misc/btrfs-show.c diff --git a/btrfs-vol.c b/misc/btrfs-vol.c similarity index 100% rename from btrfs-vol.c rename to misc/btrfs-vol.c diff --git a/btrfsck.c b/misc/btrfsck.c similarity index 100% rename from btrfsck.c rename to misc/btrfsck.c diff --git a/btrfsctl.c b/misc/btrfsctl.c similarity index 100% rename from btrfsctl.c rename to misc/btrfsctl.c diff --git a/btrfstune.c b/misc/btrfstune.c similarity index 100% rename from btrfstune.c rename to misc/btrfstune.c diff --git a/convert.c b/misc/convert.c similarity index 100% rename from convert.c rename to misc/convert.c diff --git a/debug-tree.c b/misc/debug-tree.c similarity index 100% rename from debug-tree.c rename to misc/debug-tree.c diff --git a/mkfs.c b/misc/mkfs.c similarity index 100% rename from mkfs.c rename to misc/mkfs.c diff --git a/version.sh b/misc/version.sh similarity index 100% rename from version.sh rename to misc/version.sh diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..e8df52c --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,88 @@ +CC=gcc +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g -Werror -Os +objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ + root-tree.o dir-item.o file-item.o inode-item.o \ + inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ + volumes.o utils.o + +# +CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ + -Wuninitialized -Wshadow -Wundef +DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ + +INSTALL= install +prefix ?= /usr/local +bindir = $(prefix)/bin +LIBS=-luuid + +progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ + btrfs-map-logical + +# make C=1 to enable sparse +ifdef C + check=sparse $(CHECKFLAGS) +else + check=ls +endif + +.c.o: + $(check) $< + $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< + + +all: version $(progs) manpages + +version: + bash version.sh + +btrfsctl: $(objects) btrfsctl.o + gcc $(CFLAGS) -static -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS) + +btrfs-vol: $(objects) btrfs-vol.o + gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS) + gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS) + +btrfsck: $(objects) btrfsck.o + gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS) + +mkfs.btrfs: $(objects) mkfs.o + gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) + +btrfs-debug-tree: $(objects) debug-tree.o + gcc $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS) + +btrfstune: $(objects) btrfstune.o + gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS) + +btrfs-map-logical: $(objects) btrfs-map-logical.o + gcc $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS) + +btrfs-image: $(objects) btrfs-image.o + gcc $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS) + +dir-test: $(objects) dir-test.o + gcc $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS) + +quick-test: $(objects) quick-test.o + gcc $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS) + +convert: $(objects) convert.o + gcc $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs $(LDFLAGS) $(LIBS) + +manpages: + cd man; make + +install-man: + cd man; make install + +clean : + rm -f $(progs) cscope.out *.o .*.d btrfs-convert + cd man; make clean + +install: $(progs) install-man + $(INSTALL) -m755 -d $(DESTDIR)$(bindir) + $(INSTALL) $(progs) $(DESTDIR)$(bindir) + if [ -e btrfs-convert ]; then $(INSTALL) btrfs-convert $(DESTDIR)$(bindir); fi + +-include .*.d diff --git a/dir-test.c b/tests/dir-test.c similarity index 100% rename from dir-test.c rename to tests/dir-test.c diff --git a/hasher.c b/tests/hasher.c similarity index 100% rename from hasher.c rename to tests/hasher.c diff --git a/quick-test.c b/tests/quick-test.c similarity index 100% rename from quick-test.c rename to tests/quick-test.c diff --git a/random-test.c b/tests/random-test.c similarity index 100% rename from random-test.c rename to tests/random-test.c diff --git a/show-blocks b/tests/show-blocks old mode 100755 new mode 100644 similarity index 100% rename from show-blocks rename to tests/show-blocks -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- Makefile | 3 + debugbtrfs/Makefile | 44 +++++++ debugbtrfs/cmds.c | 27 +++++ debugbtrfs/debug_btrfs.c | 59 ++++++++++ debugbtrfs/debug_btrfs.h | 29 +++++ debugbtrfs/debug_btrfs_cmds.ct | 33 ++++++ debugbtrfs/debug_tree.c | 243 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 438 insertions(+), 0 deletions(-) create mode 100644 debugbtrfs/Makefile create mode 100644 debugbtrfs/cmds.c create mode 100644 debugbtrfs/debug_btrfs.c create mode 100644 debugbtrfs/debug_btrfs.h create mode 100644 debugbtrfs/debug_btrfs_cmds.ct create mode 100644 debugbtrfs/debug_tree.c diff --git a/Makefile b/Makefile index a30c212..3efd405 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,9 @@ bindir = $(prefix)/bin LIBS=-luuid SUBDIRS=lib misc man +ifneq ($(E2FSPRGS_BUILD_DIR),) + SUBDIRS += debugbtrfs +endif # make C=1 to enable sparse ifdef C diff --git a/debugbtrfs/Makefile b/debugbtrfs/Makefile new file mode 100644 index 0000000..d9d3720 --- /dev/null +++ b/debugbtrfs/Makefile @@ -0,0 +1,44 @@ +CC=gcc +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g -Werror -Os -I$(E2FSPRGS_BUILD_DIR)/lib/ -I../lib/ + +# +CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ + -Wuninitialized -Wshadow -Wundef +DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ + +INSTALL= install +prefix ?= /usr/local +bindir = $(prefix)/bin +LIBS=-L$(E2FSPRGS_BUILD_DIR)/lib/ss -lss -ldl -lcom_err -luuid +TOPDIR=../ + +MK_CMDS= _SS_DIR_OVERRIDE=$(E2FSPRGS_BUILD_DIR)/lib/ss $(E2FSPRGS_BUILD_DIR)/lib/ss/mk_cmds + +progs = debug-btrfs + +# make C=1 to enable sparse +ifdef C + check=sparse $(CHECKFLAGS) +else + check=ls +endif + +.c.o: + $(check) $< + $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< + +all: $(progs) + +debug_btrfs_cmds.c: debug_btrfs_cmds.ct + $(MK_CMDS) debug_btrfs_cmds.ct + +debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o + $(CC) $(CFLAGS) -o debug-btrfs debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +clean: + rm -f *.o debug_btrfs_cmds.c + rm -f .*.d + rm -f debug-btrfs + +-include .*.d diff --git a/debugbtrfs/cmds.c b/debugbtrfs/cmds.c new file mode 100644 index 0000000..f5ed877 --- /dev/null +++ b/debugbtrfs/cmds.c @@ -0,0 +1,27 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include <stdio.h> +#include "debug_btrfs.h" + +void do_show_debugfs_params(int argc, char *argv[]) +{ + FILE *out = stdout; + fprintf(out, "Filesystem in use: %s\n", current_device); +} diff --git a/debugbtrfs/debug_btrfs.c b/debugbtrfs/debug_btrfs.c new file mode 100644 index 0000000..44d6f64 --- /dev/null +++ b/debugbtrfs/debug_btrfs.c @@ -0,0 +1,59 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <ss/ss.h> +#include "debug_btrfs.h" + +extern ss_request_table btrfs_debug_cmds; +const char *current_device; + +void usage(char *prg) +{ + fprintf(stderr, "Usage: %s device\n", prg); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int sci_idx; + int retval; + + if (argc < 2) + usage(argv[0]); + + current_device = argv[1]; + sci_idx = ss_create_invocation("debug-btrfs", "0.0", NULL, + &btrfs_debug_cmds, &retval); + if (retval) { + ss_perror(sci_idx, retval, "create invocation"); + exit(1); + } + ss_get_readline(sci_idx); + (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval); + if (retval) { + ss_perror(sci_idx, retval, "adding standard requests"); + exit (1); + } + ss_listen(sci_idx); + ss_delete_invocation(sci_idx); + + return 0; +} diff --git a/debugbtrfs/debug_btrfs.h b/debugbtrfs/debug_btrfs.h new file mode 100644 index 0000000..55d7b17 --- /dev/null +++ b/debugbtrfs/debug_btrfs.h @@ -0,0 +1,29 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef DEBUG_BTRFS_H +#define DEBUG_BTRFS_H +#include <getopt.h> + +extern const char *current_device; +static inline void reset_getopt(void) +{ + optind = 0; +} +#endif diff --git a/debugbtrfs/debug_btrfs_cmds.ct b/debugbtrfs/debug_btrfs_cmds.ct new file mode 100644 index 0000000..bd2e479 --- /dev/null +++ b/debugbtrfs/debug_btrfs_cmds.ct @@ -0,0 +1,33 @@ +# Copyright IBM Corporation, 2010 +# Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License v2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA. + +command_table btrfs_debug_cmds; + +request do_show_debugfs_params, "Show btrfs_debug parameters", + show_debugfs_params, params; + +request do_dump_tree, "Show full btrfs tree", + dump_tree; + +request do_dump_root_tree, "Show root tree", + dump_root_tree; + +request do_dump_chunk_tree, "Show btrfs chunk tree", + dump_chunk_tree; + +end; + diff --git a/debugbtrfs/debug_tree.c b/debugbtrfs/debug_tree.c new file mode 100644 index 0000000..1a1e5e2 --- /dev/null +++ b/debugbtrfs/debug_tree.c @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2007 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <uuid/uuid.h> +#include "kerncompat.h" +#include "radix-tree.h" +#include "ctree.h" +#include "disk-io.h" +#include "print-tree.h" +#include "transaction.h" +#include "debug_btrfs.h" + +static void print_dump_tree_usage(void) +{ + fprintf(stderr, "usage: dump-tree [ -e ] \n"); +} + +void do_dump_root_tree(int argc, char *argv[]) +{ + struct btrfs_root *root; + + radix_tree_init(); + root = open_ctree(current_device, 0, 0); + if (!root) { + fprintf(stderr, "unable to open %s\n", current_device); + return; + } + printf("root tree\n"); + btrfs_print_tree(root->fs_info->tree_root, + root->fs_info->tree_root->node); +} + +void do_dump_chunk_tree(int argc, char *argv[]) +{ + struct btrfs_root *root; + radix_tree_init(); + root = open_ctree(current_device, 0, 0); + if (!root) { + fprintf(stderr, "unable to open %s\n", current_device); + return; + } + printf("chunk tree\n"); + btrfs_print_tree(root->fs_info->chunk_root, + root->fs_info->chunk_root->node); +} + +void do_dump_tree(int argc, char *argv[]) +{ + struct btrfs_root *root; + struct btrfs_path path; + struct btrfs_key key; + struct btrfs_root_item ri; + struct extent_buffer *leaf; + struct btrfs_disk_key disk_key; + struct btrfs_key found_key; + char uuidbuf[37]; + int ret; + int slot; + int extent_only = 0; + struct btrfs_root *tree_root_scan; + + radix_tree_init(); + reset_getopt(); + while(1) { + int c; + c = getopt(argc, argv, "e"); + if (c < 0) + break; + switch(c) { + case ''e'': + extent_only = 1; + break; + default: + print_dump_tree_usage(); + return; + } + } + + root = open_ctree(current_device, 0, 0); + if (!root) { + fprintf(stderr, "unable to open %s\n", current_device); + return; + } + if (!extent_only) { + printf("root tree\n"); + btrfs_print_tree(root->fs_info->tree_root, + root->fs_info->tree_root->node); + + printf("chunk tree\n"); + btrfs_print_tree(root->fs_info->chunk_root, + root->fs_info->chunk_root->node); + } + tree_root_scan = root->fs_info->tree_root; + + btrfs_init_path(&path); +again: + key.offset = 0; + key.objectid = 0; + btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); + ret = btrfs_search_slot(NULL, tree_root_scan, &key, &path, 0, 0); + BUG_ON(ret < 0); + while(1) { + leaf = path.nodes[0]; + slot = path.slots[0]; + if (slot >= btrfs_header_nritems(leaf)) { + ret = btrfs_next_leaf(tree_root_scan, &path); + if (ret != 0) + break; + leaf = path.nodes[0]; + slot = path.slots[0]; + } + btrfs_item_key(leaf, &disk_key, path.slots[0]); + btrfs_disk_key_to_cpu(&found_key, &disk_key); + if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) { + unsigned long offset; + struct extent_buffer *buf; + int skip = extent_only; + + offset = btrfs_item_ptr_offset(leaf, slot); + read_extent_buffer(leaf, &ri, offset, sizeof(ri)); + buf = read_tree_block(tree_root_scan, + btrfs_root_bytenr(&ri), + tree_root_scan->leafsize, 0); + switch(found_key.objectid) { + case BTRFS_ROOT_TREE_OBJECTID: + if (!skip) + printf("root"); + break; + case BTRFS_EXTENT_TREE_OBJECTID: + skip = 0; + printf("extent"); + break; + case BTRFS_CHUNK_TREE_OBJECTID: + if (!skip) { + printf("chunk"); + } + break; + case BTRFS_DEV_TREE_OBJECTID: + if (!skip) { + printf("device"); + } + break; + case BTRFS_FS_TREE_OBJECTID: + if (!skip) { + printf("fs"); + } + break; + case BTRFS_ROOT_TREE_DIR_OBJECTID: + if (!skip) { + printf("directory"); + } + break; + case BTRFS_CSUM_TREE_OBJECTID: + if (!skip) { + printf("checksum"); + } + break; + case BTRFS_ORPHAN_OBJECTID: + if (!skip) { + printf("orphan"); + } + break; + case BTRFS_TREE_LOG_OBJECTID: + if (!skip) { + printf("log"); + } + break; + case BTRFS_TREE_LOG_FIXUP_OBJECTID: + if (!skip) { + printf("log fixup"); + } + break; + case BTRFS_TREE_RELOC_OBJECTID: + if (!skip) { + printf("reloc"); + } + break; + case BTRFS_DATA_RELOC_TREE_OBJECTID: + if (!skip) { + printf("data reloc"); + } + break; + case BTRFS_EXTENT_CSUM_OBJECTID: + if (!skip) { + printf("extent checksum"); + } + case BTRFS_MULTIPLE_OBJECTIDS: + if (!skip) { + printf("multiple"); + } + break; + default: + if (!skip) { + printf("file"); + } + } + if (!skip) { + printf(" tree "); + btrfs_print_key(&disk_key); + printf(" \n"); + btrfs_print_tree(tree_root_scan, buf); + } + } + path.slots[0]++; + } + btrfs_release_path(root, &path); + + if (tree_root_scan == root->fs_info->tree_root && + root->fs_info->log_root_tree) { + tree_root_scan = root->fs_info->log_root_tree; + goto again; + } + + if (extent_only) + return; + + printf("total bytes %llu\n", + (unsigned long long)btrfs_super_total_bytes(&root->fs_info->super_copy)); + printf("bytes used %llu\n", + (unsigned long long)btrfs_super_bytes_used(&root->fs_info->super_copy)); + uuidbuf[36] = ''\0''; + uuid_unparse(root->fs_info->super_copy.fsid, uuidbuf); + printf("uuid %s\n", uuidbuf); + return; +} -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Aneesh Kumar K.V
2010-Jan-31 14:21 UTC
[PATCH 3/4] debug-btrfs: Add open file system command
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- debugbtrfs/cmds.c | 23 +++++++++++++++++ debugbtrfs/debug_btrfs.c | 16 +++++------ debugbtrfs/debug_btrfs.h | 1 + debugbtrfs/debug_btrfs_cmds.ct | 3 ++ debugbtrfs/debug_tree.c | 54 ++++++++++++++++----------------------- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/debugbtrfs/cmds.c b/debugbtrfs/cmds.c index f5ed877..cd2901b 100644 --- a/debugbtrfs/cmds.c +++ b/debugbtrfs/cmds.c @@ -18,6 +18,11 @@ */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "ctree.h" +#include "disk-io.h" #include "debug_btrfs.h" void do_show_debugfs_params(int argc, char *argv[]) @@ -25,3 +30,21 @@ void do_show_debugfs_params(int argc, char *argv[]) FILE *out = stdout; fprintf(out, "Filesystem in use: %s\n", current_device); } + +void do_open_filesys(int argc, char *argv[]) +{ + if (argc != 1) { + free((void *)current_device); + current_device = strdup(argv[1]); + } + + if (current_fs_root) + close_ctree(current_fs_root); + + radix_tree_init(); + current_fs_root = open_ctree(current_device, 0, 0); + if (!current_fs_root) { + fprintf(stderr, "unable to open %s\n", current_device); + return; + } +} diff --git a/debugbtrfs/debug_btrfs.c b/debugbtrfs/debug_btrfs.c index 44d6f64..d9f10e9 100644 --- a/debugbtrfs/debug_btrfs.c +++ b/debugbtrfs/debug_btrfs.c @@ -19,27 +19,25 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <ss/ss.h> #include "debug_btrfs.h" extern ss_request_table btrfs_debug_cmds; const char *current_device; - -void usage(char *prg) -{ - fprintf(stderr, "Usage: %s device\n", prg); - exit(1); -} +struct btrfs_root *current_fs_root; +extern void do_open_filesys(int argc, char *argv[]); int main(int argc, char *argv[]) { int sci_idx; int retval; - if (argc < 2) - usage(argv[0]); + if (argc != 1) { + /* open the file system */ + do_open_filesys(argc, argv); + } - current_device = argv[1]; sci_idx = ss_create_invocation("debug-btrfs", "0.0", NULL, &btrfs_debug_cmds, &retval); if (retval) { diff --git a/debugbtrfs/debug_btrfs.h b/debugbtrfs/debug_btrfs.h index 55d7b17..1ea4fb2 100644 --- a/debugbtrfs/debug_btrfs.h +++ b/debugbtrfs/debug_btrfs.h @@ -22,6 +22,7 @@ #include <getopt.h> extern const char *current_device; +extern struct btrfs_root *current_fs_root; static inline void reset_getopt(void) { optind = 0; diff --git a/debugbtrfs/debug_btrfs_cmds.ct b/debugbtrfs/debug_btrfs_cmds.ct index bd2e479..a46dbde 100644 --- a/debugbtrfs/debug_btrfs_cmds.ct +++ b/debugbtrfs/debug_btrfs_cmds.ct @@ -20,6 +20,9 @@ command_table btrfs_debug_cmds; request do_show_debugfs_params, "Show btrfs_debug parameters", show_debugfs_params, params; +request do_open_filesys, "Open the file system", + open_filesys, open; + request do_dump_tree, "Show full btrfs tree", dump_tree; diff --git a/debugbtrfs/debug_tree.c b/debugbtrfs/debug_tree.c index 1a1e5e2..820549d 100644 --- a/debugbtrfs/debug_tree.c +++ b/debugbtrfs/debug_tree.c @@ -35,36 +35,28 @@ static void print_dump_tree_usage(void) void do_dump_root_tree(int argc, char *argv[]) { - struct btrfs_root *root; - - radix_tree_init(); - root = open_ctree(current_device, 0, 0); - if (!root) { - fprintf(stderr, "unable to open %s\n", current_device); + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } printf("root tree\n"); - btrfs_print_tree(root->fs_info->tree_root, - root->fs_info->tree_root->node); + btrfs_print_tree(current_fs_root->fs_info->tree_root, + current_fs_root->fs_info->tree_root->node); } void do_dump_chunk_tree(int argc, char *argv[]) { - struct btrfs_root *root; - radix_tree_init(); - root = open_ctree(current_device, 0, 0); - if (!root) { - fprintf(stderr, "unable to open %s\n", current_device); + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } printf("chunk tree\n"); - btrfs_print_tree(root->fs_info->chunk_root, - root->fs_info->chunk_root->node); + btrfs_print_tree(current_fs_root->fs_info->chunk_root, + current_fs_root->fs_info->chunk_root->node); } void do_dump_tree(int argc, char *argv[]) { - struct btrfs_root *root; struct btrfs_path path; struct btrfs_key key; struct btrfs_root_item ri; @@ -77,7 +69,6 @@ void do_dump_tree(int argc, char *argv[]) int extent_only = 0; struct btrfs_root *tree_root_scan; - radix_tree_init(); reset_getopt(); while(1) { int c; @@ -94,21 +85,20 @@ void do_dump_tree(int argc, char *argv[]) } } - root = open_ctree(current_device, 0, 0); - if (!root) { - fprintf(stderr, "unable to open %s\n", current_device); + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } if (!extent_only) { printf("root tree\n"); - btrfs_print_tree(root->fs_info->tree_root, - root->fs_info->tree_root->node); + btrfs_print_tree(current_fs_root->fs_info->tree_root, + current_fs_root->fs_info->tree_root->node); printf("chunk tree\n"); - btrfs_print_tree(root->fs_info->chunk_root, - root->fs_info->chunk_root->node); + btrfs_print_tree(current_fs_root->fs_info->chunk_root, + current_fs_root->fs_info->chunk_root->node); } - tree_root_scan = root->fs_info->tree_root; + tree_root_scan = current_fs_root->fs_info->tree_root; btrfs_init_path(&path); again: @@ -221,11 +211,11 @@ again: } path.slots[0]++; } - btrfs_release_path(root, &path); + btrfs_release_path(current_fs_root, &path); - if (tree_root_scan == root->fs_info->tree_root && - root->fs_info->log_root_tree) { - tree_root_scan = root->fs_info->log_root_tree; + if (tree_root_scan == current_fs_root->fs_info->tree_root && + current_fs_root->fs_info->log_root_tree) { + tree_root_scan = current_fs_root->fs_info->log_root_tree; goto again; } @@ -233,11 +223,11 @@ again: return; printf("total bytes %llu\n", - (unsigned long long)btrfs_super_total_bytes(&root->fs_info->super_copy)); + (unsigned long long)btrfs_super_total_bytes(¤t_fs_root->fs_info->super_copy)); printf("bytes used %llu\n", - (unsigned long long)btrfs_super_bytes_used(&root->fs_info->super_copy)); + (unsigned long long)btrfs_super_bytes_used(¤t_fs_root->fs_info->super_copy)); uuidbuf[36] = ''\0''; - uuid_unparse(root->fs_info->super_copy.fsid, uuidbuf); + uuid_unparse(current_fs_root->fs_info->super_copy.fsid, uuidbuf); printf("uuid %s\n", uuidbuf); return; } -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- debugbtrfs/cmds.c | 100 ++++++++++++++++++++++++++++++++++++++++ debugbtrfs/debug_btrfs_cmds.ct | 3 + 2 files changed, 103 insertions(+), 0 deletions(-) diff --git a/debugbtrfs/cmds.c b/debugbtrfs/cmds.c index cd2901b..be7da31 100644 --- a/debugbtrfs/cmds.c +++ b/debugbtrfs/cmds.c @@ -23,6 +23,8 @@ #include "ctree.h" #include "disk-io.h" +#include "extent_io.h" +#include "transaction.h" #include "debug_btrfs.h" void do_show_debugfs_params(int argc, char *argv[]) @@ -48,3 +50,101 @@ void do_open_filesys(int argc, char *argv[]) return; } } + +void dump_inode_details(u64 ino, struct extent_buffer *leaf, + struct btrfs_inode_item *inode_item) +{ + char *format_space = " "; + printf("Inode: %10llu", (unsigned long long)ino); + printf("%sMode: %5o", format_space, + btrfs_inode_mode(leaf, inode_item) & 0777); + printf("%sUser: %d\n", format_space, btrfs_inode_uid(leaf, inode_item)); + printf("Size: %llu\n", (unsigned long long) + btrfs_inode_size(leaf, inode_item)); + return; +} + +void dump_file_extent(u64 offset, struct extent_buffer *leaf, + struct btrfs_file_extent_item *file_extent_item) +{ + printf("[%15llu - %15llu (%15llu)]\t->\t", (unsigned long long) offset, + (unsigned long long) + offset + btrfs_file_extent_num_bytes(leaf, file_extent_item), + btrfs_file_extent_num_bytes(leaf, file_extent_item)); + + printf("%15llu (%15llu)\n", (unsigned long long) + btrfs_file_extent_disk_bytenr(leaf, file_extent_item), + btrfs_file_extent_disk_num_bytes(leaf, file_extent_item)); + return ; +} + +void dump_file_hole_extent(u64 offset, u64 end_offset) +{ + printf("[%15llu - %15llu (%15llu)]\t->\t", (unsigned long long) offset, + (unsigned long long) end_offset, end_offset - offset); + printf("Hole\n"); +} + +void do_print_inode(int argc, char *argv[]) +{ + int ret; + u64 offset, inode_i_size; + struct btrfs_path *path; + struct btrfs_key inode_key; + struct extent_buffer *leaf; + struct btrfs_trans_handle *trans; + struct btrfs_inode_item *inode_item; + struct btrfs_file_extent_item *file_extent_item; + + + if (argc != 2) { + fprintf(stderr, "Usage inode inode_num\n"); + return; + } + inode_key.objectid = atoll(argv[1]); + inode_key.type = BTRFS_INODE_ITEM_KEY; + inode_key.offset = 0; + + path = btrfs_alloc_path(); + btrfs_init_path(path); + trans = btrfs_start_transaction(current_fs_root, 1); + + ret = btrfs_search_slot(trans, current_fs_root, &inode_key, path, 0, 0); + if (ret != 0) { + fprintf(stderr, "Failed get the inode details for %llu\n", + (unsigned long long)inode_key.objectid); + return; + } + leaf = path->nodes[0]; + inode_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item); + dump_inode_details(inode_key.objectid, leaf, inode_item); + inode_i_size = btrfs_inode_size(leaf, inode_item); + btrfs_release_path(current_fs_root, path); + + /* get the file extent details */ + offset = 0; + /* Dump header */ + printf("Extent details:\n"); + printf("[%15s - %15s (%15s)]\t->\t%15s (%15s)\n", + "Logical offset", + "End offset", + "Extent Size", + "Disk bytenr", + "Actual disk size"); + while (offset < inode_i_size) { + btrfs_init_path(path); + ret = btrfs_lookup_file_extent(trans, current_fs_root, path, + inode_key.objectid, offset, 0); + if (ret != 0) { + fprintf(stderr, "Not able to retrive extent information\n"); + break; + } + leaf = path->nodes[0]; + file_extent_item = btrfs_item_ptr(leaf, path->slots[0], + struct btrfs_file_extent_item); + dump_file_extent(offset, leaf, file_extent_item); + offset += btrfs_file_extent_num_bytes(leaf, file_extent_item); + btrfs_release_path(current_fs_root, path); + } + btrfs_commit_transaction(trans, current_fs_root); +} diff --git a/debugbtrfs/debug_btrfs_cmds.ct b/debugbtrfs/debug_btrfs_cmds.ct index a46dbde..98a7282 100644 --- a/debugbtrfs/debug_btrfs_cmds.ct +++ b/debugbtrfs/debug_btrfs_cmds.ct @@ -32,5 +32,8 @@ request do_dump_root_tree, "Show root tree", request do_dump_chunk_tree, "Show btrfs chunk tree", dump_chunk_tree; +request do_print_inode, "Print inode details", + print_inode; + end; -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Aneesh Kumar K.V
2010-Feb-01 04:36 UTC
[PATCH 5/6] debug-btrfs: Add command to dump each of the btrfs trees
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- debugbtrfs/debug_btrfs_cmds.ct | 19 ++++- debugbtrfs/debug_tree.c | 159 ++++++++++++++++++++------------------- 2 files changed, 99 insertions(+), 79 deletions(-) diff --git a/debugbtrfs/debug_btrfs_cmds.ct b/debugbtrfs/debug_btrfs_cmds.ct index 98a7282..6b22bc1 100644 --- a/debugbtrfs/debug_btrfs_cmds.ct +++ b/debugbtrfs/debug_btrfs_cmds.ct @@ -23,17 +23,32 @@ request do_show_debugfs_params, "Show btrfs_debug parameters", request do_open_filesys, "Open the file system", open_filesys, open; +request do_print_inode, "Print inode details", + print_inode; + request do_dump_tree, "Show full btrfs tree", dump_tree; +request do_dump_extent_tree, "Show Extent tree", + dump_extent_tree; + request do_dump_root_tree, "Show root tree", dump_root_tree; request do_dump_chunk_tree, "Show btrfs chunk tree", dump_chunk_tree; -request do_print_inode, "Print inode details", - print_inode; +request do_dump_dev_tree, "Show btrfs dev tree", + dump_dev_tree; + +request do_dump_fs_tree, "Show btrfs fs tree", + dump_fs_tree; + +request do_dump_csum_tree, "Show btrfs checksum tree", + dump_csum_tree; + +request do_dump_log_tree, "Show btrfs log tree", + dump_log_tree; end; diff --git a/debugbtrfs/debug_tree.c b/debugbtrfs/debug_tree.c index 820549d..e92d6d0 100644 --- a/debugbtrfs/debug_tree.c +++ b/debugbtrfs/debug_tree.c @@ -28,9 +28,15 @@ #include "transaction.h" #include "debug_btrfs.h" -static void print_dump_tree_usage(void) +void do_dump_extent_tree(int argc, char *argv[]) { - fprintf(stderr, "usage: dump-tree [ -e ] \n"); + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); + return; + } + printf("Extent tree\n"); + btrfs_print_tree(current_fs_root->fs_info->extent_root, + current_fs_root->fs_info->extent_root->node); } void do_dump_root_tree(int argc, char *argv[]) @@ -55,6 +61,54 @@ void do_dump_chunk_tree(int argc, char *argv[]) current_fs_root->fs_info->chunk_root->node); } +void do_dump_dev_tree(int argc, char *argv[]) +{ + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); + return; + } + printf("Device tree\n"); + btrfs_print_tree(current_fs_root->fs_info->dev_root, + current_fs_root->fs_info->dev_root->node); +} + +void do_dump_fs_tree(int argc, char *argv[]) +{ + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); + return; + } + printf("FS tree\n"); + btrfs_print_tree(current_fs_root->fs_info->fs_root, + current_fs_root->fs_info->fs_root->node); +} + +void do_dump_csum_tree(int argc, char *argv[]) +{ + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); + return; + } + printf("Checksum tree\n"); + btrfs_print_tree(current_fs_root->fs_info->csum_root, + current_fs_root->fs_info->csum_root->node); +} + +void do_dump_log_tree(int argc, char *argv[]) +{ + if (!current_fs_root) { + fprintf(stderr, "File system not yet opened: %s\n", current_device); + return; + } + printf("Log tree\n"); + if (!current_fs_root->fs_info->log_root_tree) { + printf("Nothing to replay \n"); + return; + } + btrfs_print_tree(current_fs_root->fs_info->log_root_tree, + current_fs_root->fs_info->log_root_tree->node); +} + void do_dump_tree(int argc, char *argv[]) { struct btrfs_path path; @@ -66,38 +120,20 @@ void do_dump_tree(int argc, char *argv[]) char uuidbuf[37]; int ret; int slot; - int extent_only = 0; struct btrfs_root *tree_root_scan; - reset_getopt(); - while(1) { - int c; - c = getopt(argc, argv, "e"); - if (c < 0) - break; - switch(c) { - case ''e'': - extent_only = 1; - break; - default: - print_dump_tree_usage(); - return; - } - } - if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - if (!extent_only) { - printf("root tree\n"); - btrfs_print_tree(current_fs_root->fs_info->tree_root, + printf("root tree\n"); + btrfs_print_tree(current_fs_root->fs_info->tree_root, current_fs_root->fs_info->tree_root->node); - printf("chunk tree\n"); - btrfs_print_tree(current_fs_root->fs_info->chunk_root, + printf("chunk tree\n"); + btrfs_print_tree(current_fs_root->fs_info->chunk_root, current_fs_root->fs_info->chunk_root->node); - } + tree_root_scan = current_fs_root->fs_info->tree_root; btrfs_init_path(&path); @@ -122,7 +158,6 @@ again: if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) { unsigned long offset; struct extent_buffer *buf; - int skip = extent_only; offset = btrfs_item_ptr_offset(leaf, slot); read_extent_buffer(leaf, &ri, offset, sizeof(ri)); @@ -131,83 +166,56 @@ again: tree_root_scan->leafsize, 0); switch(found_key.objectid) { case BTRFS_ROOT_TREE_OBJECTID: - if (!skip) - printf("root"); + printf("root"); break; case BTRFS_EXTENT_TREE_OBJECTID: - skip = 0; printf("extent"); break; case BTRFS_CHUNK_TREE_OBJECTID: - if (!skip) { - printf("chunk"); - } + printf("chunk"); break; case BTRFS_DEV_TREE_OBJECTID: - if (!skip) { - printf("device"); - } + printf("device"); break; case BTRFS_FS_TREE_OBJECTID: - if (!skip) { - printf("fs"); - } + printf("fs"); break; case BTRFS_ROOT_TREE_DIR_OBJECTID: - if (!skip) { - printf("directory"); - } + printf("directory"); break; case BTRFS_CSUM_TREE_OBJECTID: - if (!skip) { - printf("checksum"); - } + printf("checksum"); break; case BTRFS_ORPHAN_OBJECTID: - if (!skip) { - printf("orphan"); - } + printf("orphan"); break; case BTRFS_TREE_LOG_OBJECTID: - if (!skip) { - printf("log"); - } + printf("log"); break; case BTRFS_TREE_LOG_FIXUP_OBJECTID: - if (!skip) { - printf("log fixup"); - } + printf("log fixup"); break; case BTRFS_TREE_RELOC_OBJECTID: - if (!skip) { - printf("reloc"); - } + printf("reloc"); break; case BTRFS_DATA_RELOC_TREE_OBJECTID: - if (!skip) { - printf("data reloc"); - } + printf("data reloc"); break; case BTRFS_EXTENT_CSUM_OBJECTID: - if (!skip) { - printf("extent checksum"); - } + printf("extent checksum"); + break; case BTRFS_MULTIPLE_OBJECTIDS: - if (!skip) { - printf("multiple"); - } + printf("multiple"); break; default: - if (!skip) { - printf("file"); - } - } - if (!skip) { - printf(" tree "); - btrfs_print_key(&disk_key); - printf(" \n"); - btrfs_print_tree(tree_root_scan, buf); + printf("file"); } + + printf(" tree "); + btrfs_print_key(&disk_key); + printf(" \n"); + btrfs_print_tree(tree_root_scan, buf); + } path.slots[0]++; } @@ -219,9 +227,6 @@ again: goto again; } - if (extent_only) - return; - printf("total bytes %llu\n", (unsigned long long)btrfs_super_total_bytes(¤t_fs_root->fs_info->super_copy)); printf("bytes used %llu\n", -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> --- debugbtrfs/Makefile | 5 +- debugbtrfs/debug_btrfs.h | 3 + debugbtrfs/debug_tree.c | 106 ++++++++++++-------- debugbtrfs/pager.c | 49 +++++++++ lib/ctree.c | 22 ++-- lib/extent-tree.c | 10 +- lib/print-tree.c | 256 +++++++++++++++++++++++----------------------- lib/print-tree.h | 8 +- lib/root-tree.c | 11 +- misc/debug-tree.c | 8 +- 10 files changed, 278 insertions(+), 200 deletions(-) create mode 100644 debugbtrfs/pager.c diff --git a/debugbtrfs/Makefile b/debugbtrfs/Makefile index d9d3720..8a7163c 100644 --- a/debugbtrfs/Makefile +++ b/debugbtrfs/Makefile @@ -33,8 +33,9 @@ all: $(progs) debug_btrfs_cmds.c: debug_btrfs_cmds.ct $(MK_CMDS) debug_btrfs_cmds.ct -debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o - $(CC) $(CFLAGS) -o debug-btrfs debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) +debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o pager.o + $(CC) $(CFLAGS) -o debug-btrfs debug_btrfs.o cmds.o debug_btrfs_cmds.o debug_tree.o \ + pager.o $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) clean: rm -f *.o debug_btrfs_cmds.c diff --git a/debugbtrfs/debug_btrfs.h b/debugbtrfs/debug_btrfs.h index 1ea4fb2..7f3b4b9 100644 --- a/debugbtrfs/debug_btrfs.h +++ b/debugbtrfs/debug_btrfs.h @@ -19,6 +19,7 @@ #ifndef DEBUG_BTRFS_H #define DEBUG_BTRFS_H +#include <stdio.h> #include <getopt.h> extern const char *current_device; @@ -27,4 +28,6 @@ static inline void reset_getopt(void) { optind = 0; } +extern FILE *open_pager(void); +extern void close_pager(FILE *); #endif diff --git a/debugbtrfs/debug_tree.c b/debugbtrfs/debug_tree.c index e92d6d0..f740b06 100644 --- a/debugbtrfs/debug_tree.c +++ b/debugbtrfs/debug_tree.c @@ -30,87 +30,109 @@ void do_dump_extent_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("Extent tree\n"); - btrfs_print_tree(current_fs_root->fs_info->extent_root, + fp = open_pager(); + fprintf(fp, "Extent tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->extent_root, current_fs_root->fs_info->extent_root->node); + close_pager(fp); } void do_dump_root_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("root tree\n"); - btrfs_print_tree(current_fs_root->fs_info->tree_root, + fp = open_pager(); + fprintf(fp, "root tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->tree_root, current_fs_root->fs_info->tree_root->node); + close_pager(fp); } void do_dump_chunk_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("chunk tree\n"); - btrfs_print_tree(current_fs_root->fs_info->chunk_root, + fp = open_pager(); + fprintf(fp, "chunk tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->chunk_root, current_fs_root->fs_info->chunk_root->node); + close_pager(fp); } void do_dump_dev_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("Device tree\n"); - btrfs_print_tree(current_fs_root->fs_info->dev_root, + fp = open_pager(); + fprintf(fp, "Device tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->dev_root, current_fs_root->fs_info->dev_root->node); + close_pager(fp); } void do_dump_fs_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("FS tree\n"); - btrfs_print_tree(current_fs_root->fs_info->fs_root, + fp = open_pager(); + fprintf(fp, "FS tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->fs_root, current_fs_root->fs_info->fs_root->node); + close_pager(fp); } void do_dump_csum_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("Checksum tree\n"); - btrfs_print_tree(current_fs_root->fs_info->csum_root, + fp = open_pager(); + fprintf(fp, "Checksum tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->csum_root, current_fs_root->fs_info->csum_root->node); + close_pager(fp); } void do_dump_log_tree(int argc, char *argv[]) { + FILE *fp; if (!current_fs_root) { fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("Log tree\n"); + fp = open_pager(); + fprintf(fp, "Log tree\n"); if (!current_fs_root->fs_info->log_root_tree) { - printf("Nothing to replay \n"); + fprintf(fp, "Nothing to replay \n"); return; } - btrfs_print_tree(current_fs_root->fs_info->log_root_tree, + btrfs_print_tree(fp, current_fs_root->fs_info->log_root_tree, current_fs_root->fs_info->log_root_tree->node); + close_pager(fp); } void do_dump_tree(int argc, char *argv[]) { + FILE *fp; struct btrfs_path path; struct btrfs_key key; struct btrfs_root_item ri; @@ -126,12 +148,13 @@ void do_dump_tree(int argc, char *argv[]) fprintf(stderr, "File system not yet opened: %s\n", current_device); return; } - printf("root tree\n"); - btrfs_print_tree(current_fs_root->fs_info->tree_root, + fp = open_pager(); + fprintf(fp, "root tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->tree_root, current_fs_root->fs_info->tree_root->node); - printf("chunk tree\n"); - btrfs_print_tree(current_fs_root->fs_info->chunk_root, + fprintf(fp, "chunk tree\n"); + btrfs_print_tree(fp, current_fs_root->fs_info->chunk_root, current_fs_root->fs_info->chunk_root->node); tree_root_scan = current_fs_root->fs_info->tree_root; @@ -166,55 +189,55 @@ again: tree_root_scan->leafsize, 0); switch(found_key.objectid) { case BTRFS_ROOT_TREE_OBJECTID: - printf("root"); + fprintf(fp, "root"); break; case BTRFS_EXTENT_TREE_OBJECTID: - printf("extent"); + fprintf(fp, "extent"); break; case BTRFS_CHUNK_TREE_OBJECTID: - printf("chunk"); + fprintf(fp, "chunk"); break; case BTRFS_DEV_TREE_OBJECTID: - printf("device"); + fprintf(fp, "device"); break; case BTRFS_FS_TREE_OBJECTID: - printf("fs"); + fprintf(fp, "fs"); break; case BTRFS_ROOT_TREE_DIR_OBJECTID: - printf("directory"); + fprintf(fp, "directory"); break; case BTRFS_CSUM_TREE_OBJECTID: - printf("checksum"); + fprintf(fp, "checksum"); break; case BTRFS_ORPHAN_OBJECTID: - printf("orphan"); + fprintf(fp, "orphan"); break; case BTRFS_TREE_LOG_OBJECTID: - printf("log"); + fprintf(fp, "log"); break; case BTRFS_TREE_LOG_FIXUP_OBJECTID: - printf("log fixup"); + fprintf(fp, "log fixup"); break; case BTRFS_TREE_RELOC_OBJECTID: - printf("reloc"); + fprintf(fp, "reloc"); break; case BTRFS_DATA_RELOC_TREE_OBJECTID: - printf("data reloc"); + fprintf(fp, "data reloc"); break; case BTRFS_EXTENT_CSUM_OBJECTID: - printf("extent checksum"); + fprintf(fp, "extent checksum"); break; case BTRFS_MULTIPLE_OBJECTIDS: - printf("multiple"); + fprintf(fp, "multiple"); break; default: - printf("file"); + fprintf(fp, "file"); } - printf(" tree "); - btrfs_print_key(&disk_key); - printf(" \n"); - btrfs_print_tree(tree_root_scan, buf); + fprintf(fp, " tree "); + btrfs_print_key(fp, &disk_key); + fprintf(fp, " \n"); + btrfs_print_tree(fp, tree_root_scan, buf); } path.slots[0]++; @@ -227,12 +250,13 @@ again: goto again; } - printf("total bytes %llu\n", + fprintf(fp, "total bytes %llu\n", (unsigned long long)btrfs_super_total_bytes(¤t_fs_root->fs_info->super_copy)); - printf("bytes used %llu\n", + fprintf(fp, "bytes used %llu\n", (unsigned long long)btrfs_super_bytes_used(¤t_fs_root->fs_info->super_copy)); uuidbuf[36] = ''\0''; uuid_unparse(current_fs_root->fs_info->super_copy.fsid, uuidbuf); - printf("uuid %s\n", uuidbuf); + fprintf(fp, "uuid %s\n", uuidbuf); + close_pager(fp); return; } diff --git a/debugbtrfs/pager.c b/debugbtrfs/pager.c new file mode 100644 index 0000000..b2d3a96 --- /dev/null +++ b/debugbtrfs/pager.c @@ -0,0 +1,49 @@ +/* derived from e2fsprogs debugfs/util.c */ + +#include <stdlib.h> +#include <stdio.h> +#include <signal.h> +#include <unistd.h> +#include <string.h> + +static const char *pager_search_list[] = { "pager", "more", "less", 0 }; +static const char *pager_dir_list[] = { "/usr/bin", "/bin", 0 }; + +static const char *find_pager(char *buf) +{ + const char **i, **j; + + for (i = pager_search_list; *i; i++) { + for (j = pager_dir_list; *j; j++) { + sprintf(buf, "%s/%s", *j, *i); + if (access(buf, X_OK) == 0) + return(buf); + } + } + return 0; +} + +FILE *open_pager(void) +{ + FILE *outfile = 0; + const char *pager = getenv("DEBUGFS_PAGER"); + char buf[80]; + + signal(SIGPIPE, SIG_IGN); + if (!isatty(1)) + return stdout; + if (!pager) + pager = getenv("PAGER"); + if (!pager) + pager = find_pager(buf); + if (!pager || + (strcmp(pager, "__none__") == 0) || + ((outfile = popen(pager, "w")) == 0)) + return stdout; + return outfile; +} + +void close_pager(FILE *stream) +{ + if (stream && stream != stdout) pclose(stream); +} diff --git a/lib/ctree.c b/lib/ctree.c index f70e10c..45e98ae 100644 --- a/lib/ctree.c +++ b/lib/ctree.c @@ -657,13 +657,13 @@ static int check_leaf(struct btrfs_root *root, struct btrfs_path *path, btrfs_item_key(leaf, &leaf_key, slot); btrfs_item_key_to_cpu(leaf, &cpukey, slot - 1); if (btrfs_comp_keys(&leaf_key, &cpukey) <= 0) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("slot %d offset bad key\n", slot); BUG_ON(1); } if (btrfs_item_offset_nr(leaf, slot - 1) ! btrfs_item_end_nr(leaf, slot)) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("slot %d offset bad\n", slot); BUG_ON(1); } @@ -674,7 +674,7 @@ static int check_leaf(struct btrfs_root *root, struct btrfs_path *path, BUG_ON(btrfs_comp_keys(&leaf_key, &cpukey) >= 0); if (btrfs_item_offset_nr(leaf, slot) ! btrfs_item_end_nr(leaf, slot + 1)) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("slot %d offset bad\n", slot); BUG_ON(1); } @@ -2356,7 +2356,7 @@ split: ret = 0; if (btrfs_leaf_free_space(root, leaf) < 0) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); BUG(); } kfree(buf); @@ -2456,7 +2456,7 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans, ret = 0; if (btrfs_leaf_free_space(root, leaf) < 0) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); BUG(); } return ret; @@ -2484,7 +2484,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, data_end = leaf_data_end(root, leaf); if (btrfs_leaf_free_space(root, leaf) < data_size) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); BUG(); } slot = path->slots[0]; @@ -2492,7 +2492,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, BUG_ON(slot < 0); if (slot >= nritems) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("slot %d too large, nritems %d\n", slot, nritems); BUG_ON(1); } @@ -2521,7 +2521,7 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, ret = 0; if (btrfs_leaf_free_space(root, leaf) < 0) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); BUG(); } return ret; @@ -2572,7 +2572,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, data_end = leaf_data_end(root, leaf); if (btrfs_leaf_free_space(root, leaf) < total_size) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("not enough freespace need %u have %d\n", total_size, btrfs_leaf_free_space(root, leaf)); BUG(); @@ -2586,7 +2586,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, unsigned int old_data = btrfs_item_end_nr(leaf, slot); if (old_data < data_end) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); printk("slot %d old_data %d data_end %d\n", slot, old_data, data_end); BUG_ON(1); @@ -2634,7 +2634,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, } if (btrfs_leaf_free_space(root, leaf) < 0) { - btrfs_print_leaf(root, leaf); + btrfs_print_leaf(stdout, root, leaf); BUG(); } diff --git a/lib/extent-tree.c b/lib/extent-tree.c index b2f9bb2..210da17 100644 --- a/lib/extent-tree.c +++ b/lib/extent-tree.c @@ -1447,7 +1447,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, if (ret < 0) goto out; if (ret != 0) { - btrfs_print_leaf(root, path->nodes[0]); + btrfs_print_leaf(stdout, root, path->nodes[0]); printk("failed to find block number %Lu\n", bytenr); BUG(); } @@ -1505,7 +1505,7 @@ int btrfs_set_block_flags(struct btrfs_trans_handle *trans, if (ret < 0) goto out; if (ret != 0) { - btrfs_print_leaf(root, path->nodes[0]); + btrfs_print_leaf(stdout, root, path->nodes[0]); printk("failed to find block number %Lu\n", (unsigned long long)bytenr); BUG(); @@ -2126,13 +2126,13 @@ static int __free_extent(struct btrfs_trans_handle *trans, printk(KERN_ERR "umm, got %d back from search" ", was looking for %llu\n", ret, (unsigned long long)bytenr); - btrfs_print_leaf(extent_root, path->nodes[0]); + btrfs_print_leaf(stdout, extent_root, path->nodes[0]); } BUG_ON(ret); extent_slot = path->slots[0]; } } else { - btrfs_print_leaf(extent_root, path->nodes[0]); + btrfs_print_leaf(stdout, extent_root, path->nodes[0]); WARN_ON(1); printk(KERN_ERR "btrfs unable to find ref byte nr %llu " "parent %llu root %llu owner %llu offset %llu\n", @@ -2165,7 +2165,7 @@ static int __free_extent(struct btrfs_trans_handle *trans, printk(KERN_ERR "umm, got %d back from search" ", was looking for %llu\n", ret, (unsigned long long)bytenr); - btrfs_print_leaf(extent_root, path->nodes[0]); + btrfs_print_leaf(stdout, extent_root, path->nodes[0]); } BUG_ON(ret); extent_slot = path->slots[0]; diff --git a/lib/print-tree.c b/lib/print-tree.c index 59f4358..af09b8c 100644 --- a/lib/print-tree.c +++ b/lib/print-tree.c @@ -25,7 +25,7 @@ #include "disk-io.h" #include "print-tree.h" -static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item, +static int print_dir_item(FILE *out, struct extent_buffer *eb, struct btrfs_item *item, struct btrfs_dir_item *di) { u32 total; @@ -39,14 +39,14 @@ static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item, total = btrfs_item_size(eb, item); while(cur < total) { btrfs_dir_item_key(eb, di, &location); - printf("\t\tlocation "); - btrfs_print_key(&location); - printf(" type %u\n", btrfs_dir_type(eb, di)); + fprintf(out, "\t\tlocation "); + btrfs_print_key(out, &location); + fprintf(out, " type %u\n", btrfs_dir_type(eb, di)); name_len = btrfs_dir_name_len(eb, di); data_len = btrfs_dir_data_len(eb, di); len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf); read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len); - printf("\t\tnamelen %u datalen %u name: %.*s\n", + fprintf(out, "\t\tnamelen %u datalen %u name: %.*s\n", name_len, data_len, len, namebuf); len = sizeof(*di) + name_len + data_len; di = (struct btrfs_dir_item *)((char *)di + len); @@ -55,7 +55,7 @@ static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item, return 0; } -static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *item, +static int print_inode_ref_item(FILE *out, struct extent_buffer *eb, struct btrfs_item *item, struct btrfs_inode_ref *ref) { u32 total; @@ -70,7 +70,7 @@ static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *ite index = btrfs_inode_ref_index(eb, ref); len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf); read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len); - printf("\t\tinode ref index %llu namelen %u name: %.*s\n", + fprintf(out, "\t\tinode ref index %llu namelen %u name: %.*s\n", (unsigned long long)index, name_len, len, namebuf); len = sizeof(*ref) + name_len; ref = (struct btrfs_inode_ref *)((char *)ref + len); @@ -79,32 +79,32 @@ static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *ite return 0; } -static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk) +static void print_chunk(FILE *out, struct extent_buffer *eb, struct btrfs_chunk *chunk) { int num_stripes = btrfs_chunk_num_stripes(eb, chunk); int i; - printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n", + fprintf(out, "\t\tchunk length %llu owner %llu type %llu num_stripes %d\n", (unsigned long long)btrfs_chunk_length(eb, chunk), (unsigned long long)btrfs_chunk_owner(eb, chunk), (unsigned long long)btrfs_chunk_type(eb, chunk), num_stripes); for (i = 0 ; i < num_stripes ; i++) { - printf("\t\t\tstripe %d devid %llu offset %llu\n", i, + fprintf(out, "\t\t\tstripe %d devid %llu offset %llu\n", i, (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i), (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i)); } } -static void print_dev_item(struct extent_buffer *eb, +static void print_dev_item(FILE *out, struct extent_buffer *eb, struct btrfs_dev_item *dev_item) { - printf("\t\tdev item devid %llu " + fprintf(out, "\t\tdev item devid %llu " "total_bytes %llu bytes used %Lu\n", (unsigned long long)btrfs_device_id(eb, dev_item), (unsigned long long)btrfs_device_total_bytes(eb, dev_item), (unsigned long long)btrfs_device_bytes_used(eb, dev_item)); } -static void print_uuids(struct extent_buffer *eb) +static void print_uuids(FILE *out, struct extent_buffer *eb) { char fs_uuid[37]; char chunk_uuid[37]; @@ -122,17 +122,17 @@ static void print_uuids(struct extent_buffer *eb) chunk_uuid[36] = ''\0''; uuid_unparse(disk_uuid, chunk_uuid); - printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid); + fprintf(out, "fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid); } -static void print_file_extent_item(struct extent_buffer *eb, +static void print_file_extent_item(FILE *out, struct extent_buffer *eb, struct btrfs_item *item, struct btrfs_file_extent_item *fi) { int extent_type = btrfs_file_extent_type(eb, fi); if (extent_type == BTRFS_FILE_EXTENT_INLINE) { - printf("\t\tinline extent data size %u " + fprintf(out, "\t\tinline extent data size %u " "ram %u compress %d\n", btrfs_file_extent_inline_item_len(eb, item), btrfs_file_extent_inline_len(eb, fi), @@ -140,26 +140,26 @@ static void print_file_extent_item(struct extent_buffer *eb, return; } if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { - printf("\t\tprealloc data disk byte %llu nr %llu\n", + fprintf(out, "\t\tprealloc data disk byte %llu nr %llu\n", (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi), (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi)); - printf("\t\tprealloc data offset %llu nr %llu\n", + fprintf(out, "\t\tprealloc data offset %llu nr %llu\n", (unsigned long long)btrfs_file_extent_offset(eb, fi), (unsigned long long)btrfs_file_extent_num_bytes(eb, fi)); return; } - printf("\t\textent data disk byte %llu nr %llu\n", + fprintf(out, "\t\textent data disk byte %llu nr %llu\n", (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi), (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi)); - printf("\t\textent data offset %llu nr %llu ram %llu\n", + fprintf(out, "\t\textent data offset %llu nr %llu ram %llu\n", (unsigned long long)btrfs_file_extent_offset(eb, fi), (unsigned long long)btrfs_file_extent_num_bytes(eb, fi), (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi)); - printf("\t\textent compression %d\n", + fprintf(out, "\t\textent compression %d\n", btrfs_file_extent_compression(eb, fi)); } -static void print_extent_item(struct extent_buffer *eb, int slot) +static void print_extent_item(FILE *out, struct extent_buffer *eb, int slot) { struct btrfs_extent_item *ei; struct btrfs_extent_inline_ref *iref; @@ -178,7 +178,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot) struct btrfs_extent_item_v0 *ei0; BUG_ON(item_size != sizeof(*ei0)); ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0); - printf("\t\textent refs %u\n", + fprintf(out, "\t\textent refs %u\n", btrfs_extent_refs_v0(eb, ei0)); return; #else @@ -189,7 +189,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot) ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item); flags = btrfs_extent_flags(eb, ei); - printf("\t\textent refs %llu gen %llu flags %llu\n", + fprintf(out, "\t\textent refs %llu gen %llu flags %llu\n", (unsigned long long)btrfs_extent_refs(eb, ei), (unsigned long long)btrfs_extent_generation(eb, ei), (unsigned long long)flags); @@ -198,7 +198,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot) struct btrfs_tree_block_info *info; info = (struct btrfs_tree_block_info *)(ei + 1); btrfs_tree_block_key(eb, info, &key); - printf("\t\ttree block key (%llu %x %llu) level %d\n", + fprintf(out, "\t\ttree block key (%llu %x %llu) level %d\n", (unsigned long long)btrfs_disk_key_objectid(&key), key.type, (unsigned long long)btrfs_disk_key_offset(&key), @@ -216,16 +216,16 @@ static void print_extent_item(struct extent_buffer *eb, int slot) offset = btrfs_extent_inline_ref_offset(eb, iref); switch (type) { case BTRFS_TREE_BLOCK_REF_KEY: - printf("\t\ttree block backref root %llu\n", + fprintf(out, "\t\ttree block backref root %llu\n", (unsigned long long)offset); break; case BTRFS_SHARED_BLOCK_REF_KEY: - printf("\t\tshared block backref parent %llu\n", + fprintf(out, "\t\tshared block backref parent %llu\n", (unsigned long long)offset); break; case BTRFS_EXTENT_DATA_REF_KEY: dref = (struct btrfs_extent_data_ref *)(&iref->offset); - printf("\t\textent data backref root %llu " + fprintf(out, "\t\textent data backref root %llu " "objectid %llu offset %llu count %u\n", (unsigned long long)btrfs_extent_data_ref_root(eb, dref), (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref), @@ -234,7 +234,7 @@ static void print_extent_item(struct extent_buffer *eb, int slot) break; case BTRFS_SHARED_DATA_REF_KEY: sref = (struct btrfs_shared_data_ref *)(iref + 1); - printf("\t\tshared data backref parent %llu count %u\n", + fprintf(out, "\t\tshared data backref parent %llu count %u\n", (unsigned long long)offset, btrfs_shared_data_ref_count(eb, sref)); break; @@ -247,12 +247,12 @@ static void print_extent_item(struct extent_buffer *eb, int slot) } #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 -static void print_extent_ref_v0(struct extent_buffer *eb, int slot) +static void print_extent_ref_v0(FILE *out, struct extent_buffer *eb, int slot) { struct btrfs_extent_ref_v0 *ref0; ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0); - printf("\t\textent back ref root %llu gen %llu " + fprintf(out, "\t\textent back ref root %llu gen %llu " "owner %llu num_refs %lu\n", (unsigned long long)btrfs_ref_root_v0(eb, ref0), (unsigned long long)btrfs_ref_generation_v0(eb, ref0), @@ -261,7 +261,7 @@ static void print_extent_ref_v0(struct extent_buffer *eb, int slot) } #endif -static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag) +static void print_root_ref(FILE *out, struct extent_buffer *leaf, int slot, char *tag) { struct btrfs_root_ref *ref; char namebuf[BTRFS_NAME_LEN]; @@ -270,169 +270,169 @@ static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag) ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref); namelen = btrfs_root_ref_name_len(leaf, ref); read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen); - printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag, + fprintf(out, "\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag, (unsigned long long)btrfs_root_ref_dirid(leaf, ref), (unsigned long long)btrfs_root_ref_sequence(leaf, ref), namelen, namebuf); } -static void print_key_type(u8 type) +static void print_key_type(FILE *out, u8 type) { switch (type) { case BTRFS_INODE_ITEM_KEY: - printf("INODE_ITEM"); + fprintf(out, "INODE_ITEM"); break; case BTRFS_INODE_REF_KEY: - printf("INODE_REF"); + fprintf(out, "INODE_REF"); break; case BTRFS_DIR_ITEM_KEY: - printf("DIR_ITEM"); + fprintf(out, "DIR_ITEM"); break; case BTRFS_DIR_INDEX_KEY: - printf("DIR_INDEX"); + fprintf(out, "DIR_INDEX"); break; case BTRFS_DIR_LOG_ITEM_KEY: - printf("DIR_LOG_ITEM"); + fprintf(out, "DIR_LOG_ITEM"); break; case BTRFS_DIR_LOG_INDEX_KEY: - printf("DIR_LOG_INDEX"); + fprintf(out, "DIR_LOG_INDEX"); break; case BTRFS_XATTR_ITEM_KEY: - printf("XATTR_ITEM"); + fprintf(out, "XATTR_ITEM"); break; case BTRFS_ORPHAN_ITEM_KEY: - printf("ORPHAN_ITEM"); + fprintf(out, "ORPHAN_ITEM"); break; case BTRFS_ROOT_ITEM_KEY: - printf("ROOT_ITEM"); + fprintf(out, "ROOT_ITEM"); break; case BTRFS_ROOT_REF_KEY: - printf("ROOT_REF"); + fprintf(out, "ROOT_REF"); break; case BTRFS_ROOT_BACKREF_KEY: - printf("ROOT_BACKREF"); + fprintf(out, "ROOT_BACKREF"); break; case BTRFS_EXTENT_ITEM_KEY: - printf("EXTENT_ITEM"); + fprintf(out, "EXTENT_ITEM"); break; case BTRFS_TREE_BLOCK_REF_KEY: - printf("TREE_BLOCK_REF"); + fprintf(out, "TREE_BLOCK_REF"); break; case BTRFS_SHARED_BLOCK_REF_KEY: - printf("SHARED_BLOCK_REF"); + fprintf(out, "SHARED_BLOCK_REF"); break; case BTRFS_EXTENT_DATA_REF_KEY: - printf("EXTENT_DATA_REF"); + fprintf(out, "EXTENT_DATA_REF"); break; case BTRFS_SHARED_DATA_REF_KEY: - printf("SHARED_DATA_REF"); + fprintf(out, "SHARED_DATA_REF"); break; case BTRFS_EXTENT_REF_V0_KEY: - printf("EXTENT_REF_V0"); + fprintf(out, "EXTENT_REF_V0"); break; case BTRFS_CSUM_ITEM_KEY: - printf("CSUM_ITEM"); + fprintf(out, "CSUM_ITEM"); break; case BTRFS_EXTENT_CSUM_KEY: - printf("EXTENT_CSUM"); + fprintf(out, "EXTENT_CSUM"); break; case BTRFS_EXTENT_DATA_KEY: - printf("EXTENT_DATA"); + fprintf(out, "EXTENT_DATA"); break; case BTRFS_BLOCK_GROUP_ITEM_KEY: - printf("BLOCK_GROUP_ITEM"); + fprintf(out, "BLOCK_GROUP_ITEM"); break; case BTRFS_CHUNK_ITEM_KEY: - printf("CHUNK_ITEM"); + fprintf(out, "CHUNK_ITEM"); break; case BTRFS_DEV_ITEM_KEY: - printf("DEV_ITEM"); + fprintf(out, "DEV_ITEM"); break; case BTRFS_DEV_EXTENT_KEY: - printf("DEV_EXTENT"); + fprintf(out, "DEV_EXTENT"); break; case BTRFS_STRING_ITEM_KEY: - printf("STRING_ITEM"); + fprintf(out, "STRING_ITEM"); break; default: - printf("UNKNOWN"); + fprintf(out, "UNKNOWN"); }; } -static void print_objectid(unsigned long long objectid, u8 type) +static void print_objectid(FILE *out, unsigned long long objectid, u8 type) { if (type == BTRFS_DEV_EXTENT_KEY) { - printf("%llu", objectid); /* device id */ + fprintf(out, "%llu", objectid); /* device id */ return; } switch (objectid) { case BTRFS_ROOT_TREE_OBJECTID: if (type == BTRFS_DEV_ITEM_KEY) - printf("DEV_ITEMS"); + fprintf(out, "DEV_ITEMS"); else - printf("ROOT_TREE"); + fprintf(out, "ROOT_TREE"); break; case BTRFS_EXTENT_TREE_OBJECTID: - printf("EXTENT_TREE"); + fprintf(out, "EXTENT_TREE"); break; case BTRFS_CHUNK_TREE_OBJECTID: - printf("CHUNK_TREE"); + fprintf(out, "CHUNK_TREE"); break; case BTRFS_DEV_TREE_OBJECTID: - printf("DEV_TREE"); + fprintf(out, "DEV_TREE"); break; case BTRFS_FS_TREE_OBJECTID: - printf("FS_TREE"); + fprintf(out, "FS_TREE"); break; case BTRFS_ROOT_TREE_DIR_OBJECTID: - printf("ROOT_TREE_DIR"); + fprintf(out, "ROOT_TREE_DIR"); break; case BTRFS_CSUM_TREE_OBJECTID: - printf("CSUM_TREE"); + fprintf(out, "CSUM_TREE"); break; case BTRFS_ORPHAN_OBJECTID: - printf("ORPHAN"); + fprintf(out, "ORPHAN"); break; case BTRFS_TREE_LOG_OBJECTID: - printf("TREE_LOG"); + fprintf(out, "TREE_LOG"); break; case BTRFS_TREE_LOG_FIXUP_OBJECTID: - printf("LOG_FIXUP"); + fprintf(out, "LOG_FIXUP"); break; case BTRFS_TREE_RELOC_OBJECTID: - printf("TREE_RELOC"); + fprintf(out, "TREE_RELOC"); break; case BTRFS_DATA_RELOC_TREE_OBJECTID: - printf("DATA_RELOC_TREE"); + fprintf(out, "DATA_RELOC_TREE"); break; case BTRFS_EXTENT_CSUM_OBJECTID: - printf("EXTENT_CSUM"); + fprintf(out, "EXTENT_CSUM"); break; case BTRFS_MULTIPLE_OBJECTIDS: - printf("MULTIPLE"); + fprintf(out, "MULTIPLE"); break; case BTRFS_FIRST_CHUNK_TREE_OBJECTID: - printf("FIRST_CHUNK_TREE"); + fprintf(out, "FIRST_CHUNK_TREE"); break; default: - printf("%llu", objectid); + fprintf(out, "%llu", objectid); } } -void btrfs_print_key(struct btrfs_disk_key *disk_key) +void btrfs_print_key(FILE *out, struct btrfs_disk_key *disk_key) { u8 type; - printf("key ("); + fprintf(out, "key ("); type = btrfs_disk_key_type(disk_key); - print_objectid((unsigned long long)btrfs_disk_key_objectid(disk_key), + print_objectid(out, (unsigned long long)btrfs_disk_key_objectid(disk_key), type); - printf(" "); - print_key_type(type); - printf(" %llu)", (unsigned long long)btrfs_disk_key_offset(disk_key)); + fprintf(out, " "); + print_key_type(out, type); + fprintf(out, " %llu)", (unsigned long long)btrfs_disk_key_offset(disk_key)); } -void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) +void btrfs_print_leaf(FILE *out, struct btrfs_root *root, struct extent_buffer *l) { int i; char *str; @@ -454,26 +454,26 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) u32 nr = btrfs_header_nritems(l); u32 type; - printf("leaf %llu items %d free space %d generation %llu owner %llu\n", + fprintf(out, "leaf %llu items %d free space %d generation %llu owner %llu\n", (unsigned long long)btrfs_header_bytenr(l), nr, btrfs_leaf_free_space(root, l), (unsigned long long)btrfs_header_generation(l), (unsigned long long)btrfs_header_owner(l)); - print_uuids(l); - fflush(stdout); + print_uuids(out, l); + fflush(out); for (i = 0 ; i < nr ; i++) { item = btrfs_item_nr(l, i); btrfs_item_key(l, &disk_key, i); type = btrfs_disk_key_type(&disk_key); - printf("\titem %d ", i); - btrfs_print_key(&disk_key); - printf(" itemoff %d itemsize %d\n", + fprintf(out, "\titem %d ", i); + btrfs_print_key(out, &disk_key); + fprintf(out, " itemoff %d itemsize %d\n", btrfs_item_offset(l, item), btrfs_item_size(l, item)); switch (type) { case BTRFS_INODE_ITEM_KEY: ii = btrfs_item_ptr(l, i, struct btrfs_inode_item); - printf("\t\tinode generation %llu size %llu block group %llu mode %o links %u\n", + fprintf(out, "\t\tinode generation %llu size %llu block group %llu mode %o links %u\n", (unsigned long long)btrfs_inode_generation(l, ii), (unsigned long long)btrfs_inode_size(l, ii), (unsigned long long)btrfs_inode_block_group(l,ii), @@ -482,27 +482,27 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) break; case BTRFS_INODE_REF_KEY: iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref); - print_inode_ref_item(l, item, iref); + print_inode_ref_item(out, l, item, iref); break; case BTRFS_DIR_ITEM_KEY: case BTRFS_DIR_INDEX_KEY: case BTRFS_XATTR_ITEM_KEY: di = btrfs_item_ptr(l, i, struct btrfs_dir_item); - print_dir_item(l, item, di); + print_dir_item(out, l, item, di); break; case BTRFS_DIR_LOG_INDEX_KEY: case BTRFS_DIR_LOG_ITEM_KEY: dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item); - printf("\t\tdir log end %Lu\n", + fprintf(out, "\t\tdir log end %Lu\n", btrfs_dir_log_end(l, dlog)); break; case BTRFS_ORPHAN_ITEM_KEY: - printf("\t\torphan item\n"); + fprintf(out, "\t\torphan item\n"); break; case BTRFS_ROOT_ITEM_KEY: ri = btrfs_item_ptr(l, i, struct btrfs_root_item); read_extent_buffer(l, &root_item, (unsigned long)ri, sizeof(root_item)); - printf("\t\troot data bytenr %llu level %d dirid %llu refs %u\n", + fprintf(out, "\t\troot data bytenr %llu level %d dirid %llu refs %u\n", (unsigned long long)btrfs_root_bytenr(&root_item), btrfs_root_level(&root_item), (unsigned long long)btrfs_root_dirid(&root_item), @@ -511,29 +511,29 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) struct btrfs_key drop_key; btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress); - printf("\t\tdrop "); - btrfs_print_key(&root_item.drop_progress); - printf(" level %d\n", root_item.drop_level); + fprintf(out, "\t\tdrop "); + btrfs_print_key(out, &root_item.drop_progress); + fprintf(out, " level %d\n", root_item.drop_level); } break; case BTRFS_ROOT_REF_KEY: - print_root_ref(l, i, "ref"); + print_root_ref(out, l, i, "ref"); break; case BTRFS_ROOT_BACKREF_KEY: - print_root_ref(l, i, "backref"); + print_root_ref(out, l, i, "backref"); break; case BTRFS_EXTENT_ITEM_KEY: - print_extent_item(l, i); + print_extent_item(out, l, i); break; case BTRFS_TREE_BLOCK_REF_KEY: - printf("\t\ttree block backref\n"); + fprintf(out, "\t\ttree block backref\n"); break; case BTRFS_SHARED_BLOCK_REF_KEY: - printf("\t\tshared block backref\n"); + fprintf(out, "\t\tshared block backref\n"); break; case BTRFS_EXTENT_DATA_REF_KEY: dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref); - printf("\t\textent data backref root %llu " + fprintf(out, "\t\textent data backref root %llu " "objectid %llu offset %llu count %u\n", (unsigned long long)btrfs_extent_data_ref_root(l, dref), (unsigned long long)btrfs_extent_data_ref_objectid(l, dref), @@ -542,50 +542,50 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) break; case BTRFS_SHARED_DATA_REF_KEY: sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref); - printf("\t\tshared data backref count %u\n", + fprintf(out, "\t\tshared data backref count %u\n", btrfs_shared_data_ref_count(l, sref)); break; case BTRFS_EXTENT_REF_V0_KEY: #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 - print_extent_ref_v0(l, i); + print_extent_ref_v0(out, l, i); #else BUG(); #endif break; case BTRFS_CSUM_ITEM_KEY: ci = btrfs_item_ptr(l, i, struct btrfs_csum_item); - printf("\t\tcsum item\n"); + fprintf(out, "\t\tcsum item\n"); break; case BTRFS_EXTENT_CSUM_KEY: ci = btrfs_item_ptr(l, i, struct btrfs_csum_item); - printf("\t\textent csum item\n"); + fprintf(out, "\t\textent csum item\n"); break; case BTRFS_EXTENT_DATA_KEY: fi = btrfs_item_ptr(l, i, struct btrfs_file_extent_item); - print_file_extent_item(l, item, fi); + print_file_extent_item(out, l, item, fi); break; case BTRFS_BLOCK_GROUP_ITEM_KEY: bi = btrfs_item_ptr(l, i, struct btrfs_block_group_item); read_extent_buffer(l, &bg_item, (unsigned long)bi, sizeof(bg_item)); - printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n", + fprintf(out, "\t\tblock group used %llu chunk_objectid %llu flags %llu\n", (unsigned long long)btrfs_block_group_used(&bg_item), (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item), (unsigned long long)btrfs_block_group_flags(&bg_item)); break; case BTRFS_CHUNK_ITEM_KEY: - print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk)); + print_chunk(out, l, btrfs_item_ptr(l, i, struct btrfs_chunk)); break; case BTRFS_DEV_ITEM_KEY: - print_dev_item(l, btrfs_item_ptr(l, i, + print_dev_item(out, l, btrfs_item_ptr(l, i, struct btrfs_dev_item)); break; case BTRFS_DEV_EXTENT_KEY: dev_extent = btrfs_item_ptr(l, i, struct btrfs_dev_extent); - printf("\t\tdev extent chunk_tree %llu\n" + fprintf(out, "\t\tdev extent chunk_tree %llu\n" "\t\tchunk objectid %llu chunk offset %llu " "length %llu\n", (unsigned long long) @@ -600,14 +600,14 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) case BTRFS_STRING_ITEM_KEY: /* dirty, but it''s simple */ str = l->data + btrfs_item_ptr_offset(l, i); - printf("\t\titem data %.*s\n", btrfs_item_size(l, item), str); + fprintf(out, "\t\titem data %.*s\n", btrfs_item_size(l, item), str); break; }; - fflush(stdout); + fflush(out); } } -void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb) +void btrfs_print_tree(FILE *out, struct btrfs_root *root, struct extent_buffer *eb) { int i; u32 nr; @@ -619,29 +619,29 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb) return; nr = btrfs_header_nritems(eb); if (btrfs_is_leaf(eb)) { - btrfs_print_leaf(root, eb); + btrfs_print_leaf(out, root, eb); return; } - printf("node %llu level %d items %d free %u generation %llu owner %llu\n", + fprintf(out, "node %llu level %d items %d free %u generation %llu owner %llu\n", (unsigned long long)eb->start, btrfs_header_level(eb), nr, (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr, (unsigned long long)btrfs_header_generation(eb), (unsigned long long)btrfs_header_owner(eb)); - print_uuids(eb); - fflush(stdout); + print_uuids(out, eb); + fflush(out); size = btrfs_level_size(root, btrfs_header_level(eb) - 1); for (i = 0; i < nr; i++) { u64 blocknr = btrfs_node_blockptr(eb, i); btrfs_node_key(eb, &disk_key, i); btrfs_disk_key_to_cpu(&key, &disk_key); - printf("\t"); - btrfs_print_key(&disk_key); - printf(" block %llu (%llu) gen %llu\n", + fprintf(out, "\t"); + btrfs_print_key(out, &disk_key); + fprintf(out, " block %llu (%llu) gen %llu\n", (unsigned long long)blocknr, (unsigned long long)blocknr / size, (unsigned long long)btrfs_node_ptr_generation(eb, i)); - fflush(stdout); + fflush(out); } for (i = 0; i < nr; i++) { struct extent_buffer *next = read_tree_block(root, @@ -660,7 +660,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb) if (btrfs_header_level(next) ! btrfs_header_level(eb) - 1) BUG(); - btrfs_print_tree(root, next); + btrfs_print_tree(out, root, next); free_extent_buffer(next); } } diff --git a/lib/print-tree.h b/lib/print-tree.h index 4d1a01a..a7e9826 100644 --- a/lib/print-tree.h +++ b/lib/print-tree.h @@ -18,7 +18,9 @@ #ifndef __PRINT_TREE_ #define __PRINT_TREE_ -void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l); -void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *t); -void btrfs_print_key(struct btrfs_disk_key *disk_key); +#include <stdio.h> + +void btrfs_print_leaf(FILE *out, struct btrfs_root *root, struct extent_buffer *l); +void btrfs_print_tree(FILE *out, struct btrfs_root *root, struct extent_buffer *t); +void btrfs_print_key(FILE *out, struct btrfs_disk_key *disk_key); #endif diff --git a/lib/root-tree.c b/lib/root-tree.c index 782472c..e1df044 100644 --- a/lib/root-tree.c +++ b/lib/root-tree.c @@ -182,12 +182,11 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, if (ret < 0) goto out; if (ret) { -btrfs_print_leaf(root, path->nodes[0]); -printk("failed to del %llu %u %llu\n", - (unsigned long long)key->objectid, - key->type, - (unsigned long long)key->offset); - + btrfs_print_leaf(stdout, root, path->nodes[0]); + printk("failed to del %llu %u %llu\n", + (unsigned long long)key->objectid, + key->type, + (unsigned long long)key->offset); } BUG_ON(ret != 0); leaf = path->nodes[0]; diff --git a/misc/debug-tree.c b/misc/debug-tree.c index 1d47519..64f6f83 100644 --- a/misc/debug-tree.c +++ b/misc/debug-tree.c @@ -144,11 +144,11 @@ int main(int ac, char **av) } if (!extent_only) { printf("root tree\n"); - btrfs_print_tree(root->fs_info->tree_root, + btrfs_print_tree(stdout, root->fs_info->tree_root, root->fs_info->tree_root->node); printf("chunk tree\n"); - btrfs_print_tree(root->fs_info->chunk_root, + btrfs_print_tree(stdout, root->fs_info->chunk_root, root->fs_info->chunk_root->node); } tree_root_scan = root->fs_info->tree_root; @@ -258,9 +258,9 @@ again: } if (!skip && !extent_only) { printf(" tree "); - btrfs_print_key(&disk_key); + btrfs_print_key(stdout, &disk_key); printf(" \n"); - btrfs_print_tree(tree_root_scan, buf); + btrfs_print_tree(stdout, tree_root_scan, buf); } else if (extent_only && !skip) { print_extents(tree_root_scan, buf); } -- 1.7.0.rc0.48.gdace5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html