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

« back to all changes in this revision

Viewing changes to sg_opcodes.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:
24
24
 
25
25
*/
26
26
 
27
 
static char * version_str = "0.23 20060315";
 
27
static char * version_str = "0.24 20060623";
28
28
 
29
29
 
30
30
#define SENSE_BUFF_LEN 32       /* Arbitrary, could be larger */
92
92
 
93
93
 
94
94
/* Report Supported Operation Codes */
95
 
/* Returns 0 when successful, else -1 */
 
95
/* Returns 0 when successful */
96
96
static int do_rsoc(int sg_fd, int rep_opts, int rq_opcode, int rq_servact, 
97
97
                  void * resp, int mx_resp_len, int noisy, int verbose)
98
98
{
161
161
                         "rq_sa=0x%x ", rq_opcode, rq_servact);
162
162
            sg_chk_n_print3(ebuff, &io_hdr, verbose > 1);
163
163
        }
164
 
        return -1;
 
164
        return res;
165
165
    }
166
166
}
167
167
 
168
168
/* Report Supported Task Management Function */
169
 
/* Returns 0 when successful, else -1 */
 
169
/* Returns 0 when successful */
170
170
static int do_rstmf(int sg_fd, void * resp, int mx_resp_len, int noisy,
171
171
                    int verbose)
172
172
{
218
218
            snprintf(ebuff, EBUFF_SZ, "RSTMF error ");
219
219
            sg_chk_n_print3(ebuff, &io_hdr, verbose > 1);
220
220
        }
221
 
        return -1;
 
221
        return res;
222
222
    }
223
223
}
224
224
 
359
359
 
360
360
int main(int argc, char * argv[])
361
361
{
362
 
    int sg_fd, k, num, cd_len, plen, jmp_out;
 
362
    int sg_fd, k, num, cd_len, plen, jmp_out, res;
363
363
    const char * file_name = 0;
364
364
    char ebuff[EBUFF_SZ];
365
365
    unsigned char rsoc_buff[MX_ALLOC_LEN];
372
372
    int do_unsorted = 0;
373
373
    int do_taskman = 0;
374
374
    int rep_opts = 0;
375
 
    int ret = 0;
376
375
    const char * cp;
377
376
    char buff[48];
378
377
    struct sg_simple_inquiry_resp inq_resp;
403
402
                case 'h':
404
403
                case '?':
405
404
                    usage();
406
 
                    return 1;
 
405
                    return 0;
407
406
                default:
408
407
                    jmp_out = 1;
409
408
                    break;
418
417
                if ((1 != num) || (do_opcode > 255)) {
419
418
                    fprintf(stderr, "Bad number after 'o=' option\n");
420
419
                    usage();
421
 
                    return 1;
 
420
                    return SG_LIB_SYNTAX_ERROR;
422
421
                }
423
422
            } else if (0 == strncmp("s=", cp, 2)) {
424
423
                num = sscanf(cp + 2, "%x", (unsigned int *)&do_servact);
425
424
                if (1 != num) {
426
425
                    fprintf(stderr, "Bad number after 's=' option\n");
427
426
                    usage();
428
 
                    return 1;
 
427
                    return SG_LIB_SYNTAX_ERROR;
429
428
                }
430
429
            } else if (jmp_out) {
431
430
                fprintf(stderr, "Unrecognized option: %s\n", cp);
432
431
                usage();
433
 
                return 1;
 
432
                return SG_LIB_SYNTAX_ERROR;
434
433
            }
435
434
        } else if (0 == file_name)
436
435
            file_name = cp;
438
437
            fprintf(stderr, "too many arguments, got: %s, not expecting: "
439
438
                    "%s\n", file_name, cp);
440
439
            usage();
441
 
            return 1;
 
440
            return SG_LIB_SYNTAX_ERROR;
442
441
        }
443
442
    }
444
443
    
445
444
    if (0 == file_name) {
446
445
        fprintf(stderr, "No <scsi_device> argument given\n");
447
446
        usage();
448
 
        return 1;
 
447
        return SG_LIB_SYNTAX_ERROR;
449
448
    }
450
449
    if ((-1 != do_servact) && (-1 == do_opcode)) {
451
450
        fprintf(stderr, "When '-s' is chosen, so must '-o' be chosen\n");
452
451
        usage();
453
 
        return 1;
 
452
        return SG_LIB_SYNTAX_ERROR;
454
453
    }
455
454
    if (do_unsorted && do_alpha)
456
455
        fprintf(stderr, "warning: unsorted ('-u') and alpha ('-a') options "
465
464
        snprintf(ebuff, EBUFF_SZ, "sg_opcodes: error opening file: %s (ro)",
466
465
                 file_name);
467
466
        perror(ebuff);
468
 
        return 1;
 
467
        return SG_LIB_FILE_ERROR;
469
468
    }
470
469
    if (0 == sg_simple_inquiry(sg_fd, &inq_resp, 1, do_verbose)) {
471
470
        printf("  %.8s  %.16s  %.4s\n", inq_resp.vendor, inq_resp.product,
478
477
            printf("  Peripheral device type: 0x%x\n", peri_type);
479
478
    } else {
480
479
        printf("sg_opcodes: %s doesn't respond to a SCSI INQUIRY\n", file_name);
481
 
        return 1;
 
480
        return SG_LIB_CAT_OTHER;
482
481
    }
483
482
    close(sg_fd);
484
483
#ifndef TEST_CODE
489
488
        else
490
489
            printf("'Report supported operation codes' command not "
491
490
                   "supported for CD/DVD devices\n");
492
 
        return 1;
 
491
        return SG_LIB_CAT_OTHER;
493
492
    }
494
493
#endif
495
494
 
497
496
        snprintf(ebuff, EBUFF_SZ, "sg_opcodes: error opening file: %s (rw)",
498
497
                 file_name);
499
498
        perror(ebuff);
500
 
        return 1;
 
499
        return SG_LIB_FILE_ERROR;
501
500
    }
502
501
    if (do_opcode >= 0)
503
502
        rep_opts = ((do_servact >= 0) ? 2 : 1);
504
503
    memset(rsoc_buff, 0, sizeof(rsoc_buff));
505
504
#ifndef TEST_CODE
506
505
    if (do_taskman) {
507
 
        if (0 != do_rstmf(sg_fd, rsoc_buff, sizeof(rsoc_buff), 0,
508
 
                          do_verbose)) {
 
506
        res = do_rstmf(sg_fd, rsoc_buff, sizeof(rsoc_buff), 0,
 
507
                       do_verbose);
 
508
        if (res) {
509
509
            fprintf(stderr, "Report supported task management functions failed\n");
510
 
            return 1;
 
510
            return res;
511
511
        }
512
512
    } else {
513
 
        if (0 != do_rsoc(sg_fd, rep_opts, do_opcode, do_servact, rsoc_buff,
514
 
                         sizeof(rsoc_buff), 0, do_verbose)) {
 
513
        res = do_rsoc(sg_fd, rep_opts, do_opcode, do_servact, rsoc_buff,
 
514
                      sizeof(rsoc_buff), 0, do_verbose);
 
515
        if (res) {
515
516
            fprintf(stderr, "Report supported operation codes failed\n");
516
 
            return 1;
 
517
            return res;
517
518
        }
518
519
    }
519
520
#else
581
582
        }
582
583
    }
583
584
    close(sg_fd);
584
 
    return ret;
 
585
    return 0;
585
586
}