--- fileio.c.orig Thu Dec 27 12:38:45 2001 +++ fileio.c Thu Dec 27 13:15:17 2001 @@ -46,14 +46,18 @@ } } +#define BLOCK_SIZE 4096 + void expand_file(int fd, int size) { - int s; - while (size) { - s = MIN(sizeof(buf), size); - write(fd, buf, s); - size -= s; + int i; + + for (i = 0; i < size; i += BLOCK_SIZE) { + lseek(fd, i, SEEK_SET); + write(fd, buf, 1); } + lseek(fd, size-1, SEEK_SET); + write(fd, buf, 1); } void nb_open(char *fname, int handle, int size) @@ -101,7 +105,7 @@ void nb_write(int handle, int size, int offset) { - int i; + int i, off; if (buf[0] == 0) memset(buf, 1, sizeof(buf)); @@ -115,15 +119,22 @@ #endif return; } - lseek(ftable[i].fd, offset, SEEK_SET); - if (write(ftable[i].fd, buf, size) != size) { + for (off = 0; off < size; off += BLOCK_SIZE) { + lseek(ftable[i].fd, offset + off, SEEK_SET); + if (write(ftable[i].fd, buf, 1) != 1) { + printf("write failed on handle %d\n", handle); + } + } + lseek(ftable[i].fd, offset + size-1, SEEK_SET); + if (write(ftable[i].fd, buf, 1) != 1) { printf("write failed on handle %d\n", handle); } } void nb_read(int handle, int size, int offset) { - int i; + int i, off; + for (i=0;i