* [PATCH 1/1] devfs: add symlink support
@ 2013-02-16 11:35 Jean-Christophe PLAGNIOL-VILLARD
2013-03-04 20:45 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 7:43 ` Sascha Hauer
0 siblings, 2 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-02-16 11:35 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/driver.h | 1 +
2 files changed, 71 insertions(+)
diff --git a/fs/devfs.c b/fs/devfs.c
index f089c6f..c0047e3 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -216,6 +216,12 @@ static int devfs_stat(struct device_d *_dev, const char *filename, struct stat *
if (!cdev)
return -ENOENT;
+ if (cdev->symlink) {
+ s->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
+ s->st_size = strlen(cdev->symlink);
+ return 0;
+ }
+
s->st_mode = S_IFCHR;
s->st_size = cdev->size;
if (cdev->ops->write)
@@ -235,7 +241,69 @@ static void devfs_delete(struct device_d *dev)
{
}
+static int devfs_symlink(struct device_d *dev, const char *pathname,
+ const char *newpath)
+{
+ struct cdev *cdev;
+ int ret = -ENOMEM;
+
+ cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
+ if (!cdev)
+ return -ENOMEM;
+
+ cdev->symlink = strdup(pathname);
+ if (!cdev->symlink)
+ goto err;
+
+ cdev->name = strdup(newpath + 1);
+ if (!cdev->name)
+ goto err_cdev;
+
+ ret = devfs_create(cdev);
+ if (ret)
+ goto err_create;
+
+ return 0;
+
+err_create:
+ kfree(cdev->name);
+err_cdev:
+ kfree(cdev->symlink);
+err:
+ kfree(cdev);
+ return ret;
+}
+
+static int devfs_readlink(struct device_d *dev, const char *pathname,
+ char *buf, size_t bufsiz)
+{
+ struct cdev *cdev;
+ int len;
+
+ cdev = cdev_by_name(pathname + 1);
+ if (!cdev || !cdev->symlink)
+ return -ENOENT;
+
+ len = min(bufsiz, strlen(cdev->symlink));
+
+ memcpy(buf, cdev->symlink, len);
+
+ return 0;
+}
+
+static int devfs_unlink(struct device_d *dev, const char *pathname)
+{
+ struct cdev *cdev;
+
+ cdev = cdev_by_name(pathname + 1);
+ if (!cdev || !cdev->symlink)
+ return -EPERM;
+
+ return devfs_remove(cdev);
+}
+
static struct fs_driver_d devfs_driver = {
+ .unlink = devfs_unlink,
.read = devfs_read,
.write = devfs_write,
.lseek = devfs_lseek,
@@ -248,6 +316,8 @@ static struct fs_driver_d devfs_driver = {
.truncate = devfs_truncate,
.closedir = devfs_closedir,
.stat = devfs_stat,
+ .symlink = devfs_symlink,
+ .readlink = devfs_readlink,
.erase = devfs_erase,
.protect = devfs_protect,
.memmap = devfs_memmap,
diff --git a/include/driver.h b/include/driver.h
index 151829e..1b0e619 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -432,6 +432,7 @@ struct cdev {
loff_t size;
unsigned int flags;
int open;
+ char *symlink;
struct mtd_info *mtd;
};
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] devfs: add symlink support
2013-02-16 11:35 [PATCH 1/1] devfs: add symlink support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-04 20:45 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 7:43 ` Sascha Hauer
1 sibling, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-04 20:45 UTC (permalink / raw)
To: barebox
ping
On 12:35 Sat 16 Feb , Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> include/driver.h | 1 +
> 2 files changed, 71 insertions(+)
>
> diff --git a/fs/devfs.c b/fs/devfs.c
> index f089c6f..c0047e3 100644
> --- a/fs/devfs.c
> +++ b/fs/devfs.c
> @@ -216,6 +216,12 @@ static int devfs_stat(struct device_d *_dev, const char *filename, struct stat *
> if (!cdev)
> return -ENOENT;
>
> + if (cdev->symlink) {
> + s->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
> + s->st_size = strlen(cdev->symlink);
> + return 0;
> + }
> +
> s->st_mode = S_IFCHR;
> s->st_size = cdev->size;
> if (cdev->ops->write)
> @@ -235,7 +241,69 @@ static void devfs_delete(struct device_d *dev)
> {
> }
>
> +static int devfs_symlink(struct device_d *dev, const char *pathname,
> + const char *newpath)
> +{
> + struct cdev *cdev;
> + int ret = -ENOMEM;
> +
> + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
> + if (!cdev)
> + return -ENOMEM;
> +
> + cdev->symlink = strdup(pathname);
> + if (!cdev->symlink)
> + goto err;
> +
> + cdev->name = strdup(newpath + 1);
> + if (!cdev->name)
> + goto err_cdev;
> +
> + ret = devfs_create(cdev);
> + if (ret)
> + goto err_create;
> +
> + return 0;
> +
> +err_create:
> + kfree(cdev->name);
> +err_cdev:
> + kfree(cdev->symlink);
> +err:
> + kfree(cdev);
> + return ret;
> +}
> +
> +static int devfs_readlink(struct device_d *dev, const char *pathname,
> + char *buf, size_t bufsiz)
> +{
> + struct cdev *cdev;
> + int len;
> +
> + cdev = cdev_by_name(pathname + 1);
> + if (!cdev || !cdev->symlink)
> + return -ENOENT;
> +
> + len = min(bufsiz, strlen(cdev->symlink));
> +
> + memcpy(buf, cdev->symlink, len);
> +
> + return 0;
> +}
> +
> +static int devfs_unlink(struct device_d *dev, const char *pathname)
> +{
> + struct cdev *cdev;
> +
> + cdev = cdev_by_name(pathname + 1);
> + if (!cdev || !cdev->symlink)
> + return -EPERM;
> +
> + return devfs_remove(cdev);
> +}
> +
> static struct fs_driver_d devfs_driver = {
> + .unlink = devfs_unlink,
> .read = devfs_read,
> .write = devfs_write,
> .lseek = devfs_lseek,
> @@ -248,6 +316,8 @@ static struct fs_driver_d devfs_driver = {
> .truncate = devfs_truncate,
> .closedir = devfs_closedir,
> .stat = devfs_stat,
> + .symlink = devfs_symlink,
> + .readlink = devfs_readlink,
> .erase = devfs_erase,
> .protect = devfs_protect,
> .memmap = devfs_memmap,
> diff --git a/include/driver.h b/include/driver.h
> index 151829e..1b0e619 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -432,6 +432,7 @@ struct cdev {
> loff_t size;
> unsigned int flags;
> int open;
> + char *symlink;
> struct mtd_info *mtd;
> };
>
> --
> 1.7.10.4
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] devfs: add symlink support
2013-02-16 11:35 [PATCH 1/1] devfs: add symlink support Jean-Christophe PLAGNIOL-VILLARD
2013-03-04 20:45 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-06 7:43 ` Sascha Hauer
2013-03-06 8:01 ` Jean-Christophe PLAGNIOL-VILLARD
1 sibling, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2013-03-06 7:43 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sat, Feb 16, 2013 at 12:35:53PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> include/driver.h | 1 +
> 2 files changed, 71 insertions(+)
What's your usecase with this patch? Telling me could increase my
motivation applying it.
One thing I see with this patch that the next thing would be to add
directory support to debugfs in which case we might be better off
adding real device nodes and remove the devfs like we have it now
completely.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] devfs: add symlink support
2013-03-06 7:43 ` Sascha Hauer
@ 2013-03-06 8:01 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 8:11 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-06 8:01 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 08:43 Wed 06 Mar , Sascha Hauer wrote:
> On Sat, Feb 16, 2013 at 12:35:53PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > include/driver.h | 1 +
> > 2 files changed, 71 insertions(+)
>
> What's your usecase with this patch? Telling me could increase my
> motivation applying it.
I use it to handle boot device and tty today
so the application part does not care about the real hardware they always have
the same device (file) to search
>
> One thing I see with this patch that the next thing would be to add
> directory support to debugfs in which case we might be better off
> adding real device nodes and remove the devfs like we have it now
> completely.
yeah I've the idea to rewrite the devfs completly and the ramfs too
as the ramfs should be at vfs level so the devfs will nearly implement nothing
Best Regards,
J.
>
> Sascha
>
>
> --
> Pengutronix e.K. | |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] devfs: add symlink support
2013-03-06 8:01 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-03-06 8:11 ` Sascha Hauer
2013-03-06 8:41 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2013-03-06 8:11 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Wed, Mar 06, 2013 at 09:01:18AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 08:43 Wed 06 Mar , Sascha Hauer wrote:
> > On Sat, Feb 16, 2013 at 12:35:53PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > ---
> > > fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > include/driver.h | 1 +
> > > 2 files changed, 71 insertions(+)
> >
> > What's your usecase with this patch? Telling me could increase my
> > motivation applying it.
> I use it to handle boot device and tty today
>
> so the application part does not care about the real hardware they always have
> the same device (file) to search
This is in the same league as I wanted to do with persistent device
names. We should think about this in a more general way.
> >
> > One thing I see with this patch that the next thing would be to add
> > directory support to debugfs in which case we might be better off
> > adding real device nodes and remove the devfs like we have it now
> > completely.
> yeah I've the idea to rewrite the devfs completly and the ramfs too
>
> as the ramfs should be at vfs level so the devfs will nearly implement nothing
vfs level? You would have to implement one first, we do not have a vfs
level at all ;)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] devfs: add symlink support
2013-03-06 8:11 ` Sascha Hauer
@ 2013-03-06 8:41 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-06 8:41 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 09:11 Wed 06 Mar , Sascha Hauer wrote:
> On Wed, Mar 06, 2013 at 09:01:18AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 08:43 Wed 06 Mar , Sascha Hauer wrote:
> > > On Sat, Feb 16, 2013 at 12:35:53PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > > ---
> > > > fs/devfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > include/driver.h | 1 +
> > > > 2 files changed, 71 insertions(+)
> > >
> > > What's your usecase with this patch? Telling me could increase my
> > > motivation applying it.
> > I use it to handle boot device and tty today
> >
> > so the application part does not care about the real hardware they always have
> > the same device (file) to search
>
> This is in the same league as I wanted to do with persistent device
> names. We should think about this in a more general way.
>
> > >
> > > One thing I see with this patch that the next thing would be to add
> > > directory support to debugfs in which case we might be better off
> > > adding real device nodes and remove the devfs like we have it now
> > > completely.
> > yeah I've the idea to rewrite the devfs completly and the ramfs too
> >
> > as the ramfs should be at vfs level so the devfs will nearly implement nothing
>
> vfs level? You would have to implement one first, we do not have a vfs
> level at all ;)
yeah because today we duplicate too much code so with this we wil reduce the
size of barebox
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-03-06 8:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-16 11:35 [PATCH 1/1] devfs: add symlink support Jean-Christophe PLAGNIOL-VILLARD
2013-03-04 20:45 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 7:43 ` Sascha Hauer
2013-03-06 8:01 ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 8:11 ` Sascha Hauer
2013-03-06 8:41 ` Jean-Christophe PLAGNIOL-VILLARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox