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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// caching mechanism (like in disk_track_cache.h), we just rely on the
|
||||
// operating system.
|
||||
//
|
||||
// [ MmapFileAccess ]
|
||||
// [ MmapFilehandle ]
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -37,12 +37,14 @@ MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks,
|
|||
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);
|
||||
|
@ -53,7 +55,8 @@ MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks,
|
|||
|
||||
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;
|
||||
|
@ -101,4 +104,3 @@ bool MmapFileHandle::WriteSector(const BYTE *buf, int block)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
bool WriteSector(const BYTE *buf, int block); // Sector Write
|
||||
bool GetCache(int index, int &track, DWORD &serial) const { return true; }; // Get cache information
|
||||
|
||||
|
||||
private:
|
||||
const char *memory_block;
|
||||
struct stat sb;
|
||||
|
@ -48,4 +47,3 @@ private:
|
|||
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,14 +25,15 @@ PosixFileHandle::PosixFileHandle(const Filepath& path, int size, uint32_t blocks
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -69,7 +71,8 @@ bool PosixFileHandle::ReadSector(BYTE *buf, int block)
|
|||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
size_t result = read(fd, buf, sector_size_bytes);
|
||||
if(result != 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){
|
||||
if (result != sector_size_bytes)
|
||||
{
|
||||
LOGWARN("%s only wrote %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,4 +33,3 @@ private:
|
|||
int fd;
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue