patch-2.1.63 linux/fs/ncpfs/sock.c

Next file: linux/fs/nfs/dir.c
Previous file: linux/fs/ncpfs/ncplib_kernel.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.62/linux/fs/ncpfs/sock.c linux/fs/ncpfs/sock.c
@@ -4,11 +4,11 @@
  *  Copyright (C) 1992, 1993  Rick Sladkey
  *
  *  Modified 1995, 1996 by Volker Lendecke to be usable for ncp
+ *  Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
  *
  */
 
 #include <linux/sched.h>
-#include <linux/ncp_fs.h>
 #include <linux/errno.h>
 #include <linux/socket.h>
 #include <linux/fcntl.h>
@@ -19,13 +19,13 @@
 #include <linux/mm.h>
 #include <linux/netdevice.h>
 #include <net/scm.h>
+#include <net/sock.h>
 #include <linux/ipx.h>
+#include <linux/poll.h>
 
 #include <linux/ncp.h>
 #include <linux/ncp_fs.h>
 #include <linux/ncp_fs_sb.h>
-#include <net/sock.h>
-#include <linux/poll.h>
 
 static int _recv(struct socket *sock, unsigned char *ubuf, int size,
 		 unsigned flags)
@@ -82,7 +82,7 @@
 	struct file *file;
 	struct inode *inode;
 	struct socket *sock;
-	unsigned long fs;
+	mm_segment_t fs;
 	int result;
 	char *start = server->packet;
 	poll_table wait_table;
@@ -104,10 +104,12 @@
 	file = server->ncp_filp;
 	inode = file->f_dentry->d_inode;
 	sock = &inode->u.socket_i;
+	/* N.B. this isn't needed ... check socket type? */
 	if (!sock) {
-		printk("ncp_rpc_call: socki_lookup failed\n");
+		printk(KERN_ERR "ncp_rpc_call: socki_lookup failed\n");
 		return -EBADF;
 	}
+
 	init_timeout = server->m.time_out;
 	max_timeout = NCP_MAX_RPC_TIMEOUT;
 	retrans = server->m.retry_count;
@@ -127,7 +129,8 @@
 	fs = get_fs();
 	set_fs(get_ds());
 	for (n = 0, timeout = init_timeout;; n++, timeout <<= 1) {
-		DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
+		/*
+		DDPRINTK(KERN_DEBUG "ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
 			 htonl(server->m.serv_addr.sipx_network),
 			 server->m.serv_addr.sipx_node[0],
 			 server->m.serv_addr.sipx_node[1],
@@ -136,17 +139,18 @@
 			 server->m.serv_addr.sipx_node[4],
 			 server->m.serv_addr.sipx_node[5],
 			 ntohs(server->m.serv_addr.sipx_port));
-		DDPRINTK("ncpfs: req.typ: %04X, con: %d, "
+		*/
+		DDPRINTK(KERN_DEBUG "ncpfs: req.typ: %04X, con: %d, "
 			 "seq: %d",
 			 request.type,
 			 (request.conn_high << 8) + request.conn_low,
 			 request.sequence);
-		DDPRINTK(" func: %d\n",
+		DDPRINTK(KERN_DEBUG " func: %d\n",
 			 request.function);
 
 		result = _send(sock, (void *) start, size);
 		if (result < 0) {
-			printk("ncp_rpc_call: send error = %d\n", result);
+			printk(KERN_ERR "ncp_rpc_call: send error = %d\n", result);
 			break;
 		}
 	      re_select:
@@ -159,7 +163,7 @@
 				 * This is useful to see if the system is
 				 * hanging */
 				if (acknowledge_seen == 0) {
-					printk("NCP max timeout\n");
+					printk(KERN_WARNING "NCP max timeout\n");
 				}
 				timeout = max_timeout;
 			}
@@ -176,7 +180,7 @@
 				if (n < retrans)
 					continue;
 				if (server->m.flags & NCP_MOUNT_SOFT) {
-					printk("NCP server not responding\n");
+					printk(KERN_WARNING "NCP server not responding\n");
 					result = -EIO;
 					break;
 				}
@@ -184,7 +188,7 @@
 				timeout = init_timeout;
 				init_timeout <<= 1;
 				if (!major_timeout_seen) {
-					printk("NCP server not responding\n");
+					printk(KERN_WARNING "NCP server not responding\n");
 				}
 				major_timeout_seen = 1;
 				continue;
@@ -201,15 +205,15 @@
 			       MSG_PEEK | MSG_DONTWAIT);
 		if (result < 0) {
 			if (result == -EAGAIN) {
-				DPRINTK("ncp_rpc_call: bad select ready\n");
+				DDPRINTK(KERN_DEBUG "ncp_rpc_call: bad select ready\n");
 				goto re_select;
 			}
 			if (result == -ECONNREFUSED) {
-				DPRINTK("ncp_rpc_call: server playing coy\n");
+				DPRINTK(KERN_WARNING "ncp_rpc_call: server playing coy\n");
 				goto re_select;
 			}
 			if (result != -ERESTARTSYS) {
-				printk("ncp_rpc_call: recv error = %d\n",
+				printk(KERN_ERR "ncp_rpc_call: recv error = %d\n",
 				       -result);
 			}
 			break;
@@ -217,7 +221,7 @@
 		if ((result == sizeof(reply))
 		    && (reply.type == NCP_POSITIVE_ACK)) {
 			/* Throw away the packet */
-			DPRINTK("ncp_rpc_call: got positive acknowledge\n");
+			DPRINTK(KERN_DEBUG "ncp_rpc_call: got positive acknowledge\n");
 			_recv(sock, (void *) &reply, sizeof(reply),
 			      MSG_DONTWAIT);
 			n = 0;
@@ -225,7 +229,7 @@
 			acknowledge_seen = 1;
 			goto re_select;
 		}
-		DDPRINTK("ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
+		DDPRINTK(KERN_DEBUG "ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
 			 "seq: %d\n",
 			 reply.type,
 			 (reply.conn_high << 8) + reply.conn_low,
@@ -240,7 +244,7 @@
 /* seem to get wrong task from NW311 && (reply.task      == request.task) */
 			    && (reply.conn_high == request.conn_high)))) {
 			if (major_timeout_seen)
-				printk("NCP server OK\n");
+				printk(KERN_NOTICE "NCP server OK\n");
 			break;
 		}
 		/* JEJB/JSP 2/7/94
@@ -249,7 +253,7 @@
 		 * a null buffer yet. */
 		_recv(sock, (void *) &reply, sizeof(reply), MSG_DONTWAIT);
 
-		DPRINTK("ncp_rpc_call: reply mismatch\n");
+		DPRINTK(KERN_WARNING "ncp_rpc_call: reply mismatch\n");
 		goto re_select;
 	}
 	/* 
@@ -258,11 +262,11 @@
 	 */
 	result = _recv(sock, (void *) start, server->packet_size, MSG_DONTWAIT);
 	if (result < 0) {
-		printk("NCP: notice message: result=%d\n", result);
+		printk(KERN_WARNING "NCP: notice message: result=%d\n", result);
 	} else if (result < sizeof(struct ncp_reply_header)) {
-		printk("NCP: just caught a too small read memory size..., "
+		printk(KERN_ERR "NCP: just caught a too small read memory size..., "
 		       "email to NET channel\n");
-		printk("NCP: result=%d\n", result);
+		printk(KERN_ERR "NCP: result=%d\n", result);
 		result = -EIO;
 	}
 	current->blocked = old_mask;
@@ -279,7 +283,7 @@
 	int result;
 
 	if (server->lock == 0) {
-		printk("ncpfs: Server not locked!\n");
+		printk(KERN_ERR "ncpfs: Server not locked!\n");
 		return -EIO;
 	}
 	if (!ncp_conn_valid(server)) {
@@ -287,7 +291,7 @@
 	}
 	result = do_ncp_rpc_call(server, size);
 
-	DDPRINTK("do_ncp_rpc_call returned %d\n", result);
+	DDPRINTK(KERN_DEBUG "do_ncp_rpc_call returned %d\n", result);
 
 	if (result < 0) {
 		/* There was a problem with I/O, so the connections is
@@ -299,19 +303,17 @@
 
 /* ncp_do_request assures that at least a complete reply header is
  * received. It assumes that server->current_size contains the ncp
- * request size */
+ * request size
+ */
 int ncp_request(struct ncp_server *server, int function)
 {
-	struct ncp_request_header *h
-	= (struct ncp_request_header *) (server->packet);
-	struct ncp_reply_header *reply
-	= (struct ncp_reply_header *) (server->packet);
-
+	struct ncp_request_header *h;
+	struct ncp_reply_header *reply;
 	int request_size = server->current_size
-	- sizeof(struct ncp_request_header);
-
+			 - sizeof(struct ncp_request_header);
 	int result;
 
+	h = (struct ncp_request_header *) (server->packet);
 	if (server->has_subfunction != 0) {
 		*(__u16 *) & (h->data[0]) = htons(request_size - 2);
 	}
@@ -321,13 +323,19 @@
 	h->sequence = server->sequence;
 	h->conn_low = (server->connection) & 0xff;
 	h->conn_high = ((server->connection) & 0xff00) >> 8;
-	h->task = (current->pid) & 0xff;
+	/*
+	 * The server shouldn't know or care what task is making a
+	 * request, so we always use the same task number.
+	 */
+	h->task = 2; /* (current->pid) & 0xff; */
 	h->function = function;
 
-	if ((result = ncp_do_request(server, request_size + sizeof(*h))) < 0) {
-		DPRINTK("ncp_request_error: %d\n", result);
-		return result;
+	result = ncp_do_request(server, request_size + sizeof(*h));
+	if (result < 0) {
+		DPRINTK(KERN_WARNING "ncp_request_error: %d\n", result);
+		goto out;
 	}
+	reply = (struct ncp_reply_header *) (server->packet);
 	server->completion = reply->completion_code;
 	server->conn_status = reply->connection_state;
 	server->reply_size = result;
@@ -335,48 +343,52 @@
 
 	result = reply->completion_code;
 
-	if (result != 0) {
-		DPRINTK("ncp_completion_code: %x\n", result);
-	}
+#ifdef NCPFS_PARANOIA
+if (result != 0)
+printk(KERN_DEBUG "ncp_request: completion code=%x\n", result);
+#endif
+out:
 	return result;
 }
 
 int ncp_connect(struct ncp_server *server)
 {
-	struct ncp_request_header *h
-	= (struct ncp_request_header *) (server->packet);
+	struct ncp_request_header *h;
 	int result;
 
+	h = (struct ncp_request_header *) (server->packet);
 	h->type = NCP_ALLOC_SLOT_REQUEST;
 
 	server->sequence = 0;
-	h->sequence = server->sequence;
-	h->conn_low = 0xff;
-	h->conn_high = 0xff;
-	h->task = (current->pid) & 0xff;
-	h->function = 0;
-
-	if ((result = ncp_do_request(server, sizeof(*h))) < 0) {
-		return result;
-	}
+	h->sequence	= server->sequence;
+	h->conn_low	= 0xff;
+	h->conn_high	= 0xff;
+	h->task		= 2; /* see above */
+	h->function	= 0;
+
+	result = ncp_do_request(server, sizeof(*h));
+	if (result < 0)
+		goto out;
 	server->sequence = 0;
 	server->connection = h->conn_low + (h->conn_high * 256);
-	return 0;
+	result = 0;
+out:
+	return result;
 }
 
 int ncp_disconnect(struct ncp_server *server)
 {
-	struct ncp_request_header *h
-	= (struct ncp_request_header *) (server->packet);
+	struct ncp_request_header *h;
 
+	h = (struct ncp_request_header *) (server->packet);
 	h->type = NCP_DEALLOC_SLOT_REQUEST;
 
 	server->sequence += 1;
-	h->sequence = server->sequence;
-	h->conn_low = (server->connection) & 0xff;
-	h->conn_high = ((server->connection) & 0xff00) >> 8;
-	h->task = (current->pid) & 0xff;
-	h->function = 0;
+	h->sequence	= server->sequence;
+	h->conn_low	= (server->connection) & 0xff;
+	h->conn_high	= ((server->connection) & 0xff00) >> 8;
+	h->task		= 2; /* see above */
+	h->function	= 0;
 
 	return ncp_do_request(server, sizeof(*h));
 }
@@ -386,7 +398,7 @@
 #if 0
 	/* For testing, only 1 process */
 	if (server->lock != 0) {
-		DPRINTK("ncpfs: server locked!!!\n");
+		DPRINTK(KERN_WARNING "ncpfs: server locked!!!\n");
 	}
 #endif
 	while (server->lock)
@@ -397,7 +409,7 @@
 void ncp_unlock_server(struct ncp_server *server)
 {
 	if (server->lock != 1) {
-		printk("ncp_unlock_server: was not locked!\n");
+		printk(KERN_WARNING "ncp_unlock_server: was not locked!\n");
 	}
 	server->lock = 0;
 	wake_up(&server->wait);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov