~ubuntu-branches/ubuntu/intrepid/sg3-utils/intrepid

« back to all changes in this revision

Viewing changes to examples/sg_simple4.c

  • Committer: Bazaar Package Importer
  • Author(s): Luk Claes
  • Date: 2006-11-05 17:23:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061105172329-l4loha00sk36qz6k
* Non-maintainer upload.
* Fix FTBFS due to old syscall usage (Closes: #395512).

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include <sys/types.h>
9
9
#include <sys/stat.h>
10
10
#include <sys/mman.h>
11
 
#include "sg_include.h"
12
 
#include "sg_err.h"
 
11
#include "sg_lib.h"
 
12
#include "sg_io_linux.h"
13
13
 
14
14
/* This is a simple program executing a SCSI INQUIRY command and a
15
15
   TEST UNIT READY command using the SCSI generic (sg) driver
36
36
 
37
37
#ifndef SG_FLAG_MMAP_IO
38
38
#define SG_FLAG_MMAP_IO 4
39
 
#endif  /* since /usr/include/scsi/sg.h doesn't know about this yet */
 
39
#endif  /* since /usr/include/scsi/sg.h doesn't know about this yet */
40
40
 
41
41
#define INQ_REPLY_LEN 96
42
42
#define INQ_CMD_LEN 6
83
83
    /* N.B. An access mode of O_RDWR is required for some SCSI commands */
84
84
    if ((sg_fd = open(file_name, O_RDWR)) < 0) {
85
85
        snprintf(ebuff, EBUFF_SZ,
86
 
                 "sg_simple4: error opening file: %s", file_name);
 
86
                 "sg_simple4: error opening file: %s", file_name);
87
87
        perror(ebuff);
88
88
        return 1;
89
89
    }
100
100
    inqBuff = mmap(NULL, 8000, PROT_READ | PROT_WRITE, MAP_SHARED, sg_fd, 0);
101
101
    if (MAP_FAILED == inqBuff) {
102
102
        snprintf(ebuff, EBUFF_SZ, "sg_simple4: error using mmap() on "
103
 
                 "file: %s", file_name);
 
103
                 "file: %s", file_name);
104
104
        perror(ebuff);
105
105
        return 1;
106
106
    }
107
107
    if (inqBuff[0])
108
 
        printf("non-null char at inqBuff[0]\n");
 
108
        printf("non-null char at inqBuff[0]\n");
109
109
    if (inqBuff[5000])
110
 
        printf("non-null char at inqBuff[5000]\n");
 
110
        printf("non-null char at inqBuff[5000]\n");
111
111
 
112
112
    /* Prepare INQUIRY command */
113
113
    memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
134
134
    /* now for the error processing */
135
135
    ok = 0;
136
136
    switch (sg_err_category3(&io_hdr)) {
137
 
    case SG_ERR_CAT_CLEAN:
 
137
    case SG_LIB_CAT_CLEAN:
138
138
        ok = 1;
139
139
        break;
140
 
    case SG_ERR_CAT_RECOVERED:
 
140
    case SG_LIB_CAT_RECOVERED:
141
141
        printf("Recovered error on INQUIRY, continuing\n");
142
142
        ok = 1;
143
143
        break;
144
144
    default: /* won't bother decoding other categories */
145
 
        sg_chk_n_print3("INQUIRY command error", &io_hdr);
 
145
        sg_chk_n_print3("INQUIRY command error", &io_hdr, 1);
146
146
        break;
147
147
    }
148
148
 
179
179
    /* now for the error processing */
180
180
    ok = 0;
181
181
    switch (sg_err_category3(&io_hdr)) {
182
 
    case SG_ERR_CAT_CLEAN:
 
182
    case SG_LIB_CAT_CLEAN:
183
183
        ok = 1;
184
184
        break;
185
 
    case SG_ERR_CAT_RECOVERED:
 
185
    case SG_LIB_CAT_RECOVERED:
186
186
        printf("Recovered error on Test Unit Ready, continuing\n");
187
187
        ok = 1;
188
188
        break;
189
189
    default: /* won't bother decoding other categories */
190
 
        sg_chk_n_print3("Test Unit Ready command error", &io_hdr);
 
190
        sg_chk_n_print3("Test Unit Ready command error", &io_hdr, 1);
191
191
        break;
192
192
    }
193
193
 
198
198
 
199
199
    if (do_extra)
200
200
        printf("TEST UNIT READY duration=%u millisecs, resid=%d, " 
201
 
               "msg_status=%d\n",
 
201
               "msg_status=%d\n",
202
202
               io_hdr.duration, io_hdr.resid, (int)io_hdr.msg_status);
203
203
 
204
204
    /* munmap(inqBuff, 8000); */
208
208
    inqBuff2 = mmap(NULL, 8000, PROT_READ | PROT_WRITE, MAP_SHARED, sg_fd, 0);
209
209
    if (MAP_FAILED == inqBuff2) {
210
210
        snprintf(ebuff, EBUFF_SZ, "sg_simple4: error using mmap() 2 on "
211
 
                 "file: %s", file_name);
 
211
                 "file: %s", file_name);
212
212
        perror(ebuff);
213
213
        return 1;
214
214
    }
215
215
    if (inqBuff2[0])
216
 
        printf("non-null char at inqBuff2[0]\n");
 
216
        printf("non-null char at inqBuff2[0]\n");
217
217
    if (inqBuff2[5000])
218
 
        printf("non-null char at inqBuff2[5000]\n");
 
218
        printf("non-null char at inqBuff2[5000]\n");
219
219
    {
220
 
        pid_t pid;
221
 
        pid = fork();
222
 
        if (pid) {
223
 
            inqBuff2[5000] = 33;
224
 
            munmap(inqBuff, 8000);
225
 
            sleep(3);
226
 
        }
227
 
        else {
228
 
            inqBuff[5000] = 0xaa;
229
 
            munmap(inqBuff, 8000);
230
 
            sleep(1);
231
 
        }
 
220
        pid_t pid;
 
221
        pid = fork();
 
222
        if (pid) {
 
223
            inqBuff2[5000] = 33;
 
224
            munmap(inqBuff, 8000);
 
225
            sleep(3);
 
226
        }
 
227
        else {
 
228
            inqBuff[5000] = 0xaa;
 
229
            munmap(inqBuff, 8000);
 
230
            sleep(1);
 
231
        }
232
232
    }
233
233
#endif
234
234
    close(sg_fd);