|
@@ -272,6 +272,7 @@ public:
|
|
|
{
|
|
{
|
|
|
m_israw = false;
|
|
m_israw = false;
|
|
|
m_isrom = false;
|
|
m_isrom = false;
|
|
|
|
|
+ m_isreadonly_attr = false;
|
|
|
m_blockdev = nullptr;
|
|
m_blockdev = nullptr;
|
|
|
m_bgnsector = m_endsector = m_cursector = 0;
|
|
m_bgnsector = m_endsector = m_cursector = 0;
|
|
|
}
|
|
}
|
|
@@ -319,7 +320,16 @@ public:
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- m_fsfile = SD.open(filename, O_RDWR);
|
|
|
|
|
|
|
+ m_isreadonly_attr = !!(FS_ATTRIB_READ_ONLY & SD.attrib(filename));
|
|
|
|
|
+ if (m_isreadonly_attr)
|
|
|
|
|
+ {
|
|
|
|
|
+ m_fsfile = SD.open(filename, O_RDONLY);
|
|
|
|
|
+ azlog("---- Image file is read-only, writes disabled");
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ m_fsfile = SD.open(filename, O_RDWR);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
uint32_t sectorcount = m_fsfile.size() / SD_SECTOR_SIZE;
|
|
uint32_t sectorcount = m_fsfile.size() / SD_SECTOR_SIZE;
|
|
|
uint32_t begin = 0, end = 0;
|
|
uint32_t begin = 0, end = 0;
|
|
@@ -354,7 +364,7 @@ public:
|
|
|
|
|
|
|
|
bool isWritable()
|
|
bool isWritable()
|
|
|
{
|
|
{
|
|
|
- return !m_isrom;
|
|
|
|
|
|
|
+ return !m_isrom && !m_isreadonly_attr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool isRom()
|
|
bool isRom()
|
|
@@ -506,6 +516,11 @@ public:
|
|
|
azlog("ERROR: attempted to write to ROM drive");
|
|
azlog("ERROR: attempted to write to ROM drive");
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (m_isreadonly_attr)
|
|
|
|
|
+ {
|
|
|
|
|
+ azlog("ERROR: attempted to write to a read only image");
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
return m_fsfile.write(buf, count);
|
|
return m_fsfile.write(buf, count);
|
|
@@ -514,7 +529,7 @@ public:
|
|
|
|
|
|
|
|
void flush()
|
|
void flush()
|
|
|
{
|
|
{
|
|
|
- if (!m_israw && !m_isrom)
|
|
|
|
|
|
|
+ if (!m_israw && !m_isrom && !m_isreadonly_attr)
|
|
|
{
|
|
{
|
|
|
m_fsfile.flush();
|
|
m_fsfile.flush();
|
|
|
}
|
|
}
|
|
@@ -523,6 +538,7 @@ public:
|
|
|
private:
|
|
private:
|
|
|
bool m_israw;
|
|
bool m_israw;
|
|
|
bool m_isrom;
|
|
bool m_isrom;
|
|
|
|
|
+ bool m_isreadonly_attr;
|
|
|
romdrive_hdr_t m_romhdr;
|
|
romdrive_hdr_t m_romhdr;
|
|
|
FsFile m_fsfile;
|
|
FsFile m_fsfile;
|
|
|
SdCard *m_blockdev;
|
|
SdCard *m_blockdev;
|