|
@@ -39,7 +39,7 @@ void (*SdBaseFile::dateTime_)(uint16_t* date, uint16_t* time) = 0;
|
39
|
39
|
//------------------------------------------------------------------------------
|
40
|
40
|
// add a cluster to a file
|
41
|
41
|
bool SdBaseFile::addCluster() {
|
42
|
|
- if (!vol_->allocContiguous(1, &curCluster_)) goto fail;
|
|
42
|
+ if (!vol_->allocContiguous(1, &curCluster_)) goto FAIL;
|
43
|
43
|
|
44
|
44
|
// if first cluster of file link to directory entry
|
45
|
45
|
if (firstCluster_ == 0) {
|
|
@@ -48,7 +48,7 @@ bool SdBaseFile::addCluster() {
|
48
|
48
|
}
|
49
|
49
|
return true;
|
50
|
50
|
|
51
|
|
- fail:
|
|
51
|
+ FAIL:
|
52
|
52
|
return false;
|
53
|
53
|
}
|
54
|
54
|
//------------------------------------------------------------------------------
|
|
@@ -57,10 +57,10 @@ bool SdBaseFile::addCluster() {
|
57
|
57
|
bool SdBaseFile::addDirCluster() {
|
58
|
58
|
uint32_t block;
|
59
|
59
|
// max folder size
|
60
|
|
- if (fileSize_ / sizeof(dir_t) >= 0xFFFF) goto fail;
|
|
60
|
+ if (fileSize_ / sizeof(dir_t) >= 0xFFFF) goto FAIL;
|
61
|
61
|
|
62
|
|
- if (!addCluster()) goto fail;
|
63
|
|
- if (!vol_->cacheFlush()) goto fail;
|
|
62
|
+ if (!addCluster()) goto FAIL;
|
|
63
|
+ if (!vol_->cacheFlush()) goto FAIL;
|
64
|
64
|
|
65
|
65
|
block = vol_->clusterStartBlock(curCluster_);
|
66
|
66
|
|
|
@@ -72,21 +72,21 @@ bool SdBaseFile::addDirCluster() {
|
72
|
72
|
|
73
|
73
|
// zero rest of cluster
|
74
|
74
|
for (uint8_t i = 1; i < vol_->blocksPerCluster_; i++) {
|
75
|
|
- if (!vol_->writeBlock(block + i, vol_->cacheBuffer_.data)) goto fail;
|
|
75
|
+ if (!vol_->writeBlock(block + i, vol_->cacheBuffer_.data)) goto FAIL;
|
76
|
76
|
}
|
77
|
77
|
// Increase directory file size by cluster size
|
78
|
78
|
fileSize_ += 512UL << vol_->clusterSizeShift_;
|
79
|
79
|
return true;
|
80
|
|
-fail:
|
|
80
|
+ FAIL:
|
81
|
81
|
return false;
|
82
|
82
|
}
|
83
|
83
|
//------------------------------------------------------------------------------
|
84
|
84
|
// cache a file's directory entry
|
85
|
85
|
// return pointer to cached entry or null for failure
|
86
|
86
|
dir_t* SdBaseFile::cacheDirEntry(uint8_t action) {
|
87
|
|
- if (!vol_->cacheRawBlock(dirBlock_, action)) goto fail;
|
|
87
|
+ if (!vol_->cacheRawBlock(dirBlock_, action)) goto FAIL;
|
88
|
88
|
return vol_->cache()->dir + dirIndex_;
|
89
|
|
-fail:
|
|
89
|
+ FAIL:
|
90
|
90
|
return 0;
|
91
|
91
|
}
|
92
|
92
|
//------------------------------------------------------------------------------
|
|
@@ -115,16 +115,16 @@ bool SdBaseFile::close() {
|
115
|
115
|
*/
|
116
|
116
|
bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
|
117
|
117
|
// error if no blocks
|
118
|
|
- if (firstCluster_ == 0) goto fail;
|
|
118
|
+ if (firstCluster_ == 0) goto FAIL;
|
119
|
119
|
|
120
|
120
|
for (uint32_t c = firstCluster_; ; c++) {
|
121
|
121
|
uint32_t next;
|
122
|
|
- if (!vol_->fatGet(c, &next)) goto fail;
|
|
122
|
+ if (!vol_->fatGet(c, &next)) goto FAIL;
|
123
|
123
|
|
124
|
124
|
// check for contiguous
|
125
|
125
|
if (next != (c + 1)) {
|
126
|
126
|
// error if not end of chain
|
127
|
|
- if (!vol_->isEOC(next)) goto fail;
|
|
127
|
+ if (!vol_->isEOC(next)) goto FAIL;
|
128
|
128
|
*bgnBlock = vol_->clusterStartBlock(firstCluster_);
|
129
|
129
|
*endBlock = vol_->clusterStartBlock(c)
|
130
|
130
|
+ vol_->blocksPerCluster_ - 1;
|
|
@@ -132,7 +132,7 @@ bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
|
132
|
132
|
}
|
133
|
133
|
}
|
134
|
134
|
|
135
|
|
-fail:
|
|
135
|
+ FAIL:
|
136
|
136
|
return false;
|
137
|
137
|
}
|
138
|
138
|
//------------------------------------------------------------------------------
|
|
@@ -157,8 +157,8 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
|
157
|
157
|
const char* path, uint32_t size) {
|
158
|
158
|
uint32_t count;
|
159
|
159
|
// don't allow zero length file
|
160
|
|
- if (size == 0) goto fail;
|
161
|
|
- if (!open(dirFile, path, O_CREAT | O_EXCL | O_RDWR)) goto fail;
|
|
160
|
+ if (size == 0) goto FAIL;
|
|
161
|
+ if (!open(dirFile, path, O_CREAT | O_EXCL | O_RDWR)) goto FAIL;
|
162
|
162
|
|
163
|
163
|
// calculate number of clusters needed
|
164
|
164
|
count = ((size - 1) >> (vol_->clusterSizeShift_ + 9)) + 1;
|
|
@@ -166,7 +166,7 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
|
166
|
166
|
// allocate clusters
|
167
|
167
|
if (!vol_->allocContiguous(count, &firstCluster_)) {
|
168
|
168
|
remove();
|
169
|
|
- goto fail;
|
|
169
|
+ goto FAIL;
|
170
|
170
|
}
|
171
|
171
|
fileSize_ = size;
|
172
|
172
|
|
|
@@ -174,7 +174,7 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
|
174
|
174
|
flags_ |= F_FILE_DIR_DIRTY;
|
175
|
175
|
|
176
|
176
|
return sync();
|
177
|
|
-fail:
|
|
177
|
+ FAIL:
|
178
|
178
|
return false;
|
179
|
179
|
}
|
180
|
180
|
//------------------------------------------------------------------------------
|
|
@@ -188,16 +188,16 @@ fail:
|
188
|
188
|
bool SdBaseFile::dirEntry(dir_t* dir) {
|
189
|
189
|
dir_t* p;
|
190
|
190
|
// make sure fields on SD are correct
|
191
|
|
- if (!sync()) goto fail;
|
|
191
|
+ if (!sync()) goto FAIL;
|
192
|
192
|
|
193
|
193
|
// read entry
|
194
|
194
|
p = cacheDirEntry(SdVolume::CACHE_FOR_READ);
|
195
|
|
- if (!p) goto fail;
|
|
195
|
+ if (!p) goto FAIL;
|
196
|
196
|
|
197
|
197
|
// copy to caller's struct
|
198
|
198
|
memcpy(dir, p, sizeof(dir_t));
|
199
|
199
|
return true;
|
200
|
|
-fail:
|
|
200
|
+ FAIL:
|
201
|
201
|
return false;
|
202
|
202
|
}
|
203
|
203
|
//------------------------------------------------------------------------------
|
|
@@ -395,7 +395,7 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
395
|
395
|
while (*str != '\0' && *str != '/') {
|
396
|
396
|
c = *str++;
|
397
|
397
|
if (c == '.') {
|
398
|
|
- if (n == 10) goto fail; // only one dot allowed
|
|
398
|
+ if (n == 10) goto FAIL; // only one dot allowed
|
399
|
399
|
n = 10; // max index for full 8.3 name
|
400
|
400
|
i = 8; // place for extension
|
401
|
401
|
}
|
|
@@ -403,9 +403,9 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
403
|
403
|
// illegal FAT characters
|
404
|
404
|
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
|
405
|
405
|
uint8_t b;
|
406
|
|
- while ((b = pgm_read_byte(p++))) if (b == c) goto fail;
|
|
406
|
+ while ((b = pgm_read_byte(p++))) if (b == c) goto FAIL;
|
407
|
407
|
// check size and only allow ASCII printable characters
|
408
|
|
- if (i > n || c < 0x21 || c == 0x7F) goto fail;
|
|
408
|
+ if (i > n || c < 0x21 || c == 0x7F) goto FAIL;
|
409
|
409
|
// only upper case allowed in 8.3 names - convert lower to upper
|
410
|
410
|
name[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a'));
|
411
|
411
|
}
|
|
@@ -413,7 +413,7 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
413
|
413
|
*ptr = str;
|
414
|
414
|
// must have a file name, extension is optional
|
415
|
415
|
return name[0] != ' ';
|
416
|
|
-fail:
|
|
416
|
+ FAIL:
|
417
|
417
|
return false;
|
418
|
418
|
}
|
419
|
419
|
//------------------------------------------------------------------------------
|
|
@@ -437,22 +437,22 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
|
437
|
437
|
SdBaseFile* sub = &dir1;
|
438
|
438
|
SdBaseFile* start = parent;
|
439
|
439
|
|
440
|
|
- if (!parent || isOpen()) goto fail;
|
|
440
|
+ if (!parent || isOpen()) goto FAIL;
|
441
|
441
|
|
442
|
442
|
if (*path == '/') {
|
443
|
443
|
while (*path == '/') path++;
|
444
|
444
|
if (!parent->isRoot()) {
|
445
|
|
- if (!dir2.openRoot(parent->vol_)) goto fail;
|
|
445
|
+ if (!dir2.openRoot(parent->vol_)) goto FAIL;
|
446
|
446
|
parent = &dir2;
|
447
|
447
|
}
|
448
|
448
|
}
|
449
|
449
|
while (1) {
|
450
|
|
- if (!make83Name(path, dname, &path)) goto fail;
|
|
450
|
+ if (!make83Name(path, dname, &path)) goto FAIL;
|
451
|
451
|
while (*path == '/') path++;
|
452
|
452
|
if (!*path) break;
|
453
|
453
|
if (!sub->open(parent, dname, O_READ)) {
|
454
|
454
|
if (!pFlag || !sub->mkdir(parent, dname)) {
|
455
|
|
- goto fail;
|
|
455
|
+ goto FAIL;
|
456
|
456
|
}
|
457
|
457
|
}
|
458
|
458
|
if (parent != start) parent->close();
|
|
@@ -460,7 +460,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
|
460
|
460
|
sub = parent != &dir1 ? &dir1 : &dir2;
|
461
|
461
|
}
|
462
|
462
|
return mkdir(parent, dname);
|
463
|
|
-fail:
|
|
463
|
+ FAIL:
|
464
|
464
|
return false;
|
465
|
465
|
}
|
466
|
466
|
//------------------------------------------------------------------------------
|
|
@@ -469,24 +469,24 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
469
|
469
|
dir_t d;
|
470
|
470
|
dir_t* p;
|
471
|
471
|
|
472
|
|
- if (!parent->isDir()) goto fail;
|
|
472
|
+ if (!parent->isDir()) goto FAIL;
|
473
|
473
|
|
474
|
474
|
// create a normal file
|
475
|
|
- if (!open(parent, dname, O_CREAT | O_EXCL | O_RDWR)) goto fail;
|
|
475
|
+ if (!open(parent, dname, O_CREAT | O_EXCL | O_RDWR)) goto FAIL;
|
476
|
476
|
|
477
|
477
|
// convert file to directory
|
478
|
478
|
flags_ = O_READ;
|
479
|
479
|
type_ = FAT_FILE_TYPE_SUBDIR;
|
480
|
480
|
|
481
|
481
|
// allocate and zero first cluster
|
482
|
|
- if (!addDirCluster())goto fail;
|
|
482
|
+ if (!addDirCluster())goto FAIL;
|
483
|
483
|
|
484
|
484
|
// force entry to SD
|
485
|
|
- if (!sync()) goto fail;
|
|
485
|
+ if (!sync()) goto FAIL;
|
486
|
486
|
|
487
|
487
|
// cache entry - should already be in cache due to sync() call
|
488
|
488
|
p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
489
|
|
- if (!p) goto fail;
|
|
489
|
+ if (!p) goto FAIL;
|
490
|
490
|
|
491
|
491
|
// change directory entry attribute
|
492
|
492
|
p->attributes = DIR_ATT_DIRECTORY;
|
|
@@ -498,7 +498,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
498
|
498
|
|
499
|
499
|
// cache block for '.' and '..'
|
500
|
500
|
block = vol_->clusterStartBlock(firstCluster_);
|
501
|
|
- if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto fail;
|
|
501
|
+ if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto FAIL;
|
502
|
502
|
|
503
|
503
|
// copy '.' to block
|
504
|
504
|
memcpy(&vol_->cache()->dir[0], &d, sizeof(d));
|
|
@@ -518,7 +518,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
518
|
518
|
|
519
|
519
|
// write first block
|
520
|
520
|
return vol_->cacheFlush();
|
521
|
|
-fail:
|
|
521
|
+ FAIL:
|
522
|
522
|
return false;
|
523
|
523
|
}
|
524
|
524
|
//------------------------------------------------------------------------------
|
|
@@ -592,29 +592,29 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const char* path, uint8_t oflag) {
|
592
|
592
|
SdBaseFile* parent = dirFile;
|
593
|
593
|
SdBaseFile* sub = &dir1;
|
594
|
594
|
|
595
|
|
- if (!dirFile) goto fail;
|
|
595
|
+ if (!dirFile) goto FAIL;
|
596
|
596
|
|
597
|
597
|
// error if already open
|
598
|
|
- if (isOpen()) goto fail;
|
|
598
|
+ if (isOpen()) goto FAIL;
|
599
|
599
|
|
600
|
600
|
if (*path == '/') {
|
601
|
601
|
while (*path == '/') path++;
|
602
|
602
|
if (!dirFile->isRoot()) {
|
603
|
|
- if (!dir2.openRoot(dirFile->vol_)) goto fail;
|
|
603
|
+ if (!dir2.openRoot(dirFile->vol_)) goto FAIL;
|
604
|
604
|
parent = &dir2;
|
605
|
605
|
}
|
606
|
606
|
}
|
607
|
607
|
while (1) {
|
608
|
|
- if (!make83Name(path, dname, &path)) goto fail;
|
|
608
|
+ if (!make83Name(path, dname, &path)) goto FAIL;
|
609
|
609
|
while (*path == '/') path++;
|
610
|
610
|
if (!*path) break;
|
611
|
|
- if (!sub->open(parent, dname, O_READ)) goto fail;
|
|
611
|
+ if (!sub->open(parent, dname, O_READ)) goto FAIL;
|
612
|
612
|
if (parent != dirFile) parent->close();
|
613
|
613
|
parent = sub;
|
614
|
614
|
sub = parent != &dir1 ? &dir1 : &dir2;
|
615
|
615
|
}
|
616
|
616
|
return open(parent, dname, oflag);
|
617
|
|
-fail:
|
|
617
|
+ FAIL:
|
618
|
618
|
return false;
|
619
|
619
|
}
|
620
|
620
|
//------------------------------------------------------------------------------
|
|
@@ -634,7 +634,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
634
|
634
|
while (dirFile->curPosition_ < dirFile->fileSize_) {
|
635
|
635
|
index = 0XF & (dirFile->curPosition_ >> 5);
|
636
|
636
|
p = dirFile->readDirCache();
|
637
|
|
- if (!p) goto fail;
|
|
637
|
+ if (!p) goto FAIL;
|
638
|
638
|
|
639
|
639
|
if (p->name[0] == DIR_NAME_FREE || p->name[0] == DIR_NAME_DELETED) {
|
640
|
640
|
// remember first empty slot
|
|
@@ -653,21 +653,21 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
653
|
653
|
}
|
654
|
654
|
if (fileFound) {
|
655
|
655
|
// don't open existing file if O_EXCL
|
656
|
|
- if (oflag & O_EXCL) goto fail;
|
|
656
|
+ if (oflag & O_EXCL) goto FAIL;
|
657
|
657
|
}
|
658
|
658
|
else {
|
659
|
659
|
// don't create unless O_CREAT and O_WRITE
|
660
|
|
- if (!(oflag & O_CREAT) || !(oflag & O_WRITE)) goto fail;
|
|
660
|
+ if (!(oflag & O_CREAT) || !(oflag & O_WRITE)) goto FAIL;
|
661
|
661
|
if (emptyFound) {
|
662
|
662
|
index = dirIndex_;
|
663
|
663
|
p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
664
|
|
- if (!p) goto fail;
|
|
664
|
+ if (!p) goto FAIL;
|
665
|
665
|
}
|
666
|
666
|
else {
|
667
|
|
- if (dirFile->type_ == FAT_FILE_TYPE_ROOT_FIXED) goto fail;
|
|
667
|
+ if (dirFile->type_ == FAT_FILE_TYPE_ROOT_FIXED) goto FAIL;
|
668
|
668
|
|
669
|
669
|
// add and zero cluster for dirFile - first cluster is in cache for write
|
670
|
|
- if (!dirFile->addDirCluster()) goto fail;
|
|
670
|
+ if (!dirFile->addDirCluster()) goto FAIL;
|
671
|
671
|
|
672
|
672
|
// use first entry in cluster
|
673
|
673
|
p = dirFile->vol_->cache()->dir;
|
|
@@ -692,11 +692,11 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
692
|
692
|
p->lastWriteTime = p->creationTime;
|
693
|
693
|
|
694
|
694
|
// write entry to SD
|
695
|
|
- if (!dirFile->vol_->cacheFlush()) goto fail;
|
|
695
|
+ if (!dirFile->vol_->cacheFlush()) goto FAIL;
|
696
|
696
|
}
|
697
|
697
|
// open entry in cache
|
698
|
698
|
return openCachedEntry(index, oflag);
|
699
|
|
-fail:
|
|
699
|
+ FAIL:
|
700
|
700
|
return false;
|
701
|
701
|
}
|
702
|
702
|
//------------------------------------------------------------------------------
|
|
@@ -719,26 +719,26 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
|
719
|
719
|
vol_ = dirFile->vol_;
|
720
|
720
|
|
721
|
721
|
// error if already open
|
722
|
|
- if (isOpen() || !dirFile) goto fail;
|
|
722
|
+ if (isOpen() || !dirFile) goto FAIL;
|
723
|
723
|
|
724
|
724
|
// don't open existing file if O_EXCL - user call error
|
725
|
|
- if (oflag & O_EXCL) goto fail;
|
|
725
|
+ if (oflag & O_EXCL) goto FAIL;
|
726
|
726
|
|
727
|
727
|
// seek to location of entry
|
728
|
|
- if (!dirFile->seekSet(32 * index)) goto fail;
|
|
728
|
+ if (!dirFile->seekSet(32 * index)) goto FAIL;
|
729
|
729
|
|
730
|
730
|
// read entry into cache
|
731
|
731
|
p = dirFile->readDirCache();
|
732
|
|
- if (!p) goto fail;
|
|
732
|
+ if (!p) goto FAIL;
|
733
|
733
|
|
734
|
734
|
// error if empty slot or '.' or '..'
|
735
|
735
|
if (p->name[0] == DIR_NAME_FREE ||
|
736
|
736
|
p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') {
|
737
|
|
- goto fail;
|
|
737
|
+ goto FAIL;
|
738
|
738
|
}
|
739
|
739
|
// open cached entry
|
740
|
740
|
return openCachedEntry(index & 0XF, oflag);
|
741
|
|
-fail:
|
|
741
|
+ FAIL:
|
742
|
742
|
return false;
|
743
|
743
|
}
|
744
|
744
|
//------------------------------------------------------------------------------
|
|
@@ -749,7 +749,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
749
|
749
|
|
750
|
750
|
// write or truncate is an error for a directory or read-only file
|
751
|
751
|
if (p->attributes & (DIR_ATT_READ_ONLY | DIR_ATT_DIRECTORY)) {
|
752
|
|
- if (oflag & (O_WRITE | O_TRUNC)) goto fail;
|
|
752
|
+ if (oflag & (O_WRITE | O_TRUNC)) goto FAIL;
|
753
|
753
|
}
|
754
|
754
|
// remember location of directory entry on SD
|
755
|
755
|
dirBlock_ = vol_->cacheBlockNumber();
|
|
@@ -765,11 +765,11 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
765
|
765
|
type_ = FAT_FILE_TYPE_NORMAL;
|
766
|
766
|
}
|
767
|
767
|
else if (DIR_IS_SUBDIR(p)) {
|
768
|
|
- if (!vol_->chainSize(firstCluster_, &fileSize_)) goto fail;
|
|
768
|
+ if (!vol_->chainSize(firstCluster_, &fileSize_)) goto FAIL;
|
769
|
769
|
type_ = FAT_FILE_TYPE_SUBDIR;
|
770
|
770
|
}
|
771
|
771
|
else {
|
772
|
|
- goto fail;
|
|
772
|
+ goto FAIL;
|
773
|
773
|
}
|
774
|
774
|
// save open flags for read/write
|
775
|
775
|
flags_ = oflag & F_OFLAG;
|
|
@@ -779,7 +779,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
779
|
779
|
curPosition_ = 0;
|
780
|
780
|
if ((oflag & O_TRUNC) && !truncate(0)) return false;
|
781
|
781
|
return oflag & O_AT_END ? seekEnd(0) : true;
|
782
|
|
-fail:
|
|
782
|
+ FAIL:
|
783
|
783
|
type_ = FAT_FILE_TYPE_CLOSED;
|
784
|
784
|
return false;
|
785
|
785
|
}
|
|
@@ -799,10 +799,10 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
|
799
|
799
|
dir_t* p;
|
800
|
800
|
uint8_t index;
|
801
|
801
|
|
802
|
|
- if (!dirFile) goto fail;
|
|
802
|
+ if (!dirFile) goto FAIL;
|
803
|
803
|
|
804
|
804
|
// error if already open
|
805
|
|
- if (isOpen()) goto fail;
|
|
805
|
+ if (isOpen()) goto FAIL;
|
806
|
806
|
|
807
|
807
|
vol_ = dirFile->vol_;
|
808
|
808
|
|
|
@@ -811,10 +811,10 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
|
811
|
811
|
|
812
|
812
|
// read entry into cache
|
813
|
813
|
p = dirFile->readDirCache();
|
814
|
|
- if (!p) goto fail;
|
|
814
|
+ if (!p) goto FAIL;
|
815
|
815
|
|
816
|
816
|
// done if last entry
|
817
|
|
- if (p->name[0] == DIR_NAME_FREE) goto fail;
|
|
817
|
+ if (p->name[0] == DIR_NAME_FREE) goto FAIL;
|
818
|
818
|
|
819
|
819
|
// skip empty slot or '.' or '..'
|
820
|
820
|
if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') {
|
|
@@ -825,7 +825,7 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
|
825
|
825
|
return openCachedEntry(index, oflag);
|
826
|
826
|
}
|
827
|
827
|
}
|
828
|
|
-fail:
|
|
828
|
+ FAIL:
|
829
|
829
|
return false;
|
830
|
830
|
}
|
831
|
831
|
//------------------------------------------------------------------------------
|
|
@@ -844,14 +844,14 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
|
844
|
844
|
uint32_t cluster;
|
845
|
845
|
uint32_t lbn;
|
846
|
846
|
// error if already open or dir is root or dir is not a directory
|
847
|
|
- if (isOpen() || !dir || dir->isRoot() || !dir->isDir()) goto fail;
|
|
847
|
+ if (isOpen() || !dir || dir->isRoot() || !dir->isDir()) goto FAIL;
|
848
|
848
|
vol_ = dir->vol_;
|
849
|
849
|
// position to '..'
|
850
|
|
- if (!dir->seekSet(32)) goto fail;
|
|
850
|
+ if (!dir->seekSet(32)) goto FAIL;
|
851
|
851
|
// read '..' entry
|
852
|
|
- if (dir->read(&entry, sizeof(entry)) != 32) goto fail;
|
|
852
|
+ if (dir->read(&entry, sizeof(entry)) != 32) goto FAIL;
|
853
|
853
|
// verify it is '..'
|
854
|
|
- if (entry.name[0] != '.' || entry.name[1] != '.') goto fail;
|
|
854
|
+ if (entry.name[0] != '.' || entry.name[1] != '.') goto FAIL;
|
855
|
855
|
// start cluster for '..'
|
856
|
856
|
cluster = entry.firstClusterLow;
|
857
|
857
|
cluster |= (uint32_t)entry.firstClusterHigh << 16;
|
|
@@ -860,27 +860,27 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
|
860
|
860
|
lbn = vol_->clusterStartBlock(cluster);
|
861
|
861
|
// first block of parent dir
|
862
|
862
|
if (!vol_->cacheRawBlock(lbn, SdVolume::CACHE_FOR_READ)) {
|
863
|
|
- goto fail;
|
|
863
|
+ goto FAIL;
|
864
|
864
|
}
|
865
|
865
|
p = &vol_->cacheBuffer_.dir[1];
|
866
|
866
|
// verify name for '../..'
|
867
|
|
- if (p->name[0] != '.' || p->name[1] != '.') goto fail;
|
|
867
|
+ if (p->name[0] != '.' || p->name[1] != '.') goto FAIL;
|
868
|
868
|
// '..' is pointer to first cluster of parent. open '../..' to find parent
|
869
|
869
|
if (p->firstClusterHigh == 0 && p->firstClusterLow == 0) {
|
870
|
|
- if (!file.openRoot(dir->volume())) goto fail;
|
|
870
|
+ if (!file.openRoot(dir->volume())) goto FAIL;
|
871
|
871
|
}
|
872
|
872
|
else if (!file.openCachedEntry(1, O_READ)) {
|
873
|
|
- goto fail;
|
|
873
|
+ goto FAIL;
|
874
|
874
|
}
|
875
|
875
|
// search for parent in '../..'
|
876
|
876
|
do {
|
877
|
|
- if (file.readDir(&entry, NULL) != 32) goto fail;
|
|
877
|
+ if (file.readDir(&entry, NULL) != 32) goto FAIL;
|
878
|
878
|
c = entry.firstClusterLow;
|
879
|
879
|
c |= (uint32_t)entry.firstClusterHigh << 16;
|
880
|
880
|
} while (c != cluster);
|
881
|
881
|
// open parent
|
882
|
882
|
return open(&file, file.curPosition() / 32 - 1, O_READ);
|
883
|
|
-fail:
|
|
883
|
+ FAIL:
|
884
|
884
|
return false;
|
885
|
885
|
}
|
886
|
886
|
//------------------------------------------------------------------------------
|
|
@@ -895,7 +895,7 @@ fail:
|
895
|
895
|
*/
|
896
|
896
|
bool SdBaseFile::openRoot(SdVolume* vol) {
|
897
|
897
|
// error if file is already open
|
898
|
|
- if (isOpen()) goto fail;
|
|
898
|
+ if (isOpen()) goto FAIL;
|
899
|
899
|
|
900
|
900
|
if (vol->fatType() == 16 || (FAT12_SUPPORT && vol->fatType() == 12)) {
|
901
|
901
|
type_ = FAT_FILE_TYPE_ROOT_FIXED;
|
|
@@ -905,7 +905,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
|
905
|
905
|
else if (vol->fatType() == 32) {
|
906
|
906
|
type_ = FAT_FILE_TYPE_ROOT32;
|
907
|
907
|
firstCluster_ = vol->rootDirStart();
|
908
|
|
- if (!vol->chainSize(firstCluster_, &fileSize_)) goto fail;
|
|
908
|
+ if (!vol->chainSize(firstCluster_, &fileSize_)) goto FAIL;
|
909
|
909
|
}
|
910
|
910
|
else {
|
911
|
911
|
// volume is not initialized, invalid, or FAT12 without support
|
|
@@ -923,7 +923,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
|
923
|
923
|
dirBlock_ = 0;
|
924
|
924
|
dirIndex_ = 0;
|
925
|
925
|
return true;
|
926
|
|
-fail:
|
|
926
|
+ FAIL:
|
927
|
927
|
return false;
|
928
|
928
|
}
|
929
|
929
|
//------------------------------------------------------------------------------
|
|
@@ -1055,7 +1055,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
1055
|
1055
|
uint32_t block; // raw device block number
|
1056
|
1056
|
|
1057
|
1057
|
// error if not open or write only
|
1058
|
|
- if (!isOpen() || !(flags_ & O_READ)) goto fail;
|
|
1058
|
+ if (!isOpen() || !(flags_ & O_READ)) goto FAIL;
|
1059
|
1059
|
|
1060
|
1060
|
// max bytes left in file
|
1061
|
1061
|
NOMORE(nbyte, fileSize_ - curPosition_);
|
|
@@ -1077,7 +1077,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
1077
|
1077
|
}
|
1078
|
1078
|
else {
|
1079
|
1079
|
// get next cluster from FAT
|
1080
|
|
- if (!vol_->fatGet(curCluster_, &curCluster_)) goto fail;
|
|
1080
|
+ if (!vol_->fatGet(curCluster_, &curCluster_)) goto FAIL;
|
1081
|
1081
|
}
|
1082
|
1082
|
}
|
1083
|
1083
|
block = vol_->clusterStartBlock(curCluster_) + blockOfCluster;
|
|
@@ -1089,11 +1089,11 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
1089
|
1089
|
|
1090
|
1090
|
// no buffering needed if n == 512
|
1091
|
1091
|
if (n == 512 && block != vol_->cacheBlockNumber()) {
|
1092
|
|
- if (!vol_->readBlock(block, dst)) goto fail;
|
|
1092
|
+ if (!vol_->readBlock(block, dst)) goto FAIL;
|
1093
|
1093
|
}
|
1094
|
1094
|
else {
|
1095
|
1095
|
// read block to cache and copy data to caller
|
1096
|
|
- if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_READ)) goto fail;
|
|
1096
|
+ if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_READ)) goto FAIL;
|
1097
|
1097
|
uint8_t* src = vol_->cache()->data + offset;
|
1098
|
1098
|
memcpy(dst, src, n);
|
1099
|
1099
|
}
|
|
@@ -1102,7 +1102,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
1102
|
1102
|
toRead -= n;
|
1103
|
1103
|
}
|
1104
|
1104
|
return nbyte;
|
1105
|
|
-fail:
|
|
1105
|
+ FAIL:
|
1106
|
1106
|
return -1;
|
1107
|
1107
|
}
|
1108
|
1108
|
|
|
@@ -1161,20 +1161,20 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
1161
|
1161
|
dir_t* SdBaseFile::readDirCache() {
|
1162
|
1162
|
uint8_t i;
|
1163
|
1163
|
// error if not directory
|
1164
|
|
- if (!isDir()) goto fail;
|
|
1164
|
+ if (!isDir()) goto FAIL;
|
1165
|
1165
|
|
1166
|
1166
|
// index of entry in cache
|
1167
|
1167
|
i = (curPosition_ >> 5) & 0XF;
|
1168
|
1168
|
|
1169
|
1169
|
// use read to locate and cache block
|
1170
|
|
- if (read() < 0) goto fail;
|
|
1170
|
+ if (read() < 0) goto FAIL;
|
1171
|
1171
|
|
1172
|
1172
|
// advance to next entry
|
1173
|
1173
|
curPosition_ += 31;
|
1174
|
1174
|
|
1175
|
1175
|
// return pointer to entry
|
1176
|
1176
|
return vol_->cache()->dir + i;
|
1177
|
|
-fail:
|
|
1177
|
+ FAIL:
|
1178
|
1178
|
return 0;
|
1179
|
1179
|
}
|
1180
|
1180
|
//------------------------------------------------------------------------------
|
|
@@ -1194,11 +1194,11 @@ fail:
|
1194
|
1194
|
bool SdBaseFile::remove() {
|
1195
|
1195
|
dir_t* d;
|
1196
|
1196
|
// free any clusters - will fail if read-only or directory
|
1197
|
|
- if (!truncate(0)) goto fail;
|
|
1197
|
+ if (!truncate(0)) goto FAIL;
|
1198
|
1198
|
|
1199
|
1199
|
// cache directory entry
|
1200
|
1200
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1201
|
|
- if (!d) goto fail;
|
|
1201
|
+ if (!d) goto FAIL;
|
1202
|
1202
|
|
1203
|
1203
|
// mark entry deleted
|
1204
|
1204
|
d->name[0] = DIR_NAME_DELETED;
|
|
@@ -1209,7 +1209,7 @@ bool SdBaseFile::remove() {
|
1209
|
1209
|
// write entry to SD
|
1210
|
1210
|
return vol_->cacheFlush();
|
1211
|
1211
|
return true;
|
1212
|
|
-fail:
|
|
1212
|
+ FAIL:
|
1213
|
1213
|
return false;
|
1214
|
1214
|
}
|
1215
|
1215
|
//------------------------------------------------------------------------------
|
|
@@ -1232,9 +1232,9 @@ fail:
|
1232
|
1232
|
*/
|
1233
|
1233
|
bool SdBaseFile::remove(SdBaseFile* dirFile, const char* path) {
|
1234
|
1234
|
SdBaseFile file;
|
1235
|
|
- if (!file.open(dirFile, path, O_WRITE)) goto fail;
|
|
1235
|
+ if (!file.open(dirFile, path, O_WRITE)) goto FAIL;
|
1236
|
1236
|
return file.remove();
|
1237
|
|
-fail:
|
|
1237
|
+ FAIL:
|
1238
|
1238
|
// can't set iostate - static function
|
1239
|
1239
|
return false;
|
1240
|
1240
|
}
|
|
@@ -1256,15 +1256,15 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
1256
|
1256
|
dir_t* d;
|
1257
|
1257
|
|
1258
|
1258
|
// must be an open file or subdirectory
|
1259
|
|
- if (!(isFile() || isSubDir())) goto fail;
|
|
1259
|
+ if (!(isFile() || isSubDir())) goto FAIL;
|
1260
|
1260
|
|
1261
|
1261
|
// can't move file
|
1262
|
|
- if (vol_ != dirFile->vol_) goto fail;
|
|
1262
|
+ if (vol_ != dirFile->vol_) goto FAIL;
|
1263
|
1263
|
|
1264
|
1264
|
// sync() and cache directory entry
|
1265
|
1265
|
sync();
|
1266
|
1266
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1267
|
|
- if (!d) goto fail;
|
|
1267
|
+ if (!d) goto FAIL;
|
1268
|
1268
|
|
1269
|
1269
|
// save directory entry
|
1270
|
1270
|
memcpy(&entry, d, sizeof(entry));
|
|
@@ -1295,7 +1295,7 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
1295
|
1295
|
|
1296
|
1296
|
// cache new directory entry
|
1297
|
1297
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1298
|
|
- if (!d) goto fail;
|
|
1298
|
+ if (!d) goto FAIL;
|
1299
|
1299
|
|
1300
|
1300
|
// copy all but name field to new directory entry
|
1301
|
1301
|
memcpy(&d->attributes, &entry.attributes, sizeof(entry) - sizeof(d->name));
|
|
@@ -1304,27 +1304,27 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
1304
|
1304
|
if (dirCluster) {
|
1305
|
1305
|
// get new dot dot
|
1306
|
1306
|
uint32_t block = vol_->clusterStartBlock(dirCluster);
|
1307
|
|
- if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_READ)) goto fail;
|
|
1307
|
+ if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_READ)) goto FAIL;
|
1308
|
1308
|
memcpy(&entry, &vol_->cache()->dir[1], sizeof(entry));
|
1309
|
1309
|
|
1310
|
1310
|
// free unused cluster
|
1311
|
|
- if (!vol_->freeChain(dirCluster)) goto fail;
|
|
1311
|
+ if (!vol_->freeChain(dirCluster)) goto FAIL;
|
1312
|
1312
|
|
1313
|
1313
|
// store new dot dot
|
1314
|
1314
|
block = vol_->clusterStartBlock(firstCluster_);
|
1315
|
|
- if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto fail;
|
|
1315
|
+ if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto FAIL;
|
1316
|
1316
|
memcpy(&vol_->cache()->dir[1], &entry, sizeof(entry));
|
1317
|
1317
|
}
|
1318
|
1318
|
return vol_->cacheFlush();
|
1319
|
1319
|
|
1320
|
1320
|
restore:
|
1321
|
1321
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1322
|
|
- if (!d) goto fail;
|
|
1322
|
+ if (!d) goto FAIL;
|
1323
|
1323
|
// restore entry
|
1324
|
1324
|
d->name[0] = entry.name[0];
|
1325
|
1325
|
vol_->cacheFlush();
|
1326
|
1326
|
|
1327
|
|
-fail:
|
|
1327
|
+ FAIL:
|
1328
|
1328
|
return false;
|
1329
|
1329
|
}
|
1330
|
1330
|
//------------------------------------------------------------------------------
|
|
@@ -1345,26 +1345,26 @@ fail:
|
1345
|
1345
|
*/
|
1346
|
1346
|
bool SdBaseFile::rmdir() {
|
1347
|
1347
|
// must be open subdirectory
|
1348
|
|
- if (!isSubDir()) goto fail;
|
|
1348
|
+ if (!isSubDir()) goto FAIL;
|
1349
|
1349
|
|
1350
|
1350
|
rewind();
|
1351
|
1351
|
|
1352
|
1352
|
// make sure directory is empty
|
1353
|
1353
|
while (curPosition_ < fileSize_) {
|
1354
|
1354
|
dir_t* p = readDirCache();
|
1355
|
|
- if (!p) goto fail;
|
|
1355
|
+ if (!p) goto FAIL;
|
1356
|
1356
|
// done if past last used entry
|
1357
|
1357
|
if (p->name[0] == DIR_NAME_FREE) break;
|
1358
|
1358
|
// skip empty slot, '.' or '..'
|
1359
|
1359
|
if (p->name[0] == DIR_NAME_DELETED || p->name[0] == '.') continue;
|
1360
|
1360
|
// error not empty
|
1361
|
|
- if (DIR_IS_FILE_OR_SUBDIR(p)) goto fail;
|
|
1361
|
+ if (DIR_IS_FILE_OR_SUBDIR(p)) goto FAIL;
|
1362
|
1362
|
}
|
1363
|
1363
|
// convert empty directory to normal file for remove
|
1364
|
1364
|
type_ = FAT_FILE_TYPE_NORMAL;
|
1365
|
1365
|
flags_ |= O_WRITE;
|
1366
|
1366
|
return remove();
|
1367
|
|
-fail:
|
|
1367
|
+ FAIL:
|
1368
|
1368
|
return false;
|
1369
|
1369
|
}
|
1370
|
1370
|
//------------------------------------------------------------------------------
|
|
@@ -1392,7 +1392,7 @@ bool SdBaseFile::rmRfStar() {
|
1392
|
1392
|
index = curPosition_ / 32;
|
1393
|
1393
|
|
1394
|
1394
|
dir_t* p = readDirCache();
|
1395
|
|
- if (!p) goto fail;
|
|
1395
|
+ if (!p) goto FAIL;
|
1396
|
1396
|
|
1397
|
1397
|
// done if past last entry
|
1398
|
1398
|
if (p->name[0] == DIR_NAME_FREE) break;
|
|
@@ -1403,27 +1403,27 @@ bool SdBaseFile::rmRfStar() {
|
1403
|
1403
|
// skip if part of long file name or volume label in root
|
1404
|
1404
|
if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;
|
1405
|
1405
|
|
1406
|
|
- if (!f.open(this, index, O_READ)) goto fail;
|
|
1406
|
+ if (!f.open(this, index, O_READ)) goto FAIL;
|
1407
|
1407
|
if (f.isSubDir()) {
|
1408
|
1408
|
// recursively delete
|
1409
|
|
- if (!f.rmRfStar()) goto fail;
|
|
1409
|
+ if (!f.rmRfStar()) goto FAIL;
|
1410
|
1410
|
}
|
1411
|
1411
|
else {
|
1412
|
1412
|
// ignore read-only
|
1413
|
1413
|
f.flags_ |= O_WRITE;
|
1414
|
|
- if (!f.remove()) goto fail;
|
|
1414
|
+ if (!f.remove()) goto FAIL;
|
1415
|
1415
|
}
|
1416
|
1416
|
// position to next entry if required
|
1417
|
1417
|
if (curPosition_ != (32 * (index + 1))) {
|
1418
|
|
- if (!seekSet(32 * (index + 1))) goto fail;
|
|
1418
|
+ if (!seekSet(32 * (index + 1))) goto FAIL;
|
1419
|
1419
|
}
|
1420
|
1420
|
}
|
1421
|
1421
|
// don't try to delete root
|
1422
|
1422
|
if (!isRoot()) {
|
1423
|
|
- if (!rmdir()) goto fail;
|
|
1423
|
+ if (!rmdir()) goto FAIL;
|
1424
|
1424
|
}
|
1425
|
1425
|
return true;
|
1426
|
|
-fail:
|
|
1426
|
+ FAIL:
|
1427
|
1427
|
return false;
|
1428
|
1428
|
}
|
1429
|
1429
|
//------------------------------------------------------------------------------
|
|
@@ -1451,7 +1451,7 @@ bool SdBaseFile::seekSet(uint32_t pos) {
|
1451
|
1451
|
uint32_t nCur;
|
1452
|
1452
|
uint32_t nNew;
|
1453
|
1453
|
// error if file not open or seek past end of file
|
1454
|
|
- if (!isOpen() || pos > fileSize_) goto fail;
|
|
1454
|
+ if (!isOpen() || pos > fileSize_) goto FAIL;
|
1455
|
1455
|
|
1456
|
1456
|
if (type_ == FAT_FILE_TYPE_ROOT_FIXED) {
|
1457
|
1457
|
curPosition_ = pos;
|
|
@@ -1476,14 +1476,14 @@ bool SdBaseFile::seekSet(uint32_t pos) {
|
1476
|
1476
|
nNew -= nCur;
|
1477
|
1477
|
}
|
1478
|
1478
|
while (nNew--) {
|
1479
|
|
- if (!vol_->fatGet(curCluster_, &curCluster_)) goto fail;
|
|
1479
|
+ if (!vol_->fatGet(curCluster_, &curCluster_)) goto FAIL;
|
1480
|
1480
|
}
|
1481
|
1481
|
curPosition_ = pos;
|
1482
|
1482
|
|
1483
|
1483
|
done:
|
1484
|
1484
|
return true;
|
1485
|
1485
|
|
1486
|
|
-fail:
|
|
1486
|
+ FAIL:
|
1487
|
1487
|
return false;
|
1488
|
1488
|
}
|
1489
|
1489
|
//------------------------------------------------------------------------------
|
|
@@ -1502,12 +1502,12 @@ void SdBaseFile::setpos(filepos_t* pos) {
|
1502
|
1502
|
*/
|
1503
|
1503
|
bool SdBaseFile::sync() {
|
1504
|
1504
|
// only allow open files and directories
|
1505
|
|
- if (!isOpen()) goto fail;
|
|
1505
|
+ if (!isOpen()) goto FAIL;
|
1506
|
1506
|
|
1507
|
1507
|
if (flags_ & F_FILE_DIR_DIRTY) {
|
1508
|
1508
|
dir_t* d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1509
|
1509
|
// check for deleted by another open file object
|
1510
|
|
- if (!d || d->name[0] == DIR_NAME_DELETED) goto fail;
|
|
1510
|
+ if (!d || d->name[0] == DIR_NAME_DELETED) goto FAIL;
|
1511
|
1511
|
|
1512
|
1512
|
// do not set filesize for dir files
|
1513
|
1513
|
if (!isDir()) d->fileSize = fileSize_;
|
|
@@ -1526,7 +1526,7 @@ bool SdBaseFile::sync() {
|
1526
|
1526
|
}
|
1527
|
1527
|
return vol_->cacheFlush();
|
1528
|
1528
|
|
1529
|
|
-fail:
|
|
1529
|
+ FAIL:
|
1530
|
1530
|
writeError = true;
|
1531
|
1531
|
return false;
|
1532
|
1532
|
}
|
|
@@ -1547,13 +1547,13 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
|
1547
|
1547
|
dir_t dir;
|
1548
|
1548
|
|
1549
|
1549
|
// get timestamps
|
1550
|
|
- if (!file->dirEntry(&dir)) goto fail;
|
|
1550
|
+ if (!file->dirEntry(&dir)) goto FAIL;
|
1551
|
1551
|
|
1552
|
1552
|
// update directory fields
|
1553
|
|
- if (!sync()) goto fail;
|
|
1553
|
+ if (!sync()) goto FAIL;
|
1554
|
1554
|
|
1555
|
1555
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1556
|
|
- if (!d) goto fail;
|
|
1556
|
+ if (!d) goto FAIL;
|
1557
|
1557
|
|
1558
|
1558
|
// copy timestamps
|
1559
|
1559
|
d->lastAccessDate = dir.lastAccessDate;
|
|
@@ -1566,7 +1566,7 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
|
1566
|
1566
|
// write back entry
|
1567
|
1567
|
return vol_->cacheFlush();
|
1568
|
1568
|
|
1569
|
|
-fail:
|
|
1569
|
+ FAIL:
|
1570
|
1570
|
return false;
|
1571
|
1571
|
}
|
1572
|
1572
|
//------------------------------------------------------------------------------
|
|
@@ -1619,13 +1619,13 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
1619
|
1619
|
|| hour > 23
|
1620
|
1620
|
|| minute > 59
|
1621
|
1621
|
|| second > 59) {
|
1622
|
|
- goto fail;
|
|
1622
|
+ goto FAIL;
|
1623
|
1623
|
}
|
1624
|
1624
|
// update directory entry
|
1625
|
|
- if (!sync()) goto fail;
|
|
1625
|
+ if (!sync()) goto FAIL;
|
1626
|
1626
|
|
1627
|
1627
|
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
1628
|
|
- if (!d) goto fail;
|
|
1628
|
+ if (!d) goto FAIL;
|
1629
|
1629
|
|
1630
|
1630
|
dirDate = FAT_DATE(year, month, day);
|
1631
|
1631
|
dirTime = FAT_TIME(hour, minute, second);
|
|
@@ -1643,7 +1643,7 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
1643
|
1643
|
d->lastWriteTime = dirTime;
|
1644
|
1644
|
}
|
1645
|
1645
|
return vol_->cacheFlush();
|
1646
|
|
-fail:
|
|
1646
|
+ FAIL:
|
1647
|
1647
|
return false;
|
1648
|
1648
|
}
|
1649
|
1649
|
//------------------------------------------------------------------------------
|
|
@@ -1661,10 +1661,10 @@ fail:
|
1661
|
1661
|
bool SdBaseFile::truncate(uint32_t length) {
|
1662
|
1662
|
uint32_t newPos;
|
1663
|
1663
|
// error if not a normal file or read-only
|
1664
|
|
- if (!isFile() || !(flags_ & O_WRITE)) goto fail;
|
|
1664
|
+ if (!isFile() || !(flags_ & O_WRITE)) goto FAIL;
|
1665
|
1665
|
|
1666
|
1666
|
// error if length is greater than current size
|
1667
|
|
- if (length > fileSize_) goto fail;
|
|
1667
|
+ if (length > fileSize_) goto FAIL;
|
1668
|
1668
|
|
1669
|
1669
|
// fileSize and length are zero - nothing to do
|
1670
|
1670
|
if (fileSize_ == 0) return true;
|
|
@@ -1673,23 +1673,23 @@ bool SdBaseFile::truncate(uint32_t length) {
|
1673
|
1673
|
newPos = curPosition_ > length ? length : curPosition_;
|
1674
|
1674
|
|
1675
|
1675
|
// position to last cluster in truncated file
|
1676
|
|
- if (!seekSet(length)) goto fail;
|
|
1676
|
+ if (!seekSet(length)) goto FAIL;
|
1677
|
1677
|
|
1678
|
1678
|
if (length == 0) {
|
1679
|
1679
|
// free all clusters
|
1680
|
|
- if (!vol_->freeChain(firstCluster_)) goto fail;
|
|
1680
|
+ if (!vol_->freeChain(firstCluster_)) goto FAIL;
|
1681
|
1681
|
firstCluster_ = 0;
|
1682
|
1682
|
}
|
1683
|
1683
|
else {
|
1684
|
1684
|
uint32_t toFree;
|
1685
|
|
- if (!vol_->fatGet(curCluster_, &toFree)) goto fail;
|
|
1685
|
+ if (!vol_->fatGet(curCluster_, &toFree)) goto FAIL;
|
1686
|
1686
|
|
1687
|
1687
|
if (!vol_->isEOC(toFree)) {
|
1688
|
1688
|
// free extra clusters
|
1689
|
|
- if (!vol_->freeChain(toFree)) goto fail;
|
|
1689
|
+ if (!vol_->freeChain(toFree)) goto FAIL;
|
1690
|
1690
|
|
1691
|
1691
|
// current cluster is end of chain
|
1692
|
|
- if (!vol_->fatPutEOC(curCluster_)) goto fail;
|
|
1692
|
+ if (!vol_->fatPutEOC(curCluster_)) goto FAIL;
|
1693
|
1693
|
}
|
1694
|
1694
|
}
|
1695
|
1695
|
fileSize_ = length;
|
|
@@ -1697,12 +1697,12 @@ bool SdBaseFile::truncate(uint32_t length) {
|
1697
|
1697
|
// need to update directory entry
|
1698
|
1698
|
flags_ |= F_FILE_DIR_DIRTY;
|
1699
|
1699
|
|
1700
|
|
- if (!sync()) goto fail;
|
|
1700
|
+ if (!sync()) goto FAIL;
|
1701
|
1701
|
|
1702
|
1702
|
// set file to correct position
|
1703
|
1703
|
return seekSet(newPos);
|
1704
|
1704
|
|
1705
|
|
-fail:
|
|
1705
|
+ FAIL:
|
1706
|
1706
|
return false;
|
1707
|
1707
|
}
|
1708
|
1708
|
//------------------------------------------------------------------------------
|
|
@@ -1729,11 +1729,11 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
1729
|
1729
|
uint16_t nToWrite = nbyte;
|
1730
|
1730
|
|
1731
|
1731
|
// error if not a normal file or is read-only
|
1732
|
|
- if (!isFile() || !(flags_ & O_WRITE)) goto fail;
|
|
1732
|
+ if (!isFile() || !(flags_ & O_WRITE)) goto FAIL;
|
1733
|
1733
|
|
1734
|
1734
|
// seek to end of file if append flag
|
1735
|
1735
|
if ((flags_ & O_APPEND) && curPosition_ != fileSize_) {
|
1736
|
|
- if (!seekEnd()) goto fail;
|
|
1736
|
+ if (!seekEnd()) goto FAIL;
|
1737
|
1737
|
}
|
1738
|
1738
|
|
1739
|
1739
|
while (nToWrite > 0) {
|
|
@@ -1744,7 +1744,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
1744
|
1744
|
if (curCluster_ == 0) {
|
1745
|
1745
|
if (firstCluster_ == 0) {
|
1746
|
1746
|
// allocate first cluster of file
|
1747
|
|
- if (!addCluster()) goto fail;
|
|
1747
|
+ if (!addCluster()) goto FAIL;
|
1748
|
1748
|
}
|
1749
|
1749
|
else {
|
1750
|
1750
|
curCluster_ = firstCluster_;
|
|
@@ -1752,10 +1752,10 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
1752
|
1752
|
}
|
1753
|
1753
|
else {
|
1754
|
1754
|
uint32_t next;
|
1755
|
|
- if (!vol_->fatGet(curCluster_, &next)) goto fail;
|
|
1755
|
+ if (!vol_->fatGet(curCluster_, &next)) goto FAIL;
|
1756
|
1756
|
if (vol_->isEOC(next)) {
|
1757
|
1757
|
// add cluster if at end of chain
|
1758
|
|
- if (!addCluster()) goto fail;
|
|
1758
|
+ if (!addCluster()) goto FAIL;
|
1759
|
1759
|
}
|
1760
|
1760
|
else {
|
1761
|
1761
|
curCluster_ = next;
|
|
@@ -1776,18 +1776,18 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
1776
|
1776
|
// invalidate cache if block is in cache
|
1777
|
1777
|
vol_->cacheSetBlockNumber(0xFFFFFFFF, false);
|
1778
|
1778
|
}
|
1779
|
|
- if (!vol_->writeBlock(block, src)) goto fail;
|
|
1779
|
+ if (!vol_->writeBlock(block, src)) goto FAIL;
|
1780
|
1780
|
}
|
1781
|
1781
|
else {
|
1782
|
1782
|
if (blockOffset == 0 && curPosition_ >= fileSize_) {
|
1783
|
1783
|
// start of new block don't need to read into cache
|
1784
|
|
- if (!vol_->cacheFlush()) goto fail;
|
|
1784
|
+ if (!vol_->cacheFlush()) goto FAIL;
|
1785
|
1785
|
// set cache dirty and SD address of block
|
1786
|
1786
|
vol_->cacheSetBlockNumber(block, true);
|
1787
|
1787
|
}
|
1788
|
1788
|
else {
|
1789
|
1789
|
// rewrite part of block
|
1790
|
|
- if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto fail;
|
|
1790
|
+ if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto FAIL;
|
1791
|
1791
|
}
|
1792
|
1792
|
uint8_t* dst = vol_->cache()->data + blockOffset;
|
1793
|
1793
|
memcpy(dst, src, n);
|
|
@@ -1807,11 +1807,11 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
1807
|
1807
|
}
|
1808
|
1808
|
|
1809
|
1809
|
if (flags_ & O_SYNC) {
|
1810
|
|
- if (!sync()) goto fail;
|
|
1810
|
+ if (!sync()) goto FAIL;
|
1811
|
1811
|
}
|
1812
|
1812
|
return nbyte;
|
1813
|
1813
|
|
1814
|
|
-fail:
|
|
1814
|
+ FAIL:
|
1815
|
1815
|
// return for write error
|
1816
|
1816
|
writeError = true;
|
1817
|
1817
|
return -1;
|