[file_utils] Use aligned memory in zero_superblock

This commit is contained in:
Joe Thornber 2018-04-17 11:42:43 +01:00
parent abb32897e2
commit 58048dc178

View File

@ -144,10 +144,14 @@ file_utils::get_file_length(string const &file) {
void
file_utils::zero_superblock(std::string const &path)
{
char *buffer;
unsigned const SUPERBLOCK_SIZE = 4096;
char buffer[SUPERBLOCK_SIZE];
int fd = open_block_file(path, SUPERBLOCK_SIZE, true, true);
buffer = reinterpret_cast<char *>(aligned_alloc(SUPERBLOCK_SIZE, SUPERBLOCK_SIZE));
if (!buffer)
throw runtime_error("out of memory");
memset(buffer, 0, SUPERBLOCK_SIZE);
if (::write(fd, buffer, SUPERBLOCK_SIZE) != SUPERBLOCK_SIZE)
throw runtime_error("couldn't zero superblock");