#include #include #include "block.h" enum { DEBUG = 1, }; #define dbg(fmt, ...) do{if(DEBUG)fprint(2, fmt, __VA_ARGS__);}while(0) long blockread(int fd, void *buf, long blocksize, long nblocks, vlong offset) { long i, r; char *p; dbg("blockread %d %ld %ld %lld\n", fd, blocksize, nblocks, offset); p = buf; for(i = 0; i < nblocks; i++){ r = pread(fd, p+(i*blocksize), blocksize, (offset+i)*blocksize); if(r != blocksize) return -1; } return i; } long blockwrite(int fd, void *buf, long blocksize, long nblocks, vlong offset) { long i, r; char *p; dbg("blockwrite %d %ld %ld %lld\n", fd, blocksize, nblocks, offset); p = buf; for(i = 0; i < nblocks; i++){ r = pwrite(fd, p+(i*blocksize), blocksize, (offset+i)*blocksize); if(r != blocksize) return -1; // XXX: artifically slow disk sleep(50); } return i; } int blocksync(int fd) { Dir d; nulldir(&d); return dirfwstat(fd, &d); }