From f8c6759f29db7b78ed3bc042ced53aa6bcdcb4aa Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 18 Jun 2018 17:56:22 +0200 Subject: [PATCH] btrfs-progs: btrfstune: prepare for enhanced mount check We'll want to pass non-default superblock flags so let's use the other helper that allows that. We can reuse the filesystem handle so it needs to open it read-write, unlike what the plain check_mounted does. Signed-off-by: David Sterba --- btrfstune.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/btrfstune.c b/btrfstune.c index eccedf79..889b931c 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -394,6 +394,7 @@ int main(int argc, char *argv[]) char *new_fsid_str = NULL; int ret; u64 super_flags = 0; + int fd = -1; while(1) { static const struct option long_options[] = { @@ -467,17 +468,25 @@ int main(int argc, char *argv[]) } } - ret = check_mounted(device); - if (ret < 0) { - error("could not check mount status of %s: %s", device, - strerror(-ret)); - return 1; - } else if (ret) { - error("%s is mounted", device); + fd = open(device, O_RDWR); + if (fd < 0) { + error("mount check: cannot open %s: %m", device); return 1; } - root = open_ctree(device, 0, ctree_flags); + ret = check_mounted_where(fd, device, NULL, 0, NULL, SBREAD_DEFAULT); + if (ret < 0) { + error("could not check mount status of %s: %s", device, + strerror(-ret)); + close(fd); + return 1; + } else if (ret) { + error("%s is mounted", device); + close(fd); + return 1; + } + + root = open_ctree_fd(fd, device, 0, ctree_flags); if (!root) { error("open ctree failed");