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

📄 tcl_scsi.c

📁 网络数据管理协议的开发
💻 C
字号:
/*                               -*- Mode: C -*-  * tcl_scsi.c *  * Description     : ndmpc Tcl SCSI commands. *  * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: tcl_scsi.c,v 1.7 1998/02/09 06:50:22 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: tcl_scsi.c,v 1.7 1998/02/09 06:50:22 tim Exp $";#endif#include <errno.h>#include <stdlib.h>#include "ndmp_common.h"#include "ndmpc.h"/* * scsiOpenCmd *   Sends an ndmp_scsi_open_request to the NDMP server. *   usage: scsi_open device-name  * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiOpenCmd(void*		clientData,			Tcl_Interp*	interp,			int			argc,			char*		argv[]){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_scsi_open_request	request;	ndmp_scsi_open_reply*	reply = 0;	int						r;	if (argc != 2)		{		Tcl_SetResult(interp, "usage: scsi_open device-name",					  TCL_STATIC);		return(TCL_ERROR);	}		request.device = argv[1];	r = ndmpSendRequest(connection, NDMP_SCSI_OPEN, NDMP_NO_ERR,						(void *)&request, (void *)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiCloseCmd *   Sends an ndmp_scsi_close_request to the NDMP server. *   usage: scsi_close * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiCloseCmd(void*		clientData,			Tcl_Interp*	interp,			int			argc,			char*		argv[] __attribute__ ((unused))){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_scsi_close_reply*	reply = 0;	int						r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: scsi_close",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_SCSI_CLOSE, NDMP_NO_ERR,						0, (void**)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiGetStateCmd *   Sends an ndmp_scsi_get_state_request to the NDMP server. *   usage: scsi_get_state * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiGetStateCmd(void*		clientData,				Tcl_Interp*	interp,				int			argc,				char*		argv[] __attribute__ ((unused))){	NdmpConnection				connection = (NdmpConnection)clientData;	ndmp_scsi_get_state_reply*	reply = 0;	char						buf[1024];	int							r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: scsi_get_state",					  TCL_STATIC);		return TCL_ERROR;	}	r = ndmpSendRequest(connection, NDMP_SCSI_GET_STATE, NDMP_NO_ERR,						0, (void**)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	sprintf(buf, "%d", reply->target_controller);	ndmpcTclAddToResult(interp, "target_controller", buf);	sprintf(buf, "%d", reply->target_id);	ndmpcTclAddToResult(interp, "target_id", buf);	sprintf(buf, "%d", reply->target_lun);	ndmpcTclAddToResult(interp, "target_lun", buf);	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiSetTargetCmd *   Sends an ndmp_scsi_set_target_request to the NDMP server. *   usage: scsi_set_target controller target lun ?device-name? * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiSetTargetCmd(void*			clientData,				 Tcl_Interp*	interp,				 int			argc,				 char*			argv[]){	NdmpConnection					connection = (NdmpConnection)clientData;	ndmp_scsi_set_target_request	request;	ndmp_scsi_set_target_reply*		reply = 0;	int								r;	if (argc < 4 || argc > 5)		{		Tcl_SetResult(interp,					  "usage: scsi_set_target controller target lun ?device-name?",					  TCL_STATIC);		return(TCL_ERROR);	}		request.target_controller = strtoul(argv[1], 0, 0);	request.target_id         = strtoul(argv[2], 0, 0);	request.target_lun        = strtoul(argv[3], 0, 0);		if (argc == 5)		request.device = argv[4];	else		request.device = "";			r = ndmpSendRequest(connection, NDMP_SCSI_SET_TARGET, NDMP_NO_ERR,						(void *)&request, (void *)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiResetDeviceCmd *   Sends an ndmp_scsi_reset_device_request to the NDMP server. *   usage: scsi_reset_device * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiResetDeviceCmd(void*		clientData,				   Tcl_Interp*	interp,				   int			argc,				   char*		argv[] __attribute__ ((unused))){	NdmpConnection					connection = (NdmpConnection)clientData;	ndmp_scsi_reset_device_reply*	reply = 0;	int								r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: scsi_reset_device",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_SCSI_RESET_DEVICE, NDMP_NO_ERR,						0, (void**)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiResetBusCmd *   Sends an ndmp_scsi_reset_bus_request to the NDMP server. *   usage: scsi_reset_bus * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiResetBusCmd(void*		clientData,				Tcl_Interp*	interp,				int			argc,				char*		argv[] __attribute__ ((unused))){	NdmpConnection				connection = (NdmpConnection)clientData;	ndmp_scsi_reset_bus_reply*	reply = 0;	int							r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: scsi_reset_bus",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_SCSI_RESET_BUS, NDMP_NO_ERR,						0, (void**)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	ndmpFreeMessage(connection);	return(TCL_OK);}/* * scsiExecuteCdbCmd *   Sends an ndmp_scsi_execute_cdb_request to the NDMP server. *   usage: scsi_execute_cdb flags timeout alloc-len cdb-index * *   cdb-index is the index of a predefined CDB from the CDB table *   defined in cdb.c. * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intscsiExecuteCdbCmd(void*			clientData,				 Tcl_Interp*	interp,				 int			argc,				 char*			argv[]){	NdmpConnection				connection = (NdmpConnection)clientData;	ndmp_execute_cdb_request	request;	ndmp_execute_cdb_reply*		reply = 0;	int							r;	if (argc != 5)	{		Tcl_SetResult(interp,					  "usage: scsi_execute_cdb flags timeout alloc-len cdb-index",					  TCL_STATIC);		return(TCL_ERROR);	}		request.flags      = strtoul(argv[1], 0, 0);	request.timeout    = strtoul(argv[2], 0, 0);	request.datain_len = strtoul(argv[3], 0, 0);	if (getCdb(strtoul(argv[4], 0, 0),			   &request.cdb.cdb_val, &request.cdb.cdb_len,			   &request.dataout.dataout_val,			   &request.dataout.dataout_len) < 0)	{	    Tcl_SetResult(interp, "invalid cdb-index", TCL_VOLATILE);	    return TCL_ERROR;	}	r = ndmpSendRequest(connection, NDMP_SCSI_EXECUTE_CDB, NDMP_NO_ERR,						(void *)&request, (void *)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	displayCdbReply(reply->status, reply->dataout_len,					reply->datain.datain_val, reply->datain.datain_len,					reply->ext_sense.ext_sense_val,					reply->ext_sense.ext_sense_len);	ndmpFreeMessage(connection);	return(TCL_OK);}

⌨️ 快捷键说明

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