⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ziplock.c

📁 对SCSI设备 直接存取的通用库
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <scsi/all.h>#include <scsi/zip.h>char *prg;intmain(int argc, char **argv){    SCSI *fd;    int dolock = 0;    struct sc_inquiry inq;    struct sc_zip_lock lock;    struct sc_zip_lock newlock = { 0, 0, NULL };    prg = argv[0];        if (argc > 1	&& (argv[1][1] == '\0'	    || (argv[1][2] == '\0' && argv[1][0] == '-'))) {	switch ((argv[1][0] == '-') ? argv[1][1] : argv[1][0]) {	case 't':	    newlock.state = SC_ZIP_TEMP;	    break;	case 'u':	    newlock.state = 0;	    break;	case 'w':	    newlock.state = SC_ZIP_WRITE;	    break;	case 'r':	    newlock.state = SC_ZIP_READ | SC_ZIP_PASS;	    break;	case 'p':	    newlock.state = SC_ZIP_WRITE|SC_ZIP_PASS;	    break;	}	dolock = 1;    }	        if (argc != 2+dolock) {	fprintf(stderr, "usage: %s [tuwrp] device\n", prg);	exit(1);    }    if ((fd=sc_open(argv[1+dolock])) == NULL) {	fprintf(stderr, "%s: can't open device %s: %s\n",		prg, argv[1+dolock], strerror(errno));	exit(1);    }        if (sc_inquiry(fd, &inq) < 0) {	sc_fstatus(fd, stderr, prg, "inquiry", 3);	sc_close(fd);	exit(1);    }    if (strcmp(inq.vendor, "IOMEGA") || strcmp(inq.product, "ZIP 100")) {	fprintf(stderr, "%s: not a zip drive: %s\n",		prg, argv[1+dolock]);	sc_close(fd);	exit(1);    }        if (dolock == 1) {	if (sc_zip_get_lock(fd, &lock) < 0) {	    sc_fstatus(fd, stderr, prg, "get_lock", 3);	    sc_close(fd);	    exit(1);	}	if (newlock.state & SC_ZIP_PASS	    || (lock.state & SC_ZIP_PASS)) {	    newlock.pass = strdup(getpass("Password: "));	    if (newlock.state & SC_ZIP_PASS) {		if (strcmp(newlock.pass, getpass("Again: ")) != 0) {		    fprintf(stderr, "passwords mismatch\n");		    sc_close(fd);		    exit(1);		}	    }	    newlock.len = strlen(newlock.pass);	}	if (sc_zip_set_lock(fd, &newlock) < 0) {	    sc_fstatus(fd, stderr, prg, "set_lock", 3);	    sc_close(fd);	    exit(1);	}    }        if (sc_zip_get_lock(fd, &lock) < 0) {	sc_fstatus(fd, stderr, prg, "get_lock", 3);	sc_close(fd);	exit(1);    }    printf("zip is ");    if (lock.state & SC_ZIP_PASS)	printf("password ");    if (lock.state & SC_ZIP_WRITE)	printf("write ");    if ((lock.state & (SC_ZIP_PASS|SC_ZIP_WRITE)) == 0)	printf("un");    printf("protected");    if (lock.state & SC_ZIP_TEMP)	printf(" (temporarily unlocked)");    printf("\n");        sc_close(fd);    exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -