[PATCH] (5/9) symlink patchkit (against -bk current)

From: viro
Date: Tue Jun 22 2004 - 15:16:14 EST


smbfs - switched from on-stack allocation of buffer for link
body (!) to __getname()/putname(); switched to new scheme.

diff -urN RC7-bk5-page/fs/smbfs/proto.h RC7-bk5-smb/fs/smbfs/proto.h
--- RC7-bk5-page/fs/smbfs/proto.h Sat Sep 27 22:04:57 2003
+++ RC7-bk5-smb/fs/smbfs/proto.h Tue Jun 22 15:13:11 2004
@@ -87,7 +87,5 @@
extern int smb_request_send_server(struct smb_sb_info *server);
extern int smb_request_recv(struct smb_sb_info *server);
/* symlink.c */
-extern int smb_read_link(struct dentry *dentry, char *buffer, int len);
extern int smb_symlink(struct inode *inode, struct dentry *dentry, const char *oldname);
-extern int smb_follow_link(struct dentry *dentry, struct nameidata *nd);
extern struct inode_operations smb_link_inode_operations;
diff -urN RC7-bk5-page/fs/smbfs/symlink.c RC7-bk5-smb/fs/smbfs/symlink.c
--- RC7-bk5-page/fs/smbfs/symlink.c Mon Nov 18 00:16:24 2002
+++ RC7-bk5-smb/fs/smbfs/symlink.c Tue Jun 22 15:13:11 2004
@@ -16,6 +16,7 @@
#include <linux/pagemap.h>
#include <linux/smp_lock.h>
#include <linux/net.h>
+#include <linux/namei.h>

#include <asm/uaccess.h>
#include <asm/system.h>
@@ -26,19 +27,6 @@
#include "smb_debug.h"
#include "proto.h"

-int smb_read_link(struct dentry *dentry, char *buffer, int len)
-{
- char link[256]; /* FIXME: pain ... */
- int r;
- DEBUG1("read link buffer len = %d\n", len);
-
- r = smb_proc_read_link(server_from_dentry(dentry), dentry, link,
- sizeof(link) - 1);
- if (r < 0)
- return -ENOENT;
- return vfs_readlink(dentry, buffer, len, link);
-}
-
int smb_symlink(struct inode *inode, struct dentry *dentry, const char *oldname)
{
DEBUG1("create symlink %s -> %s/%s\n", oldname, DENTRY_PATH(dentry));
@@ -46,24 +34,37 @@
return smb_proc_symlink(server_from_dentry(dentry), dentry, oldname);
}

-int smb_follow_link(struct dentry *dentry, struct nameidata *nd)
+static int smb_follow_link(struct dentry *dentry, struct nameidata *nd)
{
- char link[256]; /* FIXME: pain ... */
- int len;
+ char *link = __getname();
DEBUG1("followlink of %s/%s\n", DENTRY_PATH(dentry));

- len = smb_proc_read_link(server_from_dentry(dentry), dentry, link,
- sizeof(link) - 1);
- if(len < 0)
- return -ENOENT;
-
- link[len] = 0;
- return vfs_follow_link(nd, link);
+ if (!link) {
+ link = ERR_PTR(-ENOMEM);
+ } else {
+ int len = smb_proc_read_link(server_from_dentry(dentry),
+ dentry, link, PATH_MAX - 1);
+ if (len < 0) {
+ putname(link);
+ link = ERR_PTR(len);
+ } else {
+ link[len] = 0;
+ }
+ }
+ nd_set_link(nd, link);
+ return 0;
}

+static void smb_put_link(struct dentry *dentry, struct nameidata *nd)
+{
+ char *s = nd_get_link(nd);
+ if (!IS_ERR(s))
+ putname(s);
+}

struct inode_operations smb_link_inode_operations =
{
- .readlink = smb_read_link,
+ .readlink = generic_readlink,
.follow_link = smb_follow_link,
+ .put_link = smb_put_link,
};
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/