mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/3] devfs: add symlink support
@ 2013-10-18 16:31 Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33 ` [PATCH 1/3] " Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-18 16:31 UTC (permalink / raw)
  To: barebox

Hi,

The following changes since commit 8f23a17f9bac836e4a2f4883ca8f886f535449a8:

  Merge branch 'pu/bootloader-spec' (2013-10-14 15:46:10 +0200)

are available in the git repository at:


  git://git.jcrosoft.org/barebox.git delivery/devfs_symlink

for you to fetch changes up to 249a2883ed1d72cf735b68b5f7a0671e6de3ed14:

  USB: storage: register disks as usbdiskx symlink (2013-10-16 03:59:34 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
      devfs: add symlink support
      partition: use symlink for named partition

Sascha Hauer (1):
      USB: storage: register disks as usbdiskx symlink

 common/partitions.c       |  3 +--
 drivers/usb/storage/usb.c |  8 ++++++++
 fs/devfs-core.c           | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/devfs.c                | 42 ++++++++++++++++++++++++++++++++++++++++--
 include/driver.h          |  4 ++++
 5 files changed, 97 insertions(+), 5 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] devfs: add symlink support
  2013-10-18 16:31 [PATCH 0/3] devfs: add symlink support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-18 16:33 ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33   ` [PATCH 2/3] partition: use symlink for named partition Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-18 16:33 UTC (permalink / raw)
  To: barebox

this will allow have symlink for any device such as named partition

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 fs/devfs-core.c  | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/devfs.c       | 42 ++++++++++++++++++++++++++++++++++++++++--
 include/driver.h |  4 ++++
 3 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index a92d434..0e1ac9a 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -45,13 +45,56 @@ int devfs_partition_complete(struct string_list *sl, char *instr)
 }
 #endif
 
+struct cdev *devfs_add_symlink_index(const char *filename, struct cdev *src)
+{
+	struct cdev *cdev;
+	int ret;
+
+	if (!filename || !src)
+		return ERR_PTR(-EIO);
+
+	ret = cdev_find_free_index(filename);
+	if (ret == -1)
+		return ERR_PTR(-ENOMEM);
+
+	cdev = xzalloc(sizeof(*cdev));
+	cdev->name = asprintf("%s%d", filename, ret);
+	cdev->symlink = src;
+	ret = devfs_create(cdev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return cdev;
+}
+
+struct cdev *devfs_add_symlink(const char *filename, struct cdev *src)
+{
+	struct cdev *cdev;
+	int ret;
+
+	if (!filename || !src)
+		return ERR_PTR(-EIO);
+
+	cdev = xzalloc(sizeof(*cdev));
+	cdev->name = xstrdup(filename);
+	cdev->symlink = src;
+	ret = devfs_create(cdev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return cdev;
+}
+
 struct cdev *cdev_by_name(const char *filename)
 {
 	struct cdev *cdev;
 
 	list_for_each_entry(cdev, &cdev_list, list) {
-		if (!strcmp(cdev->name, filename))
+		if (!strcmp(cdev->name, filename)) {
+			if (cdev->symlink)
+				return cdev->symlink;
 			return cdev;
+		}
 	}
 	return NULL;
 }
diff --git a/fs/devfs.c b/fs/devfs.c
index f089c6f..f4e1e9c 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -35,6 +35,17 @@
 
 extern struct list_head cdev_list;
 
+static struct cdev *devfs_by_name(const char *filename)
+{
+	struct cdev *cdev;
+
+	list_for_each_entry(cdev, &cdev_list, list) {
+		if (!strcmp(cdev->name, filename))
+			return cdev;
+	}
+	return NULL;
+}
+
 static int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
 {
 	struct cdev *cdev = f->inode;
@@ -113,7 +124,7 @@ static int devfs_open(struct device_d *_dev, FILE *f, const char *filename)
 	struct cdev *cdev;
 	int ret;
 
-	cdev = cdev_by_name(filename + 1);
+	cdev = devfs_by_name(filename + 1);
 
 	if (!cdev)
 		return -ENOENT;
@@ -212,10 +223,15 @@ static int devfs_stat(struct device_d *_dev, const char *filename, struct stat *
 {
 	struct cdev *cdev;
 
-	cdev = cdev_by_name(filename + 1);
+	cdev = devfs_by_name(filename + 1);
 	if (!cdev)
 		return -ENOENT;
 
+	if (cdev->symlink) {
+		s->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
+		return 0;
+	}
+
 	s->st_mode = S_IFCHR;
 	s->st_size = cdev->size;
 	if (cdev->ops->write)
@@ -235,6 +251,27 @@ static void devfs_delete(struct device_d *dev)
 {
 }
 
+static int devfs_readlink(struct device_d *dev, const char *filename,
+			char *buf, size_t bufsiz)
+{
+	struct cdev *cdev;
+	struct cdev *symlink;
+	int len;
+
+	cdev = devfs_by_name(filename + 1);
+
+	if (!cdev || !cdev->symlink)
+		return -ENOENT;
+
+	symlink = cdev->symlink;
+
+	len = min(bufsiz, strlen(symlink->name));
+
+	memcpy(buf, symlink->name, len);
+
+	return 0;
+}
+
 static struct fs_driver_d devfs_driver = {
 	.read      = devfs_read,
 	.write     = devfs_write,
@@ -251,6 +288,7 @@ static struct fs_driver_d devfs_driver = {
 	.erase     = devfs_erase,
 	.protect   = devfs_protect,
 	.memmap    = devfs_memmap,
+	.readlink  = devfs_readlink,
 	.flags     = FS_DRIVER_NO_DEV,
 	.drv = {
 		.probe  = devfs_probe,
diff --git a/include/driver.h b/include/driver.h
index 7f0532e..2d42597 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -457,10 +457,14 @@ struct cdev {
 	int open;
 	struct mtd_info *mtd;
 	u8 dos_partition_type;
+
+	struct cdev *symlink;
 };
 
 int devfs_create(struct cdev *);
 int devfs_remove(struct cdev *);
+struct cdev *devfs_add_symlink(const char *filename, struct cdev *src);
+struct cdev *devfs_add_symlink_index(const char *filename, struct cdev *src);
 int cdev_find_free_index(const char *);
 struct cdev *device_find_partition(struct device_d *dev, const char *name);
 struct cdev *cdev_by_name(const char *filename);
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] partition: use symlink for named partition
  2013-10-18 16:33 ` [PATCH 1/3] " Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-18 16:33   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33   ` [PATCH 3/3] USB: storage: register disks as usbdiskx symlink Jean-Christophe PLAGNIOL-VILLARD
  2013-10-21  8:42   ` [PATCH 1/3] devfs: add symlink support Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-18 16:33 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/partitions.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/partitions.c b/common/partitions.c
index 694c6f6..b6c9819 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -76,8 +76,7 @@ static int register_one_partition(struct block_device *blk,
 
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
 				partition_name, blk->cdev.name);
-	cdev = devfs_add_partition(blk->cdev.name,
-				start, size, 0, partition_name);
+	cdev = devfs_add_symlink(partition_name, cdev);
 
 	if (IS_ERR(cdev))
 		dev_warn(blk->dev, "Registering partition %s on drive %s failed\n",
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] USB: storage: register disks as usbdiskx symlink
  2013-10-18 16:33 ` [PATCH 1/3] " Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33   ` [PATCH 2/3] partition: use symlink for named partition Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-18 16:33   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-10-21  8:42   ` [PATCH 1/3] devfs: add symlink support Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-18 16:33 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

To better identify them as USB storage devices. Also make the
info message look nicer.

We keep the old disk%d to do not brake backword compatibility for env.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/usb/storage/usb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index e4b08b9..6833983 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -25,6 +25,7 @@
 #include <scsi.h>
 #include <usb/usb.h>
 #include <usb/usb_defs.h>
+#include <linux/err.h>
 
 #undef USB_STOR_DEBUG
 
@@ -376,6 +377,7 @@ static int usb_stor_add_blkdev(struct us_data *us, struct device_d *dev,
 							unsigned char lun)
 {
 	struct us_blk_dev *pblk_dev;
+	struct cdev *cdev;
 	int result;
 
 	/* allocate a new USB block device */
@@ -406,6 +408,12 @@ static int usb_stor_add_blkdev(struct us_data *us, struct device_d *dev,
 		goto BadDevice;
 	}
 
+	cdev = devfs_add_symlink_index("usbdisk", &pblk_dev->blk.cdev);
+	if (IS_ERR(cdev))
+		dev_warn(dev, "Cannot create symlink usbdisk\n");
+	else
+		dev_info(dev, "registered /dev/%s\n", cdev->name);
+
 	/* create partitions on demand */
 	result = parse_partition_table(&pblk_dev->blk);
 	if (result != 0)
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] devfs: add symlink support
  2013-10-18 16:33 ` [PATCH 1/3] " Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33   ` [PATCH 2/3] partition: use symlink for named partition Jean-Christophe PLAGNIOL-VILLARD
  2013-10-18 16:33   ` [PATCH 3/3] USB: storage: register disks as usbdiskx symlink Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-21  8:42   ` Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-10-21  8:42 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Oct 18, 2013 at 06:33:10PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> this will allow have symlink for any device such as named partition
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  fs/devfs-core.c  | 45 ++++++++++++++++++++++++++++++++++++++++++++-
>  fs/devfs.c       | 42 ++++++++++++++++++++++++++++++++++++++++--
>  include/driver.h |  4 ++++
>  3 files changed, 88 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index a92d434..0e1ac9a 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -45,13 +45,56 @@ int devfs_partition_complete(struct string_list *sl, char *instr)
>  }
>  #endif
>  
> +struct cdev *devfs_add_symlink_index(const char *filename, struct cdev *src)
> +{
> +	struct cdev *cdev;
> +	int ret;
> +
> +	if (!filename || !src)
> +		return ERR_PTR(-EIO);
> +
> +	ret = cdev_find_free_index(filename);
> +	if (ret == -1)
> +		return ERR_PTR(-ENOMEM);
> +
> +	cdev = xzalloc(sizeof(*cdev));
> +	cdev->name = asprintf("%s%d", filename, ret);
> +	cdev->symlink = src;
> +	ret = devfs_create(cdev);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	return cdev;
> +}
> +
> +struct cdev *devfs_add_symlink(const char *filename, struct cdev *src)
> +{
> +	struct cdev *cdev;
> +	int ret;
> +
> +	if (!filename || !src)
> +		return ERR_PTR(-EIO);
> +
> +	cdev = xzalloc(sizeof(*cdev));
> +	cdev->name = xstrdup(filename);
> +	cdev->symlink = src;

This is not nice.

- You only allow a single symlink
- No check whether this symlink already exists
- calling devfs_remove leaves dangling symlinks behind

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] 5+ messages in thread

end of thread, other threads:[~2013-10-21  8:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 16:31 [PATCH 0/3] devfs: add symlink support Jean-Christophe PLAGNIOL-VILLARD
2013-10-18 16:33 ` [PATCH 1/3] " Jean-Christophe PLAGNIOL-VILLARD
2013-10-18 16:33   ` [PATCH 2/3] partition: use symlink for named partition Jean-Christophe PLAGNIOL-VILLARD
2013-10-18 16:33   ` [PATCH 3/3] USB: storage: register disks as usbdiskx symlink Jean-Christophe PLAGNIOL-VILLARD
2013-10-21  8:42   ` [PATCH 1/3] devfs: add symlink support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox