diff --git a/flexnbd.c b/flexnbd.c index 6286114..56c804c 100644 --- a/flexnbd.c +++ b/flexnbd.c @@ -92,6 +92,9 @@ void params_serve( out->bind_to.v4.sin_port = htobe16(out->bind_to.v4.sin_port); out->filename = s_file; + out->filename_incomplete = xmalloc(strlen(s_file)+11); + strcpy(out->filename_incomplete, s_file); + strcpy(out->filename_incomplete + strlen(s_file), ".INCOMPLETE"); } void params_readwrite( diff --git a/params.h b/params.h index 57df4f4..f0eb55b 100644 --- a/params.h +++ b/params.h @@ -38,11 +38,13 @@ struct mode_serve_params { int acl_entries; /** pointer to access control list entries*/ struct ip_and_mask (*acl)[0]; - /** file name to serve */ + /** (static) file name to serve */ char* filename; + /** file name of INCOMPLETE flag */ + char* filename_incomplete; /** TCP backlog for listen() */ int tcp_backlog; - /** file name of UNIX control socket (or NULL if none) */ + /** (static) file name of UNIX control socket (or NULL if none) */ char* control_socket_name; /** size of file */ off64_t size; diff --git a/readwrite.c b/readwrite.c index ff1631b..9e006eb 100644 --- a/readwrite.c +++ b/readwrite.c @@ -43,9 +43,9 @@ void read_reply(int fd, struct nbd_request *request, struct nbd_reply *reply) SERVER_ERROR_ON_FAILURE(readloop(fd, reply, sizeof(*reply)), "Couldn't read reply"); if (be32toh(reply->magic) != REPLY_MAGIC) - SERVER_ERROR("Reply magic incorrect (%p)", reply->magic); + SERVER_ERROR("Reply magic incorrect (%p)", be32toh(reply->magic)); if (be32toh(reply->error) != 0) - SERVER_ERROR("Server replied with error %d", reply->error); + SERVER_ERROR("Server replied with error %d", be32toh(reply->error)); if (strncmp(request->handle, reply->handle, 8) != 0) SERVER_ERROR("Did not reply with correct handle"); } diff --git a/serve.c b/serve.c index 17408f4..9d1cfb9 100644 --- a/serve.c +++ b/serve.c @@ -167,6 +167,12 @@ int client_serve_request(struct client_params* client) switch (be32toh(request.type)) { case REQUEST_READ: + if (access(client->serve->filename_incomplete, F_OK) == 0 ) { + debug("read request while data incomplete"); + reply.error = htobe32(10); + write(client->socket, &reply, sizeof(reply)); + return 0; + } case REQUEST_WRITE: /* check it's not out of range */ if (be64toh(request.from) < 0 ||