From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: mkfs/rootdir: Don't follow symbolic link when calcuating size
Date: Wed, 28 Mar 2018 14:39:09 +0800 [thread overview]
Message-ID: <20180328063909.937-1-wqu@suse.com> (raw)
[BUG]
If we have a symbolic link in rootdir pointing to non-existing location,
mkfs.btrfs --rootdir will just fail:
------
$ mkfs.btrfs -f --rootdir /tmp/rootdir/ /dev/data/btrfs
btrfs-progs v4.15.1
See http://btrfs.wiki.kernel.org for more information.
ERROR: ftw subdir walk of /tmp/rootdir/ failed: No such file or directory
------
[CAUSE]
Commit 599a0abed564 ("btrfs-progs: mkfs/rootdir: Use over-reserve method
to make size estimate easier") add extra ftw walk to estimate the
filesystem size.
Such default ftw walk will follow symbolic link and gives ENOENT error.
[FIX]
Use nftw() to specify FTW_PHYS so we won't follow symbolic link for size
calculation.
Reported-by: Alexander Kanavin <alexander.kanavin@intel.com>
Fixes: 599a0abed564 ("btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/rootdir.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
index a1d223a2408a..33c3ff1e18cf 100644
--- a/mkfs/rootdir.c
+++ b/mkfs/rootdir.c
@@ -696,7 +696,7 @@ out:
}
static int ftw_add_entry_size(const char *fpath, const struct stat *st,
- int type)
+ int type, struct FTW *ftwbuf)
{
/*
* Failed to read the directory, mostly due to EPERM. Abort ASAP, so
@@ -731,7 +731,12 @@ u64 btrfs_mkfs_size_dir(const char *dir_name, u32 sectorsize, u64 min_dev_size,
fs_block_size = sectorsize;
ftw_data_size = 0;
ftw_meta_nr_inode = 0;
- ret = ftw(dir_name, ftw_add_entry_size, 10);
+
+ /*
+ * Symbolic link is not followed when creating files, so no need to
+ * follow them here.
+ */
+ ret = nftw(dir_name, ftw_add_entry_size, 10, FTW_PHYS);
if (ret < 0) {
error("ftw subdir walk of %s failed: %s", dir_name,
strerror(errno));
--
2.16.2
next reply other threads:[~2018-03-28 6:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-28 6:39 Qu Wenruo [this message]
2018-03-28 14:55 ` [PATCH] btrfs-progs: mkfs/rootdir: Don't follow symbolic link when calcuating size David Sterba
2018-03-29 1:09 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180328063909.937-1-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox