btrfs-progs: slightly enhance btrfs_format_csum()

- Change it void
  The old one always return csum_size.

- Use snprintf()

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2021-08-26 14:40:35 +08:00 committed by David Sterba
parent 991a598f53
commit 773afad3e6
3 changed files with 26 additions and 7 deletions

View File

@ -7959,6 +7959,23 @@ static int record_unaligned_extent_rec(struct extent_record *rec)
}
}
if (skip)
continue;
/*
* If we repaired something and restarted we could potentially
* try to add this unaligned record multiple times, so check
* before we add a new one.
*/
list_for_each_entry(urec, &dest_root->unaligned_extent_recs, list) {
if (urec->objectid == dest_root->objectid &&
urec->owner == dback->owner &&
urec->bytenr == rec->start) {
skip = true;
break;
}
}
if (skip)
continue;

View File

@ -385,18 +385,20 @@ enum btrfs_csum_type parse_csum_type(const char *s)
return 0;
}
int btrfs_format_csum(u16 csum_type, const u8 *data, char *output)
void btrfs_format_csum(u16 csum_type, const u8 *data, char *output)
{
int i;
int cur = 0;
const int csum_size = btrfs_csum_type_size(csum_type);
sprintf(output, "0x");
output[0] = '\0';
snprintf(output, BTRFS_CSUM_STRING_LEN, "0x");
cur += strlen("0x");
for (i = 0; i < csum_size; i++) {
output += 2;
sprintf(output, "%02x", data[i]);
snprintf(output + cur, BTRFS_CSUM_STRING_LEN - cur, "%02x",
data[i]);
cur += 2;
}
return csum_size;
}
int get_device_info(int fd, u64 devid,

View File

@ -46,7 +46,7 @@ enum btrfs_csum_type parse_csum_type(const char *s);
/* 2 for "0x", 2 for each byte, plus nul */
#define BTRFS_CSUM_STRING_LEN (2 + 2 * BTRFS_CSUM_SIZE + 1)
int btrfs_format_csum(u16 csum_type, const u8 *data, char *output);
void btrfs_format_csum(u16 csum_type, const u8 *data, char *output);
u64 parse_size_from_string(const char *s);
u64 parse_qgroupid(const char *p);
u64 arg_strtou64(const char *str);