00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00031
00032
00033
00034
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
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
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;
00103
00104 FileBlockIO(int blocksize=4096)
00105 : BlockIO(blocksize), blockfd(-1) { }
00106
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
00117