constants.c

来自「linux 内核源代码」· C语言 代码 · 共 1,417 行 · 第 1/4 页

C
1,417
字号
/*  * ASCII values for a number of symbolic constants, printing functions, * etc. * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422) * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002) *   by D. Gilbert and aeb (20020609) * Additions for SPC-3 T10/1416-D Rev 21 22 Sept 2004, D. Gilbert 20041025 * Update to SPC-4 T10/1713-D Rev 5a, 14 June 2006, D. Gilbert 20060702 */#include <linux/blkdev.h>#include <linux/module.h>#include <linux/kernel.h>#include <scsi/scsi.h>#include <scsi/scsi_cmnd.h>#include <scsi/scsi_device.h>#include <scsi/scsi_host.h>#include <scsi/scsi_eh.h>#include <scsi/scsi_dbg.h>/* Commands with service actions that change the command name */#define MAINTENANCE_IN 0xa3#define MAINTENANCE_OUT 0xa4#define SERVICE_ACTION_IN_12 0xab#define SERVICE_ACTION_OUT_12 0xa9#define SERVICE_ACTION_IN_16 0x9e#define SERVICE_ACTION_OUT_16 0x9f#define VARIABLE_LENGTH_CMD 0x7f#ifdef CONFIG_SCSI_CONSTANTSstatic const char * cdb_byte0_names[] = {/* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense",/* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL,	    "Reasssign Blocks",/* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL,/* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry",  /* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)",	    "Reserve(6)",/* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)",/* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic", /* 1e-1f */ "Prevent/Allow Medium Removal", NULL,/* 20-22 */  NULL, NULL, NULL,/* 23-28 */ "Read Format Capacities", "Set Window",	    "Read Capacity(10)", NULL, NULL, "Read(10)",/* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)",            "Read updated block",/* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal",/* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position", /* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)",	    "Read Defect Data(10)", /* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer",             "Read Buffer", /* 3d-3f */ "Update Block", "Read Long(10)",  "Write Long(10)",/* 40-41 */ "Change Definition", "Write Same(10)",/* 42-48 */ "Read sub-channel", "Read TOC/PMA/ATIP", "Read density support",            "Play audio(10)", "Get configuration", "Play audio msf",            "Play audio track/index",/* 49-4f */ "Play track relative(10)", "Get event status notification",            "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",            NULL,/* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",            "Reserve track", "Send OPC info", "Mode Select(10)",/* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue",            "Mode Sense(10)", "Close track/session",/* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",            "Persistent reserve out",/* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,/* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,/* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,/* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Variable length",/* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)", "Extended copy",            "Receive copy results",/* 85-89 */ "ATA command pass through(16)", "Access control in",	    "Access control out", "Read(16)", "Memory Export Out(16)",/* 8a-8f */ "Write(16)", NULL, "Read attributes", "Write attributes",            "Write and verify(16)", "Verify(16)",/* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)",            "Lock/unlock cache(16)", "Write same(16)", NULL,/* 95-99 */ NULL, NULL, NULL, NULL, NULL,/* 9a-9f */ NULL, NULL, NULL, NULL, "Service action in(16)",            "Service action out(16)",/* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank",            "Security protocol in", "Maintenance in", "Maintenance out",	    "Move medium/play audio(12)",/* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",            "Play track relative(12)",/* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance",            "Read DVD structure", "Write and verify(12)",/* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",/* b2-b4 */ "Search data low(12)", "Set limits(12)",            "Read element status attached",/* b5-b6 */ "Security protocol out", "Send volume tag, set streaming",/* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",/* ba-bc */ "Redundancy group (in), Scan",            "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",/* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",            "Volume set (out), Send DVD structure",};struct value_name_pair {	int value;	const char * name;};static const struct value_name_pair maint_in_arr[] = {	{0x5, "Report device identifier"},	{0xa, "Report target port groups"},	{0xb, "Report aliases"},	{0xc, "Report supported operation codes"},	{0xd, "Report supported task management functions"},	{0xe, "Report priority"},	{0xf, "Report timestamp"},};#define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr)static const struct value_name_pair maint_out_arr[] = {	{0x6, "Set device identifier"},	{0xa, "Set target port groups"},	{0xb, "Change aliases"},	{0xe, "Set priority"},	{0xe, "Set timestamp"},};#define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr)static const struct value_name_pair serv_in12_arr[] = {	{0x1, "Read media serial number"},};#define SERV_IN12_SZ ARRAY_SIZE(serv_in12_arr)static const struct value_name_pair serv_out12_arr[] = {	{-1, "dummy entry"},};#define SERV_OUT12_SZ ARRAY_SIZE(serv_out12_arr)static const struct value_name_pair serv_in16_arr[] = {	{0x10, "Read capacity(16)"},	{0x11, "Read long(16)"},};#define SERV_IN16_SZ ARRAY_SIZE(serv_in16_arr)static const struct value_name_pair serv_out16_arr[] = {	{0x11, "Write long(16)"},	{0x1f, "Notify data transfer device(16)"},};#define SERV_OUT16_SZ ARRAY_SIZE(serv_out16_arr)static const struct value_name_pair variable_length_arr[] = {	{0x1, "Rebuild(32)"},	{0x2, "Regenerate(32)"},	{0x3, "Xdread(32)"},	{0x4, "Xdwrite(32)"},	{0x5, "Xdwrite extended(32)"},	{0x6, "Xpwrite(32)"},	{0x7, "Xdwriteread(32)"},	{0x8, "Xdwrite extended(64)"},	{0x9, "Read(32)"},	{0xa, "Verify(32)"},	{0xb, "Write(32)"},	{0xc, "Write an verify(32)"},	{0xd, "Write same(32)"},	{0x8801, "Format OSD"},	{0x8802, "Create (osd)"},	{0x8803, "List (osd)"},	{0x8805, "Read (osd)"},	{0x8806, "Write (osd)"},	{0x8807, "Append (osd)"},	{0x8808, "Flush (osd)"},	{0x880a, "Remove (osd)"},	{0x880b, "Create partition (osd)"},	{0x880c, "Remove partition (osd)"},	{0x880e, "Get attributes (osd)"},	{0x880f, "Set attributes (osd)"},	{0x8812, "Create and write (osd)"},	{0x8815, "Create collection (osd)"},	{0x8816, "Remove collection (osd)"},	{0x8817, "List collection (osd)"},	{0x8818, "Set key (osd)"},	{0x8819, "Set master key (osd)"},	{0x881a, "Flush collection (osd)"},	{0x881b, "Flush partition (osd)"},	{0x881c, "Flush OSD"},	{0x8f7e, "Perform SCSI command (osd)"},	{0x8f7f, "Perform task management function (osd)"},};#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr)static const char * get_sa_name(const struct value_name_pair * arr,			        int arr_sz, int service_action){	int k;	for (k = 0; k < arr_sz; ++k, ++arr) {		if (service_action == arr->value)			break;	}	return (k < arr_sz) ? arr->name : NULL;}/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */static void print_opcode_name(unsigned char * cdbp, int cdb_len){	int sa, len, cdb0;	const char * name;	cdb0 = cdbp[0];	switch(cdb0) {	case VARIABLE_LENGTH_CMD:		len = cdbp[7] + 8;		if (len < 10) {			printk("short variable length command, "			       "len=%d ext_len=%d", len, cdb_len);			break;		}		sa = (cdbp[8] << 8) + cdbp[9];		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);		if (name) {			printk("%s", name);			if ((cdb_len > 0) && (len != cdb_len))				printk(", in_cdb_len=%d, ext_len=%d",				       len, cdb_len);		} else {			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);			if ((cdb_len > 0) && (len != cdb_len))				printk(", in_cdb_len=%d, ext_len=%d",				       len, cdb_len);		}		break;	case MAINTENANCE_IN:		sa = cdbp[1] & 0x1f;		name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	case MAINTENANCE_OUT:		sa = cdbp[1] & 0x1f;		name = get_sa_name(maint_out_arr, MAINT_OUT_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	case SERVICE_ACTION_IN_12:		sa = cdbp[1] & 0x1f;		name = get_sa_name(serv_in12_arr, SERV_IN12_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	case SERVICE_ACTION_OUT_12:		sa = cdbp[1] & 0x1f;		name = get_sa_name(serv_out12_arr, SERV_OUT12_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	case SERVICE_ACTION_IN_16:		sa = cdbp[1] & 0x1f;		name = get_sa_name(serv_in16_arr, SERV_IN16_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	case SERVICE_ACTION_OUT_16:		sa = cdbp[1] & 0x1f;		name = get_sa_name(serv_out16_arr, SERV_OUT16_SZ, sa);		if (name)			printk("%s", name);		else			printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	default:		if (cdb0 < 0xc0) {			name = cdb_byte0_names[cdb0];			if (name)				printk("%s", name);			else				printk("cdb[0]=0x%x (reserved)", cdb0);		} else			printk("cdb[0]=0x%x (vendor)", cdb0);		break;	}}#else /* ifndef CONFIG_SCSI_CONSTANTS */static void print_opcode_name(unsigned char * cdbp, int cdb_len){	int sa, len, cdb0;	cdb0 = cdbp[0];	switch(cdb0) {	case VARIABLE_LENGTH_CMD:		len = cdbp[7] + 8;		if (len < 10) {			printk("short opcode=0x%x command, len=%d "			       "ext_len=%d", cdb0, len, cdb_len);			break;		}		sa = (cdbp[8] << 8) + cdbp[9];		printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		if (len != cdb_len)			printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);		break;	case MAINTENANCE_IN:	case MAINTENANCE_OUT:	case SERVICE_ACTION_IN_12:	case SERVICE_ACTION_OUT_12:	case SERVICE_ACTION_IN_16:	case SERVICE_ACTION_OUT_16:		sa = cdbp[1] & 0x1f;		printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);		break;	default:		if (cdb0 < 0xc0)			printk("cdb[0]=0x%x", cdb0);		else			printk("cdb[0]=0x%x (vendor)", cdb0);		break;	}}#endif  void __scsi_print_command(unsigned char *cdb){	int k, len;	print_opcode_name(cdb, 0);	if (VARIABLE_LENGTH_CMD == cdb[0])		len = cdb[7] + 8;	else		len = COMMAND_SIZE(cdb[0]);	/* print out all bytes in cdb */	for (k = 0; k < len; ++k) 		printk(" %02x", cdb[k]);	printk("\n");}EXPORT_SYMBOL(__scsi_print_command);void scsi_print_command(struct scsi_cmnd *cmd){	int k;	scmd_printk(KERN_INFO, cmd, "CDB: ");	print_opcode_name(cmd->cmnd, cmd->cmd_len);

⌨️ 快捷键说明

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