2009-11-21 01:45:08 +00:00
|
|
|
#ifndef __MAPPED_FILE__
|
|
|
|
#define __MAPPED_FILE__
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
namespace ProFUSE {
|
|
|
|
|
|
|
|
|
|
|
|
class MappedFile {
|
|
|
|
public:
|
2009-11-25 02:26:00 +00:00
|
|
|
|
|
|
|
enum Encoding {
|
|
|
|
ProDOSOrder = 0,
|
|
|
|
DOSOrder,
|
|
|
|
Nibblized62,
|
|
|
|
Nibblized53
|
|
|
|
};
|
|
|
|
|
2009-11-21 01:45:08 +00:00
|
|
|
MappedFile(const char *name, bool ReadOnly);
|
|
|
|
MappedFile(int fd, bool readOnly);
|
|
|
|
MappedFile(const char *name, size_t size);
|
|
|
|
|
|
|
|
~MappedFile();
|
|
|
|
|
|
|
|
void readBlock(unsigned block, void *bp);
|
|
|
|
void writeBlock(unsigned block, const void *bp);
|
|
|
|
|
|
|
|
void sync();
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
2009-11-25 02:26:00 +00:00
|
|
|
Encoding encoding() const { return _encoding; }
|
|
|
|
void setEncoding(Encoding e) { _encoding = e; }
|
2009-11-21 01:45:08 +00:00
|
|
|
|
|
|
|
unsigned offset() const { return _offset; }
|
|
|
|
void setOffset(unsigned o) { _offset = o; }
|
|
|
|
|
|
|
|
unsigned blocks() const { return _blocks; }
|
|
|
|
void setBlocks(unsigned b) { _blocks = b; }
|
|
|
|
|
|
|
|
bool readOnly() const { return _readOnly; }
|
|
|
|
size_t fileSize() const { return _size; }
|
|
|
|
void *fileData() const { return _map; }
|
2009-12-11 00:59:53 +00:00
|
|
|
void *imageData() const { return _offset + (uint8_t *)_map; }
|
2009-11-24 04:04:42 +00:00
|
|
|
|
2009-11-21 01:45:08 +00:00
|
|
|
|
|
|
|
private:
|
2009-12-11 00:59:53 +00:00
|
|
|
|
|
|
|
|
2009-11-21 01:45:08 +00:00
|
|
|
MappedFile& operator=(const MappedFile& other);
|
|
|
|
|
|
|
|
void init(int fd, bool readOnly);
|
|
|
|
|
|
|
|
static const unsigned DOSMap[];
|
|
|
|
|
|
|
|
int _fd;
|
|
|
|
void *_map;
|
|
|
|
|
|
|
|
size_t _size;
|
|
|
|
bool _readOnly;
|
|
|
|
|
2009-11-25 02:26:00 +00:00
|
|
|
Encoding _encoding;
|
2009-11-21 01:45:08 +00:00
|
|
|
unsigned _offset;
|
|
|
|
unsigned _blocks;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|