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

📄 tcl_tape.c

📁 网络数据管理协议的开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                               -*- Mode: C -*-  * tcl_tape.c *  * Description     : ndmpc Tcl tape commands. *  * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: tcl_tape.c,v 1.10 1998/05/26 03:51:57 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: tcl_tape.c,v 1.10 1998/05/26 03:51:57 tim Exp $";#endif#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/uio.h>#include "ndmp_common.h"#include "ndmpc.h"/* * tapeOpenCmd *   Sends an ndmp_tape_open_request to the NDMP server. *   usage: tape_open device-name ?r|rw? * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */inttapeOpenCmd(void*		clientData,			Tcl_Interp*	interp,			int			argc,			char*		argv[]){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_tape_open_request	request;	ndmp_tape_open_reply*	reply = 0;	int						r;	request.mode = NDMP_TAPE_RDWR_MODE;	if (argc < 2 || argc > 3)	{		Tcl_SetResult(interp, "usage: tape_open device-name ?r|rw?",					  TCL_STATIC);		return(TCL_ERROR);	}		if (argc == 3)	{		if (strcmp(argv[2], "r") == 0)			request.mode = NDMP_TAPE_READ_MODE;		else if (strcmp(argv[2], "rw") == 0)			request.mode = NDMP_TAPE_RDWR_MODE;		else		{			Tcl_SetResult(interp, "usage: tape_open device-name ?r|rw?",						  TCL_STATIC);			return TCL_ERROR;		}	}		request.device = argv[1];	r = ndmpSendRequest(connection, NDMP_TAPE_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);}/* * tapeCloseCmd *   Sends an ndmp_tape_close_request to the NDMP server. *   usage: tape_close * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */inttapeCloseCmd(void*		clientData,			Tcl_Interp*	interp,			int			argc,			char*		argv[] __attribute__ ((unused))){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_tape_close_reply*	reply = 0;	int						r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: tape_close",					  TCL_STATIC);		return(TCL_ERROR);	}	r = ndmpSendRequest(connection, NDMP_TAPE_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);}/* * tapeGetStateCmd *   Sends an ndmp_tape_get_state_request to the NDMP server. *   usage: tape_get_state * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */inttapeGetStateCmd(void*		clientData,				Tcl_Interp*	interp,				int			argc,				char*		argv[] __attribute__ ((unused))){	NdmpConnection				connection = (NdmpConnection)clientData;	ndmp_tape_get_state_reply*	reply = 0;	char						buf[64];	int							r;	if (argc != 1)	{		Tcl_SetResult(interp, "usage: tape_get_state",					  TCL_STATIC);		return TCL_ERROR;	}	r = ndmpSendRequest(connection, NDMP_TAPE_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, "NOREWIND",						reply->flags & NDMP_TAPE_STATE_NOREWIND ? "True" : "False");	ndmpcTclAddToResult(interp, "WR_PROT",						reply->flags & NDMP_TAPE_STATE_WR_PROT ? "True" : "False");	ndmpcTclAddToResult(interp, "ERROR",						reply->flags & NDMP_TAPE_STATE_ERROR ? "True" : "False");	ndmpcTclAddToResult(interp, "UNLOAD",						reply->flags & NDMP_TAPE_STATE_UNLOAD ? "True" : "False");	sprintf(buf, "%lu", reply->file_num);	ndmpcTclAddToResult(interp, "file_num", buf);	sprintf(buf, "%lu", reply->soft_errors);	ndmpcTclAddToResult(interp, "soft_errors", buf);	sprintf(buf, "%lu", reply->block_size);	ndmpcTclAddToResult(interp, "block_size", buf);	sprintf(buf, "%lu", reply->blockno);	ndmpcTclAddToResult(interp, "blockno", buf);	sprintf(buf, "0x%llx", quadToLongLong(reply->total_space));	ndmpcTclAddToResult(interp, "total_space", buf);	sprintf(buf, "0x%llx", quadToLongLong(reply->space_remain));	ndmpcTclAddToResult(interp, "space_remain", buf);	sprintf(buf, "%lu", reply->partition);	ndmpcTclAddToResult(interp, "partition", buf);	ndmpFreeMessage(connection);	return(TCL_OK);}/* * tapeMtioCmd *   Sends an ndmp_tape_mtio_request to the NDMP server. *   usage: tape_mtio fsf|bsf|fsr|bsr|rew|weof|off ?count? * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */inttapeMtioCmd(void*		clientData,			Tcl_Interp*	interp,			int			argc,			char*		argv[]){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_tape_mtio_request	request;	ndmp_tape_mtio_reply*	reply = 0;	char*					cmd;	char					buf[1024];	int						r;	request.count = 1;	if (argc < 2 || argc > 3)	{		Tcl_SetResult(interp,					  "usage: tape_mtio fsf|bsf|fsr|bsr|rew|weof|off ?count?",					  TCL_STATIC);		return(TCL_ERROR);	}		cmd = argv[1];	if (argc == 3)		request.count = strtoul(argv[2], 0, 0);	if (strcmp(cmd, "fsf") == 0)		request.tape_op = NDMP_MTIO_FSF;	else if (strcmp(cmd, "bsf") == 0)		request.tape_op = NDMP_MTIO_BSF;	else if (strcmp(cmd, "fsr") == 0)		request.tape_op = NDMP_MTIO_FSR;	else if (strcmp(cmd, "bsr") == 0)		request.tape_op = NDMP_MTIO_BSR;	else if (strcmp(cmd, "rew") == 0)		request.tape_op = NDMP_MTIO_REW;	else if (strcmp(cmd, "weof") == 0)		request.tape_op = NDMP_MTIO_EOF;	else if (strcmp(cmd, "off") == 0)		request.tape_op = NDMP_MTIO_OFF;	else	{		Tcl_SetResult(interp,					  "usage: tape_mtio fsf|bsf|fsr|bsr|rew|weof|off ?count?",					  TCL_STATIC);		return TCL_ERROR;	}	r = ndmpSendRequest(connection, NDMP_TAPE_MTIO, NDMP_NO_ERR,						(void*)&request, (void**)&reply);	if (ndmpcCheckNdmpSend(interp, r,						   reply ? reply->error : 0))	{		ndmpFreeMessage(connection);		return(r < 0 ? TCL_ERROR : TCL_OK);	}	sprintf(buf, "%lu", reply->resid_count);	ndmpcTclAddToResult(interp, "resid_count", buf);	ndmpFreeMessage(connection);	return(TCL_OK);}/* * tapeWriteCmd *   Sends an ndmp_tape_write_request to the NDMP server. *   usage: tape_write data * * Parameters: *   clientData (input) - connection handle. *   interp     (input) - Tcl interpreter. *   argc       (input) - argument count. *   argv       (input) - argument array. * * Returns: *   Tcl error code. */inttapeWriteCmd(void*			clientData,			 Tcl_Interp*	interp,			 int			argc,			 char*			argv[]){	NdmpConnection			connection = (NdmpConnection)clientData;	ndmp_tape_write_request	request;	ndmp_tape_write_reply*	reply = 0;	int						r;	if (argc != 2)	{		Tcl_SetResult(interp,					  "usage: tape_write data",					  TCL_STATIC);		return(TCL_ERROR);	}	request.data_out.data_out_len = strlen(argv[1]);	request.data_out.data_out_val = argv[1];	r = ndmpSendRequest(connection, NDMP_TAPE_WRITE, 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);

⌨️ 快捷键说明

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