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

« back to all changes in this revision

Viewing changes to sg_luns.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:
43
43
 * This program issues the SCSI command REPORT LUNS to the given SCSI device. 
44
44
 */
45
45
 
46
 
static char * version_str = "1.05 20060127";
 
46
static char * version_str = "1.06 20060623";
47
47
 
48
48
#define REPORT_LUNS_BUFF_LEN 1024
49
49
 
203
203
    int select_rep = 0;
204
204
    int verbose = 0;
205
205
    char device_name[256];
206
 
    int ret = 1;
 
206
    int ret = 0;
207
207
 
208
208
    memset(device_name, 0, sizeof device_name);
209
209
    while (1) {
226
226
           if ((1 != sscanf(optarg, "%d", &select_rep)) ||
227
227
               (select_rep < 0) || (select_rep > 255)) {
228
228
                fprintf(stderr, "bad argument to '--select'\n");
229
 
                return 1;
 
229
                return SG_LIB_SYNTAX_ERROR;
230
230
            }
231
231
            break;
232
232
        case 'v':
238
238
        default:
239
239
            fprintf(stderr, "unrecognised switch code 0x%x ??\n", c);
240
240
            usage();
241
 
            return 1;
 
241
            return SG_LIB_SYNTAX_ERROR;
242
242
        }
243
243
    }
244
244
    if (optind < argc) {
252
252
                fprintf(stderr, "Unexpected extra argument: %s\n",
253
253
                        argv[optind]);
254
254
            usage();
255
 
            return 1;
 
255
            return SG_LIB_SYNTAX_ERROR;
256
256
        }
257
257
    }
258
258
 
259
259
    if (0 == device_name[0]) {
260
260
        fprintf(stderr, "missing device name!\n");
261
261
        usage();
262
 
        return 1;
 
262
        return SG_LIB_SYNTAX_ERROR;
263
263
    }
264
264
    sg_fd = sg_cmds_open_device(device_name, 0 /* rw */, verbose);
265
265
    if (sg_fd < 0) {
266
266
        fprintf(stderr, ME "open error: %s: %s\n", device_name,
267
267
                safe_strerror(-sg_fd));
268
 
        return 1;
 
268
        return SG_LIB_FILE_ERROR;
269
269
    }
270
270
 
271
271
    memset(reportLunsBuff, 0x0, sizeof(reportLunsBuff));
273
273
 
274
274
    res = sg_ll_report_luns(sg_fd, select_rep, reportLunsBuff,
275
275
                            sizeof(reportLunsBuff), 1, verbose);
 
276
    ret = res;
276
277
    if (0 == res) {
277
278
        list_len = (reportLunsBuff[0] << 24) + (reportLunsBuff[1] << 16) +
278
279
                   (reportLunsBuff[2] << 8) + reportLunsBuff[3];
300
301
            if (decode)
301
302
                decode_lun("      ", reportLunsBuff + off - 8);
302
303
        }
303
 
        ret = 0;
304
304
    } else if (SG_LIB_CAT_INVALID_OP == res)
305
305
        fprintf(stderr, "Report Luns command not supported (support "
306
306
                "mandatory in SPC-3)\n");
314
314
 
315
315
    res = sg_cmds_close_device(sg_fd);
316
316
    if (res < 0) {
317
 
        fprintf(stderr, ME "close error: %s\n", safe_strerror(-res));
318
 
        return 1;
 
317
        fprintf(stderr, "close error: %s\n", safe_strerror(-res));
 
318
        if (0 == ret)
 
319
            return SG_LIB_FILE_ERROR;
319
320
    }
320
 
    return ret;
 
321
    return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
321
322
}