|
@@ -47,6 +47,8 @@ void (*SdBaseFile::dateTime_)(uint16_t* date, uint16_t* time) = 0;
|
47
|
47
|
|
48
|
48
|
// add a cluster to a file
|
49
|
49
|
bool SdBaseFile::addCluster() {
|
|
50
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
51
|
+
|
50
|
52
|
if (!vol_->allocContiguous(1, &curCluster_)) return false;
|
51
|
53
|
|
52
|
54
|
// if first cluster of file link to directory entry
|
|
@@ -60,6 +62,8 @@ bool SdBaseFile::addCluster() {
|
60
|
62
|
// Add a cluster to a directory file and zero the cluster.
|
61
|
63
|
// return with first block of cluster in the cache
|
62
|
64
|
bool SdBaseFile::addDirCluster() {
|
|
65
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
66
|
+
|
63
|
67
|
uint32_t block;
|
64
|
68
|
// max folder size
|
65
|
69
|
if (fileSize_ / sizeof(dir_t) >= 0xFFFF) return false;
|
|
@@ -153,6 +157,8 @@ bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
|
153
|
157
|
*
|
154
|
158
|
*/
|
155
|
159
|
bool SdBaseFile::createContiguous(SdBaseFile* dirFile, const char* path, uint32_t size) {
|
|
160
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
161
|
+
|
156
|
162
|
uint32_t count;
|
157
|
163
|
// don't allow zero length file
|
158
|
164
|
if (size == 0) return false;
|
|
@@ -419,6 +425,8 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
419
|
425
|
* directory, \a path is invalid or already exists in \a parent.
|
420
|
426
|
*/
|
421
|
427
|
bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
|
|
428
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
429
|
+
|
422
|
430
|
uint8_t dname[11];
|
423
|
431
|
SdBaseFile dir1, dir2;
|
424
|
432
|
SdBaseFile* sub = &dir1;
|
|
@@ -449,6 +457,8 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
|
449
|
457
|
}
|
450
|
458
|
|
451
|
459
|
bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
|
460
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
461
|
+
|
452
|
462
|
uint32_t block;
|
453
|
463
|
dir_t d;
|
454
|
464
|
dir_t* p;
|
|
@@ -632,7 +642,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t ofla
|
632
|
642
|
}
|
633
|
643
|
else {
|
634
|
644
|
// don't create unless O_CREAT and O_WRITE
|
635
|
|
- if (!(oflag & O_CREAT) || !(oflag & O_WRITE)) return false;
|
|
645
|
+ if ((oflag & (O_CREAT | O_WRITE)) != (O_CREAT | O_WRITE)) return false;
|
636
|
646
|
if (emptyFound) {
|
637
|
647
|
index = dirIndex_;
|
638
|
648
|
p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
|
@@ -716,8 +726,14 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
|
716
|
726
|
|
717
|
727
|
// open a cached directory entry. Assumes vol_ is initialized
|
718
|
728
|
bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
|
729
|
+ dir_t* p;
|
|
730
|
+
|
|
731
|
+ #if ENABLED(SDCARD_READONLY)
|
|
732
|
+ if (oflag & (O_WRITE | O_CREAT | O_TRUNC)) goto FAIL;
|
|
733
|
+ #endif
|
|
734
|
+
|
719
|
735
|
// location of entry in cache
|
720
|
|
- dir_t* p = &vol_->cache()->dir[dirIndex];
|
|
736
|
+ p = &vol_->cache()->dir[dirIndex];
|
721
|
737
|
|
722
|
738
|
// write or truncate is an error for a directory or read-only file
|
723
|
739
|
if (p->attributes & (DIR_ATT_READ_ONLY | DIR_ATT_DIRECTORY)) {
|
|
@@ -1135,6 +1151,8 @@ dir_t* SdBaseFile::readDirCache() {
|
1135
|
1151
|
* or an I/O error occurred.
|
1136
|
1152
|
*/
|
1137
|
1153
|
bool SdBaseFile::remove() {
|
|
1154
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1155
|
+
|
1138
|
1156
|
dir_t* d;
|
1139
|
1157
|
// free any clusters - will fail if read-only or directory
|
1140
|
1158
|
if (!truncate(0)) return false;
|
|
@@ -1172,6 +1190,8 @@ bool SdBaseFile::remove() {
|
1172
|
1190
|
* or an I/O error occurred.
|
1173
|
1191
|
*/
|
1174
|
1192
|
bool SdBaseFile::remove(SdBaseFile* dirFile, const char* path) {
|
|
1193
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1194
|
+
|
1175
|
1195
|
SdBaseFile file;
|
1176
|
1196
|
return file.open(dirFile, path, O_WRITE) ? file.remove() : false;
|
1177
|
1197
|
}
|
|
@@ -1187,6 +1207,8 @@ bool SdBaseFile::remove(SdBaseFile* dirFile, const char* path) {
|
1187
|
1207
|
* file, newPath is invalid or already exists, or an I/O error occurs.
|
1188
|
1208
|
*/
|
1189
|
1209
|
bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
|
1210
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1211
|
+
|
1190
|
1212
|
dir_t entry;
|
1191
|
1213
|
uint32_t dirCluster = 0;
|
1192
|
1214
|
SdBaseFile file;
|
|
@@ -1279,6 +1301,8 @@ restore:
|
1279
|
1301
|
* directory, is not empty, or an I/O error occurred.
|
1280
|
1302
|
*/
|
1281
|
1303
|
bool SdBaseFile::rmdir() {
|
|
1304
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1305
|
+
|
1282
|
1306
|
// must be open subdirectory
|
1283
|
1307
|
if (!isSubDir()) return false;
|
1284
|
1308
|
|
|
@@ -1317,6 +1341,8 @@ bool SdBaseFile::rmdir() {
|
1317
|
1341
|
* \return true for success, false for failure.
|
1318
|
1342
|
*/
|
1319
|
1343
|
bool SdBaseFile::rmRfStar() {
|
|
1344
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1345
|
+
|
1320
|
1346
|
uint32_t index;
|
1321
|
1347
|
SdBaseFile f;
|
1322
|
1348
|
rewind();
|
|
@@ -1424,7 +1450,7 @@ void SdBaseFile::setpos(filepos_t* pos) {
|
1424
|
1450
|
*/
|
1425
|
1451
|
bool SdBaseFile::sync() {
|
1426
|
1452
|
// only allow open files and directories
|
1427
|
|
- if (!isOpen()) goto FAIL;
|
|
1453
|
+ if (ENABLED(SDCARD_READONLY) || !isOpen()) goto FAIL;
|
1428
|
1454
|
|
1429
|
1455
|
if (flags_ & F_FILE_DIR_DIRTY) {
|
1430
|
1456
|
dir_t* d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
|
@@ -1524,6 +1550,8 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
|
1524
|
1550
|
*/
|
1525
|
1551
|
bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
1526
|
1552
|
uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) {
|
|
1553
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1554
|
+
|
1527
|
1555
|
uint16_t dirDate, dirTime;
|
1528
|
1556
|
dir_t* d;
|
1529
|
1557
|
|
|
@@ -1575,6 +1603,8 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
1575
|
1603
|
* \a length is greater than the current file size or an I/O error occurs.
|
1576
|
1604
|
*/
|
1577
|
1605
|
bool SdBaseFile::truncate(uint32_t length) {
|
|
1606
|
+ if (ENABLED(SDCARD_READONLY)) return false;
|
|
1607
|
+
|
1578
|
1608
|
uint32_t newPos;
|
1579
|
1609
|
// error if not a normal file or read-only
|
1580
|
1610
|
if (!isFile() || !(flags_ & O_WRITE)) return false;
|
|
@@ -1636,6 +1666,10 @@ bool SdBaseFile::truncate(uint32_t length) {
|
1636
|
1666
|
*
|
1637
|
1667
|
*/
|
1638
|
1668
|
int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
|
1669
|
+ #if ENABLED(SDCARD_READONLY)
|
|
1670
|
+ writeError = true; return -1;
|
|
1671
|
+ #endif
|
|
1672
|
+
|
1639
|
1673
|
// convert void* to uint8_t* - must be before goto statements
|
1640
|
1674
|
const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);
|
1641
|
1675
|
|