summaryrefslogtreecommitdiffstats
path: root/src/server/uplink.c
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-28 18:56:14 +0200
committerSimon Rettberg2013-08-28 18:56:14 +0200
commitef7c84067a74d3bd8661cd803d93749e19adb390 (patch)
tree336d32c4516ff90523a159a8a4e5c04bf197e602 /src/server/uplink.c
parent[SERVER] Remove stupid 1MiB request expansion, this clearly needs to be done ... (diff)
downloaddnbd3-ef7c84067a74d3bd8661cd803d93749e19adb390.tar.gz
dnbd3-ef7c84067a74d3bd8661cd803d93749e19adb390.tar.xz
dnbd3-ef7c84067a74d3bd8661cd803d93749e19adb390.zip
[SERVER] Save CRC-32 to disk if successfully retreived from uplink server
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r--src/server/uplink.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/server/uplink.c b/src/server/uplink.c
index 111cda6..6c50837 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <inttypes.h>
#include <zlib.h>
+#include <fcntl.h>
static void* uplink_mainloop(void *data);
static void uplink_send_requests(dnbd3_connection_t *link, int newOnly);
@@ -535,7 +536,7 @@ static void uplink_addCrc32(dnbd3_connection_t *uplink)
size_t bytes = IMGSIZE_TO_HASHBLOCKS(image->filesize) * sizeof(uint32_t);
uint32_t masterCrc;
uint32_t *buffer = malloc( bytes );
- if ( !dnbd3_get_crc32( uplink->fd, &masterCrc, &buffer, &bytes ) || bytes == 0 ) {
+ if ( !dnbd3_get_crc32( uplink->fd, &masterCrc, buffer, &bytes ) || bytes == 0 ) {
free( buffer );
return;
}
@@ -548,4 +549,13 @@ static void uplink_addCrc32(dnbd3_connection_t *uplink)
}
uplink->image->masterCrc32 = masterCrc;
uplink->image->crc32 = buffer;
+ const size_t len = strlen( uplink->image->path ) + 30;
+ char path[len];
+ snprintf( path, len, "%s.crc", uplink->image->path );
+ const int fd = open( path, O_WRONLY | O_CREAT, 0640 );
+ if ( fd >= 0 ) {
+ write( fd, &masterCrc, sizeof(uint32_t) );
+ write( fd, buffer, bytes );
+ close( fd );
+ }
}