From: Michael Schwingen <m.schwingen@stochastik.rwth-aachen.de>
Subject: Re: Iomega zip drive?
Date: Thu, 18 Jul 1996 12:32:06 +0200 (MET DST) [thread overview]
Message-ID: <b2a16cb5d86a08250986a5d23e209bd5.axp-list@archive.invalid> (raw)
In-Reply-To: <Pine.SGI.3.94.960717232236.6243A-100000@groucho.pci.uni-hannover.de>
> Is it possible to publish/post/mail your program ?
I did once on the linux/scsi list - apparently noone wanted to maintain it.
As I don't have a ZIP drive, I won't do much with it - it could need some
improvements.
I hope I have the latest version here:
/* ex:set ts=2: */
/*
* $Id: zip.c,v 1.4 1995/11/27 23:10:13 rincewind Exp $
*
* zip.c: access special protection features on IOMEGA ZIP drives
* written 1995 by Michael Schwingen, rincewind@discworld.oche.de
*
* SCSI routines based on scsiinfo.c 1.0 by Eric Youngdale
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <linux/hdreg.h>
#define SCSI_IOCTL_SEND_COMMAND 1
/*
* check if this is really a ZIP drive, since we would not want to
* send undocumented SCSI commands to a different target
*
* return value: 1 = ZIP, 0 = other
*/
int check_zip(int file)
{
int status;
unsigned char *cmd;
char buffer[2000];
memset(buffer,0,2000);
*( (int *) buffer ) = 0; /* length of input data */
*( ((int *) buffer) + 1 ) = 1000; /* length of output buffer */
cmd = (char *) ( ((int *) buffer) + 2);
cmd[0] = 0x12; /* INQUIRY */
cmd[1] = 0x00; /* lun=0, evpd=0 */
cmd[2] = 0x00; /* page code = 0 */
cmd[3] = 0x00; /* (reserved) */
cmd[4] = 0xff; /* allocation length */
cmd[5] = 0x00; /* control */
status = ioctl( file, SCSI_IOCTL_SEND_COMMAND, buffer);
if(status)
return 0;
/* check Vendor */
if (strncmp(buffer+16,"IOMEGA",6) != 0)
return 0;
if (strncmp(buffer+24,"ZIP 100",7) != 0)
return 0;
return 1;
}
/*
* send the ZIP special SCSI command
* mode specifies what to do:
* 0 = unlock (password optional)
* 2 = write protect (no password)
* 3 = write protect (password = 1..33 chars)
* 5 = lock (password = 1..33 chars)
*
* return value: 0 = success
*/
int zipspecial(int file, int mode, char *pwd)
{
int status, len;
unsigned char *cmd;
char buffer[2000];
memset(buffer,0,2000);
len = strlen(pwd);
if (len > 33)
return -1;
*( (int *) buffer) = len; /* length of input data */
*( (int *) buffer) + 1 ) = 1000; /* length of output buffer */
cmd = (char *) ( ((int *) buffer) + 2 );
cmd[0] = 0x0C; /* ZIP special OpCode */
cmd[1] = mode;
cmd[2] = 0x00; /* page code = 0 */
cmd[3] = 0x00; /* (reserved) */
cmd[4] = len; /* allocation length */
cmd[5] = 0x00; /* control */
memcpy(cmd+6, pwd, len);
status = ioctl(file, SCSI_IOCTL_SEND_COMMAND, buffer );
#if 0
if(status) printf("ioctl(SCSI_IOCTL_SEND_COMMAND) status\t= %d\n", status );
#endif
return status; /* 0 = OK */
}
void usage(char *name)
{
fprintf(stderr,
"Usage: %s device cmd [password]\n"
"valid values for cmd: lock unlock wrprot\n"
"password may be 1-33 characters long\n",name);
}
int main(int argc, char *argv[])
{
int f;
char *passwd = "";
int cmd=0,status;
if (argc != 4 && argc != 3)
{
usage(argv[1]);
return 1;
}
if (strcmp(argv[2],"lock") == 0)
{
cmd = 5;
if (argc == 3)
{
fprintf(stderr,"lock requires password!\n");
return 1;
}
}
else if (strcmp(argv[2],"unlock") == 0)
cmd = 0;
else if (strcmp(argv[2],"wrprot") == 0)
{
cmd = 3;
if (argc == 3)
cmd = 2;
}
else
{
usage(argv[1]);
return 1;
}
if (argc == 4)
passwd = argv[3];
if (strlen(passwd) > 33)
{
fprintf(stderr,"%s: passwd must be 33 chars or less\n",argv[1]);
return 1;
}
f = open(argv[1],O_RDONLY);
if (f<0)
{
perror("open");
return 1;
}
if (!check_zip(f))
{
fprintf(stderr,"error: %s is not a ZIP drive!\n",argv[1]);
return 1;
}
status = zipspecial(f,cmd,passwd);
fprintf(stderr,"%s %s\n",argv[2],status?"failed":"succeded");
close(f);
return 0;
}
--
Michael Schwingen <m.schwingen@stochastik.rwth-aachen.de>
Institut fuer Statistik und Wirtschaftsmathematik, | In the beginning there was
Wuellnerstr. 3, 52056 Aachen | nothing, which exploded.
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
next parent reply other threads:[~1996-07-18 10:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.SGI.3.94.960717232236.6243A-100000@groucho.pci.uni-hannover.de>
1996-07-18 10:32 ` Michael Schwingen [this message]
[not found] <m0ugEBR-001VADC@goonsquad.spies.com>
1996-07-17 17:22 ` Iomega zip drive? Michael Schwingen
1996-07-17 21:25 ` Dirk Wetter
1996-07-16 20:25 Stefan Kanthak
-- strict thread matches above, loose matches on Subject: below --
1996-07-16 17:45 Eric Smith
1996-07-16 5:06 Stefan Kanthak
1996-07-16 10:22 ` Dirk Wetter
1996-07-16 1:41 Bryan W. Headley
[not found] <9606158374.AA837469228@mail.amsinc.com>
1996-07-15 21:03 ` Dirk Wetter
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox