Subversion Repositories HelenOS

Rev

Rev 2363 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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
  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.
  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
  15.  *   with the distribution.
  16.  
  17.  * - Neither the name of Prentice Hall nor the names of the software
  18.  *   authors or contributors may be used to endorse or promote
  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
  42.  * @brief   Basic methods for reading blocks.
  43.  */
  44.  
  45. #include <stdio.h>
  46. #include <async.h>
  47. #include <sysinfo.h>
  48. #include "fs.h"
  49. #include "block.h"
  50. #include "super.h"
  51. #include "../rd/rd.h"
  52.  
  53. block_t* work_block; /**< A temporary variable for storing the working block */
  54.  
  55. /**
  56.  * Allocates memory for working block
  57.  */
  58. int init_block()
  59. {
  60.    
  61.     /* Allocating free space for working block. */
  62.     work_block = (block_t*)malloc(sizeof(block_t));
  63.     if (work_block != NULL)
  64.         return TRUE;
  65.  
  66.     return FALSE;  
  67. }
  68.  
  69. /**
  70.  * Returns requested block according its number
  71.  */
  72. block_t *get_block(register block_num_t block_nr)
  73. {
  74.    
  75.     if (block_nr == NO_BLOCK)
  76.         return (get_zero_block());
  77.  
  78.     work_block->b_blocknr = block_nr;
  79.     read_block(work_block);
  80.  
  81.     return work_block;
  82. }
  83.  
  84. /**
  85.  * Return a block filled with zeroes
  86.  */
  87. block_t *get_zero_block()
  88. {
  89.  
  90.     /* Setting all bytes inside block to 0 */
  91.     memset(work_block->b.b__data, 0, BLOCK_SIZE);
  92.  
  93.     return work_block; 
  94. }
  95.  
  96. /**
  97.  * Process reading of requested block
  98.  */
  99. void read_block(register block_t *bp)
  100. {
  101.  
  102.     int r;
  103.     offset_t pos, header_size;
  104.  
  105.     header_size = sysinfo_value("rd.header_size");
  106.     pos = header_size + (offset_t)bp->b_blocknr * BLOCK_SIZE;
  107.    
  108.     /* Reading a block with specified number from ramdisk into shared buffer. */
  109.     r = async_req_2(rd_phone, RD_READ_BLOCK, pos, BLOCK_SIZE, NULL, NULL);
  110.     if (r < 0) {
  111.         print_console_int("Unrecoverable disk error on RAMDISK, block: %d\n", bp->b_blocknr);
  112.         print_console_int("Error number: %d\n", r);
  113.         status = FS_EIO;
  114.         return;
  115.     }
  116.    
  117.     /* Copy retrieved data from buffer into work block. */
  118.     memcpy((void *)(bp->b.b__data), (void *)buffer, BLOCK_SIZE);
  119.     status = BLOCK_SIZE;   
  120. }
  121.  
  122.  
  123. /**
  124.  * }
  125.  */
  126.  
  127.