Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

blockdev.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_BLOCKDEV_H
00004 #define TORSION_BLOCKDEV_H
00005 
00007 
00016 class Block_device {
00017 public:
00018   void* device;                         
00019   unsigned int block_size;              
00020   unsigned int total_blocks;            
00021   unsigned int blocks_per_page;         
00022   void (*init_func)(void*);
00023   void (*deinit_func)(void*);
00024   bool (*read_block_func)(void*, unsigned int block, void* data);
00025   bool (*write_block_func)(void*, unsigned int block, void* data);
00026 
00028   inline void
00029   init() {
00030     init_func(device);
00031   }
00032 
00034   inline void
00035   deinit() {
00036     deinit_func(device);
00037   }
00038 
00041   bool
00042   read_page(unsigned int block, void* data) {
00043                                         // read enough blocks to fill the page
00044     for (unsigned int i = 0; i < blocks_per_page; i++) {
00045       bool result = read_block_func(device, block, data);
00046 
00047       if (result == false)              // bail on errors
00048         return false;
00049 
00050       block++;
00051       (unsigned char*)data += block_size;
00052     }
00053     return true;
00054   }
00055   
00058   bool
00059   write_page(unsigned int block, void* data) {
00060                                         // write enough blocks to fill the page
00061     for (unsigned int i = 0; i < blocks_per_page; i++) {
00062       bool result = write_block_func(device, block, data);
00063 
00064       if (result == false)              // bail on errors
00065         return false;
00066 
00067       block++;
00068       (unsigned char*)data += block_size;
00069     }
00070     return true;
00071   }
00072   
00074   inline bool
00075   read_block(unsigned int block, void* data) {
00076     return read_block_func(device, block, data);
00077   }
00078   
00080   inline bool
00081   write_block(unsigned int block, void* data) {
00082     return write_block_func(device, block, data);
00083   }
00084 };
00085 
00086 #endif
00087 
00088 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman
00089  *
00090  * This program is free software; you can redistribute it and/or modify it
00091  * under the terms of the GNU General Public License as published by the
00092  * Free Software Foundation; either version 2 of the License, or (at your
00093  * option) any later version.
00094  * 
00095  * This program is distributed in the hope that it will be useful, but
00096  * WITHOUT ANY WARRANTY; without even the implied warranty of
00097  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00098  * General Public License for more details (in the COPYING file).
00099  * 
00100  * You should have received a copy of the GNU General Public License along
00101  * with this program; if not, write to the Free Software Foundation, Inc.,
00102  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00103  */

Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman