comm.v1.c

来自「一个LINUX下一个框架文件系统,运行编译环境:RED HAT LINUX7.3」· C语言 代码 · 共 54 行

C
54
字号
#include "common.h"
#include "mytypes.h"

/*	This is the communication module of the simple NFS
	the communication implemented here is rather simple:
	TCP one-one diagram
	send the request to the server with a specially defined structure
	and then receive back a structure (also specified firstly)

   Important: Non-ReEnterable, single on single back!
*/

extern struct 	socket *		tcpsock;
extern struct	sockaddr_in	    tcpsin;

extern int tcp_create_socket();
extern int tcp_sendbuffer(struct socket *sock, const char *buffer,const size_t length);
extern int tcp_recvbuffer(struct socket *sock, char *buffer, const size_t buflen);

struct outmessage{
	int		type;		//loop up == 1
	char	dirname[200];
};

struct inmessage{
	int		type;
	struct myfs_meta meta;
};

int lookup_root( char* dirname, struct myfs_meta *pmeta )
{
	struct outmessage*	poutmes;
	struct inmessage	inmes;

	poutmes = kmalloc( sizeof( struct outmessage ), GFP_KERNEL );
	poutmes->type = 1;
	sprintf( poutmes->dirname, "%s", dirname );

	//ready to communcation
	tcp_create_socket();
	tcp_sendbuffer( tcpsock, (char*)poutmes, sizeof( struct outmessage ) );
	tcp_recvbuffer( tcpsock, (char*)&inmes, sizeof( struct inmessage ) );
	sock_release( tcpsock );

	if (inmes.type == 1){
		printk( "The Incomming message is valid!\n" );
		memcpy( pmeta, &inmes.meta, sizeof(struct myfs_meta) );
	}else{
		return -1;
	}
	return 0;
}

⌨️ 快捷键说明

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