Skip to contentSkip to conversation

fs/mount: add autodetection support

PATCH In review Jean-Christophe PLAGNIOL-VILLARD 2 participants 8 messages Aug 12, 2012 – Sep 4, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover fs/mount: add autodetection support

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

----------------------------------------------------------------
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH v2 1/4 fs/mount: add autodetection type support

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

---
 fs/Kconfig   |    5 +++++
 fs/fs.c      |   28 ++++++++++++++++++++++++++++
 include/fs.h |    5 +++++
 3 files changed, 38 insertions(+)
fs/Kconfig +5 -0
index b75820f..4c66543 100644
@@ -1,6 +1,11 @@
 
 menu "Filesystem support            "
 
+config FS
+	bool
+	default y
+	select FILETYPE
+
 config FS_AUTOMOUNT
 	bool
 
fs/fs.c +28 -0
index 0b376a5..e80d907 100644
@@ -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);
include/fs.h +5 -0
index c0b9f71..22470e6 100644
@@ -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
  */
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/4 filetype: add fat filesystem support

---
 common/filetype.c  |   20 ++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 21 insertions(+)
common/filetype.c +20 -0
index 1a5b82d..e736d43 100644
@@ -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;
 }
include/filetype.h +1 -0
index f5de8ed..179ec0f 100644
@@ -18,6 +18,7 @@ enum filetype {
 	filetype_aimage,
 	filetype_sh,
 	filetype_mips_barebox,
+	filetype_fat,
 };
 
 const char *file_type_to_string(enum filetype f);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/4 fs/fat: add filetype

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 fs/fat/fat.c |    1 +
 1 file changed, 1 insertion(+)
fs/fat/fat.c +1 -0
index 5e6c81c..01724a2 100644
@@ -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,
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/4 command/mount: add autodetection support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 .../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(-)
arch/arm/boards/crystalfontz-cfa10036/env/init/automount +1 -1
index fe67e55..668775d 100644
@@ -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'
arch/arm/boards/mioa701/env/bin/sdcard_override +1 -1
index 4b2ad51..ab83534 100644
@@ -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
arch/arm/boards/pcm049/env/bin/nand_bootstrap +1 -1
index acd00dc..f8873fa 100644
@@ -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
arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap +1 -1
index acd00dc..f8873fa 100644
@@ -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
commands/mount.c +15 -3
index b32faef..5b12ad4 100644
@@ -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
 
defaultenv-2/base/init/automount +3 -3
index 7b53309..fe56d92 100644
@@ -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'
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 1/4] fs/mount: add autodetection type support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 fs/Kconfig   |    5 +++++
 fs/fs.c      |   28 ++++++++++++++++++++++++++++
 include/fs.h |    5 +++++
 3 files changed, 38 insertions(+)
fs/Kconfig +5 -0
index b75820f..4c66543 100644
@@ -1,6 +1,11 @@
 
 menu "Filesystem support            "
 
+config FS
+	bool
+	default y
+	select FILETYPE
+
 config FS_AUTOMOUNT
 	bool
 
fs/fs.c +0 -0
index 0b376a5..e80d907 100644

fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 957

Quoted 4 lines
fs/fs.c +1 -0
@@ -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

Quoted 5 lines
fs/fs.c +5 -0
+{
+	enum filetype type = file_name_detect_type(filename);
+	struct driver_d *drv;
+	struct fs_driver_d *fdrv;
+

fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 972

Quoted 10 lines
fs/fs.c +10 -0
+	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 (

Quoted 10 lines
fs/fs.c +6 -0
+			return drv->name;
+	}
+
+	return NULL;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem

fs/fs.c int mount(const char *device, const char *fsname, const char *_path) · line 1014

Quoted 8 lines
fs/fs.c +5 -0
@@ -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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH 1/4] fs/mount: add autodetection type support

Quoted 71 lines · Sascha Hauer
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 fs/Kconfig   |    5 +++++
 fs/fs.c      |   28 ++++++++++++++++++++++++++++
 include/fs.h |    5 +++++
 3 files changed, 38 insertions(+)
fs/Kconfig +5 -0
index b75820f..4c66543 100644
@@ -1,6 +1,11 @@
 
 menu "Filesystem support            "
 
+config FS
+	bool
+	default y
+	select FILETYPE
+
 config FS_AUTOMOUNT
 	bool
 
fs/fs.c +0 -0
index 0b376a5..e80d907 100644

fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 957

Quoted 4 lines
fs/fs.c +1 -0
@@ -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

Quoted 5 lines
fs/fs.c +5 -0
+{
+	enum filetype type = file_name_detect_type(filename);
+	struct driver_d *drv;
+	struct fs_driver_d *fdrv;
+

fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 972

Quoted 10 lines
fs/fs.c +10 -0
+	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 (

Quoted 13 lines
fs/fs.c +6 -0
+			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)
 		}
 	}
 
Quoted 8 lines

fs/fs.c int mount(const char *device, const char *fsname, const char *_path) · line 1014

Quoted 5 lines
fs/fs.c +5 -0
+	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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 11 lines · Jean-Christophe PLAGNIOL-VILLARD

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)

Quoted 7 lines

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox