From patchwork Mon May 30 21:19:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 830932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4ULJrmR003885 for ; Mon, 30 May 2011 21:19:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754065Ab1E3VTu (ORCPT ); Mon, 30 May 2011 17:19:50 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:54900 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753986Ab1E3VTu (ORCPT ); Mon, 30 May 2011 17:19:50 -0400 Received: from gentoo.org (unknown [178.125.169.231]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id 1B3431B4010; Mon, 30 May 2011 21:19:47 +0000 (UTC) Received: by gentoo.org (sSMTP sendmail emulation); Tue, 31 May 2011 00:19:43 +0300 From: Sergei Trofimovich To: Chris Mason Cc: linux-btrfs@vger.kernel.org, Sergei Trofimovich Subject: [PATCH 3/9] mkfs.btrfs: fail on scandir error (-r mode) Date: Tue, 31 May 2011 00:19:02 +0300 Message-Id: <1306790348-9553-4-git-send-email-slyfox@gentoo.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1306790348-9553-1-git-send-email-slyfox@gentoo.org> References: <1306790348-9553-1-git-send-email-slyfox@gentoo.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 30 May 2011 21:19:53 +0000 (UTC) mkfs.btrfs does not handle relative pathnames for now. When they are passed to it it creates empty image. So first time I thought it does not work at all. This patch adds error handling for scandir(). With patch it behaves this way: $ mkfs.btrfs -r ./root ... fs created label (null) on output.img nodesize 4096 leafsize 4096 sectorsize 4096 size 256.00MB Btrfs v0.19-52-g438c5ff-dirty scandir for ./root failed: No such file or directory unable to traverse_directory Making image is aborted. mkfs.btrfs: mkfs.c:1402: main: Assertion `!(ret)' failed. Signed-off-by: Sergei Trofimovich --- mkfs.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/mkfs.c b/mkfs.c index 57c88f9..9d7b792 100644 --- a/mkfs.c +++ b/mkfs.c @@ -895,6 +895,12 @@ static int traverse_directory(struct btrfs_trans_handle *trans, count = scandir(parent_dir_entry->path, &files, directory_select, NULL); + if (count == -1) + { + fprintf(stderr, "scandir for %s failed: %s\n", + parent_dir_name, strerror (errno)); + goto fail; + } for (i = 0; i < count; i++) { cur_file = files[i];