* [patch] F_GETPATH implementation (rev 2)
@ 2008-04-15 0:35 Davide Libenzi
2008-04-15 2:41 ` Linus Torvalds
0 siblings, 1 reply; 4+ messages in thread
From: Davide Libenzi @ 2008-04-15 0:35 UTC (permalink / raw)
To: Linux Kernel Mailing List
Cc: Linus Torvalds, Andrew Morton, Arnd Bergmann, Al Viro,
Michael Kerrisk, Christoph Hellwig
This is a small patch to support BSD's F_GETPATH on Linux.
IMO the simplicity of the patch and the portability advantages makes it
worth it. I'll leave to others to further comments it.
Built and tested on my box against 2.6.25-rc9. Simple test program here:
http://www.xmailserver.org/fgetpath-test.c
Changes from the initial post:
- Removed the un-needed export (Arnd)
- Moved F_GETPATH definition inside the Linux specific range (Linus)
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
- Davide
---
fs/fcntl.c | 26 ++++++++++++++++++++++++++
fs/proc/base.c | 26 +-------------------------
include/linux/fcntl.h | 13 ++++++++-----
include/linux/fs.h | 1 +
4 files changed, 36 insertions(+), 30 deletions(-)
Index: linux-2.6.mod/fs/fcntl.c
===================================================================
--- linux-2.6.mod.orig/fs/fcntl.c 2008-04-14 13:17:37.000000000 -0700
+++ linux-2.6.mod/fs/fcntl.c 2008-04-14 16:01:32.000000000 -0700
@@ -316,6 +316,28 @@
return pid;
}
+int fcntl_getpath(struct path *fpath, char __user *path, int maxsize)
+{
+ int size;
+ char *buf, *pathname;
+
+ buf = (char *) __get_free_page(GFP_TEMPORARY);
+ if (!buf)
+ return -ENOMEM;
+ pathname = d_path(fpath, buf, PAGE_SIZE);
+ size = PTR_ERR(pathname);
+ if (IS_ERR(pathname))
+ goto error;
+ size = buf + PAGE_SIZE - 1 - pathname;
+ if (size > maxsize)
+ size = maxsize;
+ if (copy_to_user(path, pathname, size))
+ size = -EFAULT;
+error:
+ free_page((unsigned long) buf);
+ return size;
+}
+
static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
struct file *filp)
{
@@ -381,6 +403,10 @@
case F_NOTIFY:
err = fcntl_dirnotify(fd, filp, arg);
break;
+ case F_GETPATH:
+ err = fcntl_getpath(&filp->f_path, (char __user *) arg,
+ PATH_MAX);
+ break;
default:
break;
}
Index: linux-2.6.mod/fs/proc/base.c
===================================================================
--- linux-2.6.mod.orig/fs/proc/base.c 2008-04-14 13:17:37.000000000 -0700
+++ linux-2.6.mod/fs/proc/base.c 2008-04-14 16:01:32.000000000 -0700
@@ -1192,30 +1192,6 @@
return ERR_PTR(error);
}
-static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
-{
- char *tmp = (char*)__get_free_page(GFP_TEMPORARY);
- char *pathname;
- int len;
-
- if (!tmp)
- return -ENOMEM;
-
- pathname = d_path(path, tmp, PAGE_SIZE);
- len = PTR_ERR(pathname);
- if (IS_ERR(pathname))
- goto out;
- len = tmp + PAGE_SIZE - 1 - pathname;
-
- if (len > buflen)
- len = buflen;
- if (copy_to_user(buffer, pathname, len))
- len = -EFAULT;
- out:
- free_page((unsigned long)tmp);
- return len;
-}
-
static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen)
{
int error = -EACCES;
@@ -1230,7 +1206,7 @@
if (error)
goto out;
- error = do_proc_readlink(&path, buffer, buflen);
+ error = fcntl_getpath(&path, buffer, buflen);
path_put(&path);
out:
return error;
Index: linux-2.6.mod/include/linux/fs.h
===================================================================
--- linux-2.6.mod.orig/include/linux/fs.h 2008-04-14 13:17:37.000000000 -0700
+++ linux-2.6.mod/include/linux/fs.h 2008-04-14 16:01:32.000000000 -0700
@@ -960,6 +960,7 @@
/* only for net: no internal synchronization */
extern void __kill_fasync(struct fasync_struct *, int, int);
+extern int fcntl_getpath(struct path *fpath, char __user *path, int maxsize);
extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
extern int f_setown(struct file *filp, unsigned long arg, int force);
extern void f_delown(struct file *filp);
Index: linux-2.6.mod/include/linux/fcntl.h
===================================================================
--- linux-2.6.mod.orig/include/linux/fcntl.h 2008-04-14 16:04:31.000000000 -0700
+++ linux-2.6.mod/include/linux/fcntl.h 2008-04-14 16:06:31.000000000 -0700
@@ -7,6 +7,12 @@
#define F_GETLEASE (F_LINUX_SPECIFIC_BASE + 1)
/*
+ * Request nofications on a directory.
+ * See below for events that may be notified.
+ */
+#define F_NOTIFY (F_LINUX_SPECIFIC_BASE+2)
+
+/*
* Cancel a blocking posix lock; internal use only until we expose an
* asynchronous lock api to userspace:
*/
@@ -15,11 +21,8 @@
/* Create a file descriptor with FD_CLOEXEC set. */
#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6)
-/*
- * Request nofications on a directory.
- * See below for events that may be notified.
- */
-#define F_NOTIFY (F_LINUX_SPECIFIC_BASE+2)
+/* Retrieve the path associated with the file descriptor */
+#define F_GETPATH (F_LINUX_SPECIFIC_BASE+7)
/*
* Types of directory notifications that may be requested.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] F_GETPATH implementation (rev 2)
2008-04-15 0:35 [patch] F_GETPATH implementation (rev 2) Davide Libenzi
@ 2008-04-15 2:41 ` Linus Torvalds
2008-04-15 6:34 ` Michael Kerrisk
0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2008-04-15 2:41 UTC (permalink / raw)
To: Davide Libenzi
Cc: Linux Kernel Mailing List, Andrew Morton, Arnd Bergmann, Al Viro,
Michael Kerrisk, Christoph Hellwig
On Mon, 14 Apr 2008, Davide Libenzi wrote:
>
> This is a small patch to support BSD's F_GETPATH on Linux.
> IMO the simplicity of the patch and the portability advantages makes it
> worth it. I'll leave to others to further comments it.
So, I'd like to know who (if anybody) really uses F_GETPATH.
I think the patch is simple enough, and if there is a real program that is
worth porting for which this actually matters, I don't really see any
downsides. But I'd like to hear more about it, and I also wonder if others
do it differently.
Also, are there any other interfaces that other OS's use for this, do you
know? Would be good to know before/if we decide to support something like
this..
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] F_GETPATH implementation (rev 2)
2008-04-15 2:41 ` Linus Torvalds
@ 2008-04-15 6:34 ` Michael Kerrisk
2008-04-15 17:43 ` Davide Libenzi
0 siblings, 1 reply; 4+ messages in thread
From: Michael Kerrisk @ 2008-04-15 6:34 UTC (permalink / raw)
To: Linus Torvalds
Cc: Davide Libenzi, Linux Kernel Mailing List, Andrew Morton,
Arnd Bergmann, Al Viro, Michael Kerrisk, Christoph Hellwig
On Tue, Apr 15, 2008 at 4:41 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
>
> On Mon, 14 Apr 2008, Davide Libenzi wrote:
> >
> > This is a small patch to support BSD's F_GETPATH on Linux.
> > IMO the simplicity of the patch and the portability advantages makes it
> > worth it. I'll leave to others to further comments it.
>
> So, I'd like to know who (if anybody) really uses F_GETPATH.
Davide described this as "BSD's F_GETPATH". It's worth clarifying
that more accurately this is "MacOS's F_GETPATH". I can't find any
trace of F_GETPATH on Net/Open/FreeBSD, Solaris doesn't seem to have
it either, and none of the other systems I checked has it either.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] F_GETPATH implementation (rev 2)
2008-04-15 6:34 ` Michael Kerrisk
@ 2008-04-15 17:43 ` Davide Libenzi
0 siblings, 0 replies; 4+ messages in thread
From: Davide Libenzi @ 2008-04-15 17:43 UTC (permalink / raw)
To: Michael Kerrisk
Cc: Linus Torvalds, Linux Kernel Mailing List, Andrew Morton,
Arnd Bergmann, Al Viro, Michael Kerrisk, Christoph Hellwig
On Tue, 15 Apr 2008, Michael Kerrisk wrote:
> On Tue, Apr 15, 2008 at 4:41 AM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> >
> > On Mon, 14 Apr 2008, Davide Libenzi wrote:
> > >
> > > This is a small patch to support BSD's F_GETPATH on Linux.
> > > IMO the simplicity of the patch and the portability advantages makes it
> > > worth it. I'll leave to others to further comments it.
> >
> > So, I'd like to know who (if anybody) really uses F_GETPATH.
>
> Davide described this as "BSD's F_GETPATH". It's worth clarifying
> that more accurately this is "MacOS's F_GETPATH". I can't find any
> trace of F_GETPATH on Net/Open/FreeBSD, Solaris doesn't seem to have
> it either, and none of the other systems I checked has it either.
Oh, I thought it was a common BSD-isdh thing. I did find it inside some
OSX code indeed.
Given this, and given that the interface is not that great too (buffer
size bolt in), I think we can safely drop it.
- Davide
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-04-15 17:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-15 0:35 [patch] F_GETPATH implementation (rev 2) Davide Libenzi
2008-04-15 2:41 ` Linus Torvalds
2008-04-15 6:34 ` Michael Kerrisk
2008-04-15 17:43 ` Davide Libenzi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®