include/blockio.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00031 /* Modification History:
00032  * $Log: blockio.h,v $
00033  * Revision 1.5  2004/08/28 13:35:25  jrush
00034  * Catching up CVS to various incomplete versions on local disk.
00035  *
00036  *
00037  */
00038 
00039 #ifndef __UDANAX_BLOCKIO_H__
00040 #define __UDANAX_BLOCKIO_H__
00041 
00042 typedef unsigned int BlockNum;
00043 #define NULLBLOCKNUM static_cast<BlockNum>(~0) //Invalid Disk Address: All Ones
00044 
00045 // Usage Note: if you try to get a block that hasn't been written, you get a block of garbage.
00046 
00055 class BlockIO
00056 {
00057   protected:
00058     struct stats {
00059         unsigned long blocks_read;    
00060         unsigned long blocks_written; 
00061     } stats;
00062 
00063     int blocksize;      
00064 
00065   public:
00066     enum OpenStatus {
00067         OS_FAILED  = -1,  
00068         OS_OPENED  =  0,  
00069         OS_CREATED =  1,  
00070     };
00071 
00072     BlockIO(int blocksize=4096)
00073     : blocksize(blocksize)
00074     {}
00075 
00076 //    virtual ~BlockIO() { if (isopen) close(); }
00077 
00078     virtual OpenStatus  open(const char *name) = 0;
00079     virtual bool const  is_open() = 0;
00080     virtual void        close() = 0;
00081 
00082     virtual bool get(void *buf, int buflen, BlockNum blockno) = 0;
00083     virtual bool put(void *buf, int buflen, BlockNum blockno) = 0;
00084 
00085     unsigned long blocksRead()    const { return stats.blocks_read; }
00086     unsigned long blocksWritten() const { return stats.blocks_written; }
00087 };
00088 
00097 class FileBlockIO: public BlockIO
00098 {
00099   protected:
00100 
00101   public:
00102     int blockfd; //fixme: temporarily public during code transition
00103 
00104     FileBlockIO(int blocksize=4096)
00105     : BlockIO(blocksize), blockfd(-1) { }
00106 //    virtual ~FileBlockIO() {}
00107 
00108     virtual OpenStatus  open(const char *filename="enf.enf");
00109     virtual bool const  is_open() { return blockfd >= 0; }
00110     virtual void        close();
00111 
00112     virtual bool get(void *buf, int buflen, BlockNum blockno);
00113     virtual bool put(void *buf, int buflen, BlockNum blockno);
00114 };
00115 
00116 #endif /* !__UDANAX_BLOCKIO_H__*/
00117 

Generated on Sun Aug 21 04:18:13 2005 for Udanax-Green by doxygen1.3.4