~ubuntu-branches/ubuntu/hardy/sg3-utils/hardy

« back to all changes in this revision

Viewing changes to sg_persist.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-09-19 21:00:55 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060919210055-j9deachd976os9my
Tags: 1.21-1ubuntu1
* Sync with Debian
* debian/control:
  + Let the -dev package depend on the runtime package
* llseek.c:
  + Fix syntax errors. Patch taken from Gentoo:
    http://mir2.ovh.net/gentoo-portage/sys-apps/sg3_utils/files/sg3_utils-llseek.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
*/
22
22
 
23
 
static char * version_str = "0.25 20060117";
 
23
static char * version_str = "0.26 20060623";
24
24
 
25
25
 
26
26
#define PRIN_RKEY_SA     0x0
104
104
{
105
105
    fprintf(stderr,
106
106
            "Usage: 'sg_persist [<options>] [<scsi_device>]\n"
107
 
            " where Persistent Reservation (PR) <options> include:\n"
 
107
            " where Persistent Reserve (PR) <options> include:\n"
108
108
            "       --clear|-C             PR Out: Clear\n"
109
109
            "       --device=<scsi_device> device to query or change\n"
110
110
            "       -d <scsi_device>       device to query or change "
279
279
                                      sizeof(pr_buff), 1, do_verbose);
280
280
    if (res) {
281
281
       if (SG_LIB_CAT_INVALID_OP == res)
282
 
            fprintf(stderr, "Persistent reserve in command not supported\n");
 
282
            fprintf(stderr, "Persistent reserve in, command not "
 
283
                    "supported\n");
283
284
        else if (SG_LIB_CAT_ILLEGAL_REQ == res)
284
 
            fprintf(stderr, "bad field in Persistent reserve in cdb\n");
 
285
            fprintf(stderr, "Persistent reserve in: bad field in cdb\n");
 
286
        else if (SG_LIB_CAT_UNIT_ATTENTION == res)
 
287
            fprintf(stderr, "Persistent reserve in: unit attention\n");
285
288
        else
286
 
            fprintf(stderr, "Persistent reserve in command failed\n");
 
289
            fprintf(stderr, "Persistent reserve in, command failed\n");
287
290
        return 1;
288
291
    }
289
292
    if (PRIN_RCAP_SA == prin_sa) {
461
464
                                       pr_buff, len, 1, do_verbose);
462
465
    if (res) {
463
466
       if (SG_LIB_CAT_INVALID_OP == res)
464
 
            fprintf(stderr, "Persistent reserve out command not supported\n");
 
467
            fprintf(stderr, "Persistent reserve out, command not supported\n");
465
468
        else if (SG_LIB_CAT_ILLEGAL_REQ == res)
466
 
            fprintf(stderr, "bad field in Persistent reserve out cdb\n");
 
469
            fprintf(stderr, "Persistent reserve out, bad field in cdb\n");
 
470
        else if (SG_LIB_CAT_UNIT_ATTENTION == res)
 
471
            fprintf(stderr, "Persistent reserve out, unit attention\n");
467
472
        else
468
 
            fprintf(stderr, "Persistent reserve out command failed\n");
 
473
            fprintf(stderr, "Persistent reserve out, command failed\n");
469
474
        return 1;
470
475
    } else if (do_verbose) {
471
476
        char buff[64];
521
526
       if (SG_LIB_CAT_INVALID_OP == res)
522
527
            fprintf(stderr, "Persistent reserve out command not supported\n");
523
528
        else if (SG_LIB_CAT_ILLEGAL_REQ == res)
524
 
            fprintf(stderr, "bad field in Persistent reserve out cdb\n");
 
529
            fprintf(stderr, "Persistent reserve out, bad field in cdb\n");
 
530
        else if (SG_LIB_CAT_UNIT_ATTENTION == res)
 
531
            fprintf(stderr, "Persistent reserve out, unit attention\n");
525
532
        else
526
533
            fprintf(stderr, "Persistent reserve out command failed\n");
527
534
        return 1;
665
672
 
666
673
int main(int argc, char * argv[])
667
674
{
668
 
    int sg_fd, c;
 
675
    int sg_fd, c, res;
669
676
    unsigned int prout_type;
670
677
    unsigned long long param_rk = 0;
671
678
    unsigned long long param_sark = 0;
744
751
        case 'K':
745
752
            if (1 != sscanf(optarg, "%llx", &param_rk)) {
746
753
                fprintf(stderr, "bad argument to '--param-rk'\n");
747
 
                return 1;
 
754
                return SG_LIB_SYNTAX_ERROR;
748
755
            }
749
756
            ++num_prout_param;
750
757
            break;
769
776
        case 'Q':
770
777
            if (1 != sscanf(optarg, "%x", &param_rtp)) {
771
778
                fprintf(stderr, "bad argument to '--relative-target-port'\n");
772
 
                return 1;
 
779
                return SG_LIB_SYNTAX_ERROR;
773
780
            }
774
781
            if (param_rtp > 0xffff) {
775
782
                fprintf(stderr, "argument to '--relative-target-port' 0 to "
776
783
                        "ffff inclusive\n");
777
 
                return 1;
 
784
                return SG_LIB_SYNTAX_ERROR;
778
785
            }
779
786
            ++num_prout_param;
780
787
            break;
793
800
        case 'S':
794
801
            if (1 != sscanf(optarg, "%llx", &param_sark)) {
795
802
                fprintf(stderr, "bad argument to '--param-sark'\n");
796
 
                return 1;
 
803
                return SG_LIB_SYNTAX_ERROR;
797
804
            }
798
805
            ++num_prout_param;
799
806
            break;
800
807
        case 'T':
801
808
            if (1 != sscanf(optarg, "%x", &prout_type)) {
802
809
                fprintf(stderr, "bad argument to '--prout-type'\n");
803
 
                return 1;
 
810
                return SG_LIB_SYNTAX_ERROR;
804
811
            }
805
812
            ++num_prout_param;
806
813
            break;
820
827
                                       &num_transportids,
821
828
                                       sizeof(transportid_arr))) {
822
829
                fprintf(stderr, "bad argument to '--transport-id'\n");
823
 
                return 1;
 
830
                return SG_LIB_SYNTAX_ERROR;
824
831
            }
825
832
            ++num_prout_param;
826
833
            break;
834
841
            break;
835
842
        case '?':
836
843
            usage();
837
 
            return 1;
 
844
            return 0;
838
845
        default:
839
846
            fprintf(stderr, "unrecognised switch "
840
847
                                "code 0x%x ??\n", c);
841
848
            usage();
842
 
            return 1;
 
849
            return SG_LIB_SYNTAX_ERROR;
843
850
        }
844
851
    }
845
852
    if (optind < argc) {
853
860
                fprintf(stderr, "Unexpected extra argument: %s\n",
854
861
                        argv[optind]);
855
862
            usage();
856
 
            return 1;
 
863
            return SG_LIB_SYNTAX_ERROR;
857
864
        }
858
865
    }
859
866
 
860
867
    if ('\0' == device_name[0]) {
861
868
        fprintf(stderr, "No device name given\n");
862
869
        usage();
863
 
        return 1;
 
870
        return SG_LIB_SYNTAX_ERROR;
864
871
    }
865
872
    if ((want_prout + want_prin) > 1) {
866
873
        fprintf(stderr, "choose '--in' _or_ '--out' (not both)\n");
867
874
        usage();
868
 
        return 1;
 
875
        return SG_LIB_SYNTAX_ERROR;
869
876
    } else if (want_prout) { /* syntax check on PROUT arguments */
870
877
        prin = 0;
871
878
        if ((1 != num_prout_sa) || (0 != num_prin_sa)) {
872
879
            fprintf(stderr, ">> For Persistent Reserve Out one and "
873
880
                    "only one appropriate\n>> service action must be "
874
881
                    "chosen (e.g. '--register')\n");
875
 
            return 1;
 
882
            return SG_LIB_SYNTAX_ERROR;
876
883
        }
877
884
    } else { /* syntax check on PRIN arguments */
878
885
        if (num_prout_sa > 0) {
879
886
            fprintf(stderr, ">> When a service action for Persistent "
880
887
                    "Reserve Out is chosen the\n"
881
888
                    ">> '--out' option must be given (as a safeguard)\n");
882
 
            return 1;
 
889
            return SG_LIB_SYNTAX_ERROR;
883
890
        }
884
891
        if (0 == num_prin_sa) {
885
892
            fprintf(stderr, ">> No service action given; assume Persistent"
891
898
            fprintf(stderr, "Too many service actions given; choose "
892
899
                    "one only\n");
893
900
            usage();
894
 
            return 1;
 
901
            return SG_LIB_SYNTAX_ERROR;
895
902
        }
896
903
    }
897
904
    if ((param_unreg || param_rtp) && (PROUT_REG_MOVE_SA != prout_sa)) {
898
905
        fprintf(stderr, "--unreg or --relative-target-port"
899
906
                " only useful with --register-move\n");
900
907
        usage();
901
 
        return 1;
 
908
        return SG_LIB_SYNTAX_ERROR;
902
909
    }
903
910
    if ((PROUT_REG_MOVE_SA == prout_sa) && (1 != num_transportids)) {
904
911
        fprintf(stderr, "with --register-move one (and only one) "
905
912
                "--transport-id should be given\n");
906
913
        usage();
907
 
        return 1;
 
914
        return SG_LIB_SYNTAX_ERROR;
908
915
    }
909
916
    if (((PROUT_RES_SA == prout_sa) ||
910
917
         (PROUT_REL_SA == prout_sa) ||
926
933
                                         do_verbose)) < 0) {
927
934
            fprintf(stderr, "sg_persist: error opening file (ro): %s: %s\n",
928
935
                     device_name, safe_strerror(-sg_fd));
929
 
            return 1;
 
936
            return SG_LIB_FILE_ERROR;
930
937
        }
931
938
        if (0 == sg_simple_inquiry(sg_fd, &inq_resp, 1, do_verbose)) {
932
939
            printf("  %.8s  %.16s  %.4s\n", inq_resp.vendor, inq_resp.product,
940
947
        } else {
941
948
            printf("sg_persist: %s doesn't respond to a SCSI INQUIRY\n", 
942
949
                   device_name);
943
 
            return 1;
 
950
            return SG_LIB_CAT_OTHER;
944
951
        }
945
952
        sg_cmds_close_device(sg_fd);
946
953
    }
949
956
                                     do_verbose)) < 0) {
950
957
        fprintf(stderr, "sg_persist: error opening file (rw): %s: %s\n",
951
958
                device_name, safe_strerror(-sg_fd));
952
 
        return 1;
 
959
        return SG_LIB_FILE_ERROR;
953
960
    }
954
961
 
955
962
    if (prin)
965
972
                         param_sark, param_alltgpt, param_aptpl,
966
973
                         transportid_arr, transportid_arr_len, do_verbose);
967
974
 
968
 
    sg_cmds_close_device(sg_fd);
969
 
    return ret;
 
975
    res = sg_cmds_close_device(sg_fd);
 
976
    if (res < 0) {
 
977
        fprintf(stderr, "close error: %s\n", safe_strerror(-res));
 
978
        if (0 == ret)
 
979
            return SG_LIB_FILE_ERROR;
 
980
    }
 
981
    return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
970
982
}