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

📄 mode-sense.c

📁 对SCSI设备 直接存取的通用库
💻 C
字号:
#include <stdlib.h>#include <stdio.h>#include <sys/types.h>#include <fcntl.h>#include <errno.h>#include <scsi/all.h>intmain(int argc, char **argv){    SCSI *fd;    u_char data[0x3fff], *p;    struct sc_mode_header6 *h6;    struct sc_mode_header10 *h10;    struct sc_mode_block_descriptor *bdesc;    int length, bdno;    int i, len, nl = 0;    if ((fd=sc_open(argv[1])) == NULL) {	fprintf(stderr, "%s: can't open device: %s\n",		argv[0], strerror(errno));	exit(1);    }    if (sc_mode_sense10(fd, 0x3f, 0, 0, 0x3fff, data) >= 0) {	h10 = (struct sc_mode_header10 *)data;	length = h10->length - sizeof(struct sc_mode_header10) + 2;	bdno = h10->bdno;	p = data+sizeof(struct sc_mode_header10);	printf("medium type:\t\t%02x\n", h10->mtype);	printf("device specific:\t%02x\n", h10->dspec);    }    else if (sc_clearerr(fd),	     sc_mode_sense6(fd, 0x3f, 0, 0, 255, data) >= 0) {	h6 = (struct sc_mode_header6 *)data;	length = h6->length - sizeof(struct sc_mode_header10) + 1;	bdno = h6->bdno;	p = data+sizeof(struct sc_mode_header6);	printf("medium type:\t\t%02x\n", h6->mtype);	printf("device specific:\t%02x\n", h6->dspec);    }    else {	sc_fstatus(fd, stderr, argv[0], "mode-sense-6", 3);	sc_close(fd);	exit(1);    }    sc_close(fd);    if (bdno > 0) {	printf("block descriptors:\n");	while (bdno > 0) {	    bdesc = (struct sc_mode_block_descriptor *)p;	    p += 8;	    length -= 8;	    --bdno;	    printf("\t%02x: %02x%02x%02x / %02x%02x%02x\n",		   bdesc->dcode,		   bdesc->nob[0], bdesc->nob[1], bdesc->nob[2],		   bdesc->bl[0], bdesc->bl[1], bdesc->bl[2]);	}	printf("\n");    }    printf("pages:\n");    while (length > 0) {	len = p[1]+2;	for (i=0; i<len; i++) {	    if (i%16 == 0)		printf("%s\t", (nl ? "\n" : ""));	    else		printf(" ");	    printf("%02x", p[i]);	}	nl = 1;	printf("\n");	length -= len;	p += len;    }        exit(0);}

⌨️ 快捷键说明

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