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

📄 file_history.c

📁 网络数据管理协议的开发
💻 C
📖 第 1 页 / 共 2 页
字号:
			fileStatEntry->ftype     = NDMP_FILE_CSPEC;			break;		case S_IFDIR:			fileStatEntry->ftype     = NDMP_FILE_DIR;			break;		case S_IFBLK:			fileStatEntry->ftype     = NDMP_FILE_BSPEC;			break;		case S_IFREG:			fileStatEntry->ftype     = NDMP_FILE_REG;			break;		case S_IFLNK:			fileStatEntry->ftype     = NDMP_FILE_SLINK;			break;		default:			fileStatEntry->ftype     = NDMP_FILE_SOCK;			break;	}	fileStatEntry->invalid = 0;	fileStatEntry->fs_type = NDMP_FS_UNIX;	fileStatEntry->mtime   = fileStat->st_mtime;	fileStatEntry->atime   = fileStat->st_atime;	fileStatEntry->ctime   = fileStat->st_ctime;	fileStatEntry->owner   = fileStat->st_uid;	fileStatEntry->group   = fileStat->st_gid;	fileStatEntry->fattr   = fileStat->st_mode & 0x0fff;	fileStatEntry->size    = longLongToQuad((u_longlong_t)fileStat->st_size);	fileStatEntry->links   = fileStat->st_nlink;		session->fh.fileIndex++;	return(0);}/* * ndmpdApiFileHistoryDir *   Add a file history dir entry to the buffer. *   History data is buffered until the buffer is filled. *   Full buffers are then sent to the client. * * Parameters: *   cookie (input) - session pointer. *   name   (input) - file name. *                    NULL forces buffered data to be sent. *   node   (input) - file inode. *   parent (input) - file parent inode. *                    Should equal node if the file is the root of *                    the filesystem and has no parent. * * Returns: *   0 - success *  -1 - error */intndmpdApiFileHistoryDir(void		*cookie,					   char		*name,					   u_long	node,					   u_long	parent){	NdmpdSession*		session = (NdmpdSession *)cookie;	ndmp_dir*			dirEntry;	ndmp_file_name*		dirNameEntry;		Debug(DBG_CAT_HISTORY|DBG_FOC_FLOW,		  "ndmpdApiFileHistoryDir: name:%s node:%ld parent:%ld\n",		  name == 0 ? "nil" : name,		  node, parent);	if (name == 0 && session->fh.dirIndex == 0)		return(0);		/*	 * If the buffer does not have space	 * for the current entry, send the buffered data to the client.	 * A NULL name indicates that any buffered data should be sent.	 */	if (name == 0 ||		session->fh.dirIndex == N_DIR_ENTRIES ||		session->fh.dirNameBufIndex + strlen(name) + 1 > DIR_NAME_BUF_SIZE)	{		ndmp_fh_add_dir_request		request;		Debug(DBG_CAT_HISTORY|DBG_FOC_FLOW,			  "ndmpdApiFileHistoryDir: sending %ld entries\n",			  session->fh.dirIndex);		request.dirs.dirs_val = session->fh.dirs;		request.dirs.dirs_len = session->fh.dirIndex;		if (ndmpSendRequest(session->connection, NDMP_FH_ADD_DIR,							  NDMP_NO_ERR, (void *)&request, 0) < 0)		{			Error(LOG_ERR,				   "ndmpdApiFileHistoryDir: error sending ndmp_fh_add_dir_request.\n");			return(-1);		}				session->fh.dirIndex        = 0;		session->fh.dirNameBufIndex = 0;	}	if (name == 0)		return(0);		if (session->fh.dirs == 0)	{		session->fh.dirs =			(ndmp_dir*)malloc(N_DIR_ENTRIES*								  sizeof(ndmp_dir));		if (session->fh.dirs == 0)		{			Error(LOG_ERR, "ndmpdApiFileHistoryDir: malloc error: %s.\n",				  strerror(errno));			return(-1);		}	}		if (session->fh.dirNames == 0)	{		session->fh.dirNames =			(ndmp_file_name*)malloc(N_DIR_ENTRIES*									sizeof(ndmp_file_name));		if (session->fh.dirNames == 0)		{			Error(LOG_ERR, "ndmpdApiFileHistoryDir: malloc error: %s.\n",				  strerror(errno));			return(-1);		}	}		if (session->fh.dirNameBuf == 0)	{		session->fh.dirNameBuf = (char*)malloc(DIR_NAME_BUF_SIZE);		if (session->fh.dirNameBuf == 0)		{			Error(LOG_ERR, "ndmpdApiFileHistoryDir: malloc error: %s.\n",				  strerror(errno));			return(-1);		}	}		dirEntry     = &session->fh.dirs[session->fh.dirIndex];	dirNameEntry = &session->fh.dirNames[session->fh.dirIndex];	dirNameEntry->fs_type                    = NDMP_FS_UNIX;	dirNameEntry->ndmp_file_name_u.unix_name =		&session->fh.dirNameBuf[session->fh.dirNameBufIndex];	strcpy(&session->fh.dirNameBuf[session->fh.dirNameBufIndex], name);	session->fh.dirNameBufIndex += strlen(name) + 1;			dirEntry->names.names_len = 1;	dirEntry->names.names_val = dirNameEntry;	dirEntry->node            = longLongToQuad(node);	dirEntry->parent          = longLongToQuad(parent);		session->fh.dirIndex++;	return(0);}/* * ndmpdApiFileHistoryNode *   Add a file history node entry to the buffer. *   History data is buffered until the buffer is filled. *   Full buffers are then sent to the client. * * Parameters: *   cookie   (input) - session pointer. *   node     (input) - file inode. *                      must match a node from a prior ndmpdApiFileHistoryDir() *                      call. *   fileStat (input) - file status pointer. *                      0 forces buffered data to be sent. *   fh_info  (input) - data stream position of file data used during *                      fast restore. * * Returns: *   0 - success *  -1 - error. */intndmpdApiFileHistoryNode(void			*cookie,						u_long			node,						struct stat		*fileStat,						u_longlong_t	fh_info){	NdmpdSession*			session = (NdmpdSession *)cookie;	ndmp_node*				nodeEntry;	ndmp_file_stat*			fileStatEntry;		Debug(DBG_CAT_HISTORY|DBG_FOC_FLOW,		  "ndmpdApiFileHistoryNode: node:%ld\n", node);	if (fileStat == 0 && session->fh.nodeIndex == 0)		return(0);		/*	 * If the buffer does not have space	 * for the current entry, send the buffered data to the client.	 * A 0 fileStat pointer indicates that any buffered data should be sent.	 */	if (fileStat == 0 ||		session->fh.nodeIndex == N_NODE_ENTRIES)	{		ndmp_fh_add_node_request	request;		Debug(DBG_CAT_HISTORY|DBG_FOC_FLOW,			  "ndmpdApiFileHistoryNode: sending %ld entries\n",			  session->fh.nodeIndex);		request.nodes.nodes_len = session->fh.nodeIndex;		request.nodes.nodes_val = session->fh.nodes;		if (ndmpSendRequest(session->connection, NDMP_FH_ADD_NODE,							  NDMP_NO_ERR, (void *)&request, 0) < 0)		{			Error(LOG_ERR,				   "ndmpdApiFileHistoryNode: error sending ndmp_fh_add_node_request.\n");			return(-1);		}				session->fh.nodeIndex = 0;	}	if (fileStat == 0)		return(0);		if (session->fh.nodes == 0)	{		session->fh.nodes =			(ndmp_node*)malloc(N_NODE_ENTRIES*							   sizeof(ndmp_node));		if (session->fh.nodes == 0)		{			Error(LOG_ERR, "ndmpdApiFileHistoryNode: malloc error: %s.\n",				  strerror(errno));			return(-1);		}	}		if (session->fh.nodeStats == 0)	{		session->fh.nodeStats =			(ndmp_file_stat*)malloc(N_NODE_ENTRIES*							   sizeof(ndmp_file_stat));		if (session->fh.nodeStats == 0)		{			Error(LOG_ERR, "ndmpdApiFileHistoryNode: malloc error: %s.\n",				  strerror(errno));			return(-1);		}	}		nodeEntry     = &session->fh.nodes[session->fh.nodeIndex];	fileStatEntry = &session->fh.nodeStats[session->fh.nodeIndex];	switch (fileStat->st_mode & S_IFMT)	{		case S_IFIFO:			fileStatEntry->ftype     = NDMP_FILE_FIFO;			break;		case S_IFCHR:			fileStatEntry->ftype     = NDMP_FILE_CSPEC;			break;		case S_IFDIR:			fileStatEntry->ftype     = NDMP_FILE_DIR;			break;		case S_IFBLK:			fileStatEntry->ftype     = NDMP_FILE_BSPEC;			break;		case S_IFREG:			fileStatEntry->ftype     = NDMP_FILE_REG;			break;		case S_IFLNK:			fileStatEntry->ftype     = NDMP_FILE_SLINK;			break;		default:			fileStatEntry->ftype     = NDMP_FILE_SOCK;			break;	}	fileStatEntry->invalid = 0;	fileStatEntry->fs_type = NDMP_FS_UNIX;	fileStatEntry->mtime   = fileStat->st_mtime;	fileStatEntry->atime   = fileStat->st_atime;	fileStatEntry->ctime   = fileStat->st_ctime;	fileStatEntry->owner   = fileStat->st_uid;	fileStatEntry->group   = fileStat->st_gid;	fileStatEntry->fattr   = fileStat->st_mode & 0x0fff;	fileStatEntry->size    = longLongToQuad((u_longlong_t)fileStat->st_size);	fileStatEntry->links   = fileStat->st_nlink;		nodeEntry->stats.stats_len = 1;	nodeEntry->stats.stats_val = fileStatEntry;	nodeEntry->node            = longLongToQuad(node);	nodeEntry->fh_info         = longLongToQuad(fh_info);		session->fh.nodeIndex++;	return(0);}

⌨️ 快捷键说明

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