mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4 v2] fs/mount: add autodetection support
@ 2012-08-12 18:05 Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
  2012-09-04  8:02 ` [PATCH 0/4 v2] fs/mount: add autodetection support Sascha Hauer
  0 siblings, 2 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 18:05 UTC (permalink / raw)
  To: barebox

HI,

v2:
	fix typo
	move convert to fs_driver after check

please pull
The following changes since commit 58713d32746d49ad39ba17658fe82f1b98b80b2e:

  commands: memset: fix help message (2012-08-09 08:44:38 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git tags/fs

for you to fetch changes up to 7565f1e0f6877357c3e38f40d73f5773957f94b6:

  command/mount: add autodetection support (2012-08-12 21:46:15 +0800)

----------------------------------------------------------------
fs/mount: add autodetection type support

This will allow to simplify automount support
Make also mount command more linux like

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (4):
      fs/mount: add autodetection type support
      filetype: add fat filesystem support
      fs/fat: add filetype
      command/mount: add autodetection support

 arch/arm/boards/crystalfontz-cfa10036/env/init/automount |    2 +-
 arch/arm/boards/mioa701/env/bin/sdcard_override          |    2 +-
 arch/arm/boards/pcm049/env/bin/nand_bootstrap            |    2 +-
 arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap     |    2 +-
 commands/mount.c                                         |   18 +++++++++++++++---
 common/filetype.c                                        |   20 ++++++++++++++++++++
 defaultenv-2/base/init/automount                         |    6 +++---
 fs/Kconfig                                               |    5 +++++
 fs/fat/fat.c                                             |    1 +
 fs/fs.c                                                  |   28 ++++++++++++++++++++++++++++
 include/filetype.h                                       |    1 +
 include/fs.h                                             |    5 +++++
 12 files changed, 82 insertions(+), 10 deletions(-)

Best Regards,
J.

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

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

* [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-12 18:05 [PATCH 0/4 v2] fs/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 18:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 2/4] filetype: add fat filesystem support Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 more replies)
  2012-09-04  8:02 ` [PATCH 0/4 v2] fs/mount: add autodetection support Sascha Hauer
  1 sibling, 4 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 18:10 UTC (permalink / raw)
  To: barebox

if NULL is pass as type mount will try to autodetect the filesystem type

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 fs/Kconfig   |    5 +++++
 fs/fs.c      |   28 ++++++++++++++++++++++++++++
 include/fs.h |    5 +++++
 3 files changed, 38 insertions(+)

diff --git a/fs/Kconfig b/fs/Kconfig
index b75820f..4c66543 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1,6 +1,11 @@
 
 menu "Filesystem support            "
 
+config FS
+	bool
+	default y
+	select FILETYPE
+
 config FS_AUTOMOUNT
 	bool
 
diff --git a/fs/fs.c b/fs/fs.c
index 0b376a5..e80d907 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -954,6 +954,28 @@ int register_fs_driver(struct fs_driver_d *fsdrv)
 }
 EXPORT_SYMBOL(register_fs_driver);
 
+static const char * detect_fs(const char *filename)
+{
+	enum filetype type = file_name_detect_type(filename);
+	struct driver_d *drv;
+	struct fs_driver_d *fdrv;
+
+	if (type == filetype_unknown)
+		return NULL;
+
+	for_each_driver(drv) {
+		if (drv->bus != &fs_bus)
+			continue;
+
+		fdrv = drv_to_fs_driver(drv);
+
+		if(type == fdrv->type)
+			return drv->name;
+	}
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -985,6 +1007,12 @@ int mount(const char *device, const char *fsname, const char *_path)
 		}
 	}
 
+	if (!fsname)
+		fsname = detect_fs(device);
+
+	if (!fsname)
+		return -ENOENT;
+
 	fsdev = xzalloc(sizeof(struct fs_device_d));
 	fsdev->backingstore = xstrdup(device);
 	safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
diff --git a/include/fs.h b/include/fs.h
index c0b9f71..22470e6 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -2,6 +2,7 @@
 #define __FS_H
 
 #include <driver.h>
+#include <filetype.h>
 
 #define PATH_MAX       1024        /* include/linux/limits.h */
 
@@ -72,6 +73,8 @@ struct fs_driver_d {
 
 	struct driver_d drv;
 
+	enum filetype type;
+
 	unsigned long flags;
 };
 
@@ -93,6 +96,8 @@ struct fs_device_d {
 	struct list_head list;
 };
 
+#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
+
 /*
  * standard posix file functions
  */
-- 
1.7.10.4


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

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

* [PATCH 2/4] filetype: add fat filesystem support
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 18:10   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 3/4] fs/fat: add filetype Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 18:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/filetype.c  |   20 ++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 21 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 1a5b82d..e736d43 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -22,6 +22,7 @@
 #include <common.h>
 #include <filetype.h>
 #include <asm/byteorder.h>
+#include <asm/unaligned.h>
 #include <fcntl.h>
 #include <fs.h>
 #include <malloc.h>
@@ -40,6 +41,7 @@ static const char *filetype_str[] = {
 	[filetype_aimage] = "Android boot image",
 	[filetype_sh] = "Bourne Shell",
 	[filetype_mips_barebox] = "MIPS barebox image",
+	[filetype_fat] = "FAT filesytem",
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -50,6 +52,22 @@ const char *file_type_to_string(enum filetype f)
 	return NULL;
 }
 
+static int is_fat(u8 *buf)
+{
+	if (get_unaligned_le16(&buf[510]) != 0xAA55)
+		return 0;
+
+	/* FAT */
+	if ((get_unaligned_le32(&buf[54]) & 0xFFFFFF) == 0x544146)
+		return 1;
+
+	/* FAT32 */
+	if ((get_unaligned_le32(&buf[82]) & 0xFFFFFF) == 0x544146)
+		return 1;
+
+	return 0;
+}
+
 enum filetype file_detect_type(void *_buf)
 {
 	u32 *buf = _buf;
@@ -81,6 +99,8 @@ enum filetype file_detect_type(void *_buf)
 		return filetype_aimage;
 	if (strncmp(buf8 + 0x10, "barebox", 7) == 0)
 		return filetype_mips_barebox;
+	if (is_fat(buf8))
+		return filetype_fat;
 
 	return filetype_unknown;
 }
diff --git a/include/filetype.h b/include/filetype.h
index f5de8ed..179ec0f 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -18,6 +18,7 @@ enum filetype {
 	filetype_aimage,
 	filetype_sh,
 	filetype_mips_barebox,
+	filetype_fat,
 };
 
 const char *file_type_to_string(enum filetype f);
-- 
1.7.10.4


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

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

* [PATCH 3/4] fs/fat: add filetype
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 2/4] filetype: add fat filesystem support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 18:10   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 4/4] command/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-13 18:49   ` [PATCH 1/4] fs/mount: add autodetection type support Sascha Hauer
  3 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 18:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 fs/fat/fat.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 5e6c81c..01724a2 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -430,6 +430,7 @@ static struct fs_driver_d fat_driver = {
 	.write     = fat_write,
 	.truncate  = fat_truncate,
 #endif
+	.type = filetype_fat,
 	.flags     = 0,
 	.drv = {
 		.probe  = fat_probe,
-- 
1.7.10.4


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

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

* [PATCH 4/4] command/mount: add autodetection support
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 2/4] filetype: add fat filesystem support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10   ` [PATCH 3/4] fs/fat: add filetype Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 18:10   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-13 18:49   ` [PATCH 1/4] fs/mount: add autodetection type support Sascha Hauer
  3 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 18:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 .../boards/crystalfontz-cfa10036/env/init/automount  |    2 +-
 arch/arm/boards/mioa701/env/bin/sdcard_override      |    2 +-
 arch/arm/boards/pcm049/env/bin/nand_bootstrap        |    2 +-
 arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap |    2 +-
 commands/mount.c                                     |   18 +++++++++++++++---
 defaultenv-2/base/init/automount                     |    6 +++---
 6 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boards/crystalfontz-cfa10036/env/init/automount b/arch/arm/boards/crystalfontz-cfa10036/env/init/automount
index fe67e55..668775d 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/env/init/automount
+++ b/arch/arm/boards/crystalfontz-cfa10036/env/init/automount
@@ -6,4 +6,4 @@ if [ "$1" = menu ]; then
 fi
 
 mkdir -p /mnt/disk0.1
-automount -d /mnt/disk0.1 '[ -e /dev/disk0.1 ] && mount /dev/disk0.1 fat /mnt/disk0.1'
+automount -d /mnt/disk0.1 '[ -e /dev/disk0.1 ] && mount /dev/disk0.1 /mnt/disk0.1'
diff --git a/arch/arm/boards/mioa701/env/bin/sdcard_override b/arch/arm/boards/mioa701/env/bin/sdcard_override
index 4b2ad51..ab83534 100644
--- a/arch/arm/boards/mioa701/env/bin/sdcard_override
+++ b/arch/arm/boards/mioa701/env/bin/sdcard_override
@@ -8,7 +8,7 @@
 mci0.probe=1
 if [ $mci0.probe = 1 ]; then
 	mkdir /sdcard
-	mount /dev/disk0.0 fat /sdcard
+	mount /dev/disk0.0 /sdcard
 	if [ -f /sdcard/barebox.env ]; then
 		loadenv /sdcard/barebox.env /env.sd
 		/env.sd/bin/init
diff --git a/arch/arm/boards/pcm049/env/bin/nand_bootstrap b/arch/arm/boards/pcm049/env/bin/nand_bootstrap
index acd00dc..f8873fa 100644
--- a/arch/arm/boards/pcm049/env/bin/nand_bootstrap
+++ b/arch/arm/boards/pcm049/env/bin/nand_bootstrap
@@ -4,7 +4,7 @@ echo "copying barebox to nand..."
 mci0.probe=1
 mkdir mnt
 
-mount /dev/disk0.0 fat /mnt
+mount /dev/disk0.0 /mnt
 if [ $? != 0 ]; then
 	echo "failed to mount mmc card"
 	exit 1
diff --git a/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap b/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap
index acd00dc..f8873fa 100644
--- a/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap
+++ b/arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap
@@ -4,7 +4,7 @@ echo "copying barebox to nand..."
 mci0.probe=1
 mkdir mnt
 
-mount /dev/disk0.0 fat /mnt
+mount /dev/disk0.0 /mnt
 if [ $? != 0 ]; then
 	echo "failed to mount mmc card"
 	exit 1
diff --git a/commands/mount.c b/commands/mount.c
index b32faef..5b12ad4 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -29,11 +29,14 @@
 #include <command.h>
 #include <fs.h>
 #include <errno.h>
+#include <getopt.h>
 
 static int do_mount(int argc, char *argv[])
 {
+	int opt;
 	int ret = 0;
 	struct fs_device_d *fsdev;
+	char *type = NULL;
 
 	if (argc == 1) {
 		for_each_fs_device(fsdev) {
@@ -45,10 +48,18 @@ static int do_mount(int argc, char *argv[])
 		return 0;
 	}
 
-	if (argc != 4)
+	while ((opt = getopt(argc, argv, "t:")) > 0) {
+		switch (opt) {
+		case 't':
+			type = optarg;
+			break;
+		}
+	}
+
+	if (argc < optind + 2)
 		return COMMAND_ERROR_USAGE;
 
-	if ((ret = mount(argv[1], argv[2], argv[3]))) {
+	if ((ret = mount(argv[optind], type, argv[optind + 1]))) {
 		perror("mount");
 		return 1;
 	}
@@ -56,8 +67,9 @@ static int do_mount(int argc, char *argv[])
 }
 
 BAREBOX_CMD_HELP_START(mount)
-BAREBOX_CMD_HELP_USAGE("mount [<device> <fstype> <mountpoint>]\n")
+BAREBOX_CMD_HELP_USAGE("mount [[-t <fstype] <device> <mountpoint>]\n")
 BAREBOX_CMD_HELP_SHORT("Mount a filesystem of a given type to a mountpoint.\n")
+BAREBOX_CMD_HELP_SHORT("If no fstpye is specified detected it.\n")
 BAREBOX_CMD_HELP_SHORT("If no argument is given, list mounted filesystems.\n")
 BAREBOX_CMD_HELP_END
 
diff --git a/defaultenv-2/base/init/automount b/defaultenv-2/base/init/automount
index 7b53309..fe56d92 100644
--- a/defaultenv-2/base/init/automount
+++ b/defaultenv-2/base/init/automount
@@ -8,15 +8,15 @@ fi
 # automount tftp server based on $eth0.serverip
 
 mkdir -p /mnt/tftp
-automount /mnt/tftp 'ifup eth0 && mount $eth0.serverip tftp /mnt/tftp'
+automount /mnt/tftp 'ifup eth0 && mount -t tftp $eth0.serverip /mnt/tftp'
 
 # automount nfs server example
 
 #nfshost=somehost
 #mkdir -p /mnt/${nfshost}
-#automount /mnt/$nfshost "ifup eth0 && mount ${nfshost}:/tftpboot nfs /mnt/${nfshost}"
+#automount /mnt/$nfshost "ifup eth0 && mount -t nfs ${nfshost}:/tftpboot /mnt/${nfshost}"
 
 # FAT on usb disk example
 
 #mkdir -p /mnt/fat
-#automount -d /mnt/fat 'usb && [ -e /dev/disk0.0 ] && mount /dev/disk0.0 fat /mnt/fat'
+#automount -d /mnt/fat 'usb && [ -e /dev/disk0.0 ] && mount /dev/disk0.0 /mnt/fat'
-- 
1.7.10.4


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

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2012-08-12 18:10   ` [PATCH 4/4] command/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-13 18:49   ` Sascha Hauer
  2012-08-15  7:25     ` Jean-Christophe PLAGNIOL-VILLARD
  3 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2012-08-13 18:49 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Aug 12, 2012 at 08:10:40PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> if NULL is pass as type mount will try to autodetect the filesystem type
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  fs/Kconfig   |    5 +++++
>  fs/fs.c      |   28 ++++++++++++++++++++++++++++
>  include/fs.h |    5 +++++
>  3 files changed, 38 insertions(+)
> 
> diff --git a/fs/Kconfig b/fs/Kconfig
> index b75820f..4c66543 100644
> --- a/fs/Kconfig
> +++ b/fs/Kconfig
> @@ -1,6 +1,11 @@
>  
>  menu "Filesystem support            "
>  
> +config FS
> +	bool
> +	default y
> +	select FILETYPE
> +
>  config FS_AUTOMOUNT
>  	bool
>  
> diff --git a/fs/fs.c b/fs/fs.c
> index 0b376a5..e80d907 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -954,6 +954,28 @@ int register_fs_driver(struct fs_driver_d *fsdrv)
>  }
>  EXPORT_SYMBOL(register_fs_driver);
>  
> +static const char * detect_fs(const char *filename)

static const char *detect_fs(const char *filename)

please

> +{
> +	enum filetype type = file_name_detect_type(filename);
> +	struct driver_d *drv;
> +	struct fs_driver_d *fdrv;
> +
> +	if (type == filetype_unknown)
> +		return NULL;
> +
> +	for_each_driver(drv) {
> +		if (drv->bus != &fs_bus)
> +			continue;
> +
> +		fdrv = drv_to_fs_driver(drv);
> +
> +		if(type == fdrv->type)

if (

> +			return drv->name;
> +	}
> +
> +	return NULL;
> +}
> +
>  /*
>   * Mount a device to a directory.
>   * We do this by registering a new device on which the filesystem
> @@ -985,6 +1007,12 @@ int mount(const char *device, const char *fsname, const char *_path)
>  		}
>  	}
>  
> +	if (!fsname)
> +		fsname = detect_fs(device);
> +
> +	if (!fsname)
> +		return -ENOENT;

Should be -ENODEV I think. At least that's what Linux mount returns in
this case.

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-13 18:49   ` [PATCH 1/4] fs/mount: add autodetection type support Sascha Hauer
@ 2012-08-15  7:25     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-15  7:25 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 20:49 Mon 13 Aug     , Sascha Hauer wrote:
> On Sun, Aug 12, 2012 at 08:10:40PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > if NULL is pass as type mount will try to autodetect the filesystem type
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> >  fs/Kconfig   |    5 +++++
> >  fs/fs.c      |   28 ++++++++++++++++++++++++++++
> >  include/fs.h |    5 +++++
> >  3 files changed, 38 insertions(+)
> > 
> > diff --git a/fs/Kconfig b/fs/Kconfig
> > index b75820f..4c66543 100644
> > --- a/fs/Kconfig
> > +++ b/fs/Kconfig
> > @@ -1,6 +1,11 @@
> >  
> >  menu "Filesystem support            "
> >  
> > +config FS
> > +	bool
> > +	default y
> > +	select FILETYPE
> > +
> >  config FS_AUTOMOUNT
> >  	bool
> >  
> > diff --git a/fs/fs.c b/fs/fs.c
> > index 0b376a5..e80d907 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -954,6 +954,28 @@ int register_fs_driver(struct fs_driver_d *fsdrv)
> >  }
> >  EXPORT_SYMBOL(register_fs_driver);
> >  
> > +static const char * detect_fs(const char *filename)
> 
> static const char *detect_fs(const char *filename)
> 
> please
> 
> > +{
> > +	enum filetype type = file_name_detect_type(filename);
> > +	struct driver_d *drv;
> > +	struct fs_driver_d *fdrv;
> > +
> > +	if (type == filetype_unknown)
> > +		return NULL;
> > +
> > +	for_each_driver(drv) {
> > +		if (drv->bus != &fs_bus)
> > +			continue;
> > +
> > +		fdrv = drv_to_fs_driver(drv);
> > +
> > +		if(type == fdrv->type)
> 
> if (
> 
> > +			return drv->name;
> > +	}
> > +
> > +	return NULL;
> > +}
> > +
> >  /*
> >   * Mount a device to a directory.
> >   * We do this by registering a new device on which the filesystem
> > @@ -985,6 +1007,12 @@ int mount(const char *device, const char *fsname, const char *_path)
> >  		}
> >  	}
> >  
> > +	if (!fsname)
> > +		fsname = detect_fs(device);
> > +
> > +	if (!fsname)
> > +		return -ENOENT;
> 
> Should be -ENODEV I think. At least that's what Linux mount returns in
> this case.
tag updated with it

Best Regards,
J.

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

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

* Re: [PATCH 0/4 v2] fs/mount: add autodetection support
  2012-08-12 18:05 [PATCH 0/4 v2] fs/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-09-04  8:02 ` Sascha Hauer
  1 sibling, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2012-09-04  8:02 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Aug 12, 2012 at 08:05:35PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> HI,
> 
> v2:
> 	fix typo
> 	move convert to fs_driver after check
> 
> please pull
> The following changes since commit 58713d32746d49ad39ba17658fe82f1b98b80b2e:
> 
>   commands: memset: fix help message (2012-08-09 08:44:38 +0200)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git tags/fs
> 
> for you to fetch changes up to 7565f1e0f6877357c3e38f40d73f5773957f94b6:
> 
>   command/mount: add autodetection support (2012-08-12 21:46:15 +0800)

This series breaks compilation on several architectures due to missing
asm/unaligned.h header:

- openrisc
- blackfin
- ppc

For ppc Renaud Barbier already sent a fix. I fixed the remaining myself.

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-13  8:16       ` Uwe Kleine-König
@ 2012-08-13 10:56         ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-13 10:56 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On 10:16 Mon 13 Aug     , Uwe Kleine-König wrote:
> On Mon, Aug 13, 2012 at 09:30:01AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 09:08 Mon 13 Aug     , Uwe Kleine-König wrote:
> > > Hello,
> > > 
> > > On Sun, Aug 12, 2012 at 01:49:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > +static const char * detect_fs(const char *filename)
> > > > +{
> > > > +	enum filetype type = file_name_detect_type(filename);
> > > > +	struct driver_d *drv;
> > > > +	struct fs_driver_d *fdrv;
> > > > +
> > > > +	if (type == filetype_unknown)
> > > > +		return NULL;
> > > > +
> > > > +	for_each_driver(drv) {
> > > > +		fdrv = drv_to_fs_driver(drv);
> > > > +
> > > > +		if (drv->bus != &fs_bus)
> > > > +			continue;
> > > > +
> > > > +		if(type == fdrv->type)
> > > > +			return drv->name;
> > > fdrv could be local to this loop only.
> > I never declare a var in a loop
> reading over
> 
> 	git log --grep=scope
> 
> in the kernel suggests that at least there it's considered good style.
> With some false hits the list includes:
> 
> 	ccece235d3737221e7a1118fdbd8474112adac84:
> 		Finally, move the definition of the local variable "i"
> 		to the innermost scope in which it's needed.
> 	22a4cca2f4c2d60c703cdc42158c907570f508e6:
> 		Reduced the scope of the loop variable in
> 		e1000e_write_itr().
> 	2c2453f3e46139b86c1e5b0fbd821823b04e4ada:
> 		Patch shortens locals scope ...
> 	74ad8fdaefe6ccb8ef1918394a9d04a036658346:
> 		Shorten scope for iobase
> 
> which all got in after v3.6-rc1.
no sorry I really do not like this

Best Regards,
J.

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

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-13  7:30     ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-13  8:16       ` Uwe Kleine-König
  2012-08-13 10:56         ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 14+ messages in thread
From: Uwe Kleine-König @ 2012-08-13  8:16 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Aug 13, 2012 at 09:30:01AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 09:08 Mon 13 Aug     , Uwe Kleine-König wrote:
> > Hello,
> > 
> > On Sun, Aug 12, 2012 at 01:49:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > +static const char * detect_fs(const char *filename)
> > > +{
> > > +	enum filetype type = file_name_detect_type(filename);
> > > +	struct driver_d *drv;
> > > +	struct fs_driver_d *fdrv;
> > > +
> > > +	if (type == filetype_unknown)
> > > +		return NULL;
> > > +
> > > +	for_each_driver(drv) {
> > > +		fdrv = drv_to_fs_driver(drv);
> > > +
> > > +		if (drv->bus != &fs_bus)
> > > +			continue;
> > > +
> > > +		if(type == fdrv->type)
> > > +			return drv->name;
> > fdrv could be local to this loop only.
> I never declare a var in a loop
reading over

	git log --grep=scope

in the kernel suggests that at least there it's considered good style.
With some false hits the list includes:

	ccece235d3737221e7a1118fdbd8474112adac84:
		Finally, move the definition of the local variable "i"
		to the innermost scope in which it's needed.
	22a4cca2f4c2d60c703cdc42158c907570f508e6:
		Reduced the scope of the loop variable in
		e1000e_write_itr().
	2c2453f3e46139b86c1e5b0fbd821823b04e4ada:
		Patch shortens locals scope ...
	74ad8fdaefe6ccb8ef1918394a9d04a036658346:
		Shorten scope for iobase

which all got in after v3.6-rc1.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-13  7:08   ` Uwe Kleine-König
@ 2012-08-13  7:30     ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-13  8:16       ` Uwe Kleine-König
  0 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-13  7:30 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On 09:08 Mon 13 Aug     , Uwe Kleine-König wrote:
> Hello,
> 
> On Sun, Aug 12, 2012 at 01:49:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > +static const char * detect_fs(const char *filename)
> > +{
> > +	enum filetype type = file_name_detect_type(filename);
> > +	struct driver_d *drv;
> > +	struct fs_driver_d *fdrv;
> > +
> > +	if (type == filetype_unknown)
> > +		return NULL;
> > +
> > +	for_each_driver(drv) {
> > +		fdrv = drv_to_fs_driver(drv);
> > +
> > +		if (drv->bus != &fs_bus)
> > +			continue;
> > +
> > +		if(type == fdrv->type)
> > +			return drv->name;
> fdrv could be local to this loop only.
I never declare a var in a loop

Best Regards,
J.

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

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-12 11:49 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 12:46   ` Sascha Hauer
@ 2012-08-13  7:08   ` Uwe Kleine-König
  2012-08-13  7:30     ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 14+ messages in thread
From: Uwe Kleine-König @ 2012-08-13  7:08 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hello,

On Sun, Aug 12, 2012 at 01:49:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> +static const char * detect_fs(const char *filename)
> +{
> +	enum filetype type = file_name_detect_type(filename);
> +	struct driver_d *drv;
> +	struct fs_driver_d *fdrv;
> +
> +	if (type == filetype_unknown)
> +		return NULL;
> +
> +	for_each_driver(drv) {
> +		fdrv = drv_to_fs_driver(drv);
> +
> +		if (drv->bus != &fs_bus)
> +			continue;
> +
> +		if(type == fdrv->type)
> +			return drv->name;
fdrv could be local to this loop only.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re: [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-12 11:49 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 12:46   ` Sascha Hauer
  2012-08-13  7:08   ` Uwe Kleine-König
  1 sibling, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2012-08-12 12:46 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Aug 12, 2012 at 01:49:36PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> if NULL is pass as type mount will try to autodetect the filesystem type
> 
> +static const char * detect_fs(const char *filename)
> +{
> +	enum filetype type = file_name_detect_type(filename);
> +	struct driver_d *drv;
> +	struct fs_driver_d *fdrv;
> +
> +	if (type == filetype_unknown)
> +		return NULL;
> +
> +	for_each_driver(drv) {
> +		fdrv = drv_to_fs_driver(drv);
> +
> +		if (drv->bus != &fs_bus)
> +			continue;

Please convert drv to a fdrv after checking that this is really a
filesystem driver, not before.
I know, it's both the same in this case, but it looks confusing.

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

* [PATCH 1/4] fs/mount: add autodetection type support
  2012-08-12 11:46 [PATCH 0/4] " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-08-12 11:49 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-08-12 12:46   ` Sascha Hauer
  2012-08-13  7:08   ` Uwe Kleine-König
  0 siblings, 2 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-08-12 11:49 UTC (permalink / raw)
  To: barebox

if NULL is pass as type mount will try to autodetect the filesystem type

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 fs/Kconfig   |    5 +++++
 fs/fs.c      |   28 ++++++++++++++++++++++++++++
 include/fs.h |    5 +++++
 3 files changed, 38 insertions(+)

diff --git a/fs/Kconfig b/fs/Kconfig
index b75820f..4c66543 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1,6 +1,11 @@
 
 menu "Filesystem support            "
 
+config FS
+	bool
+	default y
+	select FILETYPE
+
 config FS_AUTOMOUNT
 	bool
 
diff --git a/fs/fs.c b/fs/fs.c
index 0b376a5..7126577 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -954,6 +954,28 @@ int register_fs_driver(struct fs_driver_d *fsdrv)
 }
 EXPORT_SYMBOL(register_fs_driver);
 
+static const char * detect_fs(const char *filename)
+{
+	enum filetype type = file_name_detect_type(filename);
+	struct driver_d *drv;
+	struct fs_driver_d *fdrv;
+
+	if (type == filetype_unknown)
+		return NULL;
+
+	for_each_driver(drv) {
+		fdrv = drv_to_fs_driver(drv);
+
+		if (drv->bus != &fs_bus)
+			continue;
+
+		if(type == fdrv->type)
+			return drv->name;
+	}
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -985,6 +1007,12 @@ int mount(const char *device, const char *fsname, const char *_path)
 		}
 	}
 
+	if (!fsname)
+		fsname = detect_fs(device);
+
+	if (!fsname)
+		return -ENOENT;
+
 	fsdev = xzalloc(sizeof(struct fs_device_d));
 	fsdev->backingstore = xstrdup(device);
 	safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
diff --git a/include/fs.h b/include/fs.h
index c0b9f71..22470e6 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -2,6 +2,7 @@
 #define __FS_H
 
 #include <driver.h>
+#include <filetype.h>
 
 #define PATH_MAX       1024        /* include/linux/limits.h */
 
@@ -72,6 +73,8 @@ struct fs_driver_d {
 
 	struct driver_d drv;
 
+	enum filetype type;
+
 	unsigned long flags;
 };
 
@@ -93,6 +96,8 @@ struct fs_device_d {
 	struct list_head list;
 };
 
+#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
+
 /*
  * standard posix file functions
  */
-- 
1.7.10.4


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

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

end of thread, other threads:[~2012-09-04  8:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-12 18:05 [PATCH 0/4 v2] fs/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10   ` [PATCH 2/4] filetype: add fat filesystem support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10   ` [PATCH 3/4] fs/fat: add filetype Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10   ` [PATCH 4/4] command/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
2012-08-13 18:49   ` [PATCH 1/4] fs/mount: add autodetection type support Sascha Hauer
2012-08-15  7:25     ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-04  8:02 ` [PATCH 0/4 v2] fs/mount: add autodetection support Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2012-08-12 11:46 [PATCH 0/4] " Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 11:49 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 12:46   ` Sascha Hauer
2012-08-13  7:08   ` Uwe Kleine-König
2012-08-13  7:30     ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-13  8:16       ` Uwe Kleine-König
2012-08-13 10:56         ` 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