From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: X-Archive-Original-Message-ID: <199607181032.MAA02749@jupiter.stochastik.rwth-aachen.de> Date: Thu, 18 Jul 1996 12:32:06 +0200 (MET DST) From: Michael Schwingen Subject: Re: Iomega zip drive? In-Reply-To: > 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 #include #include #include #include #include #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 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