ref: fb7898cf13af74d49c56e7f04273b82b281b0515
dir: /testextents.c/
#include <u.h> #include <libc.h> #include "extents.h" #include <bio.h> /* test the extents functionality { echo 2 3 ; echo 100 3; } | ./6.testextents */ int chatty9p = 0; static void usage(void) { fprint(2, "usage: testextents [-D ]\n"); exits("usage"); } void panic(char *fmt, ...) { char buf[8192], *s; va_list arg; s = buf; s += sprint(s, "%s %d: ", argv0, getpid()); va_start(arg, fmt); s = vseprint(s, buf + sizeof(buf) / sizeof(*buf), fmt, arg); va_end(arg); *s++ = '\n'; write(2, buf, s - buf); abort(); exits(buf); } static void * emalloc(u32 sz) { void *v; if((v = mallocz(sz, 1)) == nil) sysfatal("emalloc: %r"); setmalloctag(v, getcallerpc(&sz)); return v; } void main(int argc, char *argv[]) { Extents es; s8 *line, *p; Biobuf *bp; u64 bno, len; char act; ARGBEGIN{ default: usage(); case 'D': chatty9p=8; break; }ARGEND if(argc != 0) usage(); bp = Bfdopen(0, OREAD); Blethal(bp, nil); initextents(&es, "testextents", 1, 0, 1, nil, nil, panic, emalloc); while((line = Brdstr(bp, '\n', 1)) != nil) { act = line[0]; if(act == '-'){ len = strtoull(line+1, nil, 10); qalloc(&es, len); }else{ bno = strtoull(line, &p, 10); p++; /* for the space */ len = strtoull(p, nil, 10); qfree(&es, bno, len); } free(line); } showextentslists(1, "", &es); /* why bother? just exits(nil) as cinap suggests */ Bterm(bp); exits(nil); }