From 53f43ea9a4c3300bfa9359eb12c4dd7468e1bcc3 Mon Sep 17 00:00:00 2001
From: Nick Withers <nick.withers@anu.edu.au>
Date: Thu, 5 Dec 2013 12:52:42 +1100
Subject: [PATCH] Correct error return mismatches
See https://www.rtems.org/bugzilla/show_bug.cgi?id=2139
---
cpukit/libfs/src/rfs/rtems-rfs-buffer.h | 4 +-
cpukit/libfs/src/rfs/rtems-rfs-file-system.c | 1 -
cpukit/libfs/src/rfs/rtems-rfs-file-system.h | 4 +-
cpukit/libfs/src/rfs/rtems-rfs-format.c | 61 ++++++++++++++++++++--------
cpukit/libfs/src/rfs/rtems-rfs-rtems.c | 4 +-
5 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer.h b/cpukit/libfs/src/rfs/rtems-rfs-buffer.h
index 40b5891..7b11b89 100644
a
|
b
|
typedef struct _rtems_rfs_buffer |
68 | 68 | size_t size; |
69 | 69 | uint32_t references; |
70 | 70 | } rtems_rfs_buffer; |
71 | | #define rtems_rfs_buffer_io_request rtems_rfs_buffer_devceio_request |
72 | | #define rtems_rfs_buffer_io_release rtems_rfs_uffer_deviceio_release |
| 71 | #define rtems_rfs_buffer_io_request rtems_rfs_buffer_deviceio_request |
| 72 | #define rtems_rfs_buffer_io_release rtems_rfs_buffer_deviceio_release |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Request a buffer from the device I/O. |
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system.c b/cpukit/libfs/src/rfs/rtems-rfs-file-system.c
index 8cedda4..59aa8a2 100644
a
|
b
|
rtems_rfs_fs_open (const char* name, |
301 | 301 | return -1; |
302 | 302 | } |
303 | 303 | |
304 | | errno = 0; |
305 | 304 | return 0; |
306 | 305 | } |
307 | 306 | |
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system.h b/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
index 7c80aed..0ece3dc 100644
a
|
b
|
uint64_t rtems_rfs_fs_media_size (rtems_rfs_file_system* fs); |
389 | 389 | * @param[in] max_held_buffers is the maximum number of buffers the RFS holds. |
390 | 390 | * |
391 | 391 | * @retval 0 Successful operation. |
392 | | * @retval error_code An error occurred. |
| 392 | * @retval -1 Error. See errno |
393 | 393 | */ |
394 | 394 | int rtems_rfs_fs_open (const char* name, |
395 | 395 | void* user, |
… |
… |
int rtems_rfs_fs_open (const char* name, |
403 | 403 | * @param[in] fs is the file system data. |
404 | 404 | * |
405 | 405 | * @retval 0 Successful operation. |
406 | | * @retval error_code An error occurred. |
| 406 | * @retval -1 Error. See errno |
407 | 407 | */ |
408 | 408 | int rtems_rfs_fs_close (rtems_rfs_file_system* fs); |
409 | 409 | |
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-format.c b/cpukit/libfs/src/rfs/rtems-rfs-format.c
index 47da939..1c24ecd 100644
a
|
b
|
rtems_rfs_write_root_dir (const char* name) |
467 | 467 | rc = rtems_rfs_fs_open (name, NULL, |
468 | 468 | RTEMS_RFS_FS_FORCE_OPEN | RTEMS_RFS_FS_NO_LOCAL_CACHE, |
469 | 469 | 0, &fs); |
470 | | if (rc < 0) |
| 470 | if (rc != 0) |
471 | 471 | { |
| 472 | rc = errno; |
| 473 | |
472 | 474 | printf ("rtems-rfs: format: file system open failed: %d: %s\n", |
473 | | errno, strerror (errno)); |
474 | | return -1; |
| 475 | rc, strerror (rc)); |
| 476 | |
| 477 | return rc; |
475 | 478 | } |
476 | 479 | |
477 | 480 | rc = rtems_rfs_inode_alloc (fs, RTEMS_RFS_ROOT_INO, &ino); |
478 | | if (rc > 0) |
| 481 | if (rc != 0) |
479 | 482 | { |
480 | 483 | printf ("rtems-rfs: format: inode allocation failed: %d: %s\n", |
481 | 484 | rc, strerror (rc)); |
… |
… |
rtems_rfs_write_root_dir (const char* name) |
487 | 490 | { |
488 | 491 | printf ("rtems-rfs: format: allocated inode not root ino: %" PRId32 "\n", ino); |
489 | 492 | rtems_rfs_fs_close (fs); |
490 | | return rc; |
| 493 | return EINVAL; |
491 | 494 | } |
492 | 495 | |
493 | 496 | rc = rtems_rfs_inode_open (fs, ino, &inode, true); |
494 | | if (rc > 0) |
| 497 | if (rc != 0) |
495 | 498 | { |
496 | 499 | printf ("rtems-rfs: format: inode open failed: %d: %s\n", |
497 | 500 | rc, strerror (rc)); |
… |
… |
rtems_rfs_write_root_dir (const char* name) |
504 | 507 | (RTEMS_RFS_S_IFDIR | RTEMS_RFS_S_IRWXU | |
505 | 508 | RTEMS_RFS_S_IXGRP | RTEMS_RFS_S_IXOTH), |
506 | 509 | 0, 0); |
507 | | if (rc > 0) |
| 510 | if (rc != 0) |
508 | 511 | printf ("rtems-rfs: format: inode initialise failed: %d: %s\n", |
509 | 512 | rc, strerror (rc)); |
510 | 513 | |
511 | 514 | rc = rtems_rfs_dir_add_entry (fs, &inode, ".", 1, ino); |
512 | | if (rc > 0) |
| 515 | if (rc != 0) |
513 | 516 | printf ("rtems-rfs: format: directory add failed: %d: %s\n", |
514 | 517 | rc, strerror (rc)); |
515 | 518 | |
516 | 519 | rc = rtems_rfs_inode_close (fs, &inode); |
517 | | if (rc > 0) |
| 520 | if (rc != 0) |
518 | 521 | printf ("rtems-rfs: format: inode close failed: %d: %s\n", |
519 | 522 | rc, strerror (rc)); |
520 | 523 | |
521 | 524 | rc = rtems_rfs_fs_close (fs); |
522 | | if (rc < 0) |
| 525 | if (rc != 0) |
| 526 | { |
| 527 | rc = errno; |
| 528 | |
523 | 529 | printf ("rtems-rfs: format: file system close failed: %d: %s\n", |
524 | | errno, strerror (errno)); |
| 530 | rc, strerror (rc)); |
| 531 | |
| 532 | return rc; |
| 533 | } |
525 | 534 | |
526 | | return rc; |
| 535 | return 0; |
527 | 536 | } |
528 | 537 | |
529 | 538 | int |
… |
… |
rtems_rfs_format (const char* name, const rtems_rfs_format_config* config) |
554 | 563 | * Open the buffer interface. |
555 | 564 | */ |
556 | 565 | rc = rtems_rfs_buffer_open (name, &fs); |
557 | | if (rc > 0) |
| 566 | if (rc != 0) |
558 | 567 | { |
559 | 568 | printf ("rtems-rfs: format: buffer open failed: %d: %s\n", |
560 | 569 | rc, strerror (rc)); |
| 570 | |
| 571 | errno = rc; |
561 | 572 | return -1; |
562 | 573 | } |
563 | 574 | |
… |
… |
rtems_rfs_format (const char* name, const rtems_rfs_format_config* config) |
568 | 579 | { |
569 | 580 | printf ("rtems-rfs: media block is invalid: %" PRIu32 "\n", |
570 | 581 | rtems_rfs_fs_media_block_size (&fs)); |
| 582 | |
| 583 | errno = EINVAL; |
571 | 584 | return -1; |
572 | 585 | } |
573 | 586 | |
… |
… |
rtems_rfs_format (const char* name, const rtems_rfs_format_config* config) |
575 | 588 | * Check the configuration data. |
576 | 589 | */ |
577 | 590 | if (!rtems_rfs_check_config (&fs, config)) |
| 591 | { |
| 592 | errno = EINVAL; |
578 | 593 | return -1; |
| 594 | } |
579 | 595 | |
580 | 596 | if (config->verbose) |
581 | 597 | { |
… |
… |
rtems_rfs_format (const char* name, const rtems_rfs_format_config* config) |
604 | 620 | } |
605 | 621 | |
606 | 622 | rc = rtems_rfs_buffer_setblksize (&fs, rtems_rfs_fs_block_size (&fs)); |
607 | | if (rc > 0) |
| 623 | if (rc != 0) |
608 | 624 | { |
609 | 625 | printf ("rtems-rfs: format: setting block size failed: %d: %s\n", |
610 | 626 | rc, strerror (rc)); |
| 627 | |
| 628 | errno = rc; |
611 | 629 | return -1; |
612 | 630 | } |
613 | 631 | |
614 | 632 | if (!rtems_rfs_write_superblock (&fs)) |
615 | 633 | { |
616 | 634 | printf ("rtems-rfs: format: superblock write failed\n"); |
| 635 | |
| 636 | errno = EIO; |
617 | 637 | return -1; |
618 | 638 | } |
619 | 639 | |
620 | 640 | for (group = 0; group < fs.group_count; group++) |
621 | 641 | if (!rtems_rfs_write_group (&fs, group, |
622 | 642 | config->initialise_inodes, config->verbose)) |
623 | | return -1; |
| 643 | { |
| 644 | errno = EIO; |
| 645 | return -1; |
| 646 | } |
624 | 647 | |
625 | 648 | if (config->verbose) |
626 | 649 | printf ("\n"); |
627 | 650 | |
628 | 651 | rc = rtems_rfs_buffer_close (&fs); |
629 | | if (rc > 0) |
| 652 | if (rc != 0) |
630 | 653 | { |
631 | 654 | printf ("rtems-rfs: format: buffer close failed: %d: %s\n", |
632 | 655 | rc, strerror (rc)); |
| 656 | |
| 657 | errno = rc; |
633 | 658 | return -1; |
634 | 659 | } |
635 | 660 | |
636 | 661 | rc = rtems_rfs_write_root_dir (name); |
637 | | if (rc > 0) |
| 662 | if (rc != 0) |
638 | 663 | { |
639 | 664 | printf ("rtems-rfs: format: writing root dir failed: %d: %s\n", |
640 | 665 | rc, strerror (rc)); |
| 666 | |
| 667 | errno = rc; |
641 | 668 | return -1; |
642 | 669 | } |
643 | 670 | |
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c
index 5f30cf7..b5de66f 100644
a
|
b
|
rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry, |
885 | 885 | } |
886 | 886 | |
887 | 887 | rc = rtems_rfs_fs_open (mt_entry->dev, rtems, flags, max_held_buffers, &fs); |
888 | | if (rc) |
| 888 | if (rc != 0) |
889 | 889 | { |
890 | 890 | free (rtems); |
891 | | return rtems_rfs_rtems_error ("initialise: open", rc); |
| 891 | return rtems_rfs_rtems_error ("initialise: open", errno); |
892 | 892 | } |
893 | 893 | |
894 | 894 | mt_entry->fs_info = fs; |