diff options
author | David Sterba <dsterba@suse.com> | 2015-11-06 18:10:29 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-11-13 18:24:34 +0100 |
commit | 927747bc828fed5a1649e87b7d2b5cacdf00e6e5 (patch) | |
tree | 13d6beebd7da3fd11f0b3c3fb1e08b5b69f7a05c | |
parent | 89b40ab5bbd8f2aff8c0a595a4d25faade0016d9 (diff) |
btrfs-progs: use fixed size buffer in zero_output_file
Rewrite the loop so we don't need to allocate sectorsize and write in 4k
steps instead. We know that sectorsize is divisible by 4096.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | mkfs.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -1091,23 +1091,20 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize, static int zero_output_file(int out_fd, u64 size, u32 sectorsize) { - int len = sectorsize; - int loop_num = size / sectorsize; + int loop_num; u64 location = 0; - char *buf = malloc(len); + char buf[4096]; int ret = 0, i; ssize_t written; - if (!buf) - return -ENOMEM; - memset(buf, 0, len); + memset(buf, 0, 4096); + loop_num = size / 4096; for (i = 0; i < loop_num; i++) { - written = pwrite64(out_fd, buf, len, location); - if (written != len) + written = pwrite64(out_fd, buf, 4096, location); + if (written != 4096) ret = -EIO; - location += sectorsize; + location += 4096; } - free(buf); return ret; } |