if (argc
> 1 && !strcmp(argv
[1], "-b"))
fprintf(stderr
, "usage: copyout [ -b ] inum disk\n");
if (open(argv
[2], 0) != 0) {
lseek(0, itod(atoi(argv
[1])) * BSIZE
+ itoo(atoi(argv
[1])) * sizeof (di
), 0);
if (read(0, &di
, sizeof (di
)) != sizeof (di
)) {
fprintf(stderr
, "error reading inode ");
i
.i_number
= atoi(argv
[1]);
l3tol(i
.i_un
.i_addr
, di
.di_addr
, NADDR
);
pte
= (struct pte
*)calloc(btoc(i
.i_size
), sizeof (struct pte
));
fprintf(stderr
, "Not enough core for block pointers\n");
vinizfod(&p
, pte
, 0, (btoc(i
.i_size
)+(CLSIZE
-1)) / CLSIZE
);
for (j
= 0; j
< (btoc(i
.i_size
)+(CLSIZE
-1)) / CLSIZE
; j
++)
printf("#%d: block %d\n", j
, pte
[j
].pg_pfnum
);
write(1, bread(0, pte
[j
].pg_pfnum
)->b_un
.b_words
, k
);
printf("getblk %x\n", blk
);
lseek(0, blk
* BSIZE
, 0);
if (read(0, b
.b_un
.b_addr
, BSIZE
) != BSIZE
) {
printf("block %d: ", blk
);
* Initialize the page tables for paging from an inode,
* by scouring up the indirect blocks in order.
vinizfod(p
, pte
, bstart
, count
)
register struct pte
*pte
;
register struct inode
*ip
= p
->p_textp
->x_iptr
;
if (bstart
< NADDR
- 3) {
pte
++->pg_pfnum
= ip
->i_un
.i_addr
[bstart
];
indx
= (bstart
- (NADDR
- 3)) % NINDIR
;
i
= imin(NINDIR
- indx
, count
);
pp
= &bp
->b_un
.b_daddr
[indx
];
* Vbmap returns a block full of indirect pointers for a given block offset
* in a file. It returns 0 if a missing address block was encountered,
* in which case the pages can be normal zfod pages.
register struct inode
*ip
;
* addresses NADDR-3, NADDR-2, and NADDR-1
* have single, double, triple indirect blocks.
* the first step is to determine
* how many levels of indirection.
for (j
= 3; j
> 0; j
--) {
* fetch the address from the inode
nb
= ip
->i_un
.i_addr
[NADDR
-j
];
* fetch through the indirect blocks
if (bp
->b_flags
& B_ERROR
) {
nb
= bp
->b_un
.b_daddr
[i
];
return ((struct buf
*)0);