]> git.saurik.com Git - apple/hfs.git/blobdiff - CopyHFSMeta/DeviceWrapper.c
hfs-226.1.1.tar.gz
[apple/hfs.git] / CopyHFSMeta / DeviceWrapper.c
index 54f62ec22c00c70af6ffaae9a1be0ebcd7e95192..e9bf6be2147d7438439aa579ce85c5fa7456d80b 100644 (file)
@@ -46,24 +46,37 @@ writeExtent(struct IOWrapper *context, DeviceInfo_t *devp, off_t start, off_t le
 {
        const size_t bufSize = 1024 * 1024;
        struct DeviceWrapperContext *ctx = (struct DeviceWrapperContext*)context->context;
-       uint8_t buffer[bufSize];
+       uint8_t *buffer = NULL;
+       ssize_t retval = 0;
        off_t total = 0;
 
        if (debug) printf("Writing extent <%lld, %lld> to device %s", start, len, ctx->pathname);
 
+       buffer = malloc(bufSize);
+       if (buffer == NULL) {
+               warn("%s(%s): Could not allocate %zu bytes for buffer", __FILE__, __FUNCTION__, bufSize);
+               retval = -1;
+               goto done;
+       }
+
        while (total < len) {
                ssize_t nread;
                size_t amt = MIN(bufSize, len - total);
+               // XXX - currently, DeviceWrapepr isn't used, but it needs to deal wit unaligned I/O when it is.
                nread = pread(devp->fd, buffer, amt, start + total);
                if (nread == -1) {
                        warn("Cannot read from device at offset %lld", start + total);
-                       return -1;
+                       retval = -1;
+                       goto done;
                }
                (void)pwrite(ctx->fd, (char*)buffer, nread, start + total);
                bp(nread);
                total += nread;
        }
-       return 0;
+done:
+       if (buffer)
+               free(buffer);
+       return retval;
 }
 
 /*