aboutsummaryrefslogtreecommitdiffstats
path: root/disk-io.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-05-13 17:15:34 +0800
committerDavid Sterba <dsterba@suse.com>2015-10-21 14:27:23 +0200
commitf409cad534dced3b391b1091d05e005f5fcd0e1f (patch)
treeaa7c03f3a90b34dc0d40981b3917bf64928fd2ad /disk-io.c
parentf156ceb1b5e27e237d022083890f9d92f723a3b1 (diff)
downloadbtrfs-progs-f409cad534dced3b391b1091d05e005f5fcd0e1f.tar.gz
btrfs-progs-f409cad534dced3b391b1091d05e005f5fcd0e1f.tar.xz
btrfs-progs-f409cad534dced3b391b1091d05e005f5fcd0e1f.zip
btrfs-progs: Read the whole superblock instead of struct btrfs_super_block
Before the patch, btrfs-progs will only read sizeof(struct btrfs_super_block) and restore it into super_copy. This makes checksum check for superblock impossible. Change it to read the whole superblock. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/disk-io.c b/disk-io.c
index c3da18c..0f5e8ae 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1328,7 +1328,8 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
{
u8 fsid[BTRFS_FSID_SIZE];
int fsid_is_initialized = 0;
- struct btrfs_super_block buf;
+ char tmp[BTRFS_SUPER_INFO_SIZE];
+ struct btrfs_super_block *buf = (struct btrfs_super_block *)tmp;
int i;
int ret;
int max_super = super_recover ? BTRFS_SUPER_MIRROR_MAX : 1;
@@ -1336,15 +1337,15 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
u64 bytenr;
if (sb_bytenr != BTRFS_SUPER_INFO_OFFSET) {
- ret = pread64(fd, &buf, sizeof(buf), sb_bytenr);
- if (ret < sizeof(buf))
+ ret = pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, sb_bytenr);
+ if (ret < BTRFS_SUPER_INFO_SIZE)
return -1;
- if (btrfs_super_bytenr(&buf) != sb_bytenr ||
- btrfs_super_magic(&buf) != BTRFS_MAGIC)
+ if (btrfs_super_bytenr(buf) != sb_bytenr ||
+ btrfs_super_magic(buf) != BTRFS_MAGIC)
return -1;
- memcpy(sb, &buf, sizeof(*sb));
+ memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE);
return 0;
}
@@ -1357,22 +1358,22 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
for (i = 0; i < max_super; i++) {
bytenr = btrfs_sb_offset(i);
- ret = pread64(fd, &buf, sizeof(buf), bytenr);
- if (ret < sizeof(buf))
+ ret = pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr);
+ if (ret < BTRFS_SUPER_INFO_SIZE)
break;
- if (btrfs_super_bytenr(&buf) != bytenr )
+ if (btrfs_super_bytenr(buf) != bytenr )
continue;
/* if magic is NULL, the device was removed */
- if (btrfs_super_magic(&buf) == 0 && i == 0)
+ if (btrfs_super_magic(buf) == 0 && i == 0)
return -1;
- if (btrfs_super_magic(&buf) != BTRFS_MAGIC)
+ if (btrfs_super_magic(buf) != BTRFS_MAGIC)
continue;
if (!fsid_is_initialized) {
- memcpy(fsid, buf.fsid, sizeof(fsid));
+ memcpy(fsid, buf->fsid, sizeof(fsid));
fsid_is_initialized = 1;
- } else if (memcmp(fsid, buf.fsid, sizeof(fsid))) {
+ } else if (memcmp(fsid, buf->fsid, sizeof(fsid))) {
/*
* the superblocks (the original one and
* its backups) contain data of different
@@ -1381,9 +1382,9 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
continue;
}
- if (btrfs_super_generation(&buf) > transid) {
- memcpy(sb, &buf, sizeof(*sb));
- transid = btrfs_super_generation(&buf);
+ if (btrfs_super_generation(buf) > transid) {
+ memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE);
+ transid = btrfs_super_generation(buf);
}
}