Rev 2363 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2363 | Rev 2435 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | /* |
|
- | 2 | * Copyright (c) 1987,1997, Prentice Hall |
|
- | 3 | * All rights reserved. |
|
- | 4 | * |
|
- | 5 | * Redistribution and use of the MINIX operating system in source and |
|
- | 6 | * binary forms, with or without modification, are permitted provided |
|
1 | /* Basic methods for reading blocks. */ |
7 | * that the following conditions are met: |
- | 8 | ||
- | 9 | * - Redistributions of source code must retain the above copyright |
|
- | 10 | * notice, this list of conditions and the following disclaimer. |
|
2 | 11 | ||
- | 12 | * - Redistributions in binary form must reproduce the above |
|
- | 13 | * copyright notice, this list of conditions and the following |
|
- | 14 | * disclaimer in the documentation and/or other materials provided |
|
3 | /* Methods: |
15 | * with the distribution. |
- | 16 | ||
- | 17 | * - Neither the name of Prentice Hall nor the names of the software |
|
4 | * init_block: Allocates memory for working block |
18 | * authors or contributors may be used to endorse or promote |
5 | * get_block: Returns requested block according its number |
19 | * products derived from this software without specific prior |
- | 20 | * written permission. |
|
- | 21 | ||
- | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND |
|
- | 23 | * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
- | 24 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
- | 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
- | 26 | * IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE |
|
- | 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
- | 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
- | 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
- | 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
- | 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
- | 32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
- | 33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
- | 34 | */ |
|
- | 35 | ||
- | 36 | /** @addtogroup FileSystemImpl |
|
- | 37 | * @{ |
|
- | 38 | */ |
|
- | 39 | ||
- | 40 | /** |
|
- | 41 | * @file block.c |
|
6 | * read_block: Process reading of requested block |
42 | * @brief Basic methods for reading blocks. |
7 | */ |
43 | */ |
8 | - | ||
9 | 44 | ||
10 | #include <stdio.h> |
45 | #include <stdio.h> |
11 | #include <async.h> |
46 | #include <async.h> |
12 | #include <sysinfo.h> |
47 | #include <sysinfo.h> |
13 | #include "fs.h" |
48 | #include "fs.h" |
14 | #include "block.h" |
49 | #include "block.h" |
15 | #include "super.h" |
50 | #include "super.h" |
16 | #include "../rd/rd.h" |
51 | #include "../rd/rd.h" |
17 | 52 | ||
- | 53 | block_t* work_block; /**< A temporary variable for storing the working block */ |
|
18 | 54 | ||
- | 55 | /** |
|
19 | block_t* work_block; |
56 | * Allocates memory for working block |
20 | 57 | */ |
|
21 | int init_block() |
58 | int init_block() |
22 | { |
59 | { |
23 | 60 | ||
24 | /* Allocating free space for working block. */ |
61 | /* Allocating free space for working block. */ |
25 | work_block = (block_t*)malloc(sizeof(block_t)); |
62 | work_block = (block_t*)malloc(sizeof(block_t)); |
Line 27... | Line 64... | ||
27 | return TRUE; |
64 | return TRUE; |
28 | 65 | ||
29 | return FALSE; |
66 | return FALSE; |
30 | } |
67 | } |
31 | 68 | ||
- | 69 | /** |
|
- | 70 | * Returns requested block according its number |
|
- | 71 | */ |
|
32 | block_t *get_block(register block_num_t block_nr) |
72 | block_t *get_block(register block_num_t block_nr) |
33 | { |
73 | { |
34 | 74 | ||
35 | if (block_nr == NO_BLOCK) |
75 | if (block_nr == NO_BLOCK) |
36 | return (get_zero_block()); |
76 | return (get_zero_block()); |
Line 39... | Line 79... | ||
39 | read_block(work_block); |
79 | read_block(work_block); |
40 | 80 | ||
41 | return work_block; |
81 | return work_block; |
42 | } |
82 | } |
43 | 83 | ||
- | 84 | /** |
|
- | 85 | * Return a block filled with zeroes |
|
- | 86 | */ |
|
44 | block_t *get_zero_block() |
87 | block_t *get_zero_block() |
45 | { |
88 | { |
46 | 89 | ||
47 | /* Setting all bytes inside block to 0 */ |
90 | /* Setting all bytes inside block to 0 */ |
48 | memset(work_block->b.b__data, 0, BLOCK_SIZE); |
91 | memset(work_block->b.b__data, 0, BLOCK_SIZE); |
49 | 92 | ||
50 | return work_block; |
93 | return work_block; |
51 | } |
94 | } |
52 | 95 | ||
- | 96 | /** |
|
- | 97 | * Process reading of requested block |
|
- | 98 | */ |
|
53 | void read_block(register block_t *bp) |
99 | void read_block(register block_t *bp) |
54 | { |
100 | { |
55 | 101 | ||
56 | int r; |
102 | int r; |
57 | offset_t pos, header_size; |
103 | offset_t pos, header_size; |
Line 72... | Line 118... | ||
72 | memcpy((void *)(bp->b.b__data), (void *)buffer, BLOCK_SIZE); |
118 | memcpy((void *)(bp->b.b__data), (void *)buffer, BLOCK_SIZE); |
73 | status = BLOCK_SIZE; |
119 | status = BLOCK_SIZE; |
74 | } |
120 | } |
75 | 121 | ||
76 | 122 | ||
- | 123 | /** |
|
- | 124 | * } |
|
- | 125 | */ |
|
- | 126 |