Skip to content
Permalink
Browse files

btrfs-progs: all tools in one binary

Build several standalone tools into one binary and switch the function
by name (symlink or hardlink).

* btrfs
* mkfs.btrfs
* btrfstun
* btrfs-image
* btrfs-convert
* btrfs-debug-tree
* btrfs-show-super
* btrfs-find-root

The static target is also supported. The name of resulting boxed
binaries is btrfs.box and btrfs.box.static .

   text    data     bss     dec     hex filename
 550988   19120   15444  585552   8ef50 btrfs
1562099   25316   42256 1629671  18dde7 btrfs.static
 659504   21104   16492  697100   aa30c btrfs.box
1817274   27988   44088 1889350  1cd446 btrfs.box.static

Signed-off-by: David Sterba <dsterba@suse.cz>
  • Loading branch information
kdave committed Jun 21, 2015
1 parent bdc6c85 commit 8fc697a7f763f39f3afe0abaa68ac13a49ac8a86
Showing with 112 additions and 9 deletions.
  1. +49 −1 Makefile.in
  2. +18 −0 box.h
  3. +3 −1 btrfs-convert.c
  4. +3 −1 btrfs-debug-tree.c
  5. +3 −1 btrfs-find-root.c
  6. +3 −1 btrfs-image.c
  7. +3 −2 btrfs-show-super.c
  8. +25 −0 btrfs.c
  9. +3 −1 btrfstune.c
  10. +2 −1 mkfs.c
@@ -72,6 +72,13 @@ MAKEOPTS = --no-print-directory Q=$(Q)
# build all by default
progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size

# built-in sources into "busybox"
progs_box = btrfstune.c mkfs.c btrfs-image.c btrfs-convert.c btrfs-debug-tree.c \
btrfs-find-root.c btrfs-show-super.c

progs_box_objects = $(patsubst %.c, %.box.o, $(progs_box))
progs_box_static_objects = $(patsubst %.c, %.box.static.o, $(progs_box))

# install only selected
progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
btrfs-map-logical btrfs-image btrfs-zero-log \
@@ -145,6 +152,9 @@ endif
%.o.d: %.c
$(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<

%.box.o.d: $(progs_box)
$(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<

.c.o:
@$(check_echo) " [SP] $<"
$(Q)$(check) $(CFLAGS) $<
@@ -155,6 +165,14 @@ endif
@echo " [CC] $@"
$(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@

%.box.o: %.c
@echo " [CC] $@"
$(Q)$(CC) -DENABLE_BOX $(CFLAGS) -c $< -o $@

%.box.static.o: %.c
@echo " [CC] $@"
$(Q)$(CC) -DENABLE_BOX $(STATIC_CFLAGS) -c $< -o $@

all: $(progs) $(BUILDDIRS)
$(SUBDIRS): $(BUILDDIRS)
$(BUILDDIRS):
@@ -234,6 +252,36 @@ btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objec
$(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
$(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)

btrfs.box: $(objects) btrfs.box.o help.o $(cmds_objects) $(libs_static) $(progs_box_objects)
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfs.box btrfs.box.o help.o $(cmds_objects) \
$(objects) $(progs_box_objects) \
$(btrfs_convert_libs) \
$(libs_static) $(LDFLAGS) $(LIBS)

btrfs.box.static: $(static_objects) btrfs.box.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects) $(progs_box_static_objects)
@echo " [LD] $@"
$(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.box.static btrfs.box.static.o help.static.o $(static_cmds_objects) \
$(progs_box_static_objects) \
$(btrfs_convert_libs) \
$(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)

box-links: btrfs.box
@echo " [LN] btrfstune"
$(Q)$(LN_S) -sf btrfs.box btrfstune
@echo " [LN] mkfs.btrfs"
$(Q)$(LN_S) -sf btrfs.box mkfs.btrfs
@echo " [LN] btrfs-image"
$(Q)$(LN_S) -sf btrfs.box btrfs-image
@echo " [LN] btrfs-convert"
$(Q)$(LN_S) -sf btrfs.box btrfs-convert
@echo " [LN] btrfs-debug-tree"
$(Q)$(LN_S) -sf btrfs.box btrfs-debug-tree
@echo " [LN] btrfs-find-root"
$(Q)$(LN_S) -sf btrfs.box btrfs-find-root
@echo " [LN] btrfs-show-super"
$(Q)$(LN_S) -sf btrfs.box btrfs-show-super

# For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
btrfsck: btrfs
@echo " [LN] $@"
@@ -309,7 +357,7 @@ clean: $(CLEANDIRS)
@echo "Cleaning"
$(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
dir-test ioctl-test quick-test send-test library-test library-test-static \
btrfs.static mkfs.btrfs.static \
btrfs.static mkfs.btrfs.static btrfs.box btrfs.box.static \
$(check_defs) \
$(libs) $(lib_links) \
$(progs_static) $(progs_extra)
18 box.h
@@ -0,0 +1,18 @@
#ifndef __BTRFS_BOX_H__
#define __BTRFS_BOX_H__

#ifdef ENABLE_BOX
#define BOX_MAIN(standalone) standalone##_main
#else
#define BOX_MAIN(standalone) main
#endif

int btrfstune_main(int argc, char **argv);
int mkfs_main(int argc, char **argv);
int image_main(int argc, char **argv);
int convert_main(int argc, char **argv);
int debug_tree_main(int argc, char **argv);
int find_root_main(int argc, char **argv);
int show_super_main(int argc, char **argv);

#endif
@@ -41,6 +41,8 @@
#include <ext2fs/ext2fs.h>
#include <ext2fs/ext2_ext_attr.h>

#include "box.h"

#define INO_OFFSET (BTRFS_FIRST_FREE_OBJECTID - EXT2_ROOT_INO)
#define CONV_IMAGE_SUBVOL_OBJECTID BTRFS_FIRST_FREE_OBJECTID

@@ -2839,7 +2841,7 @@ static void print_usage(void)
printf("\t--no-progress show only overview, not the detailed progress\n");
}

int main(int argc, char *argv[])
int BOX_MAIN(convert)(int argc, char *argv[])
{
int ret;
int packing = 1;
@@ -30,6 +30,8 @@
#include "transaction.h"
#include "utils.h"

#include "box.h"

static int print_usage(int ret)
{
fprintf(stderr, "usage: btrfs-debug-tree [-e] [-d] [-r] [-R] [-u]\n");
@@ -121,7 +123,7 @@ static void print_old_roots(struct btrfs_super_block *super)
}
}

int main(int ac, char **av)
int BOX_MAIN(debug_tree)(int ac, char **av)
{
struct btrfs_root *root;
struct btrfs_fs_info *info;
@@ -36,6 +36,8 @@
#include "extent-cache.h"
#include "find-root.h"

#include "box.h"

static void usage(void)
{
fprintf(stderr, "Usage: find-roots [-a] [-o search_objectid] "
@@ -138,7 +140,7 @@ static void print_find_root_result(struct cache_tree *result,
}
}

int main(int argc, char **argv)
int BOX_MAIN(find_root)(int argc, char **argv)
{
struct btrfs_root *root;
struct btrfs_find_root_filter filter = {0};
@@ -36,6 +36,8 @@
#include "volumes.h"
#include "extent_io.h"

#include "box.h"

#define HEADER_MAGIC 0xbd5c25e27295668bULL
#define MAX_PENDING_SIZE (256 * 1024)
#define BLOCK_SIZE 1024
@@ -2706,7 +2708,7 @@ static void print_usage(int ret)
exit(ret);
}

int main(int argc, char *argv[])
int BOX_MAIN(image)(int argc, char *argv[])
{
char *source;
char *target;
@@ -34,9 +34,10 @@
#include "utils.h"
#include "crc32c.h"

#include "box.h"

static void print_usage(void);
static void dump_superblock(struct btrfs_super_block *sb, int full);
int main(int argc, char **argv);
static int load_and_dump_sb(char *, int fd, u64 sb_bytenr, int full, int force);


@@ -51,7 +52,7 @@ static void print_usage(void)
fprintf(stderr, "%s\n", PACKAGE_STRING);
}

int main(int argc, char **argv)
int BOX_MAIN(show_super)(int argc, char **argv)
{
int opt;
int all = 0;
25 btrfs.c
@@ -22,6 +22,8 @@
#include "commands.h"
#include "utils.h"

#include "box.h"

static const char * const btrfs_cmd_group_usage[] = {
"btrfs [--help] [--version] <group> [<group>...] <command> [<args>]",
NULL
@@ -222,6 +224,29 @@ int main(int argc, char **argv)

if (!strcmp(bname, "btrfsck")) {
argv[0] = "check";
#ifdef ENABLE_BOX
} else if (!strcmp(bname, "btrfstune")) {
printf("*** I'm going to be btrfstune now ***\n");
return btrfstune_main(argc, argv);
} else if (!strcmp(bname, "mkfs.btrfs")) {
printf("*** I'm going to be mkfs.btrfs now ***\n");
return mkfs_main(argc, argv);
} else if (!strcmp(bname, "btrfs-image")) {
printf("*** I'm going to be btrfs-image now ***\n");
return image_main(argc, argv);
} else if (!strcmp(bname, "btrfs-convert")) {
printf("*** I'm going to be btrfs-convert now ***\n");
return convert_main(argc, argv);
} else if (!strcmp(bname, "btrfs-debug-tree")) {
printf("*** I'm going to be btrfs-debug-tree now ***\n");
return debug_tree_main(argc, argv);
} else if (!strcmp(bname, "btrfs-find-root")) {
printf("*** I'm going to be btrfs-find-root now ***\n");
return find_root_main(argc, argv);
} else if (!strcmp(bname, "btrfs-show-super")) {
printf("*** I'm going to be btrfs-show-super now ***\n");
return show_super_main(argc, argv);
#endif
} else {
argc--;
argv++;
@@ -33,6 +33,8 @@
#include "utils.h"
#include "volumes.h"

#include "box.h"

static char *device;
static int force = 0;

@@ -408,7 +410,7 @@ static void print_usage(void)
fprintf(stderr, "\t-U UUID\t\tchange fsid to UUID\n");
}

int main(int argc, char *argv[])
int BOX_MAIN(btrfstune)(int argc, char *argv[])
{
struct btrfs_root *root;
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_WRITES;
3 mkfs.c
@@ -41,6 +41,7 @@
#include "volumes.h"
#include "transaction.h"
#include "utils.h"
#include "box.h"

static u64 index_cnt = 2;
static int verbose = 1;
@@ -1160,7 +1161,7 @@ static void list_all_devices(struct btrfs_root *root)
printf("\n");
}

int main(int ac, char **av)
int BOX_MAIN(mkfs)(int ac, char **av)
{
char *file;
struct btrfs_root *root;

0 comments on commit 8fc697a

Please sign in to comment.
You can’t perform that action at this time.