From patchwork Thu Oct 25 23:38:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rock Lee X-Patchwork-Id: 1648031 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 02F253FD4E for ; Thu, 25 Oct 2012 23:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751147Ab2JYXjc (ORCPT ); Thu, 25 Oct 2012 19:39:32 -0400 Received: from m59-178.qiye.163.com ([123.58.178.59]:33638 "EHLO m59-178.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750854Ab2JYXjc (ORCPT ); Thu, 25 Oct 2012 19:39:32 -0400 Received: from localhost.localdomain (unknown [221.223.99.110]) by m59-178.qiye.163.com (HMail) with ESMTPA id BD8DC81031D; Fri, 26 Oct 2012 07:39:29 +0800 (CST) From: zimilo@code-trick.com To: linux-btrfs@vger.kernel.org Cc: Rock Subject: [RESEND PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Date: Fri, 26 Oct 2012 07:38:57 +0800 Message-Id: <1351208337-3455-1-git-send-email-zimilo@code-trick.com> X-Mailer: git-send-email 1.7.9.5 X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQUpCVUNJQkJCQkJJSExLTUtOTldZCQ4XHghZQVkoKz0kLz42KyQ#KSk0 KSQyNSQzPjo*PilBS1VLQDYjJCI#KCQyNSQzPjo*PilBS1VLQCsvKSQ1NCQyNSQzPjo*PilBSVVL QDg0LjUvKSIkODVBS1VLQCk#PDI0NSQ6KDI6QUtVS0ArKTQtMjU4PiQ5PjIxMjU8QUtVS0A*IjU6 NjI4JDIrJCI#KCQyNSQzPjo*PilBSVVLQCk#OjckMiskMjUkKTk3JDI1JDM#Oj8#KUFKSVVLQDYu Ny8yJCk4Ky8kPzI9PT4pPjUvJDI1JDM#Oj8#KUFJVUtAMiskSiQ2MjUuLz4kODUvJEskSktBS1VL QDIrJEhLJDYyNS4vPiQ4NS8kSyROS0FLVUtAMiskLzQ*OiIkODUvJEskSktLQUtVS0AyKyROJDYy NS4vPiQ4NS8kSyRKS0FLVUtAMiskSiQzNC4pJDg1LyRLJEpLS0FLVUtAKC45JD5BSlVOTkA9NSQo LjkkPjUsNCk*KCQzNzEkSktLSUtKQUtVSUNZBg++ X-HM-Sender-Digest: e1kSHx4VD1lBWUc6MxA6MRw6ETo5CElRPj4uEwMOHzIKCzhVSlVKSE5KSUtDSE1CTE9PVTMWGhIX VQESFhIXFDsYFB8eVg8JEhgQVRgUFkVZV1kMHhlZQR0aFwgeBg++ Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Rock Reproduce steps: > dd if=/dev/zero of=btrfs-small.img bs=1M count=1 > ls -lh btrfs-small.img -rw-rw-r--. 1 rock rock 1.0M Oct 24 09:51 btrfs-small.img ^^^ > mkfs.btrfs btrfs-small.img -rw-rw-r--. 1 rock rock 2.0M Oct 24 09:53 btrfs-small.img ^^^ Here you can see the original img file's size goes larger to 2Mb. Signed-off-by: Rock Lee --- utils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils.c b/utils.c index 205e667..7ba746e 100644 --- a/utils.c +++ b/utils.c @@ -557,6 +557,12 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, } if (max_block_count) block_count = min(block_count, max_block_count); + + if (block_count < 2 * 1024 * 1024) { + fprintf(stderr, "size of %s is too small(less than 2Mb)\n", file); + exit(1); + } + zero_end = 1; if (block_count < 1024 * 1024 * 1024 && !(*mixed)) {