Commit 45cf2151 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Use VFIL_allocate in vsm_zerofile

Here we insist the file is completely allocated
parent eb1ca9d7
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "flopen.h" #include "flopen.h"
#include "vapi/vsm_int.h" #include "vapi/vsm_int.h"
#include "vmb.h" #include "vmb.h"
#include "vfil.h"
#ifndef MAP_HASSEMAPHORE #ifndef MAP_HASSEMAPHORE
#define MAP_HASSEMAPHORE 0 /* XXX Linux */ #define MAP_HASSEMAPHORE 0 /* XXX Linux */
...@@ -147,8 +148,6 @@ static int ...@@ -147,8 +148,6 @@ static int
vsm_zerofile(const char *fn, ssize_t size) vsm_zerofile(const char *fn, ssize_t size)
{ {
int fd; int fd;
ssize_t i, u;
char buf[64*1024];
int flags; int flags;
fd = flopen(fn, O_RDWR | O_CREAT | O_EXCL | O_NONBLOCK, 0644); fd = flopen(fn, O_RDWR | O_CREAT | O_EXCL | O_NONBLOCK, 0644);
...@@ -161,18 +160,11 @@ vsm_zerofile(const char *fn, ssize_t size) ...@@ -161,18 +160,11 @@ vsm_zerofile(const char *fn, ssize_t size)
assert(flags != -1); assert(flags != -1);
flags &= ~O_NONBLOCK; flags &= ~O_NONBLOCK;
AZ(fcntl(fd, F_SETFL, flags)); AZ(fcntl(fd, F_SETFL, flags));
if (VFIL_allocate(fd, (off_t)size, 1)) {
memset(buf, 0, sizeof buf); fprintf(stderr, "File allocation error %s: %s\n",
for (u = 0; u < size; ) { fn, strerror(errno));
i = write(fd, buf, sizeof buf); return (-1);
if (i <= 0) {
fprintf(stderr, "Write error %s: %s\n",
fn, strerror(errno));
return (-1);
}
u += i;
} }
AZ(ftruncate(fd, (off_t)size));
return (fd); return (fd);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment