diff options
author | Hubert Feurstein <h.feurstein@gmail.com> | 2013-04-19 10:46:04 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-04-29 09:32:54 +0200 |
commit | c06956e15f8fb32d46e479950719c30bae57e5bb (patch) | |
tree | f52e3c182e13be25387c3a408996e3d41ea3ae6c /common/filetype.c | |
parent | 57c64582a029c75e21c5e4347ca3e59255af90fe (diff) | |
download | barebox-c06956e15f8fb32d46e479950719c30bae57e5bb.tar.gz barebox-c06956e15f8fb32d46e479950719c30bae57e5bb.tar.xz |
common/filetype: move partition-table detection into own function
Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/filetype.c')
-rw-r--r-- | common/filetype.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/common/filetype.c b/common/filetype.c index 8652f1d7af..1ff3dd202a 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -151,6 +151,28 @@ enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec) return filetype_mbr; } +enum filetype file_detect_partition_table(const void *_buf, size_t bufsize) +{ + const u8 *buf8 = _buf; + enum filetype type; + + if (bufsize < 512) + return filetype_unknown; + + /* + * EFI GPT need to be detected before MBR otherwise + * we will detect a MBR + */ + if (bufsize >= 520 && is_gpt_valid(buf8)) + return filetype_gpt; + + type = is_fat_or_mbr(buf8, NULL); + if (type != filetype_unknown) + return type; + + return filetype_unknown; +} + enum filetype file_detect_type(const void *_buf, size_t bufsize) { const u32 *buf = _buf; @@ -204,21 +226,11 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize) if (bufsize < 512) return filetype_unknown; - /* - * EFI GPT need to be detected before MBR otherwise - * we will detect a MBR - */ - if (bufsize >= 520 && is_gpt_valid(buf8)) - return filetype_gpt; - - type = is_fat_or_mbr(buf8, NULL); + type = file_detect_partition_table(_buf, bufsize); if (type != filetype_unknown) return type; - if (bufsize < 1536) - return filetype_unknown; - - if (buf16[512 + 28] == le16_to_cpu(0xef53)) + if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53)) return filetype_ext; return filetype_unknown; |