Bläddra i källkod

Patch goto labels for consistency

Scott Lahteine 7 år sedan
förälder
incheckning
8fd58cd6dc
3 ändrade filer med 220 tillägg och 220 borttagningar
  1. 38
    38
      Marlin/Sd2Card.cpp
  2. 144
    144
      Marlin/SdBaseFile.cpp
  3. 38
    38
      Marlin/SdVolume.cpp

+ 38
- 38
Marlin/Sd2Card.cpp Visa fil

@@ -244,7 +244,7 @@ void Sd2Card::chipSelectLow() {
244 244
  */
245 245
 bool Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
246 246
   csd_t csd;
247
-  if (!readCSD(&csd)) goto fail;
247
+  if (!readCSD(&csd)) goto FAIL;
248 248
   // check for single block erase
249 249
   if (!csd.v1.erase_blk_en) {
250 250
     // erase size mask
@@ -252,7 +252,7 @@ bool Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
252 252
     if ((firstBlock & m) != 0 || ((lastBlock + 1) & m) != 0) {
253 253
       // error card can't erase specified area
254 254
       error(SD_CARD_ERROR_ERASE_SINGLE_BLOCK);
255
-      goto fail;
255
+      goto FAIL;
256 256
     }
257 257
   }
258 258
   if (type_ != SD_CARD_TYPE_SDHC) {
@@ -263,15 +263,15 @@ bool Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
263 263
       || cardCommand(CMD33, lastBlock)
264 264
       || cardCommand(CMD38, 0)) {
265 265
     error(SD_CARD_ERROR_ERASE);
266
-    goto fail;
266
+    goto FAIL;
267 267
   }
268 268
   if (!waitNotBusy(SD_ERASE_TIMEOUT)) {
269 269
     error(SD_CARD_ERROR_ERASE_TIMEOUT);
270
-    goto fail;
270
+    goto FAIL;
271 271
   }
272 272
   chipSelectHigh();
273 273
   return true;
274
-fail:
274
+  FAIL:
275 275
   chipSelectHigh();
276 276
   return false;
277 277
 }
@@ -335,7 +335,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
335 335
   while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
336 336
     if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
337 337
       error(SD_CARD_ERROR_CMD0);
338
-      goto fail;
338
+      goto FAIL;
339 339
     }
340 340
   }
341 341
   // check SD version
@@ -347,7 +347,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
347 347
     for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
348 348
     if (status_ != 0xAA) {
349 349
       error(SD_CARD_ERROR_CMD8);
350
-      goto fail;
350
+      goto FAIL;
351 351
     }
352 352
     type(SD_CARD_TYPE_SD2);
353 353
   }
@@ -358,14 +358,14 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
358 358
     // check for timeout
359 359
     if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
360 360
       error(SD_CARD_ERROR_ACMD41);
361
-      goto fail;
361
+      goto FAIL;
362 362
     }
363 363
   }
364 364
   // if SD2 read OCR register to check for SDHC card
365 365
   if (type() == SD_CARD_TYPE_SD2) {
366 366
     if (cardCommand(CMD58, 0)) {
367 367
       error(SD_CARD_ERROR_CMD58);
368
-      goto fail;
368
+      goto FAIL;
369 369
     }
370 370
     if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
371 371
     // discard rest of ocr - contains allowed voltage range
@@ -380,7 +380,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
380 380
     return true;
381 381
   #endif  // SOFTWARE_SPI
382 382
 
383
-fail:
383
+  FAIL:
384 384
   chipSelectHigh();
385 385
   return false;
386 386
 }
@@ -486,12 +486,12 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
486 486
   while ((status_ = spiRec()) == 0XFF) {
487 487
     if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
488 488
       error(SD_CARD_ERROR_READ_TIMEOUT);
489
-      goto fail;
489
+      goto FAIL;
490 490
     }
491 491
   }
492 492
   if (status_ != DATA_START_BLOCK) {
493 493
     error(SD_CARD_ERROR_READ);
494
-    goto fail;
494
+    goto FAIL;
495 495
   }
496 496
   // transfer data
497 497
   spiRead(dst, count);
@@ -503,7 +503,7 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
503 503
     recvCrc |= spiRec();
504 504
     if (calcCrc != recvCrc) {
505 505
       error(SD_CARD_ERROR_CRC);
506
-      goto fail;
506
+      goto FAIL;
507 507
     }
508 508
   }
509 509
 #else
@@ -515,7 +515,7 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
515 515
   // Send an additional dummy byte, required by Toshiba Flash Air SD Card
516 516
   spiSend(0XFF);
517 517
   return true;
518
-fail:
518
+  FAIL:
519 519
   chipSelectHigh();
520 520
   // Send an additional dummy byte, required by Toshiba Flash Air SD Card
521 521
   spiSend(0XFF);
@@ -527,10 +527,10 @@ bool Sd2Card::readRegister(uint8_t cmd, void* buf) {
527 527
   uint8_t* dst = reinterpret_cast<uint8_t*>(buf);
528 528
   if (cardCommand(cmd, 0)) {
529 529
     error(SD_CARD_ERROR_READ_REG);
530
-    goto fail;
530
+    goto FAIL;
531 531
   }
532 532
   return readData(dst, 16);
533
-fail:
533
+  FAIL:
534 534
   chipSelectHigh();
535 535
   return false;
536 536
 }
@@ -549,11 +549,11 @@ bool Sd2Card::readStart(uint32_t blockNumber) {
549 549
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
550 550
   if (cardCommand(CMD18, blockNumber)) {
551 551
     error(SD_CARD_ERROR_CMD18);
552
-    goto fail;
552
+    goto FAIL;
553 553
   }
554 554
   chipSelectHigh();
555 555
   return true;
556
-fail:
556
+  FAIL:
557 557
   chipSelectHigh();
558 558
   return false;
559 559
 }
@@ -567,11 +567,11 @@ bool Sd2Card::readStop() {
567 567
   chipSelectLow();
568 568
   if (cardCommand(CMD12, 0)) {
569 569
     error(SD_CARD_ERROR_CMD12);
570
-    goto fail;
570
+    goto FAIL;
571 571
   }
572 572
   chipSelectHigh();
573 573
   return true;
574
-fail:
574
+  FAIL:
575 575
   chipSelectHigh();
576 576
   return false;
577 577
 }
@@ -601,10 +601,10 @@ bool Sd2Card::setSckRate(uint8_t sckRateID) {
601 601
 bool Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
602 602
   uint16_t t0 = millis();
603 603
   while (spiRec() != 0XFF) {
604
-    if (((uint16_t)millis() - t0) >= timeoutMillis) goto fail;
604
+    if (((uint16_t)millis() - t0) >= timeoutMillis) goto FAIL;
605 605
   }
606 606
   return true;
607
-fail:
607
+  FAIL:
608 608
   return false;
609 609
 }
610 610
 //------------------------------------------------------------------------------
@@ -621,23 +621,23 @@ bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
621 621
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
622 622
   if (cardCommand(CMD24, blockNumber)) {
623 623
     error(SD_CARD_ERROR_CMD24);
624
-    goto fail;
624
+    goto FAIL;
625 625
   }
626
-  if (!writeData(DATA_START_BLOCK, src)) goto fail;
626
+  if (!writeData(DATA_START_BLOCK, src)) goto FAIL;
627 627
 
628 628
   // wait for flash programming to complete
629 629
   if (!waitNotBusy(SD_WRITE_TIMEOUT)) {
630 630
     error(SD_CARD_ERROR_WRITE_TIMEOUT);
631
-    goto fail;
631
+    goto FAIL;
632 632
   }
633 633
   // response is r2 so get and check two bytes for nonzero
634 634
   if (cardCommand(CMD13, 0) || spiRec()) {
635 635
     error(SD_CARD_ERROR_WRITE_PROGRAMMING);
636
-    goto fail;
636
+    goto FAIL;
637 637
   }
638 638
   chipSelectHigh();
639 639
   return true;
640
-fail:
640
+  FAIL:
641 641
   chipSelectHigh();
642 642
   return false;
643 643
 }
@@ -650,11 +650,11 @@ fail:
650 650
 bool Sd2Card::writeData(const uint8_t* src) {
651 651
   chipSelectLow();
652 652
   // wait for previous write to finish
653
-  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
654
-  if (!writeData(WRITE_MULTIPLE_TOKEN, src)) goto fail;
653
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto FAIL;
654
+  if (!writeData(WRITE_MULTIPLE_TOKEN, src)) goto FAIL;
655 655
   chipSelectHigh();
656 656
   return true;
657
-fail:
657
+  FAIL:
658 658
   error(SD_CARD_ERROR_WRITE_MULTIPLE);
659 659
   chipSelectHigh();
660 660
   return false;
@@ -670,10 +670,10 @@ bool Sd2Card::writeData(uint8_t token, const uint8_t* src) {
670 670
   status_ = spiRec();
671 671
   if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
672 672
     error(SD_CARD_ERROR_WRITE);
673
-    goto fail;
673
+    goto FAIL;
674 674
   }
675 675
   return true;
676
-fail:
676
+  FAIL:
677 677
   chipSelectHigh();
678 678
   return false;
679 679
 }
@@ -693,17 +693,17 @@ bool Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
693 693
   // send pre-erase count
694 694
   if (cardAcmd(ACMD23, eraseCount)) {
695 695
     error(SD_CARD_ERROR_ACMD23);
696
-    goto fail;
696
+    goto FAIL;
697 697
   }
698 698
   // use address if not SDHC card
699 699
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
700 700
   if (cardCommand(CMD25, blockNumber)) {
701 701
     error(SD_CARD_ERROR_CMD25);
702
-    goto fail;
702
+    goto FAIL;
703 703
   }
704 704
   chipSelectHigh();
705 705
   return true;
706
-fail:
706
+  FAIL:
707 707
   chipSelectHigh();
708 708
   return false;
709 709
 }
@@ -715,12 +715,12 @@ fail:
715 715
  */
716 716
 bool Sd2Card::writeStop() {
717 717
   chipSelectLow();
718
-  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
718
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto FAIL;
719 719
   spiSend(STOP_TRAN_TOKEN);
720
-  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
720
+  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto FAIL;
721 721
   chipSelectHigh();
722 722
   return true;
723
-fail:
723
+  FAIL:
724 724
   error(SD_CARD_ERROR_STOP_TRAN);
725 725
   chipSelectHigh();
726 726
   return false;

+ 144
- 144
Marlin/SdBaseFile.cpp Visa fil

@@ -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;

+ 38
- 38
Marlin/SdVolume.cpp Visa fil

@@ -73,14 +73,14 @@ bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
73 73
   // search the FAT for free clusters
74 74
   for (uint32_t n = 0;; n++, endCluster++) {
75 75
     // can't find space checked all clusters
76
-    if (n >= clusterCount_) goto fail;
76
+    if (n >= clusterCount_) goto FAIL;
77 77
 
78 78
     // past end - start from beginning of FAT
79 79
     if (endCluster > fatEnd) {
80 80
       bgnCluster = endCluster = 2;
81 81
     }
82 82
     uint32_t f;
83
-    if (!fatGet(endCluster, &f)) goto fail;
83
+    if (!fatGet(endCluster, &f)) goto FAIL;
84 84
 
85 85
     if (f != 0) {
86 86
       // cluster in use try next cluster as bgnCluster
@@ -92,16 +92,16 @@ bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
92 92
     }
93 93
   }
94 94
   // mark end of chain
95
-  if (!fatPutEOC(endCluster)) goto fail;
95
+  if (!fatPutEOC(endCluster)) goto FAIL;
96 96
 
97 97
   // link clusters
98 98
   while (endCluster > bgnCluster) {
99
-    if (!fatPut(endCluster - 1, endCluster)) goto fail;
99
+    if (!fatPut(endCluster - 1, endCluster)) goto FAIL;
100 100
     endCluster--;
101 101
   }
102 102
   if (*curCluster != 0) {
103 103
     // connect chains
104
-    if (!fatPut(*curCluster, bgnCluster)) goto fail;
104
+    if (!fatPut(*curCluster, bgnCluster)) goto FAIL;
105 105
   }
106 106
   // return first cluster number to caller
107 107
   *curCluster = bgnCluster;
@@ -110,38 +110,38 @@ bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
110 110
   if (setStart) allocSearchStart_ = bgnCluster + 1;
111 111
 
112 112
   return true;
113
-fail:
113
+  FAIL:
114 114
   return false;
115 115
 }
116 116
 //------------------------------------------------------------------------------
117 117
 bool SdVolume::cacheFlush() {
118 118
   if (cacheDirty_) {
119 119
     if (!sdCard_->writeBlock(cacheBlockNumber_, cacheBuffer_.data)) {
120
-      goto fail;
120
+      goto FAIL;
121 121
     }
122 122
     // mirror FAT tables
123 123
     if (cacheMirrorBlock_) {
124 124
       if (!sdCard_->writeBlock(cacheMirrorBlock_, cacheBuffer_.data)) {
125
-        goto fail;
125
+        goto FAIL;
126 126
       }
127 127
       cacheMirrorBlock_ = 0;
128 128
     }
129 129
     cacheDirty_ = 0;
130 130
   }
131 131
   return true;
132
-fail:
132
+  FAIL:
133 133
   return false;
134 134
 }
135 135
 //------------------------------------------------------------------------------
136 136
 bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) {
137 137
   if (cacheBlockNumber_ != blockNumber) {
138
-    if (!cacheFlush()) goto fail;
139
-    if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) goto fail;
138
+    if (!cacheFlush()) goto FAIL;
139
+    if (!sdCard_->readBlock(blockNumber, cacheBuffer_.data)) goto FAIL;
140 140
     cacheBlockNumber_ = blockNumber;
141 141
   }
142 142
   if (dirty) cacheDirty_ = true;
143 143
   return true;
144
-fail:
144
+  FAIL:
145 145
   return false;
146 146
 }
147 147
 //------------------------------------------------------------------------------
@@ -149,29 +149,29 @@ fail:
149 149
 bool SdVolume::chainSize(uint32_t cluster, uint32_t* size) {
150 150
   uint32_t s = 0;
151 151
   do {
152
-    if (!fatGet(cluster, &cluster)) goto fail;
152
+    if (!fatGet(cluster, &cluster)) goto FAIL;
153 153
     s += 512UL << clusterSizeShift_;
154 154
   } while (!isEOC(cluster));
155 155
   *size = s;
156 156
   return true;
157
-fail:
157
+  FAIL:
158 158
   return false;
159 159
 }
160 160
 //------------------------------------------------------------------------------
161 161
 // Fetch a FAT entry
162 162
 bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
163 163
   uint32_t lba;
164
-  if (cluster > (clusterCount_ + 1)) goto fail;
164
+  if (cluster > (clusterCount_ + 1)) goto FAIL;
165 165
   if (FAT12_SUPPORT && fatType_ == 12) {
166 166
     uint16_t index = cluster;
167 167
     index += index >> 1;
168 168
     lba = fatStartBlock_ + (index >> 9);
169
-    if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
169
+    if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto FAIL;
170 170
     index &= 0x1FF;
171 171
     uint16_t tmp = cacheBuffer_.data[index];
172 172
     index++;
173 173
     if (index == 512) {
174
-      if (!cacheRawBlock(lba + 1, CACHE_FOR_READ)) goto fail;
174
+      if (!cacheRawBlock(lba + 1, CACHE_FOR_READ)) goto FAIL;
175 175
       index = 0;
176 176
     }
177 177
     tmp |= cacheBuffer_.data[index] << 8;
@@ -185,10 +185,10 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
185 185
     lba = fatStartBlock_ + (cluster >> 7);
186 186
   }
187 187
   else {
188
-    goto fail;
188
+    goto FAIL;
189 189
   }
190 190
   if (lba != cacheBlockNumber_) {
191
-    if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
191
+    if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto FAIL;
192 192
   }
193 193
   if (fatType_ == 16) {
194 194
     *value = cacheBuffer_.fat16[cluster & 0xFF];
@@ -197,7 +197,7 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
197 197
     *value = cacheBuffer_.fat32[cluster & 0x7F] & FAT32MASK;
198 198
   }
199 199
   return true;
200
-fail:
200
+  FAIL:
201 201
   return false;
202 202
 }
203 203
 //------------------------------------------------------------------------------
@@ -205,16 +205,16 @@ fail:
205 205
 bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
206 206
   uint32_t lba;
207 207
   // error if reserved cluster
208
-  if (cluster < 2) goto fail;
208
+  if (cluster < 2) goto FAIL;
209 209
 
210 210
   // error if not in FAT
211
-  if (cluster > (clusterCount_ + 1)) goto fail;
211
+  if (cluster > (clusterCount_ + 1)) goto FAIL;
212 212
 
213 213
   if (FAT12_SUPPORT && fatType_ == 12) {
214 214
     uint16_t index = cluster;
215 215
     index += index >> 1;
216 216
     lba = fatStartBlock_ + (index >> 9);
217
-    if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
217
+    if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto FAIL;
218 218
     // mirror second FAT
219 219
     if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
220 220
     index &= 0x1FF;
@@ -227,7 +227,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
227 227
     if (index == 512) {
228 228
       lba++;
229 229
       index = 0;
230
-      if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
230
+      if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto FAIL;
231 231
       // mirror second FAT
232 232
       if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
233 233
     }
@@ -245,9 +245,9 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
245 245
     lba = fatStartBlock_ + (cluster >> 7);
246 246
   }
247 247
   else {
248
-    goto fail;
248
+    goto FAIL;
249 249
   }
250
-  if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
250
+  if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto FAIL;
251 251
   // store entry
252 252
   if (fatType_ == 16) {
253 253
     cacheBuffer_.fat16[cluster & 0xFF] = value;
@@ -258,7 +258,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
258 258
   // mirror second FAT
259 259
   if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
260 260
   return true;
261
-fail:
261
+  FAIL:
262 262
   return false;
263 263
 }
264 264
 //------------------------------------------------------------------------------
@@ -270,16 +270,16 @@ bool SdVolume::freeChain(uint32_t cluster) {
270 270
   allocSearchStart_ = 2;
271 271
 
272 272
   do {
273
-    if (!fatGet(cluster, &next)) goto fail;
273
+    if (!fatGet(cluster, &next)) goto FAIL;
274 274
 
275 275
     // free cluster
276
-    if (!fatPut(cluster, 0)) goto fail;
276
+    if (!fatPut(cluster, 0)) goto FAIL;
277 277
 
278 278
     cluster = next;
279 279
   } while (!isEOC(cluster));
280 280
 
281 281
   return true;
282
-fail:
282
+  FAIL:
283 283
   return false;
284 284
 }
285 285
 //------------------------------------------------------------------------------
@@ -349,25 +349,25 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
349 349
   // if part == 0 assume super floppy with FAT boot sector in block zero
350 350
   // if part > 0 assume mbr volume with partition table
351 351
   if (part) {
352
-    if (part > 4)goto fail;
353
-    if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
352
+    if (part > 4)goto FAIL;
353
+    if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto FAIL;
354 354
     part_t* p = &cacheBuffer_.mbr.part[part - 1];
355 355
     if ((p->boot & 0x7F) != 0  ||
356 356
         p->totalSectors < 100 ||
357 357
         p->firstSector == 0) {
358 358
       // not a valid partition
359
-      goto fail;
359
+      goto FAIL;
360 360
     }
361 361
     volumeStartBlock = p->firstSector;
362 362
   }
363
-  if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
363
+  if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto FAIL;
364 364
   fbs = &cacheBuffer_.fbs32;
365 365
   if (fbs->bytesPerSector != 512 ||
366 366
       fbs->fatCount == 0 ||
367 367
       fbs->reservedSectorCount == 0 ||
368 368
       fbs->sectorsPerCluster == 0) {
369 369
     // not valid FAT volume
370
-    goto fail;
370
+    goto FAIL;
371 371
   }
372 372
   fatCount_ = fbs->fatCount;
373 373
   blocksPerCluster_ = fbs->sectorsPerCluster;
@@ -375,7 +375,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
375 375
   clusterSizeShift_ = 0;
376 376
   while (blocksPerCluster_ != _BV(clusterSizeShift_)) {
377 377
     // error if not power of 2
378
-    if (clusterSizeShift_++ > 7) goto fail;
378
+    if (clusterSizeShift_++ > 7) goto FAIL;
379 379
   }
380 380
   blocksPerFat_ = fbs->sectorsPerFat16 ?
381 381
                   fbs->sectorsPerFat16 : fbs->sectorsPerFat32;
@@ -404,7 +404,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
404 404
   // FAT type is determined by cluster count
405 405
   if (clusterCount_ < 4085) {
406 406
     fatType_ = 12;
407
-    if (!FAT12_SUPPORT) goto fail;
407
+    if (!FAT12_SUPPORT) goto FAIL;
408 408
   }
409 409
   else if (clusterCount_ < 65525) {
410 410
     fatType_ = 16;
@@ -414,7 +414,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
414 414
     fatType_ = 32;
415 415
   }
416 416
   return true;
417
-fail:
417
+  FAIL:
418 418
   return false;
419 419
 }
420 420
 #endif

Laddar…
Avbryt
Spara