From: Vicente Bergas <vicencb@gmail.com>
To: barebox@lists.infradead.org, s.hauer@pengutronix.de
Cc: Vicente Bergas <vicencb@gmail.com>
Subject: [PATCH 1/2] detect_fs: use device instead of file
Date: Fri, 2 Oct 2015 00:08:38 +0100 [thread overview]
Message-ID: <1443740919-6341-2-git-send-email-vicencb@gmail.com> (raw)
In-Reply-To: <1443740919-6341-1-git-send-email-vicencb@gmail.com>
detect_fs would usually mount a device on a directory,
so, use a device-specific type detection.
Signed-off-by: Vicente Bergas <vicencb@gmail.com>
---
common/filetype.c | 37 +++++++++++++++++++++++++++++++++++++++
fs/fs.c | 2 +-
include/filetype.h | 1 +
3 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/common/filetype.c b/common/filetype.c
index 28a4b2c..6240fd1 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -361,3 +361,40 @@ err_out:
return type;
}
+
+enum filetype cdev_detect_type(const char *name)
+{
+ enum filetype type = filetype_unknown;
+ int ret;
+ struct cdev *cdev;
+ void *buf;
+
+ cdev = cdev_by_name(name);
+ if (!cdev)
+ return type;
+ buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
+ ret = cdev_read(cdev, buf, FILE_TYPE_SAFE_BUFSIZE, 0, 0);
+ if (ret < 0)
+ goto err_out;
+
+ 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);
+ return type;
+}
diff --git a/fs/fs.c b/fs/fs.c
index 67c78cd..c041e41 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1201,7 +1201,7 @@ EXPORT_SYMBOL(register_fs_driver);
static const char *detect_fs(const char *filename)
{
- enum filetype type = file_name_detect_type(filename);
+ enum filetype type = cdev_detect_type(filename);
struct driver_d *drv;
struct fs_driver_d *fdrv;
diff --git a/include/filetype.h b/include/filetype.h
index e452b7a..cde543e 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -45,6 +45,7 @@ const char *file_type_to_short_string(enum filetype f);
enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
enum filetype file_detect_type(const void *_buf, size_t bufsize);
enum filetype file_name_detect_type(const char *filename);
+enum filetype cdev_detect_type(const char *name);
enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
int is_fat_boot_sector(const void *_buf);
--
2.6.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-10-01 23:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-27 14:08 [PATCH] xload: be more flexible when searching for second stage bootloader Vicente Bergas
2015-09-29 7:05 ` Sascha Hauer
2015-09-29 19:06 ` vj
2015-09-30 7:19 ` Sascha Hauer
2015-09-30 17:49 ` vj
2015-10-01 6:04 ` Sascha Hauer
2015-10-01 23:08 ` [PATCH 0/2] second version for "be more flexible when searching for second stage" Vicente Bergas
2015-10-01 23:08 ` Vicente Bergas [this message]
2015-10-01 23:08 ` [PATCH 2/2] xload: be more flexible when searching for second stage bootloader Vicente Bergas
2015-10-02 7:11 ` [PATCH 0/2] second version for "be more flexible when searching for second stage" Sascha Hauer
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=1443740919-6341-2-git-send-email-vicencb@gmail.com \
--to=vicencb@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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