Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

storage.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_STORAGE_H
00004 #define TORSION_STORAGE_H
00005 
00006 #include "blockdev.h"
00007 #include "blockmap.h"
00008 #include "segment.h"
00009 #include "virtmem.h"
00010 #include "addrmap.h"
00011 #include "types.h"
00012 #include "screen.h"
00013 
00014 class Storage_system;
00015 extern Storage_system storage_system;
00016 
00025 
00026 class Superblock {
00027 public:
00028   unsigned signature;     
00029   unsigned checkpoint_counter;    
00030   unsigned block_directory;   
00031   unsigned segment_directory;   
00032   Size blocks_per_segment;    
00033   unsigned curr_empty_segment;    
00034   static const unsigned CORRECT_SIGNATURE = 0xbb66;
00035 
00037   void
00038   print();
00039 };
00040 
00050 
00051 class Storage_system {
00052 protected:
00053   Block_device* disk;     
00054   Segment curr_segment;     
00055 
00056   unsigned first_block;     
00057   Size blocks_per_segment;    
00058   Size blocks_per_page;     
00059   unsigned checkpoint_counter;    
00060   unsigned curr_superblock;   
00061   Block_map block_map;      
00062   Segment_map segment_map;    
00063   Array<unsigned> cleaned_segments; 
00064   bool checkpointing_dirty_pages; 
00065   bool enabled;       
00066 
00067   static const unsigned block_map_id_mask = 1 << 11;
00068 
00069 public:
00073   void
00074   format(unsigned first_block_to_use = 0, Size segment_size = 0);
00075 
00078   bool
00079   is_formatted(unsigned first_block_to_use = 0);
00080 
00083   void
00084   init(unsigned first_block_to_use = 0);
00085 
00089   void
00090   write_superblock(unsigned block_directory = 0,
00091                    unsigned segment_directory = 0,
00092                    unsigned curr_empty_segment = 0);
00093 
00097   void
00098   checkpoint();
00099 
00106   unsigned
00107   log_page(void* page, bool update_block_map = true,
00108            void* actual_page_addr = NULL);
00109 
00111   inline void
00112   free_page(void* page) {
00113     block_map.set_block_number(page, 0);
00114   }
00115 
00119   unsigned
00120   log_map(Address_map& map);
00121 
00125   unsigned*
00126   load_table(Address_map& map, unsigned dir_index, void* virtual_table);
00127 
00129   void
00130   load_page(void* virtual_page);
00131 
00133   void
00134   write_segment();
00135 
00137   void
00138   write_segment_if_full();
00139 
00147   bool
00148   clean(unsigned segments_to_clean);
00149 
00152   void
00153   get_live_pages(Segment& segment, Array<void*>& live_pages);
00154 
00156   inline void
00157   set_device(Block_device* device) {
00158     disk = device;
00159   }
00160 
00164   inline unsigned
00165   block_to_segment_index(unsigned segment_block) {
00166               // - 2 because of the two superblocks
00167     return (segment_block - first_block - 2) / blocks_per_segment;
00168   }
00169 
00171   inline unsigned
00172   segment_index_to_block(unsigned segment_index) {
00173               // + 2 because of the two superblocks
00174     return segment_index * blocks_per_segment + first_block + 2;
00175   }
00176 
00178   inline void
00179   enable() {
00180     enabled = true;
00181   }
00182   
00184   inline void
00185   disable() {
00186     enabled = false;
00187   }
00188 
00191   inline bool
00192   is_checkpointing_dirty_pages() {
00193     return checkpointing_dirty_pages;
00194   }
00195 
00197   void
00198   print();
00199 };
00200 
00201 #endif
00202 
00203 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00204  *
00205  * This program is free software; you can redistribute it and/or modify it
00206  * under the terms of the GNU General Public License as published by the
00207  * Free Software Foundation; either version 2 of the License, or (at your
00208  * option) any later version.
00209  * 
00210  * This program is distributed in the hope that it will be useful, but
00211  * WITHOUT ANY WARRANTY; without even the implied warranty of
00212  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00213  * General Public License for more details (in the COPYING file).
00214  * 
00215  * You should have received a copy of the GNU General Public License along
00216  * with this program; if not, write to the Free Software Foundation, Inc.,
00217  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00218  */

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