From: Sascha Hauer <s.hauer@pengutronix.de>
To: Franck Jullien <franck.jullien@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] [v2] filetype: Improve FAT detection
Date: Tue, 18 Sep 2012 10:38:18 +0200 [thread overview]
Message-ID: <20120918083818.GR6180@pengutronix.de> (raw)
In-Reply-To: <1347827613-25769-1-git-send-email-franck.jullien@gmail.com>
Hi Franck,
On Sun, Sep 16, 2012 at 10:33:32PM +0200, Franck Jullien wrote:
> We may have some disk with MBR as a first sector. In this case, the
> current FAT check returns an error. However, the FAT sector exist and
> the MBR can tell us where it is.
>
> This patch add to file_name_detect_type function the ability to find
> the FAT boot sector on the first sector of the first partition in case
> it is not on sector 0.
>
> It also introduce is_fat_boot_sector to check if a buffer is a FAT boot
> sector.
I think it would be cleaner to introduce a filetype MBR as a first
step...
> @@ -110,6 +128,7 @@ enum filetype file_name_detect_type(const char *filename)
> int fd, ret;
> void *buf;
> enum filetype type = filetype_unknown;
> + unsigned long bootsec;
>
> fd = open(filename, O_RDONLY);
> if (fd < 0)
> @@ -123,6 +142,25 @@ enum filetype file_name_detect_type(const char *filename)
>
> type = file_detect_type(buf);
>
> + /* Let's give FAT another chance */
> + if (type == filetype_unknown) {
... then you could check for type == filetype_mbr here instead and
return filetype_mbr when the check for fat below fails.
> + ret = is_fat_boot_sector((u8 *)buf, &bootsec);
> + if (ret && bootsec != 0) {
> + /* The first sector is an MBR, now check for
> + * FAT in the first partition */
> + lseek(fd, (bootsec) * 512, SEEK_SET);
Please check the return value of lseek here. lseek will fail when the file
is on a tftp filesystem or when the file is not large enough.
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
prev parent reply other threads:[~2012-09-18 8:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-16 20:33 Franck Jullien
2012-09-16 20:33 ` [PATCH 2/2] fs/fat: Handle MBR on the first sector Franck Jullien
2012-09-17 5:49 ` [PATCH 1/2] [v2] filetype: Improve FAT detection Jean-Christophe PLAGNIOL-VILLARD
2012-09-17 6:08 ` Franck Jullien
2012-09-18 8:38 ` Sascha Hauer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120918083818.GR6180@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=franck.jullien@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox