mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* devfs fixes
@ 2015-10-13  7:51 Sascha Hauer
  2015-10-13  7:51 ` [PATCH 1/4] fs: devfs: Allow mounting only on /dev/ Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  7:51 UTC (permalink / raw)
  To: Barebox List

We have some places in the code where we expect a cdev name, but
also allow a full /dev/ path. We handle this by doing:

	if (!strncmp(name, "/dev/", 5))
		name += 5;

As Peter noticed this of course only works when devfs is mounted on
/dev/. With this series we actually enforce that to avoid surprises.
Also we "officially" allow to pass a /dev/ path for opening a cdev
by moving the above code to cdev_open.

Sascha

----------------------------------------------------------------
Sascha Hauer (4):
      fs: devfs: Allow mounting only on /dev/
      fs: devfs: Allow mount path in cdev_open
      filetype: Use cdev_open
      fs: pass path directly to cdev_open

 common/filetype.c | 4 +++-
 fs/devfs-core.c   | 6 +++++-
 fs/devfs.c        | 7 +++++++
 fs/fs.c           | 9 +--------
 4 files changed, 16 insertions(+), 10 deletions(-)

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

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

* [PATCH 1/4] fs: devfs: Allow mounting only on /dev/
  2015-10-13  7:51 devfs fixes Sascha Hauer
@ 2015-10-13  7:51 ` Sascha Hauer
  2015-10-13  7:51 ` [PATCH 2/4] fs: devfs: Allow mount path in cdev_open Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  7:51 UTC (permalink / raw)
  To: Barebox List

We have places in the code where we assume that devfs is mounted on
/dev/, so enforce this path to avoid surprises.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/devfs.c b/fs/devfs.c
index c6db25c..5c96682 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -228,6 +228,13 @@ static int devfs_stat(struct device_d *_dev, const char *filename, struct stat *
 
 static int devfs_probe(struct device_d *dev)
 {
+	struct fs_device_d *fsdev = dev_to_fs_device(dev);
+
+	if (strcmp(fsdev->path, "/dev")) {
+		dev_err(dev, "devfs can only be mounted on /dev/\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.6.0


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

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

* [PATCH 2/4] fs: devfs: Allow mount path in cdev_open
  2015-10-13  7:51 devfs fixes Sascha Hauer
  2015-10-13  7:51 ` [PATCH 1/4] fs: devfs: Allow mounting only on /dev/ Sascha Hauer
@ 2015-10-13  7:51 ` Sascha Hauer
  2015-10-13  8:25   ` Sascha Hauer
  2015-10-13  7:51 ` [PATCH 3/4] filetype: Use cdev_open Sascha Hauer
  2015-10-13  7:51 ` [PATCH 4/4] fs: pass path directly to cdev_open Sascha Hauer
  3 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  7:51 UTC (permalink / raw)
  To: Barebox List

When opening a cdev also allow a path beginning with /dev/ as some
users of cdev_open already open coded this behaviour.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 62571fb..26f56d9 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -121,9 +121,13 @@ int cdev_do_open(struct cdev *cdev, unsigned long flags)
 
 struct cdev *cdev_open(const char *name, unsigned long flags)
 {
-	struct cdev *cdev = cdev_by_name(name);
+	struct cdev *cdev;
 	int ret;
 
+	if (strncmp(name, "/dev/", 5))
+		name += 5;
+
+	cdev = cdev_by_name(name);
 	if (!cdev)
 		return NULL;
 
-- 
2.6.0


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

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

* [PATCH 3/4] filetype: Use cdev_open
  2015-10-13  7:51 devfs fixes Sascha Hauer
  2015-10-13  7:51 ` [PATCH 1/4] fs: devfs: Allow mounting only on /dev/ Sascha Hauer
  2015-10-13  7:51 ` [PATCH 2/4] fs: devfs: Allow mount path in cdev_open Sascha Hauer
@ 2015-10-13  7:51 ` Sascha Hauer
  2015-10-13  7:51 ` [PATCH 4/4] fs: pass path directly to cdev_open Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  7:51 UTC (permalink / raw)
  To: Barebox List

a cdev has to be opened before usage. Use cdev_open instead of
cdev_by_name.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c | 4 +++-
 fs/fs.c           | 2 --
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index dc2ff3f..9ec8ebf 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -369,9 +369,10 @@ enum filetype cdev_detect_type(const char *name)
 	struct cdev *cdev;
 	void *buf;
 
-	cdev = cdev_by_name(name);
+	cdev = cdev_open(name, O_RDONLY);
 	if (!cdev)
 		return type;
+
 	buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
 	ret = cdev_read(cdev, buf, FILE_TYPE_SAFE_BUFSIZE, 0, 0);
 	if (ret < 0)
@@ -396,5 +397,6 @@ enum filetype cdev_detect_type(const char *name)
 
 err_out:
 	free(buf);
+	cdev_close(cdev);
 	return type;
 }
diff --git a/fs/fs.c b/fs/fs.c
index c2a20e1..2d7578b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1205,8 +1205,6 @@ static const char *detect_fs(const char *filename)
 	struct driver_d *drv;
 	struct fs_driver_d *fdrv;
 
-	if (!strncmp(filename, "/dev/", 5))
-		filename += 5;
 	type = cdev_detect_type(filename);
 
 	if (type == filetype_unknown)
-- 
2.6.0


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

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

* [PATCH 4/4] fs: pass path directly to cdev_open
  2015-10-13  7:51 devfs fixes Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-10-13  7:51 ` [PATCH 3/4] filetype: Use cdev_open Sascha Hauer
@ 2015-10-13  7:51 ` Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  7:51 UTC (permalink / raw)
  To: Barebox List

Now that cdev_open handles a path we no longer have to add /dev/ to
the name.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 2d7578b..4983fc7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1222,12 +1222,7 @@ static const char *detect_fs(const char *filename)
 
 int fsdev_open_cdev(struct fs_device_d *fsdev)
 {
-	const char *backingstore = fsdev->backingstore;
-
-	if (!strncmp(backingstore , "/dev/", 5))
-		backingstore += 5;
-
-	fsdev->cdev = cdev_open(backingstore, O_RDWR);
+	fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR);
 	if (!fsdev->cdev)
 		return -EINVAL;
 
-- 
2.6.0


_______________________________________________
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 2/4] fs: devfs: Allow mount path in cdev_open
  2015-10-13  7:51 ` [PATCH 2/4] fs: devfs: Allow mount path in cdev_open Sascha Hauer
@ 2015-10-13  8:25   ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-10-13  8:25 UTC (permalink / raw)
  To: Barebox List

On Tue, Oct 13, 2015 at 09:51:52AM +0200, Sascha Hauer wrote:
> When opening a cdev also allow a path beginning with /dev/ as some
> users of cdev_open already open coded this behaviour.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  fs/devfs-core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index 62571fb..26f56d9 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -121,9 +121,13 @@ int cdev_do_open(struct cdev *cdev, unsigned long flags)
>  
>  struct cdev *cdev_open(const char *name, unsigned long flags)
>  {
> -	struct cdev *cdev = cdev_by_name(name);
> +	struct cdev *cdev;
>  	int ret;
>  
> +	if (strncmp(name, "/dev/", 5))
> +		name += 5;

And with the missing '!' before strncmp this works as expected.

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

end of thread, other threads:[~2015-10-13  8:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-13  7:51 devfs fixes Sascha Hauer
2015-10-13  7:51 ` [PATCH 1/4] fs: devfs: Allow mounting only on /dev/ Sascha Hauer
2015-10-13  7:51 ` [PATCH 2/4] fs: devfs: Allow mount path in cdev_open Sascha Hauer
2015-10-13  8:25   ` Sascha Hauer
2015-10-13  7:51 ` [PATCH 3/4] filetype: Use cdev_open Sascha Hauer
2015-10-13  7:51 ` [PATCH 4/4] fs: pass path directly to cdev_open Sascha Hauer

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