From patchwork Thu Oct 25 16:12:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rock Lee X-Patchwork-Id: 1645551 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 0FF52DFB7E for ; Thu, 25 Oct 2012 16:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935761Ab2JYQNM (ORCPT ); Thu, 25 Oct 2012 12:13:12 -0400 Received: from m53-178.qiye.163.com ([123.58.178.53]:51503 "EHLO m53-178.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759996Ab2JYQNK (ORCPT ); Thu, 25 Oct 2012 12:13:10 -0400 Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by m53-178.qiye.163.com (HMail) with ESMTPA id DF58312281FB for ; Fri, 26 Oct 2012 00:13:06 +0800 (CST) Received: by mail-wi0-f172.google.com with SMTP id hq12so6161352wib.1 for ; Thu, 25 Oct 2012 09:13:04 -0700 (PDT) Received: by 10.180.86.65 with SMTP id n1mr14985411wiz.0.1351181584450; Thu, 25 Oct 2012 09:13:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.236.78 with HTTP; Thu, 25 Oct 2012 09:12:24 -0700 (PDT) From: Rock Lee Date: Fri, 26 Oct 2012 00:12:24 +0800 Message-ID: Subject: [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file To: linux-btrfs@vger.kernel.org X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQUpVQ0lCQkJCQklITEtNS05PTFdZCQ4XHghZQVkoKz0kKzooKCQyNSQz Pjo*PilBS1VLQDYjJCI#KCQyNSQzPjo*PilBS1VLQCsvKSQiPigkMjUkMz46Pz4pQUtVS0A*IjU6 NjI4JDIrJDU0JDI1JDM#Oj8#KUFLVUtAMiskSiQ2MjUuLz4kODUvJEskSktBS1VLQDIrJEhLJDYy NS4vPiQ4NS8kSyROS0FLVUtAMiskTiQ2MjUuLz4kODUvJEskSktBS1VLQDIrJC80PzoiJDg1LyRL JEpLS0FLVUtAMiskSiQzNC4pJDg1LyRLJEpLS0FLVUtAKC45JD5BSlVOTkA9NSQoLjkkPjUsNCk* KCQzNzEkSktLSUtKQUtVSUNZBg++ X-HM-Sender-Digest: e1kSHx4VD1lBWUc6Ngg6Dzo6KDo4SUkUAR0xVksXPxAaCkhVSlVKSE5KSkNKTkNNTk1OVTMWGhIX VQESFhIXFDsYFB8eVg8JEhgQVRgUFkVZV1kMHhlZQR0aFwgeBg++ Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Fix Bug to corrupt the img file 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(+) if (block_count < 1024 * 1024 * 1024 && !(*mixed)) { 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;