config.c

来自「网络数据管理协议的开发」· C语言 代码 · 共 618 行 · 第 1/2 页

C
618
字号
		if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0)			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: error sending ndmp_config_get_fs_info_reply.\n");		fclose(fp);		return;	}	memset((void*)fsInfo, 0, nMounts*sizeof(ndmp_fs_info));	rewind(fp);	reply.error = NDMP_NO_ERR;		for (i = 0; i < nMounts; i++)	{		err = getmntent(fp, &mt);		/* Check for EOF */		if (err < 0)			break;		if (err > 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: getmntent error.\n");			reply.error = NDMP_UNDEFINED_ERR;			break;		}		fsInfo[i].fs_type = malloc(strlen(mt.mnt_fstype) + 1);		if (fsInfo[i].fs_type == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		strcpy(fsInfo[i].fs_type, mt.mnt_fstype);		fsInfo[i].fs_logical_device = malloc(strlen(mt.mnt_mountp) + 1);		if (fsInfo[i].fs_logical_device == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		strcpy(fsInfo[i].fs_logical_device, mt.mnt_mountp);		fsInfo[i].fs_physical_device = malloc(strlen(mt.mnt_special) + 1);		if (fsInfo[i].fs_physical_device == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		strcpy(fsInfo[i].fs_physical_device, mt.mnt_special);		fsInfo[i].fs_env.fs_env_val = malloc(2 * sizeof(ndmp_pval));		if (fsInfo[i].fs_env.fs_env_val == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		memset((void*)fsInfo[i].fs_env.fs_env_val, 0,			   2 * sizeof(ndmp_pval));				fsInfo[i].fs_env.fs_env_len = 2;		fsInfo[i].fs_env.fs_env_val[0].name = "MNTOPTS";		fsInfo[i].fs_env.fs_env_val[0].value = malloc(strlen(mt.mnt_mntopts)+1);		if (fsInfo[i].fs_env.fs_env_val[0].value == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		strcpy(fsInfo[i].fs_env.fs_env_val[0].value, mt.mnt_mntopts);				fsInfo[i].fs_env.fs_env_val[1].name = "MNTTIME";		fsInfo[i].fs_env.fs_env_val[1].value = malloc(strlen(mt.mnt_time)+1);		if (fsInfo[i].fs_env.fs_env_val[1].value == 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: malloc error.\n");			reply.error = NDMP_NO_MEM_ERR;			break;		}		strcpy(fsInfo[i].fs_env.fs_env_val[1].value, mt.mnt_time);		if (statvfs(mt.mnt_mountp, &statBuf) < 0)		{			Error(LOG_ERR,				  "ndmpdConfigGetFsInfo: statvfs(%s) error.\n",				  mt.mnt_mountp);			fsInfo[i].fs_status    = "statvfs error: unable to determine filesystem attributes";		}		else		{			fsInfo[i].invalid      = 0;			fsInfo[i].total_size   = longLongToQuad((u_longlong_t)statBuf.f_frsize *													(u_longlong_t)statBuf.f_blocks);			fsInfo[i].used_size    = longLongToQuad((u_longlong_t)statBuf.f_frsize *													(u_longlong_t)(statBuf.f_blocks - statBuf.f_bfree));			fsInfo[i].avail_size   = longLongToQuad((u_longlong_t)statBuf.f_frsize *													(u_longlong_t)statBuf.f_bfree);			fsInfo[i].total_inodes = longLongToQuad((u_longlong_t)statBuf.f_files);			fsInfo[i].used_inodes  = longLongToQuad((u_longlong_t)statBuf.f_ffree);			fsInfo[i].fs_status    = "";		}	}		fclose(fp);		if (reply.error == NDMP_NO_ERR)	{		reply.fs_info.fs_info_len = nMounts;		reply.fs_info.fs_info_val = fsInfo;	}	else	{		reply.fs_info.fs_info_len = 0;		reply.fs_info.fs_info_val = 0;	}		if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0)		Error(LOG_ERR,			  "ndmpdConfigGetFsInfo: error sending ndmp_config_get_fs_info_reply.\n");	for (i = 0; i < nMounts; i++)	{		if (fsInfo[i].fs_type != 0)			free(fsInfo[i].fs_type);		if (fsInfo[i].fs_logical_device != 0)			free(fsInfo[i].fs_logical_device);		if (fsInfo[i].fs_physical_device != 0)			free(fsInfo[i].fs_physical_device);		if (fsInfo[i].fs_env.fs_env_val != 0)		{			if (fsInfo[i].fs_env.fs_env_val[0].value)				free(fsInfo[i].fs_env.fs_env_val[0].value);			if (fsInfo[i].fs_env.fs_env_val[1].value)				free(fsInfo[i].fs_env.fs_env_val[1].value);			free(fsInfo[i].fs_env.fs_env_val);		}	}}/* * ndmpdConfigGetTapeInfo * * This handler handles the ndmp_config_get_tape_info_request. * Information about all connected tape drives is returned. * * NOTE: currently this function is not fully implemented. *       It returns hardcoded dummy information simply to exercise *       the protocol and the NDMP client. * * Parameters: *   connection (input) - connection handle. *   body       (input) - request message body. * * Returns: *   void */voidndmpdConfigGetTapeInfo(NdmpConnection	connection,					   void*			body __attribute__ ((unused))){	ndmp_config_get_tape_info_reply	reply;	ndmp_device_info				tapeInfo;	ndmp_device_capability			devCap[2];	ndmp_pval						pval1;	ndmp_pval						pval2;		Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW,		  "ndmpdConfigGetTapeInfo: \n");		memset((void*)&reply, 0, sizeof(reply));		reply.error           = NDMP_NO_ERR;	reply.tape_info.tape_info_len = 1;	reply.tape_info.tape_info_val = &tapeInfo;	tapeInfo.model = "ACME 2000 SuperTape";	tapeInfo.caplist.caplist_len = 2;	tapeInfo.caplist.caplist_val = devCap;		devCap[0].device = "/dev/rst0";	devCap[0].attr   = NDMP_TAPE_ATTR_REWIND;	devCap[0].capability.capability_len = 1;	devCap[0].capability.capability_val = &pval1;	pval1.name  = "LENGTH";	pval1.value = "4GB";	devCap[1].device = "/dev/nrst0";	devCap[1].attr   = 0;	devCap[1].capability.capability_len = 1;	devCap[1].capability.capability_val = &pval2;	pval2.name  = "LENGTH";	pval2.value = "4GB";		if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0)		Error(LOG_ERR,			  "ndmpdConfigGetServerInfo: error sending ndmp_config_get_tape_info reply.\n");}/* * ndmpdConfigGetScsiInfo * * This handler handles the ndmp_config_get_tape_scsi_request. * Information about all connected scsi tape stacker and jukeboxes is returned. * * NOTE: currently this function is not fully implemented. *       It returns hardcoded dummy information simply to exercise *       the protocol and the NDMP client. * * Parameters: *   connection (input) - connection handle. *   body       (input) - request message body. * * Returns: *   void */voidndmpdConfigGetScsiInfo(NdmpConnection	connection,					   void*			body __attribute__ ((unused))){	ndmp_config_get_scsi_info_reply	reply;	ndmp_device_info				scsiInfo;	ndmp_device_capability			devCap;	ndmp_pval						pval1;		Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW,		  "ndmpdConfigGetTapeInfo: \n");		memset((void*)&reply, 0, sizeof(reply));		reply.error           = NDMP_NO_ERR;	reply.scsi_info.scsi_info_len = 1;	reply.scsi_info.scsi_info_val = &scsiInfo;	scsiInfo.model = "ACME 2000 Tape Jukebox";	scsiInfo.caplist.caplist_len = 1;	scsiInfo.caplist.caplist_val = &devCap;		devCap.device = "/dev/rsjb0";	devCap.attr   = 0;	devCap.capability.capability_len = 1;	devCap.capability.capability_val = &pval1;	pval1.name  = "NUM_TAPES";	pval1.value = "100";	if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0)		Error(LOG_ERR,			  "ndmpdConfigGetServerInfo: error sending ndmp_config_get_scsi_info_reply.\n");}/* * ndmpdConfigGetServerInfo * * This handler handles the ndmp_config_get_server_info request. * Host specific information is returned. * * Parameters: *   connection (input) - connection handle. *   body       (input) - request message body. * * Returns: *   void */voidndmpdConfigGetServerInfo(NdmpConnection	connection,						 void*			body __attribute__ ((unused))){	ndmp_config_get_server_info_reply	reply;	ndmp_auth_type						auth_types[3];		Debug(DBG_CAT_CONFIG|DBG_FOC_FLOW,		  "ndmpdConfigGetServerInfo: \n");		memset((void*)&reply, 0, sizeof(reply));		reply.error           = NDMP_NO_ERR;	reply.vendor_name     = "ndmp.org";	reply.product_name    = "NDMP SDK ndmpd";	reply.revision_number = NDMP_SDK_VERSION;	auth_types[0]  = NDMP_AUTH_NONE;	auth_types[1]  = NDMP_AUTH_TEXT;	auth_types[2]  = NDMP_AUTH_MD5;	reply.auth_type.auth_type_len = 3;	reply.auth_type.auth_type_val = auth_types;		if (ndmpSendReply(connection, NDMP_NO_ERR, (void *)&reply) < 0)		Error(LOG_ERR,			  "ndmpdConfigGetServerInfo: error sending ndmp_config_get_server_info reply.\n");}

⌨️ 快捷键说明

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