mirror of https://github.com/akuker/RASCSI.git
Ran formatting tool
This commit is contained in:
parent
8e48e72bf1
commit
9ba4a9243d
|
@ -108,7 +108,7 @@ void Disk::Open(const Filepath& path)
|
|||
|
||||
// Cache initialization
|
||||
assert (!disk.dcache);
|
||||
disk.dcache = DiskImageHandleFactory::CreateFileAccess(path, disk.size, disk.blocks, disk.image_offset);
|
||||
disk.dcache = DiskImageHandleFactory::CreateDiskImageHandle(path, disk.size, disk.blocks, disk.image_offset);
|
||||
|
||||
// Can read/write open
|
||||
Fileio fio;
|
||||
|
|
|
@ -533,7 +533,7 @@ int SCSICD::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
|
|||
// Recreate the disk cache
|
||||
Filepath path;
|
||||
track[index]->GetPath(path);
|
||||
disk.dcache = DiskImageHandleFactory::CreateFileAccess(path, GetSectorSizeShiftCount(), GetBlockCount());
|
||||
disk.dcache = DiskImageHandleFactory::CreateDiskImageHandle(path, GetSectorSizeShiftCount(), GetBlockCount());
|
||||
disk.dcache->SetRawMode(rawfile);
|
||||
|
||||
// Reset data index
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
#include "disk_image/disk_image_handle.h"
|
||||
|
||||
DiskImageHandle::DiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff){
|
||||
DiskImageHandle::DiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff)
|
||||
{
|
||||
|
||||
serial = 0;
|
||||
sec_path = path;
|
||||
|
@ -21,29 +22,33 @@ DiskImageHandle::DiskImageHandle(const Filepath& path, int size, uint32_t blocks
|
|||
sec_blocks = blocks;
|
||||
imgoffset = imgoff;
|
||||
}
|
||||
DiskImageHandle::~DiskImageHandle(){
|
||||
|
||||
DiskImageHandle::~DiskImageHandle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
off_t DiskImageHandle::GetSectorOffset(int block){
|
||||
off_t DiskImageHandle::GetSectorOffset(int block)
|
||||
{
|
||||
|
||||
int sector_num = block & 0xff;
|
||||
return (off_t)sector_num << sec_size;
|
||||
}
|
||||
|
||||
off_t DiskImageHandle::GetTrackOffset(int block){
|
||||
off_t DiskImageHandle::GetTrackOffset(int block)
|
||||
{
|
||||
|
||||
// Assuming that all tracks hold 256 sectors
|
||||
int track_num = block >> 8;
|
||||
|
||||
// Calculate offset (previous tracks are considered to hold 256 sectors)
|
||||
off_t offset = ((off_t)track_num << 8);
|
||||
if (cd_raw) {
|
||||
if (cd_raw)
|
||||
{
|
||||
ASSERT(sec_size == 11);
|
||||
offset *= 0x930;
|
||||
offset += 0x10;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
offset <<= sec_size;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
class DiskImageHandle
|
||||
{
|
||||
public:
|
||||
DiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
DiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
virtual ~DiskImageHandle();
|
||||
|
||||
void SetRawMode(bool raw) { cd_raw = raw; }; // CD-ROM raw mode setting
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
virtual bool Save() = 0; // Save and release all
|
||||
virtual bool ReadSector(BYTE *buf, int block) = 0; // Sector Read
|
||||
virtual bool WriteSector(const BYTE *buf, int block) = 0; // Sector Write
|
||||
virtual bool GetCache(int index, int& track, DWORD& serial) const = 0; // Get cache information
|
||||
virtual bool GetCache(int index, int &track, DWORD &serial) const = 0; // Get cache information
|
||||
|
||||
protected:
|
||||
bool cd_raw = false;
|
||||
|
@ -38,8 +38,6 @@ protected:
|
|||
int sec_blocks; // Blocks per sector
|
||||
off_t imgoffset; // Offset to actual data
|
||||
|
||||
|
||||
off_t GetTrackOffset(int block);
|
||||
off_t GetSectorOffset(int block);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
#include "disk_image/disk_image_handle.h"
|
||||
|
||||
enum DiskImageHandleType {
|
||||
enum DiskImageHandleType
|
||||
{
|
||||
eRamCache,
|
||||
eMmapFile,
|
||||
ePosixFile,
|
||||
|
@ -27,7 +28,7 @@ public:
|
|||
static void SetFileAccessMethod(DiskImageHandleType method) { current_access_type = method; };
|
||||
static DiskImageHandleType GetFileAccessMethod() { return current_access_type; };
|
||||
|
||||
static DiskImageHandle *CreateDiskImageHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
static DiskImageHandle *CreateDiskImageHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
|
||||
private:
|
||||
static DiskImageHandleType current_access_type;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// operating system.
|
||||
//
|
||||
// [ MmapFileAccess ]
|
||||
// [ MmapFilehandle ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -31,18 +31,20 @@
|
|||
// Direct file access that will map the file into virtual memory space
|
||||
//
|
||||
//===========================================================================
|
||||
MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
MmapFileHandle::MmapFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
{
|
||||
ASSERT(blocks > 0);
|
||||
ASSERT(imgoff >= 0);
|
||||
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if(fd < 0){
|
||||
if (fd < 0)
|
||||
{
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
}
|
||||
LOGWARN("%s opened %s", __PRETTY_FUNCTION__, path.GetPath());
|
||||
struct stat sb;
|
||||
if(fstat(fd, &sb) < 0){
|
||||
if (fstat(fd, &sb) < 0)
|
||||
{
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
}
|
||||
printf("Size: %llu\n", (uint64_t)sb.st_size);
|
||||
|
@ -51,9 +53,10 @@ MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks,
|
|||
|
||||
// int x = EACCES;
|
||||
|
||||
memory_block = (const char*)mmap(NULL, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
memory_block = (const char *)mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
int errno_val = errno;
|
||||
if (memory_block == MAP_FAILED) {
|
||||
if (memory_block == MAP_FAILED)
|
||||
{
|
||||
LOGWARN("Unabled to memory map file %s", path.GetPath());
|
||||
LOGWARN(" Errno:%d", errno_val);
|
||||
return;
|
||||
|
@ -63,7 +66,7 @@ MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks,
|
|||
|
||||
MmapFileHandle::~MmapFileHandle()
|
||||
{
|
||||
munmap((void*)memory_block, sb.st_size);
|
||||
munmap((void *)memory_block, sb.st_size);
|
||||
close(fd);
|
||||
|
||||
// Force the OS to save any cached data to the disk
|
||||
|
@ -97,8 +100,7 @@ bool MmapFileHandle::WriteSector(const BYTE *buf, int block)
|
|||
|
||||
ASSERT((block * sec_size) <= (sb.st_size + sec_size));
|
||||
|
||||
memcpy((void*)&memory_block[(block * sec_size)], buf, sec_size);
|
||||
memcpy((void *)&memory_block[(block * sec_size)], buf, sec_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class MmapFileHandle : public DiskImageHandle
|
|||
{
|
||||
|
||||
public:
|
||||
MmapFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
MmapFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
~MmapFileHandle();
|
||||
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
|
@ -38,8 +38,7 @@ public:
|
|||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int& track, DWORD& serial) const { return true; }; // Get cache information
|
||||
|
||||
bool GetCache(int index, int &track, DWORD &serial) const { return true; }; // Get cache information
|
||||
|
||||
private:
|
||||
const char *memory_block;
|
||||
|
@ -48,4 +47,3 @@ private:
|
|||
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,19 +20,20 @@
|
|||
// Direct file access that will map the file into virtual memory space
|
||||
//
|
||||
//===========================================================================
|
||||
PosixFileHandle::PosixFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
PosixFileHandle::PosixFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff) : DiskImageHandle(path, size, blocks, imgoff)
|
||||
{
|
||||
ASSERT(blocks > 0);
|
||||
ASSERT(imgoff >= 0);
|
||||
|
||||
|
||||
fd = open(path.GetPath(), O_RDWR);
|
||||
if(fd < 0){
|
||||
if (fd < 0)
|
||||
{
|
||||
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
|
||||
return;
|
||||
}
|
||||
struct stat sb;
|
||||
if(fstat(fd, &sb) < 0){
|
||||
if (fstat(fd, &sb) < 0)
|
||||
{
|
||||
LOGWARN("Unable to run fstat. Errno:%d", errno);
|
||||
return;
|
||||
}
|
||||
|
@ -52,7 +53,8 @@ PosixFileHandle::~PosixFileHandle()
|
|||
|
||||
bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
||||
{
|
||||
if(!initialized){
|
||||
if (!initialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -68,8 +70,9 @@ bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
|||
offset += GetSectorOffset(block);
|
||||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = read(fd, buf,sector_size_bytes);
|
||||
if(result != sector_size_bytes){
|
||||
size_t result = read(fd, buf, sector_size_bytes);
|
||||
if (result != sector_size_bytes)
|
||||
{
|
||||
LOGWARN("%s only read %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
|
||||
|
@ -78,7 +81,8 @@ bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
|||
|
||||
bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
|
||||
{
|
||||
if(!initialized){
|
||||
if (!initialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -93,14 +97,12 @@ bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
|
|||
off_t offset = GetTrackOffset(block);
|
||||
offset += GetSectorOffset(block);
|
||||
|
||||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = write(fd, buf,sector_size_bytes);
|
||||
if(result != sector_size_bytes){
|
||||
size_t result = write(fd, buf, sector_size_bytes);
|
||||
if (result != sector_size_bytes)
|
||||
{
|
||||
LOGWARN("%s only wrote %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class PosixFileHandle : public DiskImageHandle
|
|||
{
|
||||
|
||||
public:
|
||||
PosixFileHandle(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
PosixFileHandle(const Filepath &path, int size, uint32_t blocks, off_t imgoff = 0);
|
||||
~PosixFileHandle();
|
||||
|
||||
void SetRawMode(BOOL raw); // CD-ROM raw mode setting
|
||||
|
@ -27,10 +27,9 @@ public:
|
|||
bool Save() { return true; }; // Save and release all
|
||||
bool ReadSector(BYTE *buf, int block); // Sector Read
|
||||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int& track, DWORD& serial) const { return true; }; // Get cache information
|
||||
bool GetCache(int index, int &track, DWORD &serial) const { return true; }; // Get cache information
|
||||
|
||||
private:
|
||||
int fd;
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue