blob: 511a268dba32196dfcaa05c9924421e094ca4b8e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
diff -upr btrfs-progs-v4.3.1.orig/utils.c btrfs-progs-v4.3.1/utils.c
--- btrfs-progs-v4.3.1.orig/utils.c 2015-11-20 01:15:32.227019383 +0100
+++ btrfs-progs-v4.3.1/utils.c 2015-11-20 01:16:59.419971215 +0100
@@ -679,13 +1208,19 @@ static int resolve_loop_device(const cha
{
int ret;
FILE *f;
+ struct stat stat_buf;
char fmt[20];
char p[PATH_MAX];
char real_loop_dev[PATH_MAX];
if (!realpath(loop_dev, real_loop_dev))
return -errno;
- snprintf(p, PATH_MAX, "/sys/block/%s/loop/backing_file", strrchr(real_loop_dev, '/'));
+
+ if (stat(real_loop_dev, &stat_buf) || !S_ISBLK(stat_buf.st_mode))
+ return -errno;
+
+ snprintf(p, PATH_MAX, "/sys/dev/block/%d:%d/loop/backing_file",
+ major(stat_buf.st_rdev), minor(stat_buf.st_rdev));
if (!(f = fopen(p, "r"))) {
if (errno == ENOENT)
/*
|