mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-11 03:31:17 +00:00
Correct un-initialized fsid variable
This commit is contained in:
parent
bc130ecd02
commit
6eba900295
20
disk-io.c
20
disk-io.c
@ -910,6 +910,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
|
|||||||
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
|
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
|
||||||
{
|
{
|
||||||
u8 fsid[BTRFS_FSID_SIZE];
|
u8 fsid[BTRFS_FSID_SIZE];
|
||||||
|
int fsid_is_initialized = 0;
|
||||||
struct btrfs_super_block buf;
|
struct btrfs_super_block buf;
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
@ -936,15 +937,26 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
|
|||||||
if (ret < sizeof(buf))
|
if (ret < sizeof(buf))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (btrfs_super_bytenr(&buf) != bytenr ||
|
if (btrfs_super_bytenr(&buf) != bytenr )
|
||||||
strncmp((char *)(&buf.magic), BTRFS_MAGIC,
|
continue;
|
||||||
|
/* if magic is NULL, the device was removed */
|
||||||
|
if (buf.magic == 0 && i == 0)
|
||||||
|
return -1;
|
||||||
|
if (strncmp((char *)(&buf.magic), BTRFS_MAGIC,
|
||||||
sizeof(buf.magic)))
|
sizeof(buf.magic)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (i == 0)
|
if (!fsid_is_initialized) {
|
||||||
memcpy(fsid, buf.fsid, sizeof(fsid));
|
memcpy(fsid, buf.fsid, sizeof(fsid));
|
||||||
else if (memcmp(fsid, buf.fsid, sizeof(fsid)))
|
fsid_is_initialized = 1;
|
||||||
|
} else if (memcmp(fsid, buf.fsid, sizeof(fsid))) {
|
||||||
|
/*
|
||||||
|
* the superblocks (the original one and
|
||||||
|
* its backups) contain data of different
|
||||||
|
* filesystems -> the super cannot be trusted
|
||||||
|
*/
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (btrfs_super_generation(&buf) > transid) {
|
if (btrfs_super_generation(&buf) > transid) {
|
||||||
memcpy(sb, &buf, sizeof(*sb));
|
memcpy(sb, &buf, sizeof(*sb));
|
||||||
|
Loading…
Reference in New Issue
Block a user