From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: Re: [PATCH 1/1] devfs: add symlink support
Date: Mon, 4 Mar 2013 21:45:01 +0100 [thread overview]
Message-ID: <20130304204501.GK23022@game.jcrosoft.org> (raw)
In-Reply-To: <1361014553-24489-1-git-send-email-plagnioj@jcrosoft.com>
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
next prev parent reply other threads:[~2013-03-04 20:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-16 11:35 Jean-Christophe PLAGNIOL-VILLARD
2013-03-04 20:45 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130304204501.GK23022@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox