|
|
1.1 root 1: #include <libc.h>
2: #include <fio.h>
3: #include "worm.h"
4:
5: int bad = 0;
6: long nbytes;
7: long blkdone;
8: long nfiles;
9: char *argout;
10:
11: static Inode *inodes;
12: static long ip;
13: static long ninodes = 0;
14: static char *nameb;
15: static long np;
16: static long nnameb = 0;
17: static long nblocks;
18: #define IINC 1024
19: #define NINC (64*IINC)
20:
21: ininit()
22: {
23: if(nnameb == 0){
24: nameb = malloc((unsigned)(nnameb = NINC));
25: if(nameb == 0){
26: fprint(2, "wwrite: malloc fail, %d bytes\n", nnameb);
27: exit(1);
28: }
29: }
30: np = 0;
31: if(ninodes == 0){
32: inodes = (Inode *)malloc(sizeof(Inode)*(unsigned)(ninodes = IINC));
33: if(inodes == 0){
34: fprint(2, "wwrite: malloc fail, %d inodes %d bytes\n", ninodes, ninodes*sizeof(Inode));
35: exit(1);
36: }
37: }
38: ip = 0;
39: nblocks = 0;
40: }
41:
42: inadd(s, i)
43: Superblock *s;
44: register Inode *i;
45: {
46: register long len;
47:
48: len = strlen(i->name.n)+1;
49: if(np+len > nnameb){
50: while(np+len > nnameb)
51: nnameb += NINC;
52: nameb = realloc(nameb, (unsigned)nnameb);
53: if(nameb == 0){
54: fprint(2, "wwrite: realloc fail, %d bytes\n", nnameb);
55: exit(1);
56: }
57: }
58: strcpy(nameb+np, i->name.n);
59: i->name.o = np;
60: np += len;
61: i->block = s->nextffree + nblocks;
62: if(ip == ninodes){
63: ninodes += IINC;
64: inodes = (Inode *)realloc((char *)inodes, (unsigned)ninodes*sizeof(Inode));
65: if(inodes == 0){
66: fprint(2, "wwrite: realloc fail, %d inodes %d bytes\n", ninodes, ninodes*sizeof(Inode));
67: exit(1);
68: }
69: }
70: inodes[ip++] = *i;
71: nblocks += (i->nbytes+s->blocksize-1)/s->blocksize;
72: return(0);
73: }
74:
75: inwrite(s, arg)
76: Superblock *s;
77: void *arg;
78: {
79: int i, j;
80: long next = s->nextffree;
81: char *e;
82:
83: if(e = lkwri(s, inodes, ip, nameb, np, nblocks)){
84: fprint(2, "%s\n", e);
85: bad = 1;
86: return;
87: }
88: Seek(s, next);
89: argout[2] = ' ';
90: for(i = 0; i < ip; i++){
91: inodes[i].block = next;
92: inodes[i].name.n = inodes[i].name.o + nameb;
93: writeout(s, &inodes[i], &next, arg);
94: j = (blkdone*100)/nblocks;
95: argout[0] = j/10+'0';
96: argout[1] = j%10+'0';
97: }
98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.