File 0162-btrfs-progs-fix-loop-device-mount-checks.patch of Package btrfsprogs.openSUSE_13.1_Update
From fa69bc83f210e7940adf1051709178e493f58002 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.cz>
Date: Thu, 27 Oct 2011 16:23:14 -0400
Subject: [PATCH 162/170] btrfs-progs: fix loop device mount checks
When creating a fs on a loop device, mkfs checks whether the same file
is not already mounted, but the backing file of another loop dev may not
exist and mkfs fails.
Signed-off-by: David Sterba <dsterba@suse.cz>
---
utils.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
Index: btrfs-progs-v0.20-rc1-598-g8116550e1662/utils.c
===================================================================
--- btrfs-progs-v0.20-rc1-598-g8116550e1662.orig/utils.c
+++ btrfs-progs-v0.20-rc1-598-g8116550e1662/utils.c
@@ -831,11 +831,11 @@ static int is_same_blk_file(const char*
char real_a[PATH_MAX];
char real_b[PATH_MAX];
- if(!realpath(a, real_a) ||
- !realpath(b, real_b))
- {
- return -errno;
- }
+ if(!realpath(a, real_a))
+ strcpy(real_a, a);
+
+ if (!realpath(b, real_b))
+ strcpy(real_b, b);
/* Identical path? */
if(strcmp(real_a, real_b) == 0)
@@ -876,8 +876,8 @@ static int is_same_loop_file(const char*
{
char res_a[PATH_MAX];
char res_b[PATH_MAX];
- const char* final_a;
- const char* final_b;
+ const char* final_a = NULL;
+ const char* final_b = NULL;
int ret;
/* Resolve a if it is a loop device */
@@ -886,10 +886,12 @@ static int is_same_loop_file(const char*
return 0;
return ret;
} else if (ret) {
- if ((ret = resolve_loop_device(a, res_a, sizeof(res_a))) < 0)
- return ret;
-
- final_a = res_a;
+ if ((ret = resolve_loop_device(a, res_a, sizeof(res_a))) < 0) {
+ if (errno != EPERM)
+ return ret;
+ }
+ else
+ final_a = res_a;
} else {
final_a = a;
}
@@ -900,10 +902,12 @@ static int is_same_loop_file(const char*
return 0;
return ret;
} else if (ret) {
- if((ret = resolve_loop_device(b, res_b, sizeof(res_b))) < 0)
- return ret;
-
- final_b = res_b;
+ if ((ret = resolve_loop_device(b, res_b, sizeof(res_b))) < 0) {
+ if (errno != EPERM)
+ return ret;
+ }
+ else
+ final_b = res_b;
} else {
final_b = b;
}