Unified · Split
| @@ -92,5 +92,5 @@ u64int dread(Disk*,void*,u64int,u64int); · 91 unmodified lines | |||
| 92 | u64int dwrite(Disk*,void*,u64int,u64int); | 92 | u64int dwrite(Disk*,void*,u64int,u64int); |
| 93 | 93 | ||
| 94 | /* ream.c */ | 94 | /* ream.c */ |
| 95 | int ream(int,u64int); | 95 | int ream(int,u64int,int); |
| 96 | int ream1(int,u64int,u64int,u64int,u64int); | 96 | int ream1(int,u64int,u64int,u64int,u64int,int); |
| @@ -89,10 +89,10 @@ closedisk(Disk* d) · 88 unmodified lines | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | int | 91 | int |
| 92 | fd2disk(int fd, Disk* d, uchar opts) | 92 | fd2disk(int fd, Disk *bf, uchar opts) |
| 93 | { | 93 | { |
| 94 | Fn *f = infn("fd2disk"); | 94 | Fn *f = infn("fd2disk"); |
| 95 | Disk *bf = malloc(sizeof(Disk)); | 95 | bf = malloc(sizeof(Disk)); |
| 96 | Metablock *m = malloc(sizeof(Metablock)); | 96 | Metablock *m = malloc(sizeof(Metablock)); |
| 97 | bf->fd = fd; | 97 | bf->fd = fd; |
| 98 | bf->size = (u64int)seek(bf->fd,0,2); | 98 | bf->size = (u64int)seek(bf->fd,0,2); |
| @@ -112,20 +112,17 @@ fd2disk(int fd, Disk* d, uchar opts) · 13 unmodified lines | |||
| 112 | bf->blocks_cached = 1; | 112 | bf->blocks_cached = 1; |
| 113 | if(loadbptrs(bf) == 0){ | 113 | if(loadbptrs(bf) == 0){ |
| 114 | if(disksyncer(bf) == 0){ | 114 | if(disksyncer(bf) == 0){ |
| 115 | d = bf; | ||
| 116 | outfn(f); | 115 | outfn(f); |
| 117 | return 0; | 116 | return 0; |
| 118 | } | 117 | } |
| 119 | action(f,"syncer did not start (rfork error)"); | 118 | action(f,"syncer did not start (rfork error)"); |
| 120 | free(d->ptrs); | 119 | free(bf->ptrs); |
| 121 | bf->blocks_cached = 0; | 120 | bf->blocks_cached = 0; |
| 122 | d = bf; | ||
| 123 | outfn(f); | 121 | outfn(f); |
| 124 | return -3; | 122 | return -3; |
| 125 | } | 123 | } |
| 126 | action(f,"failure to enable caching"); | 124 | action(f,"failure to enable caching"); |
| 127 | } | 125 | } |
| 128 | d = bf; | ||
| 129 | outfn(f); | 126 | outfn(f); |
| 130 | return 0; | 127 | return 0; |
| 131 | } | 128 | } |
| @@ -27,10 +27,12 @@ UPDATE=\ · 26 unmodified lines | |||
| 27 | 27 | ||
| 28 | CLEANFILES=\ | 28 | CLEANFILES=\ |
| 29 | ftrace-test \ | 29 | ftrace-test \ |
| 30 | ream-test \ | ||
| 30 | tests.log \ | 31 | tests.log \ |
| 31 | 32 | ||
| 32 | TESTS=\ | 33 | TESTS=\ |
| 33 | ftrace-test \ | 34 | ftrace-test \ |
| 35 | ream-test \ | ||
| 34 | 36 | ||
| 35 | all:V: $LIB | 37 | all:V: $LIB |
| 36 | 38 | ||
| @@ -38,12 +40,16 @@ ftrace-test: · 1 unmodified line | |||
| 38 | $CC tests/ftrace-test.c | 40 | $CC tests/ftrace-test.c |
| 39 | $LD -o ftrace-test ftrace-test.$O | 41 | $LD -o ftrace-test ftrace-test.$O |
| 40 | 42 | ||
| 43 | ream-test: | ||
| 44 | $CC tests/ream-test.c | ||
| 45 | $LD -o ream-test ream-test.$O | ||
| 46 | |||
| 41 | installheaders: | 47 | installheaders: |
| 42 | for(i in $HFILES){ | 48 | for(i in $HFILES){ |
| 43 | cp $i /sys/include | 49 | cp $i /sys/include |
| 44 | } | 50 | } |
| 45 | 51 | ||
| 46 | run-tests:EVQ: ftrace-test | 52 | run-tests:EVQ: ftrace-test ream-test |
| 47 | echo 'running tests...' | 53 | echo 'running tests...' |
| 48 | { | 54 | { |
| 49 | echo -n 'tests started at ' | 55 | echo -n 'tests started at ' |
| @@ -55,7 +61,7 @@ run-tests:EVQ: ftrace-test · 5 unmodified lines | |||
| 55 | echo '-----------------------------------------------------' | 61 | echo '-----------------------------------------------------' |
| 56 | } | 62 | } |
| 57 | echo 'tests done.' | 63 | echo 'tests done.' |
| 58 | } > tests.log | 64 | } > tests.log |
| 59 | 65 | ||
| 60 | </sys/src/cmd/mksyslib | 66 | </sys/src/cmd/mksyslib |
| 61 | 67 | ||
| @@ -3,7 +3,7 @@ · 2 unmodified lines | |||
| 3 | #include <blockalloc.h> | 3 | #include <blockalloc.h> |
| 4 | 4 | ||
| 5 | int | 5 | int |
| 6 | ream(int fd, u64int blocksize) | 6 | ream(int fd, u64int blocksize, int fmtblocks) |
| 7 | { | 7 | { |
| 8 | Fn *f = infn("ream"); | 8 | Fn *f = infn("ream"); |
| 9 | u64int disksize = seek(fd,0,2); seek(fd,0,0); | 9 | u64int disksize = seek(fd,0,2); seek(fd,0,0); |
| @@ -12,15 +12,15 @@ ream(int fd, u64int blocksize) · 2 unmodified lines | |||
| 12 | u64int ptrmaplen = (bmapsize/blocksize)*sizeof(BlockptrODF); | 12 | u64int ptrmaplen = (bmapsize/blocksize)*sizeof(BlockptrODF); |
| 13 | u64int bmapstart = ptrmaplen+sizeof(BlockptrODF); | 13 | u64int bmapstart = ptrmaplen+sizeof(BlockptrODF); |
| 14 | u64int totalblocks = bmapsize/blocksize; | 14 | u64int totalblocks = bmapsize/blocksize; |
| 15 | int retval = ream1(fd,blocksize,ptrmapstart,bmapstart,totalblocks); | 15 | int retval = ream1(fd,blocksize,ptrmapstart,bmapstart,totalblocks,fmtblocks); |
| 16 | action(f,smprint("retval = %d",retval)); | 16 | action(f,smprint("retval = %d",retval)); |
| 17 | if(retval == 0){ | 17 | if(retval == 0){ |
| 18 | action(f,smprint("disksize = %d bytes",disksize)); | 18 | action(f,smprint("disksize = %ulld bytes",disksize)); |
| 19 | action(f,smprint("ptrmapstart = %x",ptrmapstart)); | 19 | action(f,smprint("ptrmapstart = %ullx",ptrmapstart)); |
| 20 | action(f,smprint("ptrmaplen = %d bytes",ptrmaplen)); | 20 | action(f,smprint("ptrmaplen = %ulld bytes",ptrmaplen)); |
| 21 | action(f,smprint("bmapstart = %x",bmapstart)); | 21 | action(f,smprint("bmapstart = %ullx",bmapstart)); |
| 22 | action(f,smprint("bmapsize = %d bytes",bmapsize)); | 22 | action(f,smprint("bmapsize = %ulld bytes",bmapsize)); |
| 23 | action(f,smprint("totalblocks = %d of %d byte blocks",totalblocks,blocksize)); | 23 | action(f,smprint("totalblocks = %ulld of %ulld byte blocks",totalblocks,blocksize)); |
| 24 | } else { | 24 | } else { |
| 25 | switch(retval){ | 25 | switch(retval){ |
| 26 | case -1: | 26 | case -1: |
| @@ -39,10 +39,11 @@ ream(int fd, u64int blocksize) · 12 unmodified lines | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | int | 41 | int |
| 42 | ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int totalblocks) | 42 | ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int totalblocks, int fmtblocks) |
| 43 | { | 43 | { |
| 44 | Fn *f = infn("ream1"); | 44 | Fn *f = infn("ream1"); |
| 45 | Metablock *m = mallocz(sizeof(Metablock),0); | 45 | Metablock *m = mallocz(sizeof(Metablock),0); |
| 46 | Metablock *w = mallocz(sizeof(Metablock),0); | ||
| 46 | BlockptrODF *blocks; | 47 | BlockptrODF *blocks; |
| 47 | if(m == nil){ | 48 | if(m == nil){ |
| 48 | shit(f,"malloc failed"); | 49 | shit(f,"malloc failed"); |
| @@ -55,7 +56,7 @@ ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int tot · 6 unmodified lines | |||
| 55 | m->bitmapstart = bmapstart; | 56 | m->bitmapstart = bmapstart; |
| 56 | // sanity checking | 57 | // sanity checking |
| 57 | if(((bmapstart-ptrmapstart)/sizeof(BlockptrODF)) >= totalblocks){ | 58 | if(((bmapstart-ptrmapstart)/sizeof(BlockptrODF)) >= totalblocks){ |
| 58 | shit(f,smprint("ptrmap not large enough (failed: %x >= %x)", | 59 | shit(f,smprint("ptrmap not large enough (failed: %ullx >= %ullx)", |
| 59 | ((bmapstart-ptrmapstart)/sizeof(BlockptrODF)), | 60 | ((bmapstart-ptrmapstart)/sizeof(BlockptrODF)), |
| 60 | totalblocks)); | 61 | totalblocks)); |
| 61 | outfn(f); | 62 | outfn(f); |
| @@ -70,6 +71,8 @@ ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int tot · 8 unmodified lines | |||
| 70 | return -5; | 71 | return -5; |
| 71 | } | 72 | } |
| 72 | u64int written = pwriten(fd,m,0,sizeof(Metablock)); | 73 | u64int written = pwriten(fd,m,0,sizeof(Metablock)); |
| 74 | u64int readback = preadn(fd,w,0,sizeof(Metablock)); | ||
| 75 | action(f,smprint("readback = %ulld, blocksize = %ulld, ptrmapstart = %ulld, totalblocks = %ulld, bitmapstart = %ulld",readback, w->blocksize, w->ptrmapstart, w->totalblocks, w->bitmapstart)); | ||
| 73 | if(written < sizeof(Metablock)){ | 76 | if(written < sizeof(Metablock)){ |
| 74 | shit(f,smprint("whole metablock not written")); | 77 | shit(f,smprint("whole metablock not written")); |
| 75 | outfn(f); | 78 | outfn(f); |
| @@ -81,16 +84,18 @@ ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int tot · 5 unmodified lines | |||
| 81 | outfn(f); | 84 | outfn(f); |
| 82 | return -7; | 85 | return -7; |
| 83 | } | 86 | } |
| 84 | action(f,"formatting blocks"); | 87 | if(fmtblocks){ |
| 85 | for(u64int i = 0; i<totalblocks; i++){ | 88 | action(f,"formatting blocks"); |
| 86 | blocks[i].used = 0; | 89 | for(u64int i = 0; i<totalblocks; i++){ |
| 87 | blocks[i].offset = blocksize*i; | 90 | blocks[i].used = 0; |
| 88 | } | 91 | blocks[i].offset = blocksize*i; |
| 89 | written = pwriten(fd,blocks,ptrmapstart,sizeof(BlockptrODF)*totalblocks); | 92 | } |
| 90 | if(written < (sizeof(BlockptrODF)*totalblocks)){ | 93 | written = pwriten(fd,blocks,ptrmapstart,sizeof(BlockptrODF)*totalblocks); |
| 91 | shit(f,"all blocksptrs not written"); | 94 | if(written < (sizeof(BlockptrODF)*totalblocks)){ |
| 92 | outfn(f); | 95 | shit(f,"all blocksptrs not written"); |
| 93 | return -8; | 96 | outfn(f); |
| 97 | return -8; | ||
| 98 | } | ||
| 94 | } | 99 | } |
| 95 | action(f,"ream done. cleaning up"); | 100 | action(f,"ream done. cleaning up"); |
| 96 | free(m); | 101 | free(m); |
| @@ -0,0 +1,99 @@ | |||
| 1 | #include <u.h> | ||
| 2 | #include <libc.h> | ||
| 3 | #include <blockalloc.h> | ||
| 4 | |||
| 5 | #define LIKE50MB 52428800 | ||
| 6 | |||
| 7 | int createtestfile(void); | ||
| 8 | int sproc(char*,char*[]); | ||
| 9 | int crucify(int); | ||
| 10 | |||
| 11 | int disksimpid; | ||
| 12 | |||
| 13 | void | ||
| 14 | main(int argc, char *argv[]) | ||
| 15 | { | ||
| 16 | initinstru(); | ||
| 17 | Fn *f = infn("main"); | ||
| 18 | action(f,"creating virtual sd device sdTT"); | ||
| 19 | int fd = createtestfile(); | ||
| 20 | if(fd<0){ | ||
| 21 | // crucify(disksimpid); | ||
| 22 | upanic(f,smprint("unable to open device /dev/sdTT/data. errstr = %r")); | ||
| 23 | } | ||
| 24 | action(f,"reaming with blocksize 1024"); | ||
| 25 | int retval = ream(fd,1024,0); | ||
| 26 | if(retval == -2) | ||
| 27 | upanic(f,smprint("ream short read errstr = %r")); | ||
| 28 | action(f,smprint("ream retval = %d",retval)); | ||
| 29 | Disk *d; | ||
| 30 | action(f,smprint("d(ptr) = %p",d)); | ||
| 31 | retval = fd2disk(fd,d,0); | ||
| 32 | action(f,smprint("fd2disk retval = %d",retval)); | ||
| 33 | action(f,smprint("d(ptr) = %p",d)); | ||
| 34 | u64int blocksize = d->meta->blocksize; | ||
| 35 | u64int ptrmapstart = d->meta->ptrmapstart; | ||
| 36 | u64int totalblocks = d->meta->totalblocks; | ||
| 37 | u64int bitmapstart = d->meta->bitmapstart; | ||
| 38 | u64int dsize = d->size; | ||
| 39 | action(f,smprint("blocksize = %d",d->meta->blocksize)); | ||
| 40 | action(f,smprint("ptrmapstart = %d",d->meta->ptrmapstart)); | ||
| 41 | action(f,smprint("totalblocks = %d",d->meta->totalblocks)); | ||
| 42 | action(f,smprint("bitmapstart = %d",d->meta->bitmapstart)); | ||
| 43 | action(f,smprint("disk size = %d",d->size)); | ||
| 44 | close(fd); | ||
| 45 | crucify(disksimpid); | ||
| 46 | action(f,"done"); | ||
| 47 | outfn(f); | ||
| 48 | exits(nil); | ||
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | createtestfile(void) | ||
| 53 | { | ||
| 54 | Fn *f = infn("createtestfile"); | ||
| 55 | action(f,"running disksim"); | ||
| 56 | // char *dsargs[] = { "aux/disksim","sdTT",0 }; | ||
| 57 | // disksimpid = sproc("/bin/aux/disksim",dsargs); | ||
| 58 | // sleep(2); | ||
| 59 | // int fd = open("/dev/sdTT/ctl",OWRITE|OREAD); | ||
| 60 | // if(fd<0) | ||
| 61 | // upanic(f,"could not open /dev/sdTT/ctl"); | ||
| 62 | // fprint(fd,"geometry %d 512 0 0 0",LIKE50MB*2); | ||
| 63 | // close(fd); | ||
| 64 | outfn(f); | ||
| 65 | return open("/n/ram/testdisk.img",OWRITE|OREAD); | ||
| 66 | } | ||
| 67 | |||
| 68 | int | ||
| 69 | sproc(char *execf, char *args[]) | ||
| 70 | { | ||
| 71 | Fn *f = infn("sproc"); | ||
| 72 | int pid; | ||
| 73 | if((pid = fork()) == 0){ | ||
| 74 | Fn *f2 = infn(smprint("sproc [pid %d]",getpid())); | ||
| 75 | action(f2,smprint("calling %s",execf)); | ||
| 76 | int x = exec(execf,args); | ||
| 77 | char *s = malloc(sizeof(char)*1024); | ||
| 78 | if(s == nil) | ||
| 79 | upanic(f2,"unable to malloc"); | ||
| 80 | errstr(s,1024); | ||
| 81 | upanic(f2,smprint("unable to exec. retval = %d, errstr = %s",x,s)); | ||
| 82 | } | ||
| 83 | outfn(f); | ||
| 84 | return pid; | ||
| 85 | } | ||
| 86 | |||
| 87 | int | ||
| 88 | crucify(int pid) | ||
| 89 | { | ||
| 90 | Fn *f = infn("crucify"); | ||
| 91 | int fd = open(smprint("/proc/%d/ctl"),OWRITE); | ||
| 92 | if(fd<0) | ||
| 93 | return -1; | ||
| 94 | fprint(fd,"kill\n"); | ||
| 95 | close(fd); | ||
| 96 | action(f,smprint("the process %d met his destiny.",pid)); | ||
| 97 | outfn(f); | ||
| 98 | return 0; | ||
| 99 | } | ||