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

« back to all changes in this revision

Viewing changes to sg_turs.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:
21
21
 
22
22
*/
23
23
 
24
 
static char * version_str = "3.19 20060106";
 
24
static char * version_str = "3.20 20060623";
25
25
 
26
26
 
27
27
static void usage()
42
42
 
43
43
int main(int argc, char * argv[])
44
44
{
45
 
    int sg_fd, k, plen, jmp_out;
 
45
    int sg_fd, k, plen, jmp_out, res;
46
46
    const char * file_name = 0;
47
47
    const char * cp;
48
48
    int num_turs = 1;
51
51
    int num_errs = 0;
52
52
    int do_time = 0;
53
53
    int verbose = 0;
 
54
    int reported = 0;
 
55
    int ret = 0;
54
56
    struct timeval start_tm, end_tm;
55
57
 
56
58
    for (k = 1; k < argc; ++k) {
75
77
                    exit(0);
76
78
                case '?':
77
79
                    usage();
78
 
                    return 1;
 
80
                    return 0;
79
81
                default:
80
82
                    jmp_out = 1;
81
83
                    break;
90
92
                if (num_turs <= 0) {
91
93
                    printf("Couldn't decode number after 'n=' option\n");
92
94
                    usage();
93
 
                    return 1;
 
95
                    return SG_LIB_SYNTAX_ERROR;
94
96
                }
95
97
            } else if (jmp_out) {
96
98
                fprintf(stderr, "Unrecognized option: %s\n", cp);
97
99
                usage();
98
 
                return 1;
 
100
                return SG_LIB_SYNTAX_ERROR;
99
101
            }
100
102
        } else if (0 == file_name)
101
103
            file_name = cp;
103
105
            fprintf(stderr, "too many arguments, got: %s, not expecting: "
104
106
                    "%s\n", file_name, cp);
105
107
            usage();
106
 
            return 1;
 
108
            return SG_LIB_SYNTAX_ERROR;
107
109
        }
108
110
    }
109
111
    if (0 == file_name) {
110
112
        fprintf(stderr, "No <scsi_device> argument given\n");
111
113
        usage();
112
 
        return 1;
 
114
        return SG_LIB_SYNTAX_ERROR;
113
115
    }
114
116
 
115
117
    if ((sg_fd = sg_cmds_open_device(file_name, 1 /* ro */, verbose)) < 0) {
116
118
        fprintf(stderr, "sg_turs: error opening file: %s: %s\n",
117
119
                file_name, safe_strerror(-sg_fd));
118
 
        return 1;
 
120
        return SG_LIB_FILE_ERROR;
119
121
    }
120
122
    if (do_progress) {
121
123
        for (k = 0; k < num_turs; ++k) {
122
124
            if (k > 0)
123
125
                sleep(30);
124
126
            progress = -1;
125
 
            sg_ll_test_unit_ready_progress(sg_fd, k, &progress,
126
 
                                ((1 == num_turs) ? 1 : 0), verbose);
127
 
            if (progress < 0)
 
127
            res = sg_ll_test_unit_ready_progress(sg_fd, k, &progress,
 
128
                                     ((1 == num_turs) ? 1 : 0), verbose);
 
129
            if (progress < 0) {
 
130
                ret = res;
128
131
                break;
129
 
            else
 
132
            } else
130
133
                printf("Progress indication: %d%% done\n",
131
134
                                (progress * 100) / 65536);
132
135
        }
140
143
            gettimeofday(&start_tm, NULL);
141
144
        }
142
145
        for (k = 0; k < num_turs; ++k) {
143
 
            if (sg_ll_test_unit_ready(sg_fd, k, ((1 == num_turs) ? 1 : 0),
144
 
                                      verbose))
 
146
            res = sg_ll_test_unit_ready(sg_fd, k, 0, verbose);
 
147
            if (res) {
145
148
                ++num_errs;
 
149
                ret = res;
 
150
                if ((1 == num_turs) && (SG_LIB_CAT_NOT_READY == res)) {
 
151
                    printf("device not ready\n");
 
152
                    reported = 1;
 
153
                    break;
 
154
                }
 
155
            }
146
156
        }
147
157
        if ((do_time) && (start_tm.tv_sec || start_tm.tv_usec)) {
148
158
            struct timeval res_tm;
166
176
                printf("\n");
167
177
        }
168
178
 
169
 
        printf("Completed %d Test Unit Ready commands with %d errors\n",
170
 
                num_turs, num_errs);
 
179
        if (((num_turs > 1) || (num_errs > 0)) && (! reported))
 
180
            printf("Completed %d Test Unit Ready commands with %d errors\n",
 
181
                   num_turs, num_errs);
171
182
    }
172
183
    sg_cmds_close_device(sg_fd);
173
 
    return num_errs ? 1 : 0;
 
184
    return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
174
185
}