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

📄 tcl_mover.c

📁 网络数据管理协议的开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                               -*- Mode: C -*-  * tcl_mover.c *  * Description     : ndmpc Tcl mover commands. *  * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: tcl_mover.c,v 1.8 1998/05/26 03:51:56 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: tcl_mover.c,v 1.8 1998/05/26 03:51:56 tim Exp $";#endif#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <errno.h>#include <tcl.h>#include "ndmp_common.h"#include "ndmpc.h"/* * moverGetStateCmd *   Sends an ndmp_mover_get_state_request to the NDMP server. *   usage: mover_get_state  * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intmoverGetStateCmd(void*			clientData,				 Tcl_Interp*	interp,				 int			argc,				 char*			argv[] __attribute__ ((unused))){	NdmpConnection						connection = (NdmpConnection)clientData;	ndmp_mover_get_state_reply*	reply = 0;	int 								r;	char								buf[32];		if (argc != 1)	{		Tcl_SetResult(interp, "usage: mover_get_state",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_MOVER_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);	}	ndmpcTclAddToResult(interp, "state",						reply->state == NDMP_MOVER_STATE_IDLE ? "NDMP_MOVER_STATE_IDLE" :						reply->state == NDMP_MOVER_STATE_LISTEN ? "NDMP_MOVER_STATE_LISTEN" :						reply->state == NDMP_MOVER_STATE_ACTIVE ? "NDMP_MOVER_STATE_ACTIVE" :						reply->state == NDMP_MOVER_STATE_PAUSED ? "NDMP_MOVER_STATE_PAUSED" :						reply->state == NDMP_MOVER_STATE_HALTED ? "NDMP_MOVER_STATE_HALTED" :						"undefined");	ndmpcTclAddToResult(interp, "pause_reason",						reply->pause_reason == NDMP_MOVER_PAUSE_NA ? "NDMP_MOVER_PAUSE_NA" :						reply->pause_reason == NDMP_MOVER_PAUSE_EOM ? "NDMP_MOVER_PAUSE_EOM" :						reply->pause_reason == NDMP_MOVER_PAUSE_EOF ? "NDMP_MOVER_PAUSE_EOF" :						reply->pause_reason == NDMP_MOVER_PAUSE_SEEK ? "NDMP_MOVER_PAUSE_SEEK" :						reply->pause_reason == NDMP_MOVER_PAUSE_MEDIA_ERROR ? "NDMP_MOVER_PAUSE_MEDIA_ERROR" :						reply->pause_reason == NDMP_MOVER_PAUSE_EOW ? "NDMP_MOVER_PAUSE_EOW" :						"undefined");	ndmpcTclAddToResult(interp, "halt_reason",						reply->halt_reason == NDMP_MOVER_HALT_NA ? "NDMP_MOVER_HALT_NA" :						reply->halt_reason == NDMP_MOVER_HALT_CONNECT_CLOSED ? "NDMP_MOVER_HALT_CONNECT_CLOSED" :						reply->halt_reason == NDMP_MOVER_HALT_ABORTED ? "NDMP_MOVER_HALT_ABORTED" :						reply->halt_reason == NDMP_MOVER_HALT_INTERNAL_ERROR ? "NDMP_MOVER_HALT_INTERNAL_ERROR" :						reply->halt_reason == NDMP_MOVER_HALT_CONNECT_ERROR ? "NDMP_MOVER_HALT_CONNECT_ERROR" :						"undefined");	sprintf(buf, "%lu", reply->record_size);	ndmpcTclAddToResult(interp, "record_size", buf);	sprintf(buf, "%lu", reply->record_num);	ndmpcTclAddToResult(interp, "record_num", buf);	sprintf(buf, "%llu", quadToLongLong(reply->data_written));	ndmpcTclAddToResult(interp, "data_written", buf);	sprintf(buf, "%llu", quadToLongLong(reply->seek_position));	ndmpcTclAddToResult(interp, "seek_position", buf);	sprintf(buf, "%llu", quadToLongLong(reply->bytes_left_to_read));	ndmpcTclAddToResult(interp, "bytes_left_to_read", buf);	sprintf(buf, "%llu", quadToLongLong(reply->window_offset));	ndmpcTclAddToResult(interp, "window_offset", buf);	sprintf(buf, "%llu", quadToLongLong(reply->window_length));	ndmpcTclAddToResult(interp, "window_length", buf);	ndmpFreeMessage(connection);	return(TCL_OK);}/* * moverListenCmd *   Sends an ndmp_mover_listen_request to the NDMP server. *   usage: mover_listen read|write local|tcp|fc|ipc * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intmoverListenCmd(void*		clientData,			   Tcl_Interp*	interp,			   int			argc,			   char*		argv[]){	NdmpConnection				connection = (NdmpConnection)clientData;	ndmp_mover_listen_request	request;	ndmp_mover_listen_reply*	reply = 0;	int 						r;	char						addrStr[400];		if (argc != 3)	{		Tcl_SetResult(interp,					  "usage: mover_listen read|write local|tcp|fc|ipc",					  TCL_STATIC);		return(TCL_ERROR);	}	if (strcmp(argv[1], "read") == 0)		request.mode = NDMP_MOVER_MODE_READ;	else if (strcmp(argv[1], "write") == 0)		request.mode = NDMP_MOVER_MODE_WRITE;	else	{		Tcl_SetResult(interp,					  "usage: mover_listen read|write local|tcp|fc|ipc",					  TCL_STATIC);		return(TCL_ERROR);	}	if (strcmp(argv[2], "local") == 0)		request.addr_type = NDMP_ADDR_LOCAL;	else if (strcmp(argv[2], "tcp") == 0)		request.addr_type = NDMP_ADDR_TCP;	else if (strcmp(argv[2], "fc") == 0)		request.addr_type = NDMP_ADDR_FC;	else if (strcmp(argv[2], "ipc") == 0)		request.addr_type = NDMP_ADDR_IPC;	else	{		Tcl_SetResult(interp,					  "usage: mover_listen read|write local|tcp|fc|ipc",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_MOVER_LISTEN, NDMP_NO_ERR,						&request, (void*)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	switch (reply->data_connection_addr.addr_type)	{		case NDMP_ADDR_LOCAL:		{			sprintf(addrStr, "LOCAL");			break;		}				case NDMP_ADDR_TCP:		{			sprintf(addrStr, "TCP 0x%lx %u",					reply->data_connection_addr.ndmp_addr_u.tcp_addr.ip_addr,					reply->data_connection_addr.ndmp_addr_u.tcp_addr.port);			break;		}				case NDMP_ADDR_FC:		{			sprintf(addrStr, "FC %ld",					reply->data_connection_addr.ndmp_addr_u.fc_addr.loop_id);			break;		}				case NDMP_ADDR_IPC:		{			char	dataStr[300];			u_long	i;			char*	p = dataStr;			u_int	length = reply->data_connection_addr.ndmp_addr_u.ipc_addr.comm_data.comm_data_len;			char*	data = reply->data_connection_addr.ndmp_addr_u.ipc_addr.comm_data.comm_data_val;							for (i = 0; i < sizeof(dataStr)/3 && i < length; i++)			{				sprintf(p, "%02x ", (u_int)data[i]&0xff);				p += 3;			}						sprintf(addrStr, "IPC 0x%s", dataStr);			break;		}				default:		{			sprintf(addrStr, "undefined");			break;		}	}		ndmpcTclAddToResult(interp, "data_connection_addr", addrStr);	ndmpFreeMessage(connection);	return(TCL_OK);}/* * moverContinueCmd *   Sends an ndmp_mover_continue_request to the NDMP server. *   usage: mover_continue  * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intmoverContinueCmd(void*			clientData,				 Tcl_Interp*	interp,				 int			argc,				 char*			argv[] __attribute__ ((unused))){	NdmpConnection						connection = (NdmpConnection)clientData;	ndmp_mover_continue_reply*	reply = 0;	int 								r;		if (argc != 1)	{		Tcl_SetResult(interp, "usage: mover_continue",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_MOVER_CONTINUE, 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);}/* * moverAbortCmd *   Sends an ndmp_mover_abort_request to the NDMP server. *   usage: mover_abort  * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */intmoverAbortCmd(void*			clientData,			  Tcl_Interp*	interp,			  int			argc,			  char*			argv[] __attribute__ ((unused))){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_mover_abort_reply*	reply = 0;	int 					r;		if (argc != 1)	{		Tcl_SetResult(interp, "usage: mover_abort",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_MOVER_ABORT, 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);}/* * moverStopCmd *   Sends a ndmp_mover_stop request to the NDMP server. *   usage: mover_stop  * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */

⌨️ 快捷键说明

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