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

« back to all changes in this revision

Viewing changes to sg_rmsn.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:
44
44
 * to the given SCSI device.
45
45
 */
46
46
 
47
 
static char * version_str = "1.01 20060106";
 
47
static char * version_str = "1.02 20060623";
48
48
 
49
49
#define ME "sg_rmsn: "
50
50
 
80
80
    int raw = 0;
81
81
    int verbose = 0;
82
82
    char device_name[512];
83
 
    int ret = 1;
 
83
    int ret = 0;
84
84
 
85
85
    memset(device_name, 0, sizeof device_name);
86
86
    while (1) {
108
108
        default:
109
109
            fprintf(stderr, "unrecognised switch code 0x%x ??\n", c);
110
110
            usage();
111
 
            return 1;
 
111
            return SG_LIB_SYNTAX_ERROR;
112
112
        }
113
113
    }
114
114
    if (optind < argc) {
122
122
                fprintf(stderr, "Unexpected extra argument: %s\n",
123
123
                        argv[optind]);
124
124
            usage();
125
 
            return 1;
 
125
            return SG_LIB_SYNTAX_ERROR;
126
126
        }
127
127
    }
128
128
 
129
129
    if (0 == device_name[0]) {
130
130
        fprintf(stderr, "missing device name!\n");
131
131
        usage();
132
 
        return 1;
 
132
        return SG_LIB_SYNTAX_ERROR;
133
133
    }
134
134
    sg_fd = sg_cmds_open_device(device_name, 0 /* rw */, verbose);
135
135
    if (sg_fd < 0) {
136
136
        fprintf(stderr, ME "open error: %s: %s\n", device_name,
137
137
                safe_strerror(-sg_fd));
138
 
        return 1;
 
138
        return SG_LIB_FILE_ERROR;
139
139
    }
140
140
 
141
141
    memset(rmsn_buff, 0x0, sizeof(rmsn_buff));
142
142
 
143
143
    res = sg_ll_read_media_serial_num(sg_fd, rmsn_buff, sizeof(rmsn_buff),
144
144
                                      1, verbose);
 
145
    ret = res;
145
146
    if (0 == res) {
146
147
        sn_len = (rmsn_buff[0] << 24) + (rmsn_buff[1] << 16) + 
147
148
                     (rmsn_buff[2] << 8) + rmsn_buff[3];
175
176
                if (sn_len > 0)
176
177
                    dStrHex((const char *)ucp + 4, sn_len, 0); 
177
178
            }
178
 
            ret = 0;
179
179
        }
180
180
    }
181
181
    if (0 != res) {
182
182
        if (SG_LIB_CAT_INVALID_OP == res)
183
183
            fprintf(stderr, "Read Media Serial Number command not "
184
184
                    "supported\n");
 
185
        else if (SG_LIB_CAT_NOT_READY == res)
 
186
            fprintf(stderr, "Read Media Serial Number failed, device not "
 
187
                    "ready\n");
 
188
        else if (SG_LIB_CAT_UNIT_ATTENTION == res)
 
189
            fprintf(stderr, "Read Media Serial Number failed, unit "
 
190
                    "attention\n");
185
191
        else if (SG_LIB_CAT_ILLEGAL_REQ == res)
186
192
            fprintf(stderr, "bad field in Read Media Serial Number cdb\n");
187
193
        else {
196
202
        free(ucp);
197
203
    res = sg_cmds_close_device(sg_fd);
198
204
    if (res < 0) {
199
 
        fprintf(stderr, ME "close error: %s\n", safe_strerror(-res));
200
 
        return 1;
 
205
        fprintf(stderr, "close error: %s\n", safe_strerror(-res));
 
206
        if (0 == ret)
 
207
            return SG_LIB_FILE_ERROR;
201
208
    }
202
 
    return ret;
 
209
    return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
203
210
}