diff -Nru btrfs-tools-0.19+20111121/bcp btrfs-tools-0.19+20120328/bcp --- btrfs-tools-0.19+20111121/bcp 2011-11-18 19:54:07.000000000 +0000 +++ btrfs-tools-0.19+20120328/bcp 1970-01-01 00:00:00.000000000 +0000 @@ -1,159 +0,0 @@ -#!/usr/bin/env python -# 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. -# -import sys, os, stat, fcntl -from optparse import OptionParser - -def copylink(srcname, dst, filename, statinfo, force_name): - dstname = os.path.join(dst, force_name or filename) - if not os.path.exists(dstname): - link_target = os.readlink(srcname) - os.symlink(link_target, dstname) - -def copydev(srcname, dst, filename, statinfo, force_name): - devbits = statinfo.st_mode & (stat.S_IFBLK | stat.S_IFCHR) - mode = stat.S_IMODE(statinfo.st_mode) | devbits - dstname = os.path.join(dst, force_name or filename) - if not os.path.exists(dstname): - os.mknod(dstname, mode, statinfo.st_rdev) - -def copyfile(srcname, dst, filename, statinfo, force_name): - written = 0 - dstname = os.path.join(dst, force_name or filename) - - st_mode = statinfo.st_mode - if stat.S_ISLNK(st_mode): - copylink(srcname, dst, part, statinfo, None) - return - elif stat.S_ISBLK(st_mode) or stat.S_ISCHR(st_mode): - copydev(srcname, dst, part, statinfo, None) - return - elif not stat.S_ISREG(st_mode): - return - - try: - os.unlink(dstname) - except: - pass - - if options.link: - os.link(srcname, dstname) - return - - dstf = file(dstname, 'w') - srcf = file(srcname, 'r') - - ret = 1 - - try: - if not options.copy: - ret = fcntl.ioctl(dstf.fileno(), 1074041865, srcf.fileno()) - except: - pass - - if ret != 0: - while True: - buf = srcf.read(256 * 1024) - if not buf: - break - written += len(buf) - dstf.write(buf) - - os.chmod(dstname, stat.S_IMODE(statinfo.st_mode)) - os.chown(dstname, statinfo.st_uid, statinfo.st_gid) - - -usage = "usage: %prog [options]" -parser = OptionParser(usage=usage) -parser.add_option("-l", "--link", help="Create hard links", default=False, - action="store_true") -parser.add_option("-c", "--copy", help="Copy file bytes (don't cow)", - default=False, action="store_true") - -(options,args) = parser.parse_args() - -if len(args) < 2: - sys.stderr.write("source or destination not specified\n") - sys.exit(1) - -if options.link and options.copy: - sys.stderr.write("Both -l and -c specified, using copy mode\n") - options.link = False - - -total_args = len(args) -src_args = total_args - 1 -orig_dst = args[-1] - -if src_args > 1: - if not os.path.exists(orig_dst): - os.makedirs(orig_dst) - if not os.path.isdir(orig_dst): - sys.stderr.write("Destination %s is not a directory\n" % orig_dst) - exit(1) - -for srci in xrange(0, src_args): - src = args[srci] - if os.path.isfile(src): - statinfo = os.lstat(src) - force_name = None - if src_args == 1: - if not os.path.isdir(orig_dst): - force_name = os.path.basename(orig_dst) - orig_dst = os.path.dirname(orig_dst) or '.' - copyfile(src, orig_dst, os.path.basename(src), statinfo, force_name) - continue - - if src_args > 1 or os.path.exists(orig_dst): - dst = os.path.join(orig_dst, os.path.basename(src)) - else: - dst = orig_dst - - if not os.path.exists(dst): - os.makedirs(dst) - statinfo = os.stat(src) - os.chmod(dst, stat.S_IMODE(statinfo.st_mode)) - os.chown(dst, statinfo.st_uid, statinfo.st_gid) - - iter = os.walk(src, topdown=True) - - for (dirpath, dirnames, filenames) in iter: - for x in dirnames: - srcname = os.path.join(dirpath, x) - statinfo = os.lstat(srcname) - - part = os.path.relpath(srcname, src) - - if stat.S_ISLNK(statinfo.st_mode): - copylink(srcname, dst, part, statinfo, None) - continue - - dst_dir = os.path.join(dst, part) - if not os.path.exists(dst_dir): - os.makedirs(dst_dir) - - os.chmod(dst_dir, stat.S_IMODE(statinfo.st_mode)) - os.chown(dst_dir, statinfo.st_uid, statinfo.st_gid) - - for f in filenames: - srcname = os.path.join(dirpath, f) - part = os.path.relpath(srcname, src) - - statinfo = os.lstat(srcname) - copyfile(srcname, dst, part, statinfo, None) - - diff -Nru btrfs-tools-0.19+20111121/btrfs.c btrfs-tools-0.19+20120328/btrfs.c --- btrfs-tools-0.19+20111121/btrfs.c 2011-11-18 19:54:07.000000000 +0000 +++ btrfs-tools-0.19+20120328/btrfs.c 2012-05-05 18:22:58.000000000 +0000 @@ -19,444 +19,258 @@ #include #include -#include "kerncompat.h" -#include "btrfs_cmds.h" +#include "commands.h" #include "version.h" -#define BASIC_HELP 0 -#define ADVANCED_HELP 1 - -typedef int (*CommandFunction)(int argc, char **argv); - -struct Command { - CommandFunction func; /* function which implements the command */ - int nargs; /* if == 999, any number of arguments - if >= 0, number of arguments, - if < 0, _minimum_ number of arguments */ - char *verb; /* verb */ - char *help; /* help lines; from the 2nd line onward they - are automatically indented */ - char *adv_help; /* advanced help message; from the 2nd line - onward they are automatically indented */ - - /* the following fields are run-time filled by the program */ - char **cmds; /* array of subcommands */ - int ncmds; /* number of subcommand */ +static const char * const btrfs_cmd_group_usage[] = { + "btrfs [--help] [--version] [...] []", + NULL }; -static struct Command commands[] = { +static const char btrfs_cmd_group_info[] = + "Use --help as an argument for information on a specific group or command."; - /* - avoid short commands different for the case only - */ - { do_clone, -2, - "subvolume snapshot", "[-r] [/]\n" - "Create a writable/readonly snapshot of the subvolume with\n" - "the name in the directory.", - NULL - }, - { do_delete_subvolume, 1, - "subvolume delete", "\n" - "Delete the subvolume .", - NULL - }, - { do_create_subvol, 1, - "subvolume create", "[/]\n" - "Create a subvolume in (or the current directory if\n" - "not passed).", - NULL - }, - { do_subvol_list, -1, "subvolume list", "[-p] \n" - "List the snapshot/subvolume of a filesystem.", - "[-p] \n" - "List the snapshot/subvolume of a filesystem.\n" - "-p print parent ID" - }, - { do_set_default_subvol, 2, - "subvolume set-default", " \n" - "Set the subvolume of the filesystem which will be mounted\n" - "as default.", - NULL - }, - { do_find_newer, 2, "subvolume find-new", " \n" - "List the recently modified files in a filesystem.", - NULL - }, - { do_defrag, -1, - "filesystem defragment", "[-vf] [-c[zlib,lzo]] [-s start] [-l len] [-t size] | [|...]\n" - "Defragment a file or a directory.", - "[-vcf] [-s start] [-l len] [-t size] | [|...]\n" - "Defragment file data or directory metadata.\n" - "-v be verbose\n" - "-c compress the file while defragmenting\n" - "-f flush data to disk immediately after defragmenting\n" - "-s start defragment only from byte onward\n" - "-l len defragment only up to len bytes\n" - "-t size minimal size of file to be considered for defragmenting\n" - }, - { do_get_default_subvol, 1, "subvolume get-default", "\n" - "Get the default subvolume of a filesystem." - }, - { do_fssync, 1, - "filesystem sync", "\n" - "Force a sync on the filesystem .", - NULL - }, - { do_resize, 2, - "filesystem resize", "[+/-][gkm]|max \n" - "Resize the file system. If 'max' is passed, the filesystem\n" - "will occupe all available space on the device.", - NULL - }, - { do_show_filesystem, 999, - "filesystem show", "[--all-devices][|