From: David van Moolenbroek Date: Fri, 24 Jul 2015 20:54:27 +0000 (+0000) Subject: LOG: fix bugs in userland write handler X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=818c405ae139c2477c949f24c5ba13747095f5bb;p=minix.git LOG: fix bugs in userland write handler - report correct number of bytes written; - correctly return partial writes on failure; - do not overwrite result if there is a pending read. Change-Id: I92aeeaee1eccb47c2aa2b6666a2f560c3cb17f42 --- diff --git a/minix/drivers/system/log/log.c b/minix/drivers/system/log/log.c index caba7cf3d..ee4393a7b 100644 --- a/minix/drivers/system/log/log.c +++ b/minix/drivers/system/log/log.c @@ -126,7 +126,7 @@ subwrite(struct logdevice *log, size_t size, endpoint_t endpt, cp_grant_id_t grant, char *localbuf) { size_t count, offset; - int overflow, r; + int overflow, r, result; devminor_t minor; char *buf; message m; @@ -134,6 +134,7 @@ subwrite(struct logdevice *log, size_t size, endpoint_t endpt, /* With a sufficiently large input size, we might wrap around the ring buffer * multiple times. */ + result = 0; for (offset = 0; offset < size; offset += count) { count = size - offset; @@ -147,8 +148,11 @@ subwrite(struct logdevice *log, size_t size, endpoint_t endpt, } else { if((r=sys_safecopyfrom(endpt, grant, offset, - (vir_bytes)buf, count)) != OK) - break; /* do process partial write upon error */ + (vir_bytes)buf, count)) != OK) { + /* return any partial success upon error */ + result = (offset > 0) ? (int)offset : r; + break; + } } LOGINC(log->log_write, count); @@ -160,7 +164,7 @@ subwrite(struct logdevice *log, size_t size, endpoint_t endpt, LOGINC(log->log_read, overflow); } - r = offset; /* this will be the return value upon success */ + result += (int)count; } if (log->log_size > 0 && log->log_source != NONE) { @@ -185,7 +189,7 @@ subwrite(struct logdevice *log, size_t size, endpoint_t endpt, log->log_selected &= ~CDEV_OP_RD; } - return r; + return result; } /*===========================================================================*