patch-2.0.37 linux/fs/ncpfs/ncplib_kernel.c

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

diff -u --recursive --new-file v2.0.36/linux/fs/ncpfs/ncplib_kernel.c linux/fs/ncpfs/ncplib_kernel.c
@@ -5,6 +5,8 @@
  *
  */
 
+#include <linux/config.h>
+
 #include "ncplib_kernel.h"
 
 typedef __u8  byte;
@@ -129,6 +131,33 @@
 	return *(dword *)(ncp_reply_data(server, offset));
 }
 
+
+/* options: 
+ *	bit 0	ipx checksum
+ *	bit 1	packet signing
+ */
+int
+ncp_negotiate_size_and_options(struct ncp_server *server, 
+	int size, int options, int *ret_size, int *ret_options) {
+	int result;
+
+	ncp_init_request(server);
+	ncp_add_word(server, htons(size));
+	ncp_add_byte(server, options);
+	
+	if ((result = ncp_request(server, 0x61)) != 0)
+	{
+		ncp_unlock_server(server);
+		return result;
+	}
+
+	*ret_size = min(ntohs(ncp_reply_word(server, 0)), size);
+	*ret_options = ncp_reply_byte(server, 4);
+
+	ncp_unlock_server(server);
+	return 0;
+}
+
 int
 ncp_negotiate_buffersize(struct ncp_server *server,
 			 int size, int *target)
@@ -261,7 +290,7 @@
 	ncp_add_byte(server, 6); /* subfunction */
 	ncp_add_byte(server, server->name_space[vol_num]);
 	ncp_add_byte(server, server->name_space[vol_num]);
-	ncp_add_word(server, 0xff); /* get all */
+	ncp_add_word(server, 0x8006); /* get all */
 	ncp_add_dword(server, RIM_ALL);
 	ncp_add_handle_path(server, vol_num, dir_base, 1, path);
 
@@ -277,8 +306,9 @@
 }
 
 static inline int
-ncp_has_os2_namespace(struct ncp_server *server, __u8 volume)
+ncp_get_known_namespace(struct ncp_server *server, __u8 volume)
 {
+#if defined(CONFIG_NCPFS_OS2_NS) || defined(CONFIG_NCPFS_NFS_NS)
 	int result;
 	__u8 *namespace;
 	__u16 no_namespaces;
@@ -291,9 +321,10 @@
 	if ((result = ncp_request(server, 87)) != 0)
 	{
 		ncp_unlock_server(server);
-		return 0;
+		return NW_NS_DOS;
 	}
 
+	result=NW_NS_DOS;
 	no_namespaces = ncp_reply_word(server, 0);
 	namespace = ncp_reply_data(server, 2);
 
@@ -301,16 +332,104 @@
 	{
 		DPRINTK("get_namespaces: found %d on %d\n", *namespace,volume);
 
-		if (*namespace == 4)
+#ifdef CONFIG_NCPFS_NFS_NS
+		if ((*namespace == NW_NS_NFS) && !(server->m.flags&NCP_MOUNT_NO_NFS))
+		{
+			result = NW_NS_NFS;
+			break;
+		}
+#endif	/* CONFIG_NCPFS_NFS_NS */
+#ifdef CONFIG_NCPFS_OS2_NS
+		if ((*namespace == NW_NS_OS2) && !(server->m.flags&NCP_MOUNT_NO_OS2))
 		{
-			DPRINTK("get_namespaces: found OS2\n");
-			ncp_unlock_server(server);
-			return 1;
+			result = NW_NS_OS2;
 		}
+#endif	/* CONFIG_NCPFS_OS2_NS */
 		namespace += 1;
 		no_namespaces -= 1;
 	}
 	ncp_unlock_server(server);
+	return result;
+#else	/* neither OS2 nor NFS - only DOS */
+	return NW_NS_DOS;
+#endif	/* defined(CONFIG_NCPFS_OS2_NS) || defined(CONFIG_NCPFS_NFS_NS) */
+}
+
+static int
+ncp_ObtainSpecificDirBase(struct ncp_server *server,
+		__u8 nsSrc, __u8 nsDst, __u8 vol_num, __u32 dir_base,
+		char *path, /* At most 1 component */
+		__u32 *dirEntNum)
+{
+	int result;
+
+	ncp_init_request(server);
+	ncp_add_byte(server, 6); /* subfunction */
+	ncp_add_byte(server, nsSrc);
+	ncp_add_byte(server, nsDst);
+	ncp_add_word(server, 0x8006); /* get all */
+	ncp_add_dword(server, RIM_ALL);
+	ncp_add_handle_path(server, vol_num, dir_base, 1, path);
+
+	if ((result = ncp_request(server, 87)) != 0)
+	{
+		ncp_unlock_server(server);
+		return result;
+	}
+
+	if (dirEntNum)
+		*dirEntNum = ncp_reply_dword(server, 0x30);
+	ncp_unlock_server(server);
+	return 0;
+}
+
+int
+ncp_mount_subdir(struct ncp_server *server,
+		__u8 volNumber,
+		__u8 srcNS, __u32 dirEntNum)
+{
+	int dstNS;
+	int result;
+	__u32 newDirEnt;
+	
+	dstNS = ncp_get_known_namespace(server, volNumber);
+	if ((result = ncp_ObtainSpecificDirBase(server, srcNS, dstNS, volNumber, 
+				      dirEntNum, NULL, &newDirEnt)) != 0)
+	{
+		return result;
+	}
+	server->name_space[volNumber] = dstNS;
+	server->root.finfo.i.volNumber = volNumber;
+	server->root.finfo.i.dirEntNum = newDirEnt;
+	server->m.mounted_vol[1] = 0;
+	server->m.mounted_vol[0] = 'X';
+	return 0;
+}
+
+static int
+ncp_obtain_DOS_dir_base(struct ncp_server *server,
+		struct nw_info_struct* file,
+		char *path, /* At most 1 component */
+		__u32 *DOS_dir_base)
+{
+	int result;
+
+	ncp_init_request(server);
+	ncp_add_byte(server, 6); /* subfunction */
+	ncp_add_byte(server, server->name_space[file->volNumber]);
+	ncp_add_byte(server, server->name_space[file->volNumber]);
+	ncp_add_word(server, 0x8006); /* get all */
+	ncp_add_dword(server, RIM_DIRECTORY);
+	ncp_add_handle_path(server, file->volNumber, file->dirEntNum, 1, path);
+
+	if ((result = ncp_request(server, 87)) != 0)
+	{
+		ncp_unlock_server(server);
+		return result;
+	}
+
+   	if (DOS_dir_base) *DOS_dir_base=ncp_reply_dword(server, 0x34);
+	ncp_unlock_server(server);
 	return 0;
 }
 
@@ -348,7 +467,8 @@
 	target->volNumber = volnum = ncp_reply_byte(server, 8);
 	ncp_unlock_server(server);
 
-	server->name_space[volnum] = ncp_has_os2_namespace(server,volnum)?4:0;
+	server->name_space[volnum] =
+		ncp_get_known_namespace(server, volnum);
 
 	DPRINTK("lookup_vol: namespace[%d] = %d\n",
 		volnum, server->name_space[volnum]);
@@ -383,25 +503,44 @@
 	return result;
 }
 
-int
-ncp_del_file_or_subdir(struct ncp_server *server,
-		       struct nw_info_struct *dir, char *name)
+static int
+ncp_DeleteNSEntry(struct ncp_server *server,
+		  __u8 have_dir_base, __u8 volume, __u32 dir_base,
+		  char* name, __u8 ns, int attr)
 {
 	int result;
 
 	ncp_init_request(server);
 	ncp_add_byte(server, 8); /* subfunction */
-	ncp_add_byte(server, server->name_space[dir->volNumber]);
+	ncp_add_byte(server, ns); /* namespace */
 	ncp_add_byte(server, 0); /* reserved */
-	ncp_add_word(server, 0x8006); /* search attribs: all */
-	ncp_add_handle_path(server, dir->volNumber,
-			    dir->dirEntNum, 1, name);
+	ncp_add_word(server, attr); /* search attribs */
+	ncp_add_handle_path(server, volume, dir_base, have_dir_base, name);
 	
 	result = ncp_request(server, 87);
 	ncp_unlock_server(server);
 	return result;
 }
 
+int
+ncp_del_file_or_subdir(struct ncp_server *server,
+		       struct nw_info_struct *dir, char *name)
+{
+#ifdef CONFIG_NCPFS_NFS_NS
+	if (server->name_space[dir->volNumber]==NW_NS_NFS)
+	{
+		__u32 DOS_dir_base;
+		int result;
+
+		result=ncp_obtain_DOS_dir_base(server, dir, name, &DOS_dir_base);
+		if (result) return result;
+		return ncp_DeleteNSEntry(server, 1, dir->volNumber, DOS_dir_base, NULL, NW_NS_DOS, 0x8006);
+	}
+	else
+#endif	/* CONFIG_NCPFS_NFS_NS */
+		return ncp_DeleteNSEntry(server, 1, dir->volNumber, dir->dirEntNum, name, server->name_space[dir->volNumber], 0x8006);
+}
+
 static inline void
 ConvertToNWfromDWORD ( __u32 sfd , __u8 ret[6] )
 {
@@ -428,7 +567,7 @@
 	if ((create_attributes & aDIR) != 0)
 	{
 		search_attribs |= 0x8000;	
-}
+        }
 
 	ncp_init_request(server);
 	ncp_add_byte(server, 1); /* subfunction */
@@ -464,7 +603,7 @@
 	if (dir != NULL)
 	{
 		/* in target there's a new finfo to fill */
-		ncp_extract_file_info(ncp_reply_data(server, 5), &(target->i));
+		ncp_extract_file_info(ncp_reply_data(server, 6), &(target->i));
 	}
 
 	ConvertToNWfromDWORD(target->server_file_handle, target->file_handle);
@@ -511,12 +650,21 @@
 	ncp_add_byte(server, 3); /* subfunction */
 	ncp_add_byte(server, server->name_space[seq->volNumber]);
 	ncp_add_byte(server, 0); /* data stream (???) */
-	ncp_add_word(server, 0xffff); /* Search attribs */
+	ncp_add_word(server, 0x8006); /* Search attribs */
 	ncp_add_dword(server, RIM_ALL);	/* return info mask */
 	ncp_add_mem(server, seq, 9);
-	ncp_add_byte(server, 2); /* 2 byte pattern */
-	ncp_add_byte(server, 0xff); /* following is a wildcard */
-	ncp_add_byte(server, '*');
+#ifdef CONFIG_NCPFS_NFS_NS
+	if (server->name_space[seq->volNumber]==NW_NS_NFS)
+	{
+		ncp_add_byte(server, 0);
+	}
+	else
+#endif	/* CONFIG_NCPFS_NFS_NS */
+	{
+		ncp_add_byte(server, 2); /* 2 byte pattern */
+		ncp_add_byte(server, 0xff); /* following is a wildcard */
+		ncp_add_byte(server, '*');
+	}
 	
 	if ((result = ncp_request(server, 87)) != 0)
 	{
@@ -532,9 +680,9 @@
 }
 
 int
-ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
-			      struct nw_info_struct *old_dir, char *old_name,
-			      struct nw_info_struct *new_dir, char *new_name)
+ncp_RenameNSEntry(struct ncp_server *server,
+		  struct nw_info_struct *old_dir, char *old_name, int old_type,
+		  struct nw_info_struct *new_dir, char *new_name)
 {
 	int result;
 
@@ -546,7 +694,7 @@
 	ncp_add_byte(server, 4); /* subfunction */
 	ncp_add_byte(server, server->name_space[old_dir->volNumber]);
 	ncp_add_byte(server, 1); /* rename flag */
-	ncp_add_word(server, 0x8006); /* search attributes */
+	ncp_add_word(server, old_type); /* search attributes */
 
 	/* source Handle Path */
 	ncp_add_byte(server, old_dir->volNumber);
@@ -570,6 +718,31 @@
 	return result;
 }
 	
+int
+ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
+			      struct nw_info_struct *old_dir, char *old_name,
+			      struct nw_info_struct *new_dir, char *new_name)
+{
+        int result;
+        int old_type = 0x0006;
+
+/* If somebody can do it atomic, call me... vandrove@vc.cvut.cz */
+	result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
+	                                   new_dir, new_name);
+        if (result == 0xFF)	/* File Not Found, try directory */
+	{
+		old_type = 0x0016;
+		result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
+						   new_dir, new_name);
+	}
+	if (result != 0x92) return result;	/* All except NO_FILES_RENAMED */
+	result = ncp_del_file_or_subdir(server, new_dir, new_name);
+	if (result != 0) return -EACCES;
+	result = ncp_RenameNSEntry(server, old_dir, old_name, old_type,
+					   new_dir, new_name);
+	return result;
+}
+	
 
 /* We have to transfer to/from user space */
 int
@@ -624,4 +797,49 @@
 	ncp_unlock_server(server);
 	return 0;
 }
+
+#ifdef CONFIG_NCPFS_IOCTL_LOCKING
+int
+ncp_LogPhysicalRecord(struct ncp_server *server, const char *file_id,
+	  __u8 locktype, __u32 offset, __u32 length, __u16 timeout)
+{
+	int result;
+
+	ncp_init_request(server);
+	ncp_add_byte(server, locktype);
+	ncp_add_mem(server, file_id, 6);
+	ncp_add_dword(server, htonl(offset));
+	ncp_add_dword(server, htonl(length));
+	ncp_add_word(server, htons(timeout));
+
+	if ((result = ncp_request(server, 0x1A)) != 0)
+	{
+		ncp_unlock_server(server);
+		return result;
+	}
+	ncp_unlock_server(server);
+	return 0;
+}
+
+int
+ncp_ClearPhysicalRecord(struct ncp_server *server, const char *file_id,
+	  __u32 offset, __u32 length)
+{
+	int result;
+
+	ncp_init_request(server);
+	ncp_add_byte(server, 0);	/* who knows... lanalyzer says that */
+	ncp_add_mem(server, file_id, 6);
+	ncp_add_dword(server, htonl(offset));
+	ncp_add_dword(server, htonl(length));
+
+	if ((result = ncp_request(server, 0x1E)) != 0)
+	{
+		ncp_unlock_server(server);
+		return result;
+	}
+	ncp_unlock_server(server);
+	return 0;
+}
+#endif	/* CONFIG_NCPFS_IOCTL_LOCKING */
 

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