* [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
@ 2015-11-09 10:32 Peter Mamonov
2015-11-09 11:18 ` Antony Pavlov
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Peter Mamonov @ 2015-11-09 10:32 UTC (permalink / raw)
To: barebox; +Cc: Peter Mamonov
Deleted pieces of code detect MBR-containig device as a FAT-type device,
if it's first partition contains a FAT filesystem. This behaviour enabled one
to mount the FAT FS which is either directly on the device (disk0) or on
the first partition (disk0.0) using the same command:
mount /dev/disk0 /fat
However, the desired behaviour can be reached with a:
mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/filetype.c | 30 ------------------------------
1 file changed, 30 deletions(-)
diff --git a/common/filetype.c b/common/filetype.c
index c59441d..f9e03f7 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -345,21 +345,6 @@ enum filetype file_name_detect_type(const char *filename)
type = file_detect_type(buf, ret);
- if (type == filetype_mbr) {
- /*
- * Get the first partition start sector
- * and check for FAT in it
- */
- is_fat_or_mbr(buf, &bootsec);
- ret = lseek(fd, (bootsec) * 512, SEEK_SET);
- if (ret < 0)
- goto err_out;
- ret = read(fd, buf, 512);
- if (ret < 0)
- goto err_out;
- type = is_fat_or_mbr((u8 *)buf, NULL);
- }
-
err_out:
close(fd);
free(buf);
@@ -385,21 +370,6 @@ enum filetype cdev_detect_type(const char *name)
type = file_detect_type(buf, ret);
- if (type == filetype_mbr) {
- unsigned long bootsec;
- /*
- * Get the first partition start sector
- * and check for FAT in it
- */
- is_fat_or_mbr(buf, &bootsec);
-
- ret = cdev_read(cdev, buf, 512, bootsec * 512, 0);
- if (ret < 0)
- goto err_out;
-
- type = is_fat_or_mbr((u8 *)buf, NULL);
- }
-
err_out:
free(buf);
cdev_close(cdev);
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-09 10:32 [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type Peter Mamonov
@ 2015-11-09 11:18 ` Antony Pavlov
2015-11-09 18:49 ` Trent Piepho
2015-11-11 7:35 ` Sascha Hauer
2 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-11-09 11:18 UTC (permalink / raw)
To: Peter Mamonov; +Cc: barebox
On Mon, 9 Nov 2015 13:32:51 +0300
Peter Mamonov <pmamonov@gmail.com> wrote:
> Deleted pieces of code detect MBR-containig device as a FAT-type device,
> if it's first partition contains a FAT filesystem. This behaviour enabled one
> to mount the FAT FS which is either directly on the device (disk0) or on
> the first partition (disk0.0) using the same command:
> mount /dev/disk0 /fat
> However, the desired behaviour can be reached with a:
> mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
>
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
^^^^^^^^^^
Ad memorandum. Sascha's ack can be found here: http://lists.infradead.org/pipermail/barebox/2015-October/024952.html
> ---
> common/filetype.c | 30 ------------------------------
> 1 file changed, 30 deletions(-)
>
> diff --git a/common/filetype.c b/common/filetype.c
> index c59441d..f9e03f7 100644
> --- a/common/filetype.c
> +++ b/common/filetype.c
> @@ -345,21 +345,6 @@ enum filetype file_name_detect_type(const char *filename)
>
> type = file_detect_type(buf, ret);
>
> - if (type == filetype_mbr) {
> - /*
> - * Get the first partition start sector
> - * and check for FAT in it
> - */
> - is_fat_or_mbr(buf, &bootsec);
> - ret = lseek(fd, (bootsec) * 512, SEEK_SET);
> - if (ret < 0)
> - goto err_out;
> - ret = read(fd, buf, 512);
> - if (ret < 0)
> - goto err_out;
> - type = is_fat_or_mbr((u8 *)buf, NULL);
> - }
> -
> err_out:
> close(fd);
> free(buf);
> @@ -385,21 +370,6 @@ enum filetype cdev_detect_type(const char *name)
>
> type = file_detect_type(buf, ret);
>
> - if (type == filetype_mbr) {
> - unsigned long bootsec;
> - /*
> - * Get the first partition start sector
> - * and check for FAT in it
> - */
> - is_fat_or_mbr(buf, &bootsec);
> -
> - ret = cdev_read(cdev, buf, 512, bootsec * 512, 0);
> - if (ret < 0)
> - goto err_out;
> -
> - type = is_fat_or_mbr((u8 *)buf, NULL);
> - }
> -
> err_out:
> free(buf);
> cdev_close(cdev);
> --
> 2.1.4
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-09 10:32 [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type Peter Mamonov
2015-11-09 11:18 ` Antony Pavlov
@ 2015-11-09 18:49 ` Trent Piepho
2015-11-10 8:04 ` Sascha Hauer
2015-11-11 7:35 ` Sascha Hauer
2 siblings, 1 reply; 7+ messages in thread
From: Trent Piepho @ 2015-11-09 18:49 UTC (permalink / raw)
To: Peter Mamonov; +Cc: barebox
On Mon, 2015-11-09 at 13:32 +0300, Peter Mamonov wrote:
> Deleted pieces of code detect MBR-containig device as a FAT-type device,
> if it's first partition contains a FAT filesystem. This behaviour enabled one
> to mount the FAT FS which is either directly on the device (disk0) or on
> the first partition (disk0.0) using the same command:
> mount /dev/disk0 /fat
> However, the desired behaviour can be reached with a:
> mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
The in flash env for omap is found by mounting a FAT filesystem and
reading an env file from it. The code that does this uses the disk as
the device, rather than the partition. Which I thought was odd and
wondered why/if that worked correctly....
Anyway, this change would break that code. I suspect than instead of
coding the disk0 || disk0.0 method it could just mount disk0.0. Because
the code does this (edited):
partname = asprintf("/dev/%s.0", diskdev);
ret = stat(partname, &s);
if (ret) {
pr_err("Failed to load environment: no device '%s'\n", diskdev);
return 0;
}
ret = mount(diskdev, "fat", "/boot", NULL);
If disk0.0 didn't exist then it wouldn't try to mount it in the 1st
place, so the ability of trying both disk0 and disk0.0 wouldn't be used.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-09 18:49 ` Trent Piepho
@ 2015-11-10 8:04 ` Sascha Hauer
2015-11-10 8:15 ` Sascha Hauer
2015-11-10 18:44 ` Trent Piepho
0 siblings, 2 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-11-10 8:04 UTC (permalink / raw)
To: Trent Piepho; +Cc: barebox, Peter Mamonov
On Mon, Nov 09, 2015 at 06:49:53PM +0000, Trent Piepho wrote:
> On Mon, 2015-11-09 at 13:32 +0300, Peter Mamonov wrote:
> > Deleted pieces of code detect MBR-containig device as a FAT-type device,
> > if it's first partition contains a FAT filesystem. This behaviour enabled one
> > to mount the FAT FS which is either directly on the device (disk0) or on
> > the first partition (disk0.0) using the same command:
> > mount /dev/disk0 /fat
> > However, the desired behaviour can be reached with a:
> > mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
>
> The in flash env for omap is found by mounting a FAT filesystem and
> reading an env file from it. The code that does this uses the disk as
> the device, rather than the partition. Which I thought was odd and
> wondered why/if that worked correctly....
>
> Anyway, this change would break that code. I suspect than instead of
> coding the disk0 || disk0.0 method it could just mount disk0.0. Because
> the code does this (edited):
>
> partname = asprintf("/dev/%s.0", diskdev);
> ret = stat(partname, &s);
> if (ret) {
> pr_err("Failed to load environment: no device '%s'\n", diskdev);
> return 0;
> }
> ret = mount(diskdev, "fat", "/boot", NULL);
This is really odd. The code first tests if the partition exists and
tries to mount the whole disk afterwards. git blame points to:
commit be322768f04603df371c9c1f08b9621690dd74c6
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date: Sat Aug 24 12:48:50 2013 +0200
ARM: omap: Allow to set mmc devname used for booting
I think what we should do here is in the following patch. With this
Trents patch can be applied as-is. Thanks for noting, Peter.
Sascha
---------------------------8<---------------------------
From 98fb34f2aa271138eab28a36aec733fe6572339c Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue, 10 Nov 2015 08:58:16 +0100
Subject: [PATCH] ARM: omap: Use correct device to mount on /boot
The current code tests if a partition (i.e. disk0.0) exists and instead
of mounting boot from this partition it uses the whole device (disk0).
This only works because the the FAT code accepts a MBR as input and
automatically skips it.
Let the code use the partition to mount /boot instead as it was
intended. We don't have to stat() the partition device, since this
error will be caught by mount() anyway, so remove the unnecessary
stat().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-omap/omap_generic.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/arch/arm/mach-omap/omap_generic.c b/arch/arm/mach-omap/omap_generic.c
index 071a1bf..4e26c6b 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -111,7 +111,6 @@ const char *omap_get_bootmmc_devname(void)
#define ENV_PATH "/boot/barebox.env"
static int omap_env_init(void)
{
- struct stat s;
char *partname;
const char *diskdev;
int ret;
@@ -128,25 +127,19 @@ static int omap_env_init(void)
partname = asprintf("/dev/%s.0", diskdev);
- ret = stat(partname, &s);
-
- free(partname);
-
- if (ret) {
- pr_err("Failed to load environment: no device '%s'\n", diskdev);
- return 0;
- }
-
mkdir("/boot", 0666);
- ret = mount(diskdev, "fat", "/boot", NULL);
+ ret = mount(partname, "fat", "/boot", NULL);
if (ret) {
- pr_err("Failed to load environment: mount %s failed (%d)\n", diskdev, ret);
- return 0;
+ pr_err("Failed to load environment: mount %s failed (%d)\n", partname, ret);
+ goto out;
}
- pr_debug("Loading default env from %s on device %s\n", ENV_PATH, diskdev);
+ pr_debug("Loading default env from %s on device %s\n", ENV_PATH, partname);
default_environment_path_set(ENV_PATH);
+out:
+ free(partname);
+
return 0;
}
late_initcall(omap_env_init);
--
2.6.1
--
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] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-10 8:04 ` Sascha Hauer
@ 2015-11-10 8:15 ` Sascha Hauer
2015-11-10 18:44 ` Trent Piepho
1 sibling, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-11-10 8:15 UTC (permalink / raw)
To: Trent Piepho; +Cc: barebox, Peter Mamonov
On Tue, Nov 10, 2015 at 09:04:23AM +0100, Sascha Hauer wrote:
> On Mon, Nov 09, 2015 at 06:49:53PM +0000, Trent Piepho wrote:
> > On Mon, 2015-11-09 at 13:32 +0300, Peter Mamonov wrote:
> > > Deleted pieces of code detect MBR-containig device as a FAT-type device,
> > > if it's first partition contains a FAT filesystem. This behaviour enabled one
> > > to mount the FAT FS which is either directly on the device (disk0) or on
> > > the first partition (disk0.0) using the same command:
> > > mount /dev/disk0 /fat
> > > However, the desired behaviour can be reached with a:
> > > mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
> >
> > The in flash env for omap is found by mounting a FAT filesystem and
> > reading an env file from it. The code that does this uses the disk as
> > the device, rather than the partition. Which I thought was odd and
> > wondered why/if that worked correctly....
> >
> > Anyway, this change would break that code. I suspect than instead of
> > coding the disk0 || disk0.0 method it could just mount disk0.0. Because
> > the code does this (edited):
> >
> > partname = asprintf("/dev/%s.0", diskdev);
> > ret = stat(partname, &s);
> > if (ret) {
> > pr_err("Failed to load environment: no device '%s'\n", diskdev);
> > return 0;
> > }
> > ret = mount(diskdev, "fat", "/boot", NULL);
>
> This is really odd. The code first tests if the partition exists and
> tries to mount the whole disk afterwards. git blame points to:
>
> commit be322768f04603df371c9c1f08b9621690dd74c6
> Author: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Sat Aug 24 12:48:50 2013 +0200
>
> ARM: omap: Allow to set mmc devname used for booting
>
> I think what we should do here is in the following patch. With this
> Trents patch can be applied as-is. Thanks for noting, Peter.
Sorry, I mixed you two up. I mean: With this Peters patch can be
applied as-is. Thanks for noting, Trent.
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] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-10 8:04 ` Sascha Hauer
2015-11-10 8:15 ` Sascha Hauer
@ 2015-11-10 18:44 ` Trent Piepho
1 sibling, 0 replies; 7+ messages in thread
From: Trent Piepho @ 2015-11-10 18:44 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox, Peter Mamonov
On Tue, 2015-11-10 at 09:04 +0100, Sascha Hauer wrote:
> From 98fb34f2aa271138eab28a36aec733fe6572339c Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Tue, 10 Nov 2015 08:58:16 +0100
> Subject: [PATCH] ARM: omap: Use correct device to mount on /boot
>
> The current code tests if a partition (i.e. disk0.0) exists and instead
> of mounting boot from this partition it uses the whole device (disk0).
> This only works because the the FAT code accepts a MBR as input and
> automatically skips it.
I agree, this should fix it.
>
> Let the code use the partition to mount /boot instead as it was
> intended. We don't have to stat() the partition device, since this
> error will be caught by mount() anyway, so remove the unnecessary
> stat().
There are copies of this code in rpi.c and socfpga/generic.c. They
don't suffer from the whole disk flaw, but they do stat() first as well.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type
2015-11-09 10:32 [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type Peter Mamonov
2015-11-09 11:18 ` Antony Pavlov
2015-11-09 18:49 ` Trent Piepho
@ 2015-11-11 7:35 ` Sascha Hauer
2 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-11-11 7:35 UTC (permalink / raw)
To: Peter Mamonov; +Cc: barebox
On Mon, Nov 09, 2015 at 01:32:51PM +0300, Peter Mamonov wrote:
> Deleted pieces of code detect MBR-containig device as a FAT-type device,
> if it's first partition contains a FAT filesystem. This behaviour enabled one
> to mount the FAT FS which is either directly on the device (disk0) or on
> the first partition (disk0.0) using the same command:
> mount /dev/disk0 /fat
> However, the desired behaviour can be reached with a:
> mount /dev/disk0 /fat || mount /dev/disk0.0 /fat || echo "Mounting failed"
>
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Please don't add Acked-by for patches the person has never seen. I
agreed to the approach of removing the check here, but I can only ever
ack a patch that I have seen.
Applied this with my ack removed.
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] 7+ messages in thread
end of thread, other threads:[~2015-11-11 7:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 10:32 [PATCH] common: filetype: do not redetect MBR-type devices as a FAT-type Peter Mamonov
2015-11-09 11:18 ` Antony Pavlov
2015-11-09 18:49 ` Trent Piepho
2015-11-10 8:04 ` Sascha Hauer
2015-11-10 8:15 ` Sascha Hauer
2015-11-10 18:44 ` Trent Piepho
2015-11-11 7:35 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox