History

made ream functions to set up the fs. imported upanic and shit from ftrace

Matthew Veety committed 10 years ago

Commit ac689a91 parent 91e59f65 files · +143 −2Browse files

Unified · Split

5 files
  1. blockalloc.h +6 −1
  2. disk.c +0 −1
  3. instru.c +36 −0
  4. mkfile +2 −0
  5. ream.c +99 −0
blockalloc.h+6−1
@@ -15,7 +15,6 @@ typedef struct Blockptr Blockptr; · 14 unmodified lines
15typedef struct BlockptrODF BlockptrODF;15typedef struct BlockptrODF BlockptrODF;
16typedef struct Metablock Metablock;16typedef struct Metablock Metablock;
17typedef struct Disk Disk;17typedef struct Disk Disk;
18typedef struct Arena Arena;
19typedef struct Fn Fn;18typedef struct Fn Fn;
20 19
21struct Fn {20struct Fn {
@@ -81,6 +80,8 @@ int disksyncer(Disk*); · 59 unmodified lines
81void enableinstru(void);80void enableinstru(void);
82Fn* infn(char*);81Fn* infn(char*);
83void action(Fn*,char*);82void action(Fn*,char*);
83void shit(Fn*,char*);
84void upanic(Fn*,char*);
84void outfn(Fn*);85void outfn(Fn*);
85void iqlock(Fn*,QLock*);86void iqlock(Fn*,QLock*);
86void iqunlock(Fn*,QLock*);87void iqunlock(Fn*,QLock*);
@@ -89,3 +90,7 @@ void iqunlock(Fn*,QLock*); · 2 unmodified lines
89// device, buffer, length, offset90// device, buffer, length, offset
90u64int dread(Disk*,void*,u64int,u64int);91u64int dread(Disk*,void*,u64int,u64int);
91u64int dwrite(Disk*,void*,u64int,u64int);92u64int dwrite(Disk*,void*,u64int,u64int);
93
94/* ream.c */
95int ream(int,u64int);
96int ream1(int,u64int,u64int,u64int,u64int);
disk.c+0−1
@@ -129,4 +129,3 @@ fd2disk(int fd, Disk* d, uchar opts) · 128 unmodified lines
129 outfn(f);129 outfn(f);
130 return 0;130 return 0;
131}131}
132
instru.c+36−0
@@ -11,6 +11,12 @@ does the same thing. · 10 unmodified lines
11 11
12int enable_instru = 0;12int enable_instru = 0;
13 13
14/*
15if using ftrace, run this *very* first. infn calls started before
16this will not start logging until the next time the function gets
17called.
18*/
19
14void20void
15initinstru(void)21initinstru(void)
16{22{
@@ -44,6 +50,36 @@ action(Fn* f, char* c) · 27 unmodified lines
44 }50 }
45}51}
46 52
53void
54shit(Fn* f, char *c)
55{
56 if(f == nil || enable_instru == 0){
57 return;
58 } else if (f->active == 1 && !canqlock(&f->l)){
59 fprint(2,"instru: error: %s: %s (explicit)\n",f->name,c);
60 } else if (canqlock(&f->l)) {
61 fprint(2,"instru: error: action %s done outside of function (automatic)\n",c);
62 }
63}
64
65void
66upanic(Fn* f, char *c)
67{
68 char *msg;
69 if(f == nil || enable_instru == 0)
70 return;
71 msg = smprint("instru: PANIC: %s: %s [pid %d]",f->name,c,getpid());
72 if (f->active == 1 && !canqlock(&f->l)){
73 fprint(2,"%s\n",msg);
74 exits(msg);
75 return;
76 } else {
77 fprint(2,"%s (panic outside function calling)\n",msg);
78 exits(smprint("%s (panic outside function calling)",msg));
79 return;
80 }
81}
82
47void83void
48outfn(Fn* f)84outfn(Fn* f)
49{85{
mkfile+2−0
@@ -7,12 +7,14 @@ OFILES=\ · 6 unmodified lines
7 pointers.$O \7 pointers.$O \
8 instru.$O \8 instru.$O \
9 io.$O \9 io.$O \
10 ream.$O \
10 11
11CFILES=\12CFILES=\
12 disk.c \13 disk.c \
13 pointers.c \14 pointers.c \
14 instru.c \15 instru.c \
15 io.c \16 io.c \
17 ream.c \
16 18
17HFILES=\19HFILES=\
18 blockalloc.h \20 blockalloc.h \
ream.c+99−0
@@ -0,0 +1,99 @@
1#include <u.h>
2#include <libc.h>
3#include <blockalloc.h>
4
5int
6ream(int fd, u64int blocksize)
7{
8 Fn *f = infn("ream");
9 u64int disksize = seek(fd,0,2); seek(fd,0,0);
10 u64int ptrmapstart = blocksize*2;
11 u64int bmapsize = (blocksize*(disksize-blocksize))/(sizeof(BlockptrODF)+blocksize);
12 u64int ptrmaplen = (bmapsize/blocksize)*sizeof(BlockptrODF);
13 u64int bmapstart = ptrmaplen+sizeof(BlockptrODF);
14 u64int totalblocks = bmapsize/blocksize;
15 int retval = ream1(fd,blocksize,ptrmapstart,bmapstart,totalblocks);
16 action(f,smprint("retval = %d",retval));
17 if(retval == 0){
18 action(f,smprint("disksize = %d bytes",disksize));
19 action(f,smprint("ptrmapstart = %x",ptrmapstart));
20 action(f,smprint("ptrmaplen = %d bytes",ptrmaplen));
21 action(f,smprint("bmapstart = %x",bmapstart));
22 action(f,smprint("bmapsize = %d bytes",bmapsize));
23 action(f,smprint("totalblocks = %d of %d byte blocks",totalblocks,blocksize));
24 } else {
25 switch(retval){
26 case -1:
27 shit(f,"non-fatal error reaming. (code 1)");
28 break;
29 default:
30 shit(f,smprint("fatal error reaming."));
31 char *err = mallocz(1024*sizeof(char),0);
32 errstr(err,1024);
33 upanic(f,smprint("retval = %d, errstr = %s",retval,err));
34 break;
35 }
36 }
37 outfn(f);
38 return retval;
39}
40
41int
42ream1(int fd, u64int blocksize, u64int ptrmapstart, u64int bmapstart, u64int totalblocks)
43{
44 Fn *f = infn("ream1");
45 Metablock *m = mallocz(sizeof(Metablock),0);
46 BlockptrODF *blocks;
47 if(m == nil){
48 shit(f,"malloc failed");
49 outfn(f);
50 return -2;
51 }
52 m->blocksize = blocksize;
53 m->ptrmapstart = ptrmapstart;
54 m->totalblocks = totalblocks;
55 m->bitmapstart = bmapstart;
56 // sanity checking
57 if(((bmapstart-ptrmapstart)/sizeof(BlockptrODF)) >= totalblocks){
58 shit(f,smprint("ptrmap not large enough (failed: %x >= %x)",
59 ((bmapstart-ptrmapstart)/sizeof(BlockptrODF)),
60 totalblocks));
61 outfn(f);
62 return -3;
63 } else if (blocksize <= sizeof(BlockptrODF)){
64 shit(f,smprint("blocksize too small (blockptr)"));
65 outfn(f);
66 return -4;
67 } else if (blocksize <= sizeof(Metablock)){
68 shit(f,smprint("blocksize too small (metablock)"));
69 outfn(f);
70 return -5;
71 }
72 u64int written = pwriten(fd,m,0,sizeof(Metablock));
73 if(written < sizeof(Metablock)){
74 shit(f,smprint("whole metablock not written"));
75 outfn(f);
76 return -6;
77 }
78 blocks = mallocz(totalblocks*sizeof(BlockptrODF),0);
79 if(blocks == nil){
80 upanic(f,"malloc");
81 outfn(f);
82 return -7;
83 }
84 action(f,"formatting blocks");
85 for(u64int i = 0; i<totalblocks; i++){
86 blocks[i].used = 0;
87 blocks[i].offset = blocksize*i;
88 }
89 written = pwriten(fd,blocks,ptrmapstart,sizeof(BlockptrODF)*totalblocks);
90 if(written < (sizeof(BlockptrODF)*totalblocks)){
91 shit(f,"all blocksptrs not written");
92 outfn(f);
93 return -8;
94 }
95 action(f,"ream done. cleaning up");
96 free(m);
97 free(blocks);
98 return 0;
99}