--- btrfs-tools-0.19.orig/debian/btrfs-tools-udeb.install +++ btrfs-tools-0.19/debian/btrfs-tools-udeb.install @@ -0,0 +1,2 @@ +btrfsctl /sbin +mkfs.btrfs /sbin --- btrfs-tools-0.19.orig/debian/rules +++ btrfs-tools-0.19/debian/rules @@ -0,0 +1,27 @@ +#!/usr/bin/make -f + +SHELL := sh -e + +%: + dh ${@} --with quilt + +override_dh_auto_build: + CFLAGS="$(CFLAGS)" $(MAKE) all btrfsck btrfstune btrfs-image convert + +override_dh_auto_install: + $(MAKE) DESTDIR=$(CURDIR)/debian/btrfs-tools prefix=/ bindir=/sbin mandir=/usr/share/man install + + # Fixing 'manpage-not-compressed-with-max-compression' + for MANPAGE in $(CURDIR)/debian/btrfs-tools/usr/share/man/*/*.gz; \ + do \ + cd $$(dirname $${MANPAGE}); \ + gunzip $$(basename $${MANPAGE}); \ + done + + # Adding initramfs-tools integration + install -D -m 0755 debian/local/btrfs.hook debian/btrfs-tools/usr/share/initramfs-tools/hooks/btrfs + install -D -m 0755 debian/local/btrfs.local-premount debian/btrfs-tools/usr/share/initramfs-tools/scripts/local-premount/btrfs + install -D -m 0644 debian/local/btrfs.modules debian/btrfs-tools//usr/share/initramfs-tools/modules.d/btrfs + +override_dh_strip: + dh_strip --dbg-package=btrfs-tools-dbg --- btrfs-tools-0.19.orig/debian/control +++ btrfs-tools-0.19/debian/control @@ -0,0 +1,45 @@ +Source: btrfs-tools +Section: admin +Priority: optional +Maintainer: Daniel Baumann +Uploaders: Daniel Baumann +Build-Depends: + debhelper (>= 7.0.50~), e2fslibs-dev, libacl1-dev, quilt (>= 0.46-7), uuid-dev, + zlib1g-dev +Standards-Version: 3.8.4 +Homepage: http://btrfs.wiki.kernel.org/ +Vcs-Browser: http://git.debian-maintainers.org/?p=daniel/btrfs-tools.git +Vcs-Git: git://git.debian-maintainers.org/git/daniel/btrfs-tools.git + +Package: btrfs-tools +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: Checksumming Copy on Write Filesystem utilities + Btrfs is a new copy on write filesystem for Linux aimed at implementing + advanced features while focusing on fault tolerance, repair and easy + administration. + . + This package contains utilities (mkfs, fsck, btrfsctl) used to work with btrfs + and an utility (btrfs-convert) to make a btrfs filesystem from an ext3. + . + WARNING: Btrfs is under heavy development, and is not suitable for any uses + other than benchmarking and review. + +Package: btrfs-tools-udeb +Section: debian-installer +Architecture: any +XC-Package-Type: udeb +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: Checksumming Copy on Write Filesystem utilities (udeb) + +Package: btrfs-tools-dbg +Section: debug +Priority: extra +Architecture: any +Depends: ${misc:Depends}, btrfs-tools (= ${binary:Version}) +Description: Checksumming Copy on Write Filesystem utilities (debug) + Btrfs is a new copy on write filesystem for Linux aimed at implementing + advanced features while focusing on fault tolerance, repair and easy + administration. + . + This package contains the debugging symbols. --- btrfs-tools-0.19.orig/debian/README.source +++ btrfs-tools-0.19/debian/README.source @@ -0,0 +1,37 @@ +Package Repositories +-------------------- + +Backports for the current stable debian distribution as well as snapshots of +unreleased versions may be available in repositories listed on the maintainers +homepage. The current URL of the maintainer homepage can be seen in +debian/copyright. + + +Source Access +------------- + +You can obtain the sources of this package with: + + $ apt-get source ${PACKAGE} + +whereas '${PACKAGE}' has to be replaced with the actual name of the package. + +This package is maintained with the Git version control system. The current git +source tree can be obtained with: + + $ git clone ${GIT_URI} + +whereas '${GIT_URI}' has to be replaced with the actual URI for the Git +repository. The current Git URI can be seen in debian/control in the extracted +package sources. + +More information about Git can be found in the git-core package. + +This package may use the Quilt patch system to manage all modifications to the +upstream source. Changes, if any, are stored in the source package as diffs in +debian/diff and are applied during the build. Current modifications can be +applied to the source tree with: + + $ QUILT_PATCHES=debian/patches quilt push -a + +More information about Quilt can be found in the quilt package. --- btrfs-tools-0.19.orig/debian/btrfs-tools.install +++ btrfs-tools-0.19/debian/btrfs-tools.install @@ -0,0 +1,2 @@ +btrfs-image /sbin +btrfstune /sbin --- btrfs-tools-0.19.orig/debian/copyright +++ btrfs-tools-0.19/debian/copyright @@ -0,0 +1,91 @@ +Upstream-Contact: Btrfs project +Upstream-Homepage: http://btrfs.wiki.kernel.org/ +Maintainer-Contact: Daniel Baumann +Maintainer-Homepage: http://daniel.debian-maintainers.org/ + +Files: * +Copyright: (C) 2007-2009 Oracle +License: GPL-2+ + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + . + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + . + On Debian systems, the complete text of the GNU General Public License + can be found in /usr/share/common-licenses/GPL-2 file. + +Files: radix-tree.c +Copyright: + (C) 2007-2009 Oracle + (C) 2001 Momchil Velikov + (C) 2001 Christoph Hellwig + (C) 2005 SGI, Christoph Lameter +License: GPL-2+ + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + . + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + . + On Debian systems, the complete text of the GNU General Public License + can be found in /usr/share/common-licenses/GPL-2 file. + +Files: radix-tree.h +Copyright: + (C) 2007-2009 Oracle + (C) 2001 Momchil Velikov + (C) 2001 Christoph Hellwig +License: GPL-2+ + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + . + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + . + On Debian systems, the complete text of the GNU General Public License + can be found in /usr/share/common-licenses/GPL-2 file. + +Files: debian/* +Copyright: (C) 2007-2010 Daniel Baumann +License: GPL-2+ + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + . + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + . + On Debian systems, the complete text of the GNU General Public License + can be found in /usr/share/common-licenses/GPL-2 file. --- btrfs-tools-0.19.orig/debian/btrfs-tools.README.Debian +++ btrfs-tools-0.19/debian/btrfs-tools.README.Debian @@ -0,0 +1,7 @@ +btrfs-tools for Debian +---------------------- + +WARNING: Btrfs is under heavy development, and is not suitable for any uses +other than benchmarking and review. + + -- Daniel Baumann Sun, 29 Jul 2007 12:19:00 +0200 --- btrfs-tools-0.19.orig/debian/changelog +++ btrfs-tools-0.19/debian/changelog @@ -0,0 +1,236 @@ +btrfs-tools (0.19-12) unstable; urgency=low + + * Setting section for udeb to debian-installer. + * Disabling valgrind patch, seems to make troubles on armel (Closes: + #582438). + + -- Daniel Baumann Mon, 24 May 2010 12:57:36 +0200 + +btrfs-tools (0.19-11) unstable; urgency=low + + * Removing fsck.btrfs symlink to circumvent that btrfsck doesn't + support -a. + * Adding initramfs-tools integration (Closes: #559710). + + -- Daniel Baumann Sun, 04 Apr 2010 17:42:30 +0200 + +btrfs-tools (0.19-10) unstable; urgency=low + + * Updating to standards 3.8.4. + * Including btrfsctl into udeb. + * Adding upstream patches to add support for deleting snapshots and + subvolumes (Closes: #567171). + + -- Daniel Baumann Sat, 06 Feb 2010 08:49:55 +0100 + +btrfs-tools (0.19-9) unstable; urgency=low + + * Adding explicit debian source version 1.0 until switch to 3.0. + * Updating year in copyright file. + * Adding patch from Joey Hess to add btrfs-tools- + udeb (Closes: #567075). + * Adding patch from Joey Hess to improve package + short-descriptions. + + -- Daniel Baumann Wed, 27 Jan 2010 05:31:57 +0100 + +btrfs-tools (0.19-8) unstable; urgency=low + + * Adding patch from Josef Bacik to fix memory + leaks and segfaults. + * Simplifying shell commands in rules. + + -- Daniel Baumann Sat, 05 Dec 2009 17:20:06 +0100 + +btrfs-tools (0.19-7) unstable; urgency=low + + * Moving tools from /usr/bin to /sbin (Closes: #559477). + * Making build-depends on quilt versioned. + * Cosmetically improve shell commands in rules. + * Updating README.source. + + -- Daniel Baumann Fri, 04 Dec 2009 20:54:42 +0100 + +btrfs-tools (0.19-6) unstable; urgency=low + + * Correcting wrong vcs-browser field. + * Updating package long-description (Closes: #552553). + + -- Daniel Baumann Wed, 28 Oct 2009 20:24:25 +0100 + +btrfs-tools (0.19-5) unstable; urgency=low + + * Adding debug package. + + -- Daniel Baumann Fri, 02 Oct 2009 19:40:09 +0200 + +btrfs-tools (0.19-4) unstable; urgency=low + + * Updating maintainer field. + * Updating vcs fields. + * Sorting build-depends and depends. + * Updating package to standards version 3.8.3. + * Bumping versioned build-depends on debhelper. + * Updating years in copyright file. + * Adding README.source. + * Adding maintainer homepage in copyright. + + -- Daniel Baumann Fri, 02 Oct 2009 19:06:02 +0200 + +btrfs-tools (0.19-3) unstable; urgency=low + + * Minimizing rules file. + * Adding patch from Luca Bruno to properly cast and + avoiding compiler warnings. Fixes FTBFS on alpha and ia64 (Closes: + #539433). + + -- Daniel Baumann Sun, 02 Aug 2009 12:08:49 +0200 + +btrfs-tools (0.19-2) unstable; urgency=low + + * Building and installing alternative utilities (Closes: #536058). + * Adding symlink from btrfsck to fsck.btrfs. + * Correcting spelling typo in package long-description. + + -- Daniel Baumann Tue, 07 Jul 2009 14:56:40 +0200 + +btrfs-tools (0.19-1) unstable; urgency=low + + * Merging upstream version 0.19. + * Removing ftbfs.patch, went upstream. + * Updating standards version to 3.8.2. + * Updating rules to cope with new upstream manpage makefiles. + * Workaround upstream makefiles wrt/ manpage compression. + + -- Daniel Baumann Mon, 06 Jul 2009 14:22:03 +0200 + +btrfs-tools (0.18-4) unstable; urgency=low + + * Using correct rfc-2822 date formats in changelog. + * Including btrfs-convert, thanks to Uwe Kleine-König (Closes: #529168). + + -- Daniel Baumann Sun, 17 May 2009 22:18:27 +0200 + +btrfs-tools (0.18-3) unstable; urgency=low + + * Tidy rules file. + * Adding patch from upstream to allow /'s in labels. + + -- Daniel Baumann Fri, 17 Apr 2009 21:02:00 +0200 + +btrfs-tools (0.18-2) unstable; urgency=medium + + * Adding patch from Luca Bruno to fix FTBFS on + alpha and ia64 (Closes: #519913). + * Updating rules file to current state of the art. + * Updating standards version to 3.8.1. + + -- Daniel Baumann Tue, 17 Mar 2009 08:22:00 +0100 + +btrfs-tools (0.18-1) unstable; urgency=low + + * Merging upstream version 0.18. + + -- Daniel Baumann Sat, 24 Jan 2009 15:59:00 +0100 + +btrfs-tools (0.17-1) unstable; urgency=low + + * Updating vcs fields in control file. + * Replacing obsolete dh_clean -k with dh_prep. + * Merging upstream version 0.17. + * Removing notes about not finalized on disk format. + * Prefixing debhelper files with package name. + * Updating year in copyright file. + * Adding zlib to build-depends. + + -- Daniel Baumann Sat, 24 Jan 2009 15:50:00 +0100 + +btrfs-tools (0.16-1) unstable; urgency=low + + * Removing cflags handling in rules, not required anymore. + * Merging upstream version 0.16. + + -- Daniel Baumann Mon, 25 Aug 2008 01:04:00 +0200 + +btrfs-tools (0.15-2) unstable; urgency=medium + + * Building on all architectures again since FTBFS on ia64 is gone. + + -- Daniel Baumann Tue, 01 Jul 2008 15:07:00 +0200 + +btrfs-tools (0.15-1) unstable; urgency=low + + * Merging upstream version 0.15. + * Updating to standards 3.8.0. + + -- Daniel Baumann Mon, 09 Jun 2008 15:01:00 +0200 + +btrfs-tools (0.14-1) unstable; urgency=low + + * Reordering rules file. + * Rewriting copyright file in machine-interpretable format. + * Updated warnings about early state of btrfs. + * Adding vcs fields in control file. + * Updating homepage field in control file. + * Upgrading package to debhelper 7. + * Merging upstream version 0.14. + + -- Daniel Baumann Sun, 04 May 2008 10:04:00 +0200 + +btrfs-tools (0.13-2) unstable; urgency=medium + + * Excluding alpha and ia64 from architectures, doesn't build there + (Closes: #465128). + + -- Daniel Baumann Fri, 07 Mar 2008 12:04:00 +0100 + +btrfs-tools (0.13-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Mon, 25 Feb 2008 20:39:00 +0100 + +btrfs-tools (0.12-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Fri, 08 Feb 2008 17:52:00 +0100 + +btrfs-tools (0.11-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Mon, 28 Jan 2008 12:58:00 +0100 + +btrfs-tools (0.10-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Thu, 17 Jan 2008 16:23:00 +0100 + +btrfs-tools (0.9-1) unstable; urgency=low + + * New upstream release. + * Updated standards. + * Removing watch file (Closes: #450102). + + -- Daniel Baumann Thu, 20 Dec 2007 08:10:00 +0100 + +btrfs-tools (0.8-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Fri, 14 Sep 2007 11:07:00 +0200 + +btrfs-tools (0.6-1) unstable; urgency=low + + * New upstream release. + + -- Daniel Baumann Wed, 08 Aug 2007 20:33:00 +0200 + +btrfs-tools (0.5-1) unstable; urgency=low + + * Initial release (Closes: #432697). + + -- Daniel Baumann Sun, 29 Jul 2007 12:19:00 +0200 --- btrfs-tools-0.19.orig/debian/compat +++ btrfs-tools-0.19/debian/compat @@ -0,0 +1 @@ +7 --- btrfs-tools-0.19.orig/debian/local/btrfs.local-premount +++ btrfs-tools-0.19/debian/local/btrfs.local-premount @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +PREREQ="" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +if [ -x /sbin/btrfsctl ] +then + modprobe btrfs + /sbin/btrfsctl -a 2>/dev/null +fi --- btrfs-tools-0.19.orig/debian/local/btrfs.hook +++ btrfs-tools-0.19/debian/local/btrfs.hook @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +PREREQ="" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +if [ -x /sbin/btrfsctl ] +then + copy_exec /sbin/btrfsctl /sbin +fi --- btrfs-tools-0.19.orig/debian/local/btrfs.modules +++ btrfs-tools-0.19/debian/local/btrfs.modules @@ -0,0 +1,4 @@ +libcrc32c +crc32c +zlib_deflate +btrfs --- btrfs-tools-0.19.orig/debian/patches/05-upstream-2.patch +++ btrfs-tools-0.19/debian/patches/05-upstream-2.patch @@ -0,0 +1,68 @@ +From 45195b216d5da399aa71c11f111b2c0b45e54c82 Mon Sep 17 00:00:00 2001 +From: Yan, Zheng +Date: Mon, 21 Sep 2009 16:03:57 -0400 +Subject: [PATCH] btrfsctl: add snapshot/subvolume destroy ioctl + +resend Aaron Straus's patch + +Signed-off-by: Yan Zheng +Signed-off-by: Chris Mason +--- + btrfsctl.c | 15 ++++++++++++++- + ioctl.h | 3 +++ + 2 files changed, 17 insertions(+), 1 deletions(-) + +diff --git a/btrfsctl.c b/btrfsctl.c +index b323818..66c4e89 100644 +--- a/btrfsctl.c ++++ b/btrfsctl.c +@@ -46,7 +46,7 @@ static inline int ioctl(int fd, int define, void *arg) { return 0; } + static void print_usage(void) + { + printf("usage: btrfsctl [ -d file|dir] [ -s snap_name subvol|tree ]\n"); +- printf(" [-r size] [-A device] [-a] [-c]\n"); ++ printf(" [-r size] [-A device] [-a] [-c] [-D dir .]\n"); + printf("\t-d filename: defragments one file\n"); + printf("\t-d directory: defragments the entire Btree\n"); + printf("\t-s snap_name dir: creates a new snapshot of dir\n"); +@@ -55,6 +55,7 @@ static void print_usage(void) + printf("\t-A device: scans the device file for a Btrfs filesystem\n"); + printf("\t-a: scans all devices for Btrfs filesystems\n"); + printf("\t-c: forces a single FS sync\n"); ++ printf("\t-D: delete snapshot\n"); + printf("%s\n", BTRFS_BUILD_VERSION); + exit(1); + } +@@ -158,6 +159,18 @@ int main(int ac, char **av) + print_usage(); + } + command = BTRFS_IOC_DEFRAG; ++ } else if (strcmp(av[i], "-D") == 0) { ++ if (i >= ac - 1) { ++ fprintf(stderr, "-D requires an arg\n"); ++ print_usage(); ++ } ++ command = BTRFS_IOC_SNAP_DESTROY; ++ name = av[i + 1]; ++ len = strlen(name); ++ if (len == 0 || len >= BTRFS_VOL_NAME_MAX) { ++ fprintf(stderr, "-D size too long\n"); ++ exit(1); ++ } + } else if (strcmp(av[i], "-A") == 0) { + if (i >= ac - 1) { + fprintf(stderr, "-A requires an arg\n"); +diff --git a/ioctl.h b/ioctl.h +index a084f33..4410ac0 100644 +--- a/ioctl.h ++++ b/ioctl.h +@@ -56,4 +56,7 @@ struct btrfs_ioctl_vol_args { + /* 13 is for CLONE_RANGE */ + #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ + struct btrfs_ioctl_vol_args) ++ ++#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ ++ struct btrfs_ioctl_vol_args) + #endif +-- +1.6.6.1 --- btrfs-tools-0.19.orig/debian/patches/series +++ btrfs-tools-0.19/debian/patches/series @@ -0,0 +1,6 @@ +01-labels.patch +02-format.patch +04-upstream-1.patch +05-upstream-2.patch +06-upstream-3.patch +07-upstream-4.patch --- btrfs-tools-0.19.orig/debian/patches/01-labels.patch +++ btrfs-tools-0.19/debian/patches/01-labels.patch @@ -0,0 +1,27 @@ +Author: Chris Mason +Description: Allow /'s in labels. + +diff -Naurp btrfs-tools.orig/mkfs.c btrfs-tools/mkfs.c +--- btrfs-tools.orig/mkfs.c 2009-03-15 13:27:12.000000000 +0100 ++++ btrfs-tools/mkfs.c 2009-04-17 20:53:12.000000000 +0200 +@@ -294,7 +294,6 @@ static u64 parse_profile(char *s) + + static char *parse_label(char *input) + { +- int i; + int len = strlen(input); + + if (len > BTRFS_LABEL_SIZE) { +@@ -302,12 +301,6 @@ static char *parse_label(char *input) + BTRFS_LABEL_SIZE); + exit(1); + } +- for (i = 0; i < len; i++) { +- if (input[i] == '/' || input[i] == '\\') { +- fprintf(stderr, "invalid label %s\n", input); +- exit(1); +- } +- } + return strdup(input); + } + --- btrfs-tools-0.19.orig/debian/patches/02-format.patch +++ btrfs-tools-0.19/debian/patches/02-format.patch @@ -0,0 +1,65 @@ +Author: Luca Bruno +Description: + Patch to properly cast and avoiding compiler warnings. Fixes FTBFS on alpha + and ia64 (Closes: #539433). + +diff -Naurp btrfs-tools.orig/convert.c btrfs-tools/convert.c +--- btrfs-tools.orig/convert.c 2009-07-14 13:44:16.000000000 +0000 ++++ btrfs-tools/convert.c 2009-08-02 10:05:58.000000000 +0000 +@@ -2579,7 +2579,7 @@ int do_rollback(const char *devname, int + ext2_root = btrfs_read_fs_root(root->fs_info, &key); + if (!ext2_root || IS_ERR(ext2_root)) { + fprintf(stderr, "unable to open subvol %llu\n", +- key.objectid); ++ (unsigned long long) key.objectid); + goto fail; + } + +diff -Naurp btrfs-tools.orig/disk-io.c btrfs-tools/disk-io.c +--- btrfs-tools.orig/disk-io.c 2009-07-14 13:44:16.000000000 +0000 ++++ btrfs-tools/disk-io.c 2009-08-02 10:05:58.000000000 +0000 +@@ -678,7 +678,8 @@ struct btrfs_root *open_ctree_fd(int fp, + ~BTRFS_FEATURE_INCOMPAT_SUPP; + if (features) { + printk("couldn't open because of unsupported " +- "option features (%Lx).\n", features); ++ "option features (%Lx).\n", ++ (unsigned long long)features); + BUG_ON(1); + } + +@@ -692,7 +693,8 @@ struct btrfs_root *open_ctree_fd(int fp, + ~BTRFS_FEATURE_COMPAT_RO_SUPP; + if (writes && features) { + printk("couldn't open RDWR because of unsupported " +- "option features (%Lx).\n", features); ++ "option features (%Lx).\n", ++ (unsigned long long) features); + BUG_ON(1); + } + +diff -Naurp btrfs-tools.orig/extent-tree.c btrfs-tools/extent-tree.c +--- btrfs-tools.orig/extent-tree.c 2009-07-14 13:44:16.000000000 +0000 ++++ btrfs-tools/extent-tree.c 2009-08-02 10:05:58.000000000 +0000 +@@ -1448,7 +1448,8 @@ int btrfs_lookup_extent_info(struct btrf + goto out; + if (ret != 0) { + btrfs_print_leaf(root, path->nodes[0]); +- printk("failed to find block number %Lu\n", bytenr); ++ printk("failed to find block number %Lu\n", ++ (unsigned long long) bytenr); + BUG(); + } + +diff -Naurp btrfs-tools.orig/print-tree.c btrfs-tools/print-tree.c +--- btrfs-tools.orig/print-tree.c 2009-07-14 13:44:16.000000000 +0000 ++++ btrfs-tools/print-tree.c 2009-08-02 10:05:58.000000000 +0000 +@@ -494,7 +494,7 @@ void btrfs_print_leaf(struct btrfs_root + case BTRFS_DIR_LOG_ITEM_KEY: + dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item); + printf("\t\tdir log end %Lu\n", +- btrfs_dir_log_end(l, dlog)); ++ (unsigned long long) btrfs_dir_log_end(l, dlog)); + break; + case BTRFS_ORPHAN_ITEM_KEY: + printf("\t\torphan item\n"); --- btrfs-tools-0.19.orig/debian/patches/03-valgrind.patch +++ btrfs-tools-0.19/debian/patches/03-valgrind.patch @@ -0,0 +1,220 @@ +Author: Josef Bacik +Description: + Started running valgrind against btrfsck since e2fsck seemed to have a myriad + of problems. btrfsck was actually not in too bad shape, only like 5 or 6 normal + errors and maybe 5 leaks. The big leak is the "seen" extent cache that we don't + seem to do anything with. Since I'm not sure what Yan is up to I just made it + so we free that cache before we return in case he wants it for something. With + these changes btrfsck doesn't spit out any errors while running valgrind and + has no leaks. This should also help any of the other utilities that use the + generic stuff. + +diff -Naurp btrfs-tools.orig/btrfsck.c btrfs-tools/btrfsck.c +--- btrfs-tools.orig/btrfsck.c 2009-10-02 14:13:35.000000000 +0200 ++++ btrfs-tools/btrfsck.c 2009-12-05 17:13:41.000000000 +0100 +@@ -2431,6 +2431,8 @@ static int check_extents(struct btrfs_ro + break; + } + ret = check_extent_refs(root, &extent_cache); ++ free_cache_tree(&seen); ++ free(bits); + return ret; + } + +diff -Naurp btrfs-tools.orig/disk-io.c btrfs-tools/disk-io.c +--- btrfs-tools.orig/disk-io.c 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/disk-io.c 2009-12-05 17:13:41.000000000 +0100 +@@ -425,8 +425,10 @@ static int find_and_setup_log_root(struc + u64 blocknr = btrfs_super_log_root(disk_super); + struct btrfs_root *log_root = malloc(sizeof(struct btrfs_root)); + +- if (blocknr == 0) ++ if (blocknr == 0) { ++ free(log_root); + return 0; ++ } + + blocksize = btrfs_level_size(tree_root, + btrfs_super_log_root_level(disk_super)); +@@ -605,7 +607,7 @@ struct btrfs_root *open_ctree_fd(int fp, + struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); + struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); + struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); +- struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); ++ struct btrfs_fs_info *fs_info = malloc(sizeof(struct btrfs_fs_info)); + int ret; + struct btrfs_super_block *disk_super; + struct btrfs_fs_devices *fs_devices = NULL; +@@ -628,7 +630,7 @@ struct btrfs_root *open_ctree_fd(int fp, + BUG_ON(ret); + } + +- memset(fs_info, 0, sizeof(*fs_info)); ++ memset(fs_info, 0, sizeof(struct btrfs_fs_info)); + fs_info->tree_root = tree_root; + fs_info->extent_root = extent_root; + fs_info->chunk_root = chunk_root; +@@ -928,15 +930,19 @@ static int close_all_devices(struct btrf + { + struct list_head *list; + struct list_head *next; ++ struct list_head *tmp; + struct btrfs_device *device; + +- return 0; +- + list = &fs_info->fs_devices->devices; +- list_for_each(next, list) { ++ list_for_each_safe(next, tmp, list) { + device = list_entry(next, struct btrfs_device, dev_list); + close(device->fd); ++ list_del(&device->dev_list); ++ free(device->name); ++ free(device->label); ++ free(device); + } ++ free(fs_info->fs_devices); + return 0; + } + +@@ -970,25 +976,26 @@ int close_ctree(struct btrfs_root *root) + if (fs_info->csum_root->node) + free_extent_buffer(fs_info->csum_root->node); + +- if (root->fs_info->log_root_tree) { +- if (root->fs_info->log_root_tree->node) +- free_extent_buffer(root->fs_info->log_root_tree->node); +- free(root->fs_info->log_root_tree); ++ if (fs_info->log_root_tree) { ++ if (fs_info->log_root_tree->node) ++ free_extent_buffer(fs_info->log_root_tree->node); + } + +- close_all_devices(root->fs_info); ++ close_all_devices(fs_info); + extent_io_tree_cleanup(&fs_info->extent_cache); + extent_io_tree_cleanup(&fs_info->free_space_cache); + extent_io_tree_cleanup(&fs_info->block_group_cache); + extent_io_tree_cleanup(&fs_info->pinned_extents); + extent_io_tree_cleanup(&fs_info->pending_del); + extent_io_tree_cleanup(&fs_info->extent_ins); ++ btrfs_mapping_tree_free(&fs_info->mapping_tree); + + free(fs_info->tree_root); + free(fs_info->extent_root); + free(fs_info->chunk_root); + free(fs_info->dev_root); + free(fs_info->csum_root); ++ free(fs_info->log_root_tree); + free(fs_info); + + return 0; +diff -Naurp btrfs-tools.orig/extent-cache.c btrfs-tools/extent-cache.c +--- btrfs-tools.orig/extent-cache.c 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/extent-cache.c 2009-12-05 17:13:41.000000000 +0100 +@@ -170,3 +170,14 @@ void remove_cache_extent(struct cache_tr + rb_erase(&pe->rb_node, &tree->root); + } + ++void free_cache_tree(struct cache_tree *tree) ++{ ++ struct rb_node *node; ++ struct cache_extent *cache; ++ ++ while ((node = rb_last(&tree->root)) != NULL) { ++ cache = rb_entry(node, struct cache_extent, rb_node); ++ remove_cache_extent(tree, cache); ++ free(cache); ++ } ++} +diff -Naurp btrfs-tools.orig/extent-cache.h btrfs-tools/extent-cache.h +--- btrfs-tools.orig/extent-cache.h 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/extent-cache.h 2009-12-05 17:13:41.000000000 +0100 +@@ -43,6 +43,7 @@ struct cache_extent *find_cache_extent(s + int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size); + int insert_existing_cache_extent(struct cache_tree *tree, + struct cache_extent *pe); ++void free_cache_tree(struct cache_tree *tree); + + static inline int cache_tree_empty(struct cache_tree *tree) + { +diff -Naurp btrfs-tools.orig/extent_io.c btrfs-tools/extent_io.c +--- btrfs-tools.orig/extent_io.c 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/extent_io.c 2009-12-05 17:13:41.000000000 +0100 +@@ -572,6 +572,7 @@ static struct extent_buffer *__alloc_ext + BUG(); + return NULL; + } ++ memset(eb, 0, sizeof(struct extent_buffer) + blocksize); + + eb->start = bytenr; + eb->len = blocksize; +diff -Naurp btrfs-tools.orig/extent-tree.c btrfs-tools/extent-tree.c +--- btrfs-tools.orig/extent-tree.c 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/extent-tree.c 2009-12-05 17:13:41.000000000 +0100 +@@ -2985,6 +2985,7 @@ out: + + int btrfs_free_block_groups(struct btrfs_fs_info *info) + { ++ struct btrfs_space_info *space_info; + u64 start; + u64 end; + u64 ptr; +@@ -3008,6 +3009,15 @@ int btrfs_free_block_groups(struct btrfs + clear_extent_dirty(&info->free_space_cache, start, + end, GFP_NOFS); + } ++ ++ while (!list_empty(&info->space_info)) { ++ space_info = list_entry(info->space_info.next, ++ struct btrfs_space_info, ++ list); ++ list_del(&space_info->list); ++ kfree(space_info); ++ } ++ + return 0; + } + +diff -Naurp btrfs-tools.orig/volumes.c btrfs-tools/volumes.c +--- btrfs-tools.orig/volumes.c 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/volumes.c 2009-12-05 17:13:41.000000000 +0100 +@@ -862,6 +862,20 @@ void btrfs_mapping_init(struct btrfs_map + cache_tree_init(&tree->cache_tree); + } + ++void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) ++{ ++ struct cache_extent *cache; ++ struct rb_node *node; ++ struct map_lookup *map; ++ ++ while ((node = rb_last(&tree->cache_tree.root)) != NULL) { ++ cache = rb_entry(node, struct cache_extent, rb_node); ++ map = container_of(cache, struct map_lookup, ce); ++ remove_cache_extent(&tree->cache_tree, cache); ++ free(map); ++ } ++} ++ + int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) + { + struct cache_extent *ce; +@@ -1340,7 +1354,7 @@ int btrfs_read_sys_array(struct btrfs_ro + if (!sb) + return -ENOMEM; + btrfs_set_buffer_uptodate(sb); +- write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE); ++ write_extent_buffer(sb, super_copy, 0, sizeof(*super_copy)); + array_size = btrfs_super_sys_array_size(super_copy); + + /* +diff -Naurp btrfs-tools.orig/volumes.h btrfs-tools/volumes.h +--- btrfs-tools.orig/volumes.h 2009-10-02 14:13:36.000000000 +0200 ++++ btrfs-tools/volumes.h 2009-12-05 17:13:41.000000000 +0100 +@@ -130,4 +130,5 @@ int btrfs_add_system_chunk(struct btrfs_ + struct btrfs_root *root, struct btrfs_key *key, + struct btrfs_chunk *chunk, int item_size); + int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); ++void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); + #endif --- btrfs-tools-0.19.orig/debian/patches/06-upstream-3.patch +++ btrfs-tools-0.19/debian/patches/06-upstream-3.patch @@ -0,0 +1,699 @@ +From 6f3cf25a4e7932bc737ed06bc95f73f80772092d Mon Sep 17 00:00:00 2001 +From: Yan, Zheng +Date: Mon, 21 Sep 2009 16:03:57 -0400 +Subject: [PATCH] btrfsck: check root back/forward references + +This patch adds semantic checks for links to snapshot/subvolume and +root back/forward references. + +Signed-off-by: Yan Zheng +Signed-off-by: Chris Mason +--- + btrfsck.c | 444 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- + 1 files changed, 410 insertions(+), 34 deletions(-) + +diff --git a/btrfsck.c b/btrfsck.c +index 40c90f8..73f1836 100644 +--- a/btrfsck.c ++++ b/btrfsck.c +@@ -36,7 +36,7 @@ static u64 total_fs_tree_bytes = 0; + static u64 btree_space_waste = 0; + static u64 data_bytes_allocated = 0; + static u64 data_bytes_referenced = 0; +-int found_old_backref = 0; ++static int found_old_backref = 0; + + struct extent_backref { + struct list_head list; +@@ -100,7 +100,11 @@ struct inode_backref { + #define REF_ERR_DUP_INODE_REF (1 << 5) + #define REF_ERR_INDEX_UNMATCH (1 << 6) + #define REF_ERR_FILETYPE_UNMATCH (1 << 7) +-#define REF_ERR_NAME_TOO_LONG (1 << 8) ++#define REF_ERR_NAME_TOO_LONG (1 << 8) // 100 ++#define REF_ERR_NO_ROOT_REF (1 << 9) ++#define REF_ERR_NO_ROOT_BACKREF (1 << 10) ++#define REF_ERR_DUP_ROOT_REF (1 << 11) ++#define REF_ERR_DUP_ROOT_BACKREF (1 << 12) + + struct inode_record { + struct list_head backrefs; +@@ -144,6 +148,29 @@ struct inode_record { + #define I_ERR_SOME_CSUM_MISSING (1 << 12) + #define I_ERR_LINK_COUNT_WRONG (1 << 13) + ++struct root_backref { ++ struct list_head list; ++ unsigned int found_dir_item:1; ++ unsigned int found_dir_index:1; ++ unsigned int found_back_ref:1; ++ unsigned int found_forward_ref:1; ++ unsigned int reachable:1; ++ int errors; ++ u64 ref_root; ++ u64 dir; ++ u64 index; ++ u16 namelen; ++ char name[0]; ++}; ++ ++struct root_record { ++ struct list_head backrefs; ++ struct cache_extent cache; ++ unsigned int found_root_item:1; ++ u64 objectid; ++ u32 found_ref; ++}; ++ + struct ptr_node { + struct cache_extent cache; + void *data; +@@ -151,6 +178,7 @@ struct ptr_node { + + struct shared_node { + struct cache_extent cache; ++ struct cache_tree root_cache; + struct cache_tree inode_cache; + struct inode_record *current; + u32 refs; +@@ -258,6 +286,14 @@ static void free_inode_rec(struct inode_record *rec) + free(rec); + } + ++static int can_free_inode_rec(struct inode_record *rec) ++{ ++ if (!rec->errors && rec->checked && rec->found_inode_item && ++ rec->nlink == rec->found_link && list_empty(&rec->backrefs)) ++ return 1; ++ return 0; ++} ++ + static void maybe_free_inode_rec(struct cache_tree *inode_cache, + struct inode_record *rec) + { +@@ -309,8 +345,7 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache, + } + + BUG_ON(rec->refs != 1); +- if (!rec->errors && rec->nlink == rec->found_link && +- list_empty(&rec->backrefs)) { ++ if (can_free_inode_rec(rec)) { + cache = find_cache_extent(inode_cache, rec->ino, 1); + node = container_of(cache, struct ptr_node, cache); + BUG_ON(node->data != rec); +@@ -338,14 +373,12 @@ static int check_orphan_item(struct btrfs_root *root, u64 ino) + return ret; + } + +-static int process_inode_item(struct btrfs_root *root, +- struct extent_buffer *eb, ++static int process_inode_item(struct extent_buffer *eb, + int slot, struct btrfs_key *key, + struct shared_node *active_node) + { + struct inode_record *rec; + struct btrfs_inode_item *item; +- int ret; + + rec = active_node->current; + BUG_ON(rec->ino != key->objectid || rec->refs > 1); +@@ -361,11 +394,8 @@ static int process_inode_item(struct btrfs_root *root, + if (btrfs_inode_flags(eb, item) & BTRFS_INODE_NODATASUM) + rec->nodatasum = 1; + rec->found_inode_item = 1; +- if (rec->nlink == 0) { +- ret = check_orphan_item(root, rec->ino); +- if (ret == -ENOENT) +- rec->errors |= I_ERR_NO_ORPHAN_ITEM; +- } ++ if (rec->nlink == 0) ++ rec->errors |= I_ERR_NO_ORPHAN_ITEM; + maybe_free_inode_rec(&active_node->inode_cache, rec); + return 0; + } +@@ -443,10 +473,9 @@ static int add_inode_backref(struct cache_tree *inode_cache, + } + + static int merge_inode_recs(struct inode_record *src, struct inode_record *dst, +- struct shared_node *dst_node) ++ struct cache_tree *dst_cache) + { + struct inode_backref *backref; +- struct cache_tree *dst_cache = &dst_node->inode_cache; + + dst->merging = 1; + list_for_each_entry(backref, &src->backrefs, list) { +@@ -510,14 +539,8 @@ static int merge_inode_recs(struct inode_record *src, struct inode_record *dst, + dst->errors |= I_ERR_DUP_INODE_ITEM; + } + } +- +- if (src->checked) { +- dst->checked = 1; +- if (dst_node->current == dst) +- dst_node->current = NULL; +- } + dst->merging = 0; +- maybe_free_inode_rec(dst_cache, dst); ++ + return 0; + } + +@@ -537,8 +560,9 @@ static int splice_shared_node(struct shared_node *src_node, + if (src_node->current) + current_ino = src_node->current->ino; + +- src = &src_node->inode_cache; +- dst = &dst_node->inode_cache; ++ src = &src_node->root_cache; ++ dst = &dst_node->root_cache; ++again: + cache = find_first_cache_extent(src, 0); + while (cache) { + node = container_of(cache, struct ptr_node, cache); +@@ -557,14 +581,28 @@ static int splice_shared_node(struct shared_node *src_node, + } + ret = insert_existing_cache_extent(dst, &ins->cache); + if (ret == -EEXIST) { ++ WARN_ON(src == &src_node->root_cache); + conflict = get_inode_rec(dst, rec->ino, 1); +- merge_inode_recs(rec, conflict, dst_node); ++ merge_inode_recs(rec, conflict, dst); ++ if (rec->checked) { ++ conflict->checked = 1; ++ if (dst_node->current == conflict) ++ dst_node->current = NULL; ++ } ++ maybe_free_inode_rec(dst, conflict); + free_inode_rec(rec); + free(ins); + } else { + BUG_ON(ret); + } + } ++ ++ if (src == &src_node->root_cache) { ++ src = &src_node->inode_cache; ++ dst = &dst_node->inode_cache; ++ goto again; ++ } ++ + if (current_ino > 0 && (!dst_node->current || + current_ino > dst_node->current->ino)) { + if (dst_node->current) { +@@ -616,6 +654,7 @@ static int add_shared_node(struct cache_tree *shared, u64 bytenr, u32 refs) + node = calloc(1, sizeof(*node)); + node->cache.start = bytenr; + node->cache.size = 1; ++ cache_tree_init(&node->root_cache); + cache_tree_init(&node->inode_cache); + node->refs = refs; + +@@ -646,6 +685,7 @@ static int enter_shared_node(struct btrfs_root *root, u64 bytenr, u32 refs, + if (wc->root_level == wc->active_node && + btrfs_root_refs(&root->root_item) == 0) { + if (--node->refs == 0) { ++ free_inode_recs(&node->root_cache); + free_inode_recs(&node->inode_cache); + remove_cache_extent(&wc->shared, &node->cache); + free(node); +@@ -708,10 +748,12 @@ static int process_dir_item(struct extent_buffer *eb, + int filetype; + struct btrfs_dir_item *di; + struct inode_record *rec; ++ struct cache_tree *root_cache; + struct cache_tree *inode_cache; + struct btrfs_key location; + char namebuf[BTRFS_NAME_LEN]; + ++ root_cache = &active_node->root_cache; + inode_cache = &active_node->inode_cache; + rec = active_node->current; + rec->found_dir_item = 1; +@@ -740,7 +782,9 @@ static int process_dir_item(struct extent_buffer *eb, + key->objectid, key->offset, namebuf, + len, filetype, key->type, error); + } else if (location.type == BTRFS_ROOT_ITEM_KEY) { +- /* fixme: check root back & forward references */ ++ add_inode_backref(root_cache, location.objectid, ++ key->objectid, key->offset, namebuf, ++ len, filetype, key->type, error); + } else { + fprintf(stderr, "warning line %d\n", __LINE__); + } +@@ -977,8 +1021,7 @@ static int process_one_leaf(struct btrfs_root *root, struct extent_buffer *eb, + ret = process_inode_ref(eb, i, &key, active_node); + break; + case BTRFS_INODE_ITEM_KEY: +- ret = process_inode_item(root, eb, i, &key, +- active_node); ++ ret = process_inode_item(eb, i, &key, active_node); + break; + case BTRFS_EXTENT_DATA_KEY: + ret = process_file_extent(root, eb, i, &key, +@@ -1176,13 +1219,23 @@ static int check_inode_recs(struct btrfs_root *root, + node = container_of(cache, struct ptr_node, cache); + rec = node->data; + remove_cache_extent(inode_cache, &node->cache); ++ free(node); + if (rec->ino == root_dirid || + rec->ino == BTRFS_ORPHAN_OBJECTID) { +- free(node); + free_inode_rec(rec); + continue; + } + ++ if (rec->errors & I_ERR_NO_ORPHAN_ITEM) { ++ ret = check_orphan_item(root, rec->ino); ++ if (ret == 0) ++ rec->errors &= ~I_ERR_NO_ORPHAN_ITEM; ++ if (can_free_inode_rec(rec)) { ++ free_inode_rec(rec); ++ continue; ++ } ++ } ++ + error++; + if (!rec->found_inode_item) + rec->errors |= I_ERR_NO_INODE_ITEM; +@@ -1205,13 +1258,314 @@ static int check_inode_recs(struct btrfs_root *root, + backref->namelen, backref->name, + backref->filetype, backref->errors); + } +- free(node); + free_inode_rec(rec); + } + return (error > 0) ? -1 : 0; + } + ++static struct root_record *get_root_rec(struct cache_tree *root_cache, ++ u64 objectid) ++{ ++ struct cache_extent *cache; ++ struct root_record *rec = NULL; ++ int ret; ++ ++ cache = find_cache_extent(root_cache, objectid, 1); ++ if (cache) { ++ rec = container_of(cache, struct root_record, cache); ++ } else { ++ rec = calloc(1, sizeof(*rec)); ++ rec->objectid = objectid; ++ INIT_LIST_HEAD(&rec->backrefs); ++ rec->cache.start = objectid; ++ rec->cache.size = 1; ++ ++ ret = insert_existing_cache_extent(root_cache, &rec->cache); ++ BUG_ON(ret); ++ } ++ return rec; ++} ++ ++static struct root_backref *get_root_backref(struct root_record *rec, ++ u64 ref_root, u64 dir, u64 index, ++ const char *name, int namelen) ++{ ++ struct root_backref *backref; ++ ++ list_for_each_entry(backref, &rec->backrefs, list) { ++ if (backref->ref_root != ref_root || backref->dir != dir || ++ backref->namelen != namelen) ++ continue; ++ if (memcmp(name, backref->name, namelen)) ++ continue; ++ return backref; ++ } ++ ++ backref = malloc(sizeof(*backref) + namelen + 1); ++ memset(backref, 0, sizeof(*backref)); ++ backref->ref_root = ref_root; ++ backref->dir = dir; ++ backref->index = index; ++ backref->namelen = namelen; ++ memcpy(backref->name, name, namelen); ++ backref->name[namelen] = '\0'; ++ list_add_tail(&backref->list, &rec->backrefs); ++ return backref; ++} ++ ++static void free_root_recs(struct cache_tree *root_cache) ++{ ++ struct cache_extent *cache; ++ struct root_record *rec; ++ struct root_backref *backref; ++ ++ while (1) { ++ cache = find_first_cache_extent(root_cache, 0); ++ if (!cache) ++ break; ++ rec = container_of(cache, struct root_record, cache); ++ remove_cache_extent(root_cache, &rec->cache); ++ ++ while (!list_empty(&rec->backrefs)) { ++ backref = list_entry(rec->backrefs.next, ++ struct root_backref, list); ++ list_del(&backref->list); ++ free(backref); ++ } ++ kfree(rec); ++ } ++} ++ ++static int add_root_backref(struct cache_tree *root_cache, ++ u64 root_id, u64 ref_root, u64 dir, u64 index, ++ const char *name, int namelen, ++ int item_type, int errors) ++{ ++ struct root_record *rec; ++ struct root_backref *backref; ++ ++ rec = get_root_rec(root_cache, root_id); ++ backref = get_root_backref(rec, ref_root, dir, index, name, namelen); ++ ++ backref->errors |= errors; ++ ++ if (item_type != BTRFS_DIR_ITEM_KEY) { ++ if (backref->found_dir_index || backref->found_back_ref || ++ backref->found_forward_ref) { ++ if (backref->index != index) ++ backref->errors |= REF_ERR_INDEX_UNMATCH; ++ } else { ++ backref->index = index; ++ } ++ } ++ ++ if (item_type == BTRFS_DIR_ITEM_KEY) { ++ backref->found_dir_item = 1; ++ backref->reachable = 1; ++ rec->found_ref++; ++ } else if (item_type == BTRFS_DIR_INDEX_KEY) { ++ backref->found_dir_index = 1; ++ } else if (item_type == BTRFS_ROOT_REF_KEY) { ++ if (backref->found_forward_ref) ++ backref->errors |= REF_ERR_DUP_ROOT_REF; ++ backref->found_forward_ref = 1; ++ } else if (item_type == BTRFS_ROOT_BACKREF_KEY) { ++ if (backref->found_back_ref) ++ backref->errors |= REF_ERR_DUP_ROOT_BACKREF; ++ backref->found_back_ref = 1; ++ } else { ++ BUG_ON(1); ++ } ++ ++ return 0; ++} ++ ++static int merge_root_recs(struct btrfs_root *root, ++ struct cache_tree *src_cache, ++ struct cache_tree *dst_cache) ++{ ++ struct cache_extent *cache; ++ struct ptr_node *node; ++ struct inode_record *rec; ++ struct inode_backref *backref; ++ ++ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { ++ free_inode_recs(src_cache); ++ return 0; ++ } ++ ++ while (1) { ++ cache = find_first_cache_extent(src_cache, 0); ++ if (!cache) ++ break; ++ node = container_of(cache, struct ptr_node, cache); ++ rec = node->data; ++ remove_cache_extent(src_cache, &node->cache); ++ free(node); ++ ++ list_for_each_entry(backref, &rec->backrefs, list) { ++ BUG_ON(backref->found_inode_ref); ++ if (backref->found_dir_item) ++ add_root_backref(dst_cache, rec->ino, ++ root->root_key.objectid, backref->dir, ++ backref->index, backref->name, ++ backref->namelen, BTRFS_DIR_ITEM_KEY, ++ backref->errors); ++ if (backref->found_dir_index) ++ add_root_backref(dst_cache, rec->ino, ++ root->root_key.objectid, backref->dir, ++ backref->index, backref->name, ++ backref->namelen, BTRFS_DIR_INDEX_KEY, ++ backref->errors); ++ } ++ free_inode_rec(rec); ++ } ++ return 0; ++} ++ ++static int check_root_refs(struct btrfs_root *root, ++ struct cache_tree *root_cache) ++{ ++ struct root_record *rec; ++ struct root_record *ref_root; ++ struct root_backref *backref; ++ struct cache_extent *cache; ++ int loop = 1; ++ int ret; ++ int error; ++ int errors = 0; ++ ++ rec = get_root_rec(root_cache, BTRFS_FS_TREE_OBJECTID); ++ rec->found_ref = 1; ++ ++ /* fixme: this can not detect circular references */ ++ while (loop) { ++ loop = 0; ++ cache = find_first_cache_extent(root_cache, 0); ++ while (1) { ++ if (!cache) ++ break; ++ rec = container_of(cache, struct root_record, cache); ++ cache = next_cache_extent(cache); ++ ++ if (rec->found_ref == 0) ++ continue; ++ ++ list_for_each_entry(backref, &rec->backrefs, list) { ++ if (!backref->reachable) ++ continue; ++ ++ ref_root = get_root_rec(root_cache, ++ backref->ref_root); ++ if (ref_root->found_ref > 0) ++ continue; ++ ++ backref->reachable = 0; ++ rec->found_ref--; ++ if (rec->found_ref == 0) ++ loop = 1; ++ } ++ } ++ } ++ ++ cache = find_first_cache_extent(root_cache, 0); ++ while (1) { ++ if (!cache) ++ break; ++ rec = container_of(cache, struct root_record, cache); ++ cache = next_cache_extent(cache); ++ ++ if (rec->found_ref == 0 && ++ rec->objectid >= BTRFS_FIRST_FREE_OBJECTID && ++ rec->objectid <= BTRFS_LAST_FREE_OBJECTID) { ++ ret = check_orphan_item(root->fs_info->tree_root, ++ rec->objectid); ++ if (ret == 0) ++ continue; ++ errors++; ++ fprintf(stderr, "fs tree %llu not referenced\n", ++ (unsigned long long)rec->objectid); ++ } ++ ++ error = 0; ++ if (rec->found_ref > 0 && !rec->found_root_item) ++ error = 1; ++ list_for_each_entry(backref, &rec->backrefs, list) { ++ if (!backref->found_dir_item) ++ backref->errors |= REF_ERR_NO_DIR_ITEM; ++ if (!backref->found_dir_index) ++ backref->errors |= REF_ERR_NO_DIR_INDEX; ++ if (!backref->found_back_ref) ++ backref->errors |= REF_ERR_NO_ROOT_BACKREF; ++ if (!backref->found_forward_ref) ++ backref->errors |= REF_ERR_NO_ROOT_REF; ++ if (backref->reachable && backref->errors) ++ error = 1; ++ } ++ if (!error) ++ continue; ++ ++ errors++; ++ fprintf(stderr, "fs tree %llu refs %u %s\n", ++ (unsigned long long)rec->objectid, rec->found_ref, ++ rec->found_root_item ? "" : "not found"); ++ ++ list_for_each_entry(backref, &rec->backrefs, list) { ++ if (!backref->reachable) ++ continue; ++ if (!backref->errors && rec->found_root_item) ++ continue; ++ fprintf(stderr, "\tunresolved ref root %llu dir %llu" ++ " index %llu namelen %u name %s error %x\n", ++ (unsigned long long)backref->ref_root, ++ (unsigned long long)backref->dir, ++ (unsigned long long)backref->index, ++ backref->namelen, backref->name, ++ backref->errors); ++ } ++ } ++ return errors > 0 ? 1 : 0; ++} ++ ++static int process_root_ref(struct extent_buffer *eb, int slot, ++ struct btrfs_key *key, ++ struct cache_tree *root_cache) ++{ ++ u64 dirid; ++ u64 index; ++ u32 len; ++ u32 name_len; ++ struct btrfs_root_ref *ref; ++ char namebuf[BTRFS_NAME_LEN]; ++ int error; ++ ++ ref = btrfs_item_ptr(eb, slot, struct btrfs_root_ref); ++ ++ dirid = btrfs_root_ref_dirid(eb, ref); ++ index = btrfs_root_ref_sequence(eb, ref); ++ name_len = btrfs_root_ref_name_len(eb, ref); ++ ++ if (name_len <= BTRFS_NAME_LEN) { ++ len = name_len; ++ error = 0; ++ } else { ++ len = BTRFS_NAME_LEN; ++ error = REF_ERR_NAME_TOO_LONG; ++ } ++ read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len); ++ ++ if (key->type == BTRFS_ROOT_REF_KEY) { ++ add_root_backref(root_cache, key->offset, key->objectid, dirid, ++ index, namebuf, len, key->type, error); ++ } else { ++ add_root_backref(root_cache, key->objectid, key->offset, dirid, ++ index, namebuf, len, key->type, error); ++ } ++ return 0; ++} ++ + static int check_fs_root(struct btrfs_root *root, ++ struct cache_tree *root_cache, + struct walk_control *wc) + { + int ret = 0; +@@ -1219,10 +1573,18 @@ static int check_fs_root(struct btrfs_root *root, + int level; + struct btrfs_path path; + struct shared_node root_node; ++ struct root_record *rec; + struct btrfs_root_item *root_item = &root->root_item; + ++ if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { ++ rec = get_root_rec(root_cache, root->root_key.objectid); ++ if (btrfs_root_refs(root_item) > 0) ++ rec->found_root_item = 1; ++ } ++ + btrfs_init_path(&path); + memset(&root_node, 0, sizeof(root_node)); ++ cache_tree_init(&root_node.root_cache); + cache_tree_init(&root_node.inode_cache); + + level = btrfs_header_level(root->node); +@@ -1266,6 +1628,8 @@ static int check_fs_root(struct btrfs_root *root, + } + btrfs_release_path(root, &path); + ++ merge_root_recs(root, &root_node.root_cache, root_cache); ++ + if (root_node.current) { + root_node.current->checked = 1; + maybe_free_inode_rec(&root_node.inode_cache, +@@ -1280,13 +1644,15 @@ static int fs_root_objectid(u64 objectid) + { + if (objectid == BTRFS_FS_TREE_OBJECTID || + objectid == BTRFS_TREE_RELOC_OBJECTID || ++ objectid == BTRFS_DATA_RELOC_TREE_OBJECTID || + (objectid >= BTRFS_FIRST_FREE_OBJECTID && +- objectid < BTRFS_LAST_FREE_OBJECTID)) ++ objectid <= BTRFS_LAST_FREE_OBJECTID)) + return 1; + return 0; + } + +-static int check_fs_roots(struct btrfs_root *root) ++static int check_fs_roots(struct btrfs_root *root, ++ struct cache_tree *root_cache) + { + struct btrfs_path path; + struct btrfs_key key; +@@ -1319,10 +1685,14 @@ static int check_fs_roots(struct btrfs_root *root) + fs_root_objectid(key.objectid)) { + tmp_root = btrfs_read_fs_root_no_cache(root->fs_info, + &key); +- ret = check_fs_root(tmp_root, &wc); ++ ret = check_fs_root(tmp_root, root_cache, &wc); + if (ret) + err = 1; + btrfs_free_fs_root(root->fs_info, tmp_root); ++ } else if (key.type == BTRFS_ROOT_REF_KEY || ++ key.type == BTRFS_ROOT_BACKREF_KEY) { ++ process_root_ref(leaf, path.slots[0], &key, ++ root_cache); + } + path.slots[0]++; + } +@@ -1895,7 +2265,6 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr, + return 0; + } + +- + static int add_pending(struct cache_tree *pending, + struct cache_tree *seen, u64 bytenr, u32 size) + { +@@ -2443,6 +2812,7 @@ static void print_usage(void) + + int main(int ac, char **av) + { ++ struct cache_tree root_cache; + struct btrfs_root *root; + int ret; + +@@ -2450,6 +2820,7 @@ int main(int ac, char **av) + print_usage(); + + radix_tree_init(); ++ cache_tree_init(&root_cache); + root = open_ctree(av[1], 0, 0); + + if (root == NULL) +@@ -2458,10 +2829,15 @@ int main(int ac, char **av) + ret = check_extents(root); + if (ret) + goto out; +- ret = check_fs_roots(root); ++ ret = check_fs_roots(root, &root_cache); ++ if (ret) ++ goto out; + ++ ret = check_root_refs(root, &root_cache); + out: ++ free_root_recs(&root_cache); + close_ctree(root); ++ + if (found_old_backref) { + /* + * there was a disk format change when mixed +-- +1.6.6.1 --- btrfs-tools-0.19.orig/debian/patches/07-upstream-4.patch +++ btrfs-tools-0.19/debian/patches/07-upstream-4.patch @@ -0,0 +1,270 @@ +From ab8fb4c99516c186641bda1dbc0e788f68b4dc77 Mon Sep 17 00:00:00 2001 +From: Chris Mason +Date: Thu, 12 Nov 2009 14:34:09 -0500 +Subject: [PATCH] Add btrfs-map-logical program to map and read logical block numbers + +This allows us to figure out which physical byte offset on which device +is the real location for a given logical block number. It can +optionally read the block in and save it to a file for debugging +analysis. + +Signed-off-by: Chris Mason +--- + Makefile | 6 +- + btrfs-map-logical.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 226 insertions(+), 1 deletions(-) + create mode 100644 btrfs-map-logical.c + +diff --git a/Makefile b/Makefile +index 8097b5a..02f881e 100644 +--- a/Makefile ++++ b/Makefile +@@ -16,7 +16,8 @@ prefix ?= /usr/local + bindir = $(prefix)/bin + LIBS=-luuid + +-progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck ++progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ ++ btrfs-map-logical + + # make C=1 to enable sparse + ifdef C +@@ -56,6 +57,9 @@ btrfs-debug-tree: $(objects) debug-tree.o + 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) + +diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c +new file mode 100644 +index 0000000..a109c6a +--- /dev/null ++++ b/btrfs-map-logical.c +@@ -0,0 +1,221 @@ ++/* ++ * Copyright (C) 2009 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. ++ */ ++ ++#define _XOPEN_SOURCE 500 ++#define _GNU_SOURCE 1 ++#include ++#include ++#include ++#include ++#include ++#include "kerncompat.h" ++#include "ctree.h" ++#include "volumes.h" ++#include "disk-io.h" ++#include "print-tree.h" ++#include "transaction.h" ++#include "list.h" ++#include "version.h" ++ ++/* we write the mirror info to stdout unless they are dumping the data ++ * to stdout ++ * */ ++static FILE *info_file; ++ ++struct extent_buffer *debug_read_block(struct btrfs_root *root, u64 bytenr, ++ u32 blocksize, int copy) ++{ ++ int ret; ++ int dev_nr; ++ struct extent_buffer *eb; ++ u64 length; ++ struct btrfs_multi_bio *multi = NULL; ++ struct btrfs_device *device; ++ int num_copies; ++ int mirror_num = 1; ++ ++ eb = btrfs_find_create_tree_block(root, bytenr, blocksize); ++ if (!eb) ++ return NULL; ++ ++ dev_nr = 0; ++ length = blocksize; ++ while (1) { ++ ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, ++ eb->start, &length, &multi, mirror_num); ++ BUG_ON(ret); ++ device = multi->stripes[0].dev; ++ eb->fd = device->fd; ++ device->total_ios++; ++ eb->dev_bytenr = multi->stripes[0].physical; ++ ++ fprintf(info_file, "mirror %d logical %Lu physical %Lu " ++ "device %s\n", mirror_num, bytenr, eb->dev_bytenr, ++ device->name); ++ kfree(multi); ++ ++ if (!copy || mirror_num == copy) ++ ret = read_extent_from_disk(eb); ++ ++ num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, ++ eb->start, eb->len); ++ if (num_copies == 1) ++ break; ++ ++ mirror_num++; ++ if (mirror_num > num_copies) ++ break; ++ } ++ return eb; ++} ++ ++static void print_usage(void) ++{ ++ fprintf(stderr, "usage: btrfs-map-logical [options] mount_point\n"); ++ fprintf(stderr, "\t-l Logical extent to map\n"); ++ fprintf(stderr, "\t-c Copy of the extent to read (usually 1 or 2)\n"); ++ fprintf(stderr, "\t-o Output file to hold the extent\n"); ++ fprintf(stderr, "\t-s Number of bytes to read\n"); ++ exit(1); ++} ++ ++static struct option long_options[] = { ++ /* { "byte-count", 1, NULL, 'b' }, */ ++ { "logical", 1, NULL, 'l' }, ++ { "copy", 1, NULL, 'c' }, ++ { "output", 1, NULL, 'c' }, ++ { "bytes", 1, NULL, 'b' }, ++ { 0, 0, 0, 0} ++}; ++ ++int main(int ac, char **av) ++{ ++ struct cache_tree root_cache; ++ struct btrfs_root *root; ++ struct extent_buffer *eb; ++ char *dev; ++ char *output_file = NULL; ++ u64 logical = 0; ++ int ret = 0; ++ int option_index = 0; ++ int copy = 0; ++ u64 bytes = 0; ++ int out_fd = 0; ++ int err; ++ ++ while(1) { ++ int c; ++ c = getopt_long(ac, av, "l:c:o:b:", long_options, ++ &option_index); ++ if (c < 0) ++ break; ++ switch(c) { ++ case 'l': ++ logical = atoll(optarg); ++ if (logical == 0) { ++ fprintf(stderr, ++ "invalid extent number\n"); ++ print_usage(); ++ } ++ break; ++ case 'c': ++ copy = atoi(optarg); ++ if (copy == 0) { ++ fprintf(stderr, ++ "invalid copy number\n"); ++ print_usage(); ++ } ++ break; ++ case 'b': ++ bytes = atoll(optarg); ++ if (bytes == 0) { ++ fprintf(stderr, ++ "invalid byte count\n"); ++ print_usage(); ++ } ++ break; ++ case 'o': ++ output_file = strdup(optarg); ++ break; ++ default: ++ print_usage(); ++ } ++ } ++ ac = ac - optind; ++ if (ac == 0) ++ print_usage(); ++ if (logical == 0) ++ print_usage(); ++ if (copy < 0) ++ print_usage(); ++ ++ dev = av[optind]; ++ ++ radix_tree_init(); ++ cache_tree_init(&root_cache); ++ ++ root = open_ctree(dev, 0, 0); ++ if (!root) { ++ fprintf(stderr, "Open ctree failed\n"); ++ exit(1); ++ } ++ ++ if (output_file) { ++ if (strcmp(output_file, "-") == 0) { ++ out_fd = 1; ++ info_file = stderr; ++ } else { ++ out_fd = open(output_file, O_RDWR | O_CREAT, 0600); ++ if (out_fd < 0) ++ goto close; ++ err = ftruncate(out_fd, 0); ++ if (err) { ++ close(out_fd); ++ goto close; ++ } ++ info_file = stdout; ++ } ++ } ++ ++ if (bytes == 0) ++ bytes = root->sectorsize; ++ ++ bytes = (bytes + root->sectorsize - 1) / root->sectorsize; ++ bytes *= root->sectorsize; ++ ++ while (bytes > 0) { ++ eb = debug_read_block(root, logical, root->sectorsize, copy); ++ if (eb && output_file) { ++ err = write(out_fd, eb->data, eb->len); ++ if (err < 0 || err != eb->len) { ++ fprintf(stderr, "output file write failed\n"); ++ goto out_close_fd; ++ } ++ } ++ free_extent_buffer(eb); ++ logical += root->sectorsize; ++ bytes -= root->sectorsize; ++ } ++ ++out_close_fd: ++ if (output_file && out_fd != 1) ++ close(out_fd); ++close: ++ close_ctree(root); ++ return ret; ++} +-- +1.6.6.1 --- btrfs-tools-0.19.orig/debian/patches/04-upstream-1.patch +++ btrfs-tools-0.19/debian/patches/04-upstream-1.patch @@ -0,0 +1,48 @@ +From 4f89b6eb0718ade63152791db32794da78fbba70 Mon Sep 17 00:00:00 2001 +From: Yan Zheng +Date: Fri, 12 Jun 2009 12:55:50 -0400 +Subject: [PATCH] used space accounting fix for the converter + +remove code that updates the total used space, since +btrfs_update_block_group does that work now. + +Signed-off-by: Yan Zheng +Signed-off-by: Chris Mason +--- + convert.c | 7 ------- + 1 files changed, 0 insertions(+), 7 deletions(-) + +diff --git a/convert.c b/convert.c +index d2c9efa..d037c98 100644 +--- a/convert.c ++++ b/convert.c +@@ -370,7 +370,6 @@ static int record_file_extent(struct btrfs_trans_handle *trans, + struct btrfs_extent_item *ei; + u32 blocksize = root->sectorsize; + u64 nbytes; +- u64 bytes_used; + + if (disk_bytenr == 0) { + ret = btrfs_insert_file_extent(trans, root, objectid, +@@ -432,9 +431,6 @@ static int record_file_extent(struct btrfs_trans_handle *trans, + nbytes = btrfs_stack_inode_nbytes(inode) + num_bytes; + btrfs_set_stack_inode_nbytes(inode, nbytes); + +- bytes_used = btrfs_root_used(&root->root_item); +- btrfs_set_root_used(&root->root_item, bytes_used + num_bytes); +- + btrfs_release_path(root, &path); + + ins_key.objectid = disk_bytenr; +@@ -454,9 +450,6 @@ static int record_file_extent(struct btrfs_trans_handle *trans, + + btrfs_mark_buffer_dirty(leaf); + +- bytes_used = btrfs_super_bytes_used(&info->super_copy); +- btrfs_set_super_bytes_used(&info->super_copy, bytes_used + +- num_bytes); + ret = btrfs_update_block_group(trans, root, disk_bytenr, + num_bytes, 1, 0); + if (ret) +-- +1.6.6.1 --- btrfs-tools-0.19.orig/debian/source/format +++ btrfs-tools-0.19/debian/source/format @@ -0,0 +1 @@ +1.0