|
|
089650 |
From 6eba9002956ac40db87d42fb653a0524dc568810 Mon Sep 17 00:00:00 2001
|
|
|
089650 |
From: Goffredo Baroncelli <kreijack@inwind.it>
|
|
|
089650 |
Date: Tue, 4 Sep 2012 19:59:26 +0200
|
|
|
089650 |
Subject: [PATCH 1/1] Correct un-initialized fsid variable
|
|
|
089650 |
|
|
|
089650 |
---
|
|
|
089650 |
disk-io.c | 20 ++++++++++++++++----
|
|
|
089650 |
1 files changed, 16 insertions(+), 4 deletions(-)
|
|
|
089650 |
|
|
|
089650 |
diff --git a/disk-io.c b/disk-io.c
|
|
|
089650 |
index b21a87f..0395205 100644
|
|
|
089650 |
--- a/disk-io.c
|
|
|
089650 |
+++ b/disk-io.c
|
|
|
089650 |
@@ -910,6 +910,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
|
|
|
089650 |
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
|
|
|
089650 |
{
|
|
|
089650 |
u8 fsid[BTRFS_FSID_SIZE];
|
|
|
089650 |
+ int fsid_is_initialized = 0;
|
|
|
089650 |
struct btrfs_super_block buf;
|
|
|
089650 |
int i;
|
|
|
089650 |
int ret;
|
|
|
089650 |
@@ -936,15 +937,26 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
|
|
|
089650 |
if (ret < sizeof(buf))
|
|
|
089650 |
break;
|
|
|
089650 |
|
|
|
089650 |
- if (btrfs_super_bytenr(&buf) != bytenr ||
|
|
|
089650 |
- strncmp((char *)(&buf.magic), BTRFS_MAGIC,
|
|
|
089650 |
+ if (btrfs_super_bytenr(&buf) != bytenr )
|
|
|
089650 |
+ continue;
|
|
|
089650 |
+ /* if magic is NULL, the device was removed */
|
|
|
089650 |
+ if (buf.magic == 0 && i == 0)
|
|
|
089650 |
+ return -1;
|
|
|
089650 |
+ if (strncmp((char *)(&buf.magic), BTRFS_MAGIC,
|
|
|
089650 |
sizeof(buf.magic)))
|
|
|
089650 |
continue;
|
|
|
089650 |
|
|
|
089650 |
- if (i == 0)
|
|
|
089650 |
+ if (!fsid_is_initialized) {
|
|
|
089650 |
memcpy(fsid, buf.fsid, sizeof(fsid));
|
|
|
089650 |
- else if (memcmp(fsid, buf.fsid, sizeof(fsid)))
|
|
|
089650 |
+ fsid_is_initialized = 1;
|
|
|
089650 |
+ } else if (memcmp(fsid, buf.fsid, sizeof(fsid))) {
|
|
|
089650 |
+ /*
|
|
|
089650 |
+ * the superblocks (the original one and
|
|
|
089650 |
+ * its backups) contain data of different
|
|
|
089650 |
+ * filesystems -> the super cannot be trusted
|
|
|
089650 |
+ */
|
|
|
089650 |
continue;
|
|
|
089650 |
+ }
|
|
|
089650 |
|
|
|
089650 |
if (btrfs_super_generation(&buf) > transid) {
|
|
|
089650 |
memcpy(sb, &buf, sizeof(*sb));
|
|
|
089650 |
--
|
|
|
089650 |
1.7.7.6
|
|
|
089650 |
|