Ran formatting tool

This commit is contained in:
RaSCSI User 2022-03-14 02:28:40 +00:00
parent 8e48e72bf1
commit 9ba4a9243d
9 changed files with 107 additions and 102 deletions

View File

@ -108,7 +108,7 @@ void Disk::Open(const Filepath& path)
// Cache initialization // Cache initialization
assert (!disk.dcache); 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 // Can read/write open
Fileio fio; Fileio fio;

View File

@ -533,7 +533,7 @@ int SCSICD::Read(const DWORD *cdb, BYTE *buf, uint64_t block)
// Recreate the disk cache // Recreate the disk cache
Filepath path; Filepath path;
track[index]->GetPath(path); track[index]->GetPath(path);
disk.dcache = DiskImageHandleFactory::CreateFileAccess(path, GetSectorSizeShiftCount(), GetBlockCount()); disk.dcache = DiskImageHandleFactory::CreateDiskImageHandle(path, GetSectorSizeShiftCount(), GetBlockCount());
disk.dcache->SetRawMode(rawfile); disk.dcache->SetRawMode(rawfile);
// Reset data index // Reset data index

View File

@ -13,7 +13,8 @@
#include "disk_image/disk_image_handle.h" #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; serial = 0;
sec_path = path; sec_path = path;
@ -21,29 +22,33 @@ DiskImageHandle::DiskImageHandle(const Filepath& path, int size, uint32_t blocks
sec_blocks = blocks; sec_blocks = blocks;
imgoffset = imgoff; imgoffset = imgoff;
} }
DiskImageHandle::~DiskImageHandle(){ DiskImageHandle::~DiskImageHandle()
{
} }
off_t DiskImageHandle::GetSectorOffset(int block)
off_t DiskImageHandle::GetSectorOffset(int block){ {
int sector_num = block & 0xff; int sector_num = block & 0xff;
return (off_t)sector_num << sec_size; 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 // Assuming that all tracks hold 256 sectors
int track_num = block >> 8; int track_num = block >> 8;
// Calculate offset (previous tracks are considered to hold 256 sectors) // Calculate offset (previous tracks are considered to hold 256 sectors)
off_t offset = ((off_t)track_num << 8); off_t offset = ((off_t)track_num << 8);
if (cd_raw) { if (cd_raw)
{
ASSERT(sec_size == 11); ASSERT(sec_size == 11);
offset *= 0x930; offset *= 0x930;
offset += 0x10; offset += 0x10;
} else { }
else
{
offset <<= sec_size; offset <<= sec_size;
} }

View File

@ -38,8 +38,6 @@ protected:
int sec_blocks; // Blocks per sector int sec_blocks; // Blocks per sector
off_t imgoffset; // Offset to actual data off_t imgoffset; // Offset to actual data
off_t GetTrackOffset(int block); off_t GetTrackOffset(int block);
off_t GetSectorOffset(int block); off_t GetSectorOffset(int block);
}; };

View File

@ -15,7 +15,8 @@
#include "disk_image/disk_image_handle.h" #include "disk_image/disk_image_handle.h"
enum DiskImageHandleType { enum DiskImageHandleType
{
eRamCache, eRamCache,
eMmapFile, eMmapFile,
ePosixFile, ePosixFile,

View File

@ -16,7 +16,7 @@
// caching mechanism (like in disk_track_cache.h), we just rely on the // caching mechanism (like in disk_track_cache.h), we just rely on the
// operating system. // operating system.
// //
// [ MmapFileAccess ] // [ MmapFilehandle ]
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -37,12 +37,14 @@ MmapFileHandle::MmapFileHandle(const Filepath& path, int size, uint32_t blocks,
ASSERT(imgoff >= 0); ASSERT(imgoff >= 0);
fd = open(path.GetPath(), O_RDWR); fd = open(path.GetPath(), O_RDWR);
if(fd < 0){ if (fd < 0)
{
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno) LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
} }
LOGWARN("%s opened %s", __PRETTY_FUNCTION__, path.GetPath()); LOGWARN("%s opened %s", __PRETTY_FUNCTION__, path.GetPath());
struct stat sb; struct stat sb;
if(fstat(fd, &sb) < 0){ if (fstat(fd, &sb) < 0)
{
LOGWARN("Unable to run fstat. Errno:%d", errno); LOGWARN("Unable to run fstat. Errno:%d", errno);
} }
printf("Size: %llu\n", (uint64_t)sb.st_size); 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); memory_block = (const char *)mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
int errno_val = errno; int errno_val = errno;
if (memory_block == MAP_FAILED) { if (memory_block == MAP_FAILED)
{
LOGWARN("Unabled to memory map file %s", path.GetPath()); LOGWARN("Unabled to memory map file %s", path.GetPath());
LOGWARN(" Errno:%d", errno_val); LOGWARN(" Errno:%d", errno_val);
return; return;
@ -101,4 +104,3 @@ bool MmapFileHandle::WriteSector(const BYTE *buf, int block)
return true; return true;
} }

View File

@ -40,7 +40,6 @@ public:
bool WriteSector(const BYTE *buf, int block); // Sector Write 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: private:
const char *memory_block; const char *memory_block;
struct stat sb; struct stat sb;
@ -48,4 +47,3 @@ private:
bool initialized = false; bool initialized = false;
}; };

View File

@ -25,14 +25,15 @@ PosixFileHandle::PosixFileHandle(const Filepath& path, int size, uint32_t blocks
ASSERT(blocks > 0); ASSERT(blocks > 0);
ASSERT(imgoff >= 0); ASSERT(imgoff >= 0);
fd = open(path.GetPath(), O_RDWR); fd = open(path.GetPath(), O_RDWR);
if(fd < 0){ if (fd < 0)
{
LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno) LOGWARN("Unable to open file %s. Errno:%d", path.GetPath(), errno)
return; return;
} }
struct stat sb; struct stat sb;
if(fstat(fd, &sb) < 0){ if (fstat(fd, &sb) < 0)
{
LOGWARN("Unable to run fstat. Errno:%d", errno); LOGWARN("Unable to run fstat. Errno:%d", errno);
return; return;
} }
@ -52,7 +53,8 @@ PosixFileHandle::~PosixFileHandle()
bool PosixFileHandle::ReadSector(BYTE *buf, int block) bool PosixFileHandle::ReadSector(BYTE *buf, int block)
{ {
if(!initialized){ if (!initialized)
{
return false; return false;
} }
@ -69,7 +71,8 @@ bool PosixFileHandle::ReadSector(BYTE *buf, int block)
lseek(fd, offset, SEEK_SET); lseek(fd, offset, SEEK_SET);
size_t result = read(fd, buf, sector_size_bytes); 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); 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) bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
{ {
if(!initialized){ if (!initialized)
{
return false; return false;
} }
@ -93,14 +97,12 @@ bool PosixFileHandle::WriteSector(const BYTE *buf, int block)
off_t offset = GetTrackOffset(block); off_t offset = GetTrackOffset(block);
offset += GetSectorOffset(block); offset += GetSectorOffset(block);
lseek(fd, offset, SEEK_SET); lseek(fd, offset, SEEK_SET);
size_t result = write(fd, buf, sector_size_bytes); 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); LOGWARN("%s only wrote %d bytes but wanted %d ", __PRETTY_FUNCTION__, result, sector_size_bytes);
} }
return true; return true;
} }

View File

@ -33,4 +33,3 @@ private:
int fd; int fd;
bool initialized = false; bool initialized = false;
}; };