1 a0d146ed 2005-07-12 devnull #include "stdinc.h"
2 a0d146ed 2005-07-12 devnull #include "dat.h"
3 a0d146ed 2005-07-12 devnull #include "fns.h"
5 a0d146ed 2005-07-12 devnull static int verbose;
8 a0d146ed 2005-07-12 devnull usage(void)
10 a0d146ed 2005-07-12 devnull fprint(2, "usage: rdarena [-v] arenapart arena\n");
11 a0d146ed 2005-07-12 devnull threadexitsall(0);
14 a0d146ed 2005-07-12 devnull static void
15 a0d146ed 2005-07-12 devnull rdarena(Arena *arena)
17 a0d146ed 2005-07-12 devnull ZBlock *b;
18 a0d146ed 2005-07-12 devnull u64int a, e;
19 a0d146ed 2005-07-12 devnull u32int bs;
21 a0d146ed 2005-07-12 devnull fprint(2, "copying %s to standard output\n", arena->name);
22 a0d146ed 2005-07-12 devnull printarena(2, arena);
24 a0d146ed 2005-07-12 devnull bs = MaxIoSize;
25 a0d146ed 2005-07-12 devnull if(bs < arena->blocksize)
26 a0d146ed 2005-07-12 devnull bs = arena->blocksize;
28 a0d146ed 2005-07-12 devnull b = alloczblock(bs, 0, arena->blocksize);
29 a0d146ed 2005-07-12 devnull e = arena->base + arena->size + arena->blocksize;
30 a0d146ed 2005-07-12 devnull for(a = arena->base - arena->blocksize; a + arena->blocksize <= e; a += bs){
31 a0d146ed 2005-07-12 devnull if(a + bs > e)
32 a0d146ed 2005-07-12 devnull bs = arena->blocksize;
33 a0d146ed 2005-07-12 devnull if(readpart(arena->part, a, b->data, bs) < 0)
34 a0d146ed 2005-07-12 devnull fprint(2, "can't copy %s, read at %lld failed: %r\n", arena->name, a);
35 a0d146ed 2005-07-12 devnull if(write(1, b->data, bs) != bs)
36 a0d146ed 2005-07-12 devnull sysfatal("can't copy %s, write at %lld failed: %r", arena->name, a);
39 a0d146ed 2005-07-12 devnull freezblock(b);
43 a0d146ed 2005-07-12 devnull threadmain(int argc, char *argv[])
45 a0d146ed 2005-07-12 devnull ArenaPart *ap;
46 a0d146ed 2005-07-12 devnull Part *part;
47 a0d146ed 2005-07-12 devnull char *file, *aname;
50 a0d146ed 2005-07-12 devnull ventifmtinstall();
51 a0d146ed 2005-07-12 devnull statsinit();
53 a0d146ed 2005-07-12 devnull ARGBEGIN{
54 a0d146ed 2005-07-12 devnull case 'v':
55 a0d146ed 2005-07-12 devnull verbose++;
62 a0d146ed 2005-07-12 devnull readonly = 1;
64 a0d146ed 2005-07-12 devnull if(argc != 2)
67 a0d146ed 2005-07-12 devnull file = argv[0];
68 a0d146ed 2005-07-12 devnull aname = argv[1];
70 a0d146ed 2005-07-12 devnull part = initpart(file, OREAD|ODIRECT);
71 a0d146ed 2005-07-12 devnull if(part == nil)
72 a0d146ed 2005-07-12 devnull sysfatal("can't open partition %s: %r", file);
74 a0d146ed 2005-07-12 devnull ap = initarenapart(part);
75 a0d146ed 2005-07-12 devnull if(ap == nil)
76 a0d146ed 2005-07-12 devnull sysfatal("can't initialize arena partition in %s: %r", file);
78 a0d146ed 2005-07-12 devnull if(verbose)
79 a0d146ed 2005-07-12 devnull printarenapart(2, ap);
81 a0d146ed 2005-07-12 devnull initdcache(8 * MaxDiskBlock);
83 a0d146ed 2005-07-12 devnull for(i = 0; i < ap->narenas; i++){
84 a0d146ed 2005-07-12 devnull if(strcmp(ap->arenas[i]->name, aname) == 0){
85 a0d146ed 2005-07-12 devnull rdarena(ap->arenas[i]);
86 a0d146ed 2005-07-12 devnull threadexitsall(0);
90 a0d146ed 2005-07-12 devnull sysfatal("couldn't find arena %s\n", aname);