Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2363 | konopa | 1 | /* Basic methods for reading blocks. */ |
2 | |||
3 | /* Methods: |
||
4 | * init_block: Allocates memory for working block |
||
5 | * get_block: Returns requested block according its number |
||
6 | * read_block: Process reading of requested block |
||
7 | */ |
||
8 | |||
9 | |||
10 | #include <stdio.h> |
||
11 | #include <async.h> |
||
12 | #include <sysinfo.h> |
||
13 | #include "fs.h" |
||
14 | #include "block.h" |
||
15 | #include "super.h" |
||
16 | #include "../rd/rd.h" |
||
17 | |||
18 | |||
19 | block_t* work_block; |
||
20 | |||
21 | int init_block() |
||
22 | { |
||
23 | |||
24 | /* Allocating free space for working block. */ |
||
25 | work_block = (block_t*)malloc(sizeof(block_t)); |
||
26 | if (work_block != NULL) |
||
27 | return TRUE; |
||
28 | |||
29 | return FALSE; |
||
30 | } |
||
31 | |||
32 | block_t *get_block(register block_num_t block_nr) |
||
33 | { |
||
34 | |||
35 | if (block_nr == NO_BLOCK) |
||
36 | return (get_zero_block()); |
||
37 | |||
38 | work_block->b_blocknr = block_nr; |
||
39 | read_block(work_block); |
||
40 | |||
41 | return work_block; |
||
42 | } |
||
43 | |||
44 | block_t *get_zero_block() |
||
45 | { |
||
46 | |||
47 | /* Setting all bytes inside block to 0 */ |
||
48 | memset(work_block->b.b__data, 0, BLOCK_SIZE); |
||
49 | |||
50 | return work_block; |
||
51 | } |
||
52 | |||
53 | void read_block(register block_t *bp) |
||
54 | { |
||
55 | |||
56 | int r; |
||
57 | offset_t pos, header_size; |
||
58 | |||
59 | header_size = sysinfo_value("rd.header_size"); |
||
60 | pos = header_size + (offset_t)bp->b_blocknr * BLOCK_SIZE; |
||
61 | |||
62 | /* Reading a block with specified number from ramdisk into shared buffer. */ |
||
63 | r = async_req_2(rd_phone, RD_READ_BLOCK, pos, BLOCK_SIZE, NULL, NULL); |
||
64 | if (r < 0) { |
||
65 | print_console_int("Unrecoverable disk error on RAMDISK, block: %d\n", bp->b_blocknr); |
||
66 | print_console_int("Error number: %d\n", r); |
||
67 | status = FS_EIO; |
||
68 | return; |
||
69 | } |
||
70 | |||
71 | /* Copy retrieved data from buffer into work block. */ |
||
72 | memcpy((void *)(bp->b.b__data), (void *)buffer, BLOCK_SIZE); |
||
73 | status = BLOCK_SIZE; |
||
74 | } |
||
75 | |||
76 |