Main Page | Class Hierarchy | Class List | File List | Class 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 
00006 #include "types.h"
00007 #include "screen.h"
00008 
00010 
00011 class Block_device {
00012 public:
00013   Size block_size;      
00014   Size total_blocks;      
00015   Size blocks_per_page;     
00016 
00018   virtual void
00019   init() = 0;
00020 
00022   virtual void
00023   deinit() = 0;
00024 
00027   bool
00028   read_page(unsigned block, void* data) {
00029           // read enough blocks to fill the page
00030     char* typed_data = (char*)data;
00031     for (unsigned i = 0; i < blocks_per_page; i++) {
00032       bool result = read_block(block, typed_data);
00033 
00034       if (result == false)    // bail on errors
00035         return false;
00036 
00037       block++;
00038       typed_data += block_size;
00039     }
00040     return true;
00041   }
00042   
00045   bool
00046   write_page(unsigned block, void* data) {
00047           // write enough blocks to fill the page
00048     char* typed_data = (char*)data;
00049     for (unsigned i = 0; i < blocks_per_page; i++) {
00050       bool result = write_block(block, typed_data);
00051 
00052       if (result == false)    // bail on errors
00053         return false;
00054 
00055       block++;
00056       typed_data += block_size;
00057     }
00058     return true;
00059   }
00060   
00062   virtual bool
00063   read_block(unsigned block, void* data) = 0;
00064   
00066   virtual bool
00067   write_block(unsigned block, void* data) = 0;
00068 };
00069 
00070 #endif
00071 
00072 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00073  *
00074  * This program is free software; you can redistribute it and/or modify it
00075  * under the terms of the GNU General Public License as published by the
00076  * Free Software Foundation; either version 2 of the License, or (at your
00077  * option) any later version.
00078  * 
00079  * This program is distributed in the hope that it will be useful, but
00080  * WITHOUT ANY WARRANTY; without even the implied warranty of
00081  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00082  * General Public License for more details (in the COPYING file).
00083  * 
00084  * You should have received a copy of the GNU General Public License along
00085  * with this program; if not, write to the Free Software Foundation, Inc.,
00086  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00087  */

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