fs/mount: add autodetection support
Subsystems (3)
cover fs/mount: add autodetection support
HI,
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 227e180bbf3b678f0b5e53b234a61dbc940fad94:
command/mount: add autodetection support (2012-08-12 19:41:54 +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 ++++++++++++++++++++ fs/Kconfig | 5 +++++ fs/fat/fat.c | 1 + fs/fs.c | 28 ++++++++++++++++++++++++++++ include/filetype.h | 1 + include/fs.h | 5 +++++ 11 files changed, 79 insertions(+), 7 deletions(-)
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 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
@@ -1,6 +1,11 @@ menu "Filesystem support " +config FS + bool + default y + select FILETYPE + config FS_AUTOMOUNT bool
fs/fs.c +28 -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) +{ +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 );
include/fs.h +5 -0
@@ -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
PATCH 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
@@ -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
@@ -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
PATCH 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
@@ -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
PATCH 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 +++++++++++++++--- 5 files changed, 19 insertions(+), 7 deletions(-)
arch/arm/boards/crystalfontz-cfa10036/env/init/automount +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 'f' : + 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
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/4] command/mount: add autodetection support
Quoted 78 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- .../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 +++++++++++++++--- 5 files changed, 19 insertions(+), 7 deletions(-)arch/arm/boards/crystalfontz-cfa10036/env/init/automount +1
-1@@ -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@@ -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/initarch/arm/boards/pcm049/env/bin/nand_bootstrap +1
-1@@ -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 1arch/arm/boards/phycard-a-xl2/env/bin/nand_bootstrap +1
-1@@ -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 1commands/mount.c +3
-0@@ -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) {
commands/mount.c static int do_mount(int argc, char *argv[]) · line 53
Quoted 7 lines
commands/mount.c +3
-1@@ -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 'f' :
'f'?
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
Re: [PATCH 1/4] fs/mount: add autodetection type support
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
if NULL is pass as type mount will try to autodetect the filesystem type
fs/fs.c +4
-0+static const char *detect_fs (const char *filename) +{ +enum filetype type =file_name_detect_type (filename); +struct driver_d *drv;
fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 970
Quoted 10 lines
fs/fs.c +10
-0+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
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
Re: [PATCH 1/4] fs/mount: add autodetection type support
In reply to Jean-Christophe PLAGNIOL-VILLARDHello,
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD
fs/fs.c +7
-0+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)
fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 973
Quoted 10 lines
fs/fs.c +10
-0+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
Signature · 7 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/4] fs/mount: add autodetection type support
Quoted 13 lines · Uwe Kleine-König
Hello,
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
fs/fs.c +10
-0+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) {
Quoted 8 lines
fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 973
Quoted 7 lines
fs/fs.c +7
-0+ 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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/4] fs/mount: add autodetection type support
Quoted 22 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Uwe Kleine-König
Hello,
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
fs/fs.c +10
-0+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) {Quoted 8 lines
fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 973
Quoted 7 lines
fs/fs.c +7
-0+ 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.
Quoted 1 line
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
Signature · 7 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/4] fs/mount: add autodetection type support
Quoted 42 lines · Uwe Kleine-König
Quoted 22 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Uwe Kleine-König
Hello,
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
fs/fs.c +10
-0+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) {Quoted 8 lines
fs/fs.c int register_fs_driver(struct fs_driver_d *fsdrv) · line 973
Quoted 7 lines
fs/fs.c +7
-0+ 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.
Quoted 1 line
I never declare a var in a loop
reading over
git log --grep=scopein 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
Quoted 1 line
which all got in after v3.6-rc1.
no sorry I really do not like this
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox