the wren device uses seek before performing read/write operation. as multiple threads could issue read/write in paralel, a race can happen. it may even cause filesystem corruption. removing the seek and replacing read/write with pread/pwrite also saves a syscall. Reference: /n/sources/patch/applied/cwfs-seek-race Date: Fri Aug 7 03:47:26 CES 2009 Signed-off-by: cinap_lenrek@gmx.de --- /sys/src/cmd/cwfs/wren.c Fri Aug 7 03:44:45 2009 +++ /sys/src/cmd/cwfs/wren.c Fri Aug 7 03:44:43 2009 @@ -91,8 +91,7 @@ if(b >= dr->max) { print("wrenread: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x040; - } else if (seek(d->wren.fd, (vlong)b*RBUFSIZE, 0) < 0 || - read(d->wren.fd, c, RBUFSIZE) != RBUFSIZE) { + } else if (pread(d->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { print("wrenread: error on %Z(%lld): %r\n", d, (Wideoff)b); cons.nwrenre++; r = 1; @@ -112,11 +111,11 @@ print("wrenwrite: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x040; - } else if (seek(d->wren.fd, (vlong)b*RBUFSIZE, 0) < 0 || - write(d->wren.fd, c, RBUFSIZE) != RBUFSIZE) { + } else if (pwrite(d->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { print("wrenwrite: error on %Z(%lld): %r\n", d, (Wideoff)b); cons.nwrenwe++; r = 1; } + return r; }