From patchwork Sat Jun 4 08:19:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 849172 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p548HEKb014486 for ; Sat, 4 Jun 2011 08:17:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754247Ab1FDIRH (ORCPT ); Sat, 4 Jun 2011 04:17:07 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:49461 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753932Ab1FDIRG (ORCPT ); Sat, 4 Jun 2011 04:17:06 -0400 Received: from gentoo.org (unknown [178.125.218.26]) (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 524A91BC011; Sat, 4 Jun 2011 08:17:04 +0000 (UTC) Received: by gentoo.org (sSMTP sendmail emulation); Sat, 04 Jun 2011 11:19:59 +0300 From: Sergei Trofimovich To: Chris Mason Cc: linux-btrfs@vger.kernel.org, Sergei Trofimovich Subject: [PATCH v2 3/9] mkfs.btrfs: fail on scandir error (-r mode) Date: Sat, 4 Jun 2011 11:19:18 +0300 Message-Id: <1307175564-25355-4-git-send-email-slyfox@gentoo.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1307175564-25355-1-git-send-email-slyfox@gentoo.org> References: <1307175564-25355-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 (demeter2.kernel.org [140.211.167.43]); Sat, 04 Jun 2011 08:17:14 +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 @@ -878,40 +878,46 @@ static int traverse_directory(struct btrfs_trans_handle *trans, btrfs_mark_buffer_dirty(leaf); btrfs_release_path(root, &path); do { parent_dir_entry = list_entry(dir_head->list.next, struct directory_name_entry, list); list_del(&parent_dir_entry->list); parent_inum = parent_dir_entry->inum; parent_dir_name = parent_dir_entry->dir_name; if (chdir(parent_dir_entry->path)) { fprintf(stderr, "chdir error for %s\n", parent_dir_name); goto fail; } 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]; if (lstat(cur_file->d_name, &st) == -1) { fprintf(stderr, "lstat failed for file %s\n", cur_file->d_name); goto fail; } cur_inum = ++highest_inum + BTRFS_FIRST_FREE_OBJECTID; ret = add_directory_items(trans, root, cur_inum, parent_inum, cur_file->d_name, &st, &dir_index_cnt); if (ret) { fprintf(stderr, "add_directory_items failed\n"); goto fail; }