2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)scsi.c 1.20 05/05/01 Copyright 1997 J. Schilling */
15 * Copyright (c) 1997 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #include "genisoimage.h"
42 #include <usal/scsireg.h>
43 #include <usal/scsitransp.h>
46 #include "../wodim/defaults.h"
49 * NOTICE: You should not make BUF_SIZE more than
50 * the buffer size of the CD-Recorder.
52 * Do not set BUF_SIZE to be more than 126 KBytes
53 * if you are running cdrecord on a sun4c machine.
55 * WARNING: Philips CDD 521 dies if BUF_SIZE is to big.
57 #define BUF_SIZE (62*1024) /* Must be a multiple of 2048 */
60 static long bufsize; /* The size of the transfer buffer */
62 int readsecs(int startsecno, void *buffer, int sectorcount);
63 int scsidev_open(char *path);
64 int scsidev_close(void);
67 readsecs(int startsecno, void *buffer, int sectorcount)
70 int secsize; /* The drive's SCSI sector size */
71 long amount; /* The number of bytes to be transfered */
72 long secno; /* The sector number to read from */
73 long secnum; /* The number of sectors to read */
77 if (in_image == NULL) {
79 * We are using the standard CD-ROM sectorsize of 2048 bytes
80 * while the drive may be switched to 512 bytes per sector.
82 * XXX We assume that secsize is no more than SECTOR_SIZE
83 * XXX and that SECTOR_SIZE / secsize is not a fraction.
85 secsize = usalp->cap->c_bsize;
86 amount = sectorcount * SECTOR_SIZE;
87 secno = startsecno * (SECTOR_SIZE / secsize);
94 secnum = amt / secsize;
96 if (read_scsi(usalp, bp, secno, secnum) < 0 ||
97 usal_getresid(usalp) != 0) {
101 comerr("Read error on old image\n");
105 amount -= secnum * secsize;
106 bp += secnum * secsize;
109 return (SECTOR_SIZE * sectorcount);
112 f = fileno(in_image);
114 if (lseek(f, (off_t)startsecno * SECTOR_SIZE, SEEK_SET) == (off_t)-1) {
116 comerr("Seek error on old image\n");
118 fprintf(stderr, "Seek error on old image\n");
122 if ((amt = read(f, buffer, (sectorcount * SECTOR_SIZE)))
123 != (sectorcount * SECTOR_SIZE)) {
126 comerr("Read error on old image\n");
127 comerrno(EX_BAD, "Short read on old image\n"); /* < secnt aber > 0 */
130 fprintf(stderr, "Read error on old image\n");
132 fprintf(stderr, "Short read on old image\n");
137 return (sectorcount * SECTOR_SIZE);
141 scsidev_open(char *path)
144 char *buf; /* ignored, bit OS/2 ASPI layer needs memory which */
145 /* has been allocated by scsi_getbuf() */
148 * Call usal_remote() to force loading the remote SCSI transport library
149 * code that is located in librusal instead of the dummy remote routines
150 * that are located inside libusal.
154 cdr_defaults(&path, NULL, NULL, NULL);
155 /* path, debug, verboseopen */
156 usalp = usal_open(path, errstr, sizeof (errstr), 0, 0);
158 errmsg("%s%sCannot open SCSI driver.\n", errstr, errstr[0]?". ":"");
162 bufsize = usal_bufsize(usalp, BUF_SIZE);
163 if ((buf = usal_getbuf(usalp, bufsize)) == NULL) {
164 errmsg("Cannot get SCSI I/O buffer.\n");
169 bufsize = (bufsize / SECTOR_SIZE) * SECTOR_SIZE;
171 allow_atapi(usalp, TRUE);
173 if (!wait_unit_ready(usalp, 60)) { /* Eat Unit att / Wait for drive */
179 read_capacity(usalp); /* Set Capacity/Sectorsize for I/O */
188 if (in_image == NULL) {
189 return (usal_close(usalp));
191 return (fclose(in_image));