patch-2.4.0-test3 linux/fs/ncpfs/symlink.c

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

diff -u --recursive --new-file v2.4.0-test2/linux/fs/ncpfs/symlink.c linux/fs/ncpfs/symlink.c
@@ -50,10 +50,6 @@
 	char *link;
 	char *buf = (char*)kmap(page);
 
-	error = -EIO;
-	if (ncp_make_open(inode,O_RDONLY))
-		goto fail;
-
 	error = -ENOMEM;
 	for (cnt = 0; (link=(char *)kmalloc(NCP_MAX_SYMLINK_SIZE, GFP_NFS))==NULL; cnt++) {
 		if (cnt > 10)
@@ -61,20 +57,22 @@
 		schedule();
 	}
 
+	if (ncp_make_open(inode,O_RDONLY))
+		goto failEIO;
+
 	error=ncp_read_kernel(NCP_SERVER(inode),NCP_FINFO(inode)->file_handle,
                          0,NCP_MAX_SYMLINK_SIZE,link,&length);
 
-	if (error) {
-		kfree(link);
-		goto fail;
-	}
+	ncp_inode_close(inode);
+	/* Close file handle if no other users... */
+	ncp_make_closed(inode);
+	if (error)
+		goto failEIO;
+
 	if (length<NCP_MIN_SYMLINK_SIZE || 
 	    ((__u32 *)link)[0]!=NCP_SYMLINK_MAGIC0 ||
-	    ((__u32 *)link)[1]!=NCP_SYMLINK_MAGIC1) {
-		error = -EIO;
-		kfree(link);
-		goto fail;
-	}
+	    ((__u32 *)link)[1]!=NCP_SYMLINK_MAGIC1)
+	    	goto failEIO;
 
 	len = NCP_MAX_SYMLINK_SIZE;
 	error = ncp_vol2io(NCP_SERVER(inode), buf, &len, link+8, length-8, 0);
@@ -86,6 +84,9 @@
 	UnlockPage(page);
 	return 0;
 
+failEIO:
+	error = -EIO;
+	kfree(link);
 fail:
 	SetPageError(page);
 	kunmap(page);
@@ -120,13 +121,15 @@
 	if ((link=(char *)kmalloc(length+9,GFP_NFS))==NULL)
 		return -ENOMEM;
 
-	if (ncp_create_new(dir,dentry,0,aSHARED|aHIDDEN)) {
-		kfree(link);
-		return -EIO;
-	}
+	err = -EIO;
+	if (ncp_create_new(dir,dentry,0,aSHARED|aHIDDEN))
+		goto failfree;
 
 	inode=dentry->d_inode;
 
+	if (ncp_make_open(inode, O_WRONLY))
+		goto failfree;
+
 	((__u32 *)link)[0]=NCP_SYMLINK_MAGIC0;
 	((__u32 *)link)[1]=NCP_SYMLINK_MAGIC1;
 
@@ -134,19 +137,26 @@
 	   symlink can point out of ncp filesystem */
 	length += 1;
 	err = ncp_io2vol(NCP_SERVER(inode),link+8,&length,symname,length-1,0);
-	if (err) {
-		kfree(link);
-		return err;
-	}
+	if (err)
+		goto fail;
 
 	if(ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle, 
 	    		    0, length+8, link, &i) || i!=length+8) {
-		kfree(link);
-		return -EIO;
+		err = -EIO;
+		goto fail;
 	}
 
+	ncp_inode_close(inode);
+	ncp_make_closed(inode);
 	kfree(link);
 	return 0;
+
+fail:
+	ncp_inode_close(inode);
+	ncp_make_closed(inode);
+failfree:
+	kfree(link);
+	return err;	
 }
 #endif
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)