#include #include #include "log.h" void mockblock(Log *l, u64int off) { int i; uchar block[LogBlockSize*2]; u64int *p; p = (u64int*)block; for(i = 0; i < sizeof block / sizeof *p; i++) p[i] = off; if(logwrite(l, off, block, sizeof block) != sizeof block) sysfatal("logwrite: %r"); } void initlog(char *path) { int i, fd; char buf[LogBlockSize]; Log log, *logp; fd = create(path, ORDWR, 0600); if(fd < 0) sysfatal("create: %r"); memset(buf, 0, sizeof buf); for(i = 0; i < 10; i++){ write(fd, buf, sizeof buf); } log.fd = fd; log.super.magic = LogMagic; log.super.start = 1; log.super.end = 1; if(logwritesuper(&log) < 0) sysfatal("logwritesuper: %r"); close(fd); } void main(int argc, char *argv[]) { char *logname; Log *log; ARGBEGIN{ }ARGEND logname = "/tmp/log"; initlog(logname); log = logopen(logname); if(log == nil) sysfatal("openlog: %r"); mockblock(log, 2); mockblock(log, 4); mockblock(log, 6); exits(nil); }