Rev 2404 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2404 | Rev 2435 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
32 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | */ |
34 | */ |
35 | 35 | ||
- | 36 | /** @addtogroup FileSystemImpl |
|
36 | 37 | * @{ |
|
37 | /* This file contains the heart of the mechanism used to read files. |
- | |
38 | * Read requests are split up into chunks that do not cross block |
- | |
39 | * boundaries. Each chunk is then processed in turn. |
- | |
40 | */ |
38 | */ |
41 | 39 | ||
- | 40 | /** |
|
42 | /* Methods: |
41 | * @file read.c |
43 | * do_read: perform the READ system call |
42 | * @brief This file contains the heart of the mechanism used to read files. |
44 | * read_map: given an inode and file position, look up its zone number |
43 | * Read requests are split up into chunks that do not cross block |
45 | * rd_indir: read an entry in an indirect block |
44 | * boundaries. Each chunk is then processed in turn. |
46 | */ |
45 | */ |
47 | 46 | ||
48 | #include <stdio.h> |
47 | #include <stdio.h> |
49 | #include "fs.h" |
48 | #include "fs.h" |
50 | #include "block.h" |
49 | #include "block.h" |
Line 56... | Line 55... | ||
56 | 55 | ||
57 | 56 | ||
58 | static int read_chunk(inode_t *rip, offset_t position, |
57 | static int read_chunk(inode_t *rip, offset_t position, |
59 | unsigned off, int chunk, char *buff); |
58 | unsigned off, int chunk, char *buff); |
60 | 59 | ||
- | 60 | /** |
|
- | 61 | * Perform the READ system call |
|
- | 62 | */ |
|
61 | int do_read() |
63 | int do_read() |
62 | { |
64 | { |
63 | 65 | ||
64 | /* Perform read(fd, buffer, nbytes) call. */ |
66 | /* Perform read(fd, buffer, nbytes) call. */ |
65 | 67 | ||
Line 159... | Line 161... | ||
159 | else { |
161 | else { |
160 | print_console("Some error occured during reading the file\n"); |
162 | print_console("Some error occured during reading the file\n"); |
161 | return r; |
163 | return r; |
162 | } |
164 | } |
163 | } |
165 | } |
164 | 166 | ||
- | 167 | /** |
|
- | 168 | * Given an inode and file position, look up its zone number |
|
- | 169 | */ |
|
165 | static int read_chunk(register inode_t *rip, offset_t position, unsigned off, |
170 | static int read_chunk(register inode_t *rip, offset_t position, unsigned off, |
166 | int chunk, char *buff) |
171 | int chunk, char *buff) |
167 | { |
172 | { |
168 | 173 | ||
169 | /* |
174 | /* |
Line 192... | Line 197... | ||
192 | /* Copy a chunk from the block buffer to user space. */ |
197 | /* Copy a chunk from the block buffer to user space. */ |
193 | memcpy((void *)buff, (void *)(bp->b.b__data+off), chunk); |
198 | memcpy((void *)buff, (void *)(bp->b.b__data+off), chunk); |
194 | 199 | ||
195 | return OK; |
200 | return OK; |
196 | } |
201 | } |
197 | 202 | ||
- | 203 | /** |
|
- | 204 | * Read an entry in an indirect block |
|
- | 205 | */ |
|
198 | block_num_t read_map(register inode_t *rip, offset_t position) |
206 | block_num_t read_map(register inode_t *rip, offset_t position) |
199 | { |
207 | { |
200 | 208 | ||
201 | /* Given an inode and a position within the corresponding file, locate the |
209 | /* Given an inode and a position within the corresponding file, locate the |
202 | * block (not zone) number in which that position is to be found and return it. |
210 | * block (not zone) number in which that position is to be found and return it. |
Line 260... | Line 268... | ||
260 | b = ((block_num_t) z << scale) + boff; |
268 | b = ((block_num_t) z << scale) + boff; |
261 | 269 | ||
262 | return b; |
270 | return b; |
263 | } |
271 | } |
264 | 272 | ||
- | 273 | /** |
|
- | 274 | * |
|
- | 275 | */ |
|
265 | zone_t rd_indir(block_t *bp, int index) |
276 | zone_t rd_indir(block_t *bp, int index) |
266 | { |
277 | { |
267 | 278 | ||
268 | super_block_t *sp; |
279 | super_block_t *sp; |
269 | zone_t zone; |
280 | zone_t zone; |
Line 283... | Line 294... | ||
283 | } |
294 | } |
284 | 295 | ||
285 | return zone; |
296 | return zone; |
286 | } |
297 | } |
287 | 298 | ||
- | 299 | ||
- | 300 | /** |
|
- | 301 | * } |
|
- | 302 | */ |
|
- | 303 |