From mboxrd@z Thu Jan 1 00:00:00 1970 From: Neil Brown Subject: Re: [PATCH -V7 5/9] vfs: Add freadlink syscall Date: Thu, 13 May 2010 16:56:06 +1000 Message-ID: <20100513165606.4bf57bd6@notabene.brown> References: <1273679444-14903-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <1273679444-14903-6-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <20100513114351.793caf70@notabene.brown> <87vdas1fnv.fsf@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: hch@infradead.org, viro@zeniv.linux.org.uk, adilger@sun.com, corbet@lwn.net, serue@us.ibm.com, linux-fsdevel@vger.kernel.org, sfrench@us.ibm.com, philippe.deniel@CEA.FR, linux-kernel@vger.kernel.org To: "Aneesh Kumar K. V" Return-path: In-Reply-To: <87vdas1fnv.fsf@linux.vnet.ibm.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Thu, 13 May 2010 11:55:56 +0530 "Aneesh Kumar K. V" wrote: > On Thu, 13 May 2010 11:43:51 +1000, Neil Brown wrote: > > On Wed, 12 May 2010 21:20:40 +0530 > > "Aneesh Kumar K.V" wrote: > > > > > This enables to use open-by-handle and then get the link target > > > details of a symlink using the fd returned by handle > > > > > > > > > I find it very frustrating that a new syscall seems to be needed here. > > We have 'readlinkat', and it should be enough. > > How: the 'dfd' has to be a 'directory', and the path name as to be non-empty. > > > > The following patch allows 'path' to be NULL and in that case 'dfd' to be a > > non-directory. This allows readlinkat and faccessat (and probably others) > > to be used on an fd with not following path name. > > > > What do people think of this alternative? > > > > I will add this in the next iteration and drop the freadlink syscall. > I wouldn't be quite that hasty. It was only a proposal. It might not be appropriate to change all those syscalls.. An alternative that I don't think is a nice, but is a lot 'safer' is to just change readlinkat to accept a NULL path: Signed-off-by: NeilBrown diff --git a/fs/stat.c b/fs/stat.c index c4ecd52..85d0856 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -284,26 +284,40 @@ SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf) SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname, char __user *, buf, int, bufsiz) { - struct path path; + struct path path, *pp; + struct file *file = NULL; int error; if (bufsiz <= 0) return -EINVAL; - error = user_path_at(dfd, pathname, 0, &path); + if (filename == NULL && dfd != AT_FDCWD) { + struct file *file = fget(dfd); + + if (file) + pp = &file->f_path; + else + error = -EBADF; + } else { + error = user_path_at(dfd, pathname, 0, &path); + pp = &path; + } if (!error) { - struct inode *inode = path.dentry->d_inode; + struct inode *inode = pp->dentry->d_inode; error = -EINVAL; if (inode->i_op->readlink) { - error = security_inode_readlink(path.dentry); + error = security_inode_readlink(pp->dentry); if (!error) { - touch_atime(path.mnt, path.dentry); - error = inode->i_op->readlink(path.dentry, + touch_atime(pp->mnt, pp->dentry); + error = inode->i_op->readlink(pp->dentry, buf, bufsiz); } } - path_put(&path); + if (file) + fput(file); + else + path_put(&path); } return error; }