diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-08-12 18:51:07 +0800 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-04 09:08:39 +0200 |
commit | 653c767213f6ae597a816a84fd3332718e0b82f3 (patch) | |
tree | b824ab54a62ebdb574b224957b96a43663e4961a | |
parent | a1b1aec6afa625451f531e0b870c8206a3841f69 (diff) | |
download | barebox-653c767213f6ae597a816a84fd3332718e0b82f3.tar.gz barebox-653c767213f6ae597a816a84fd3332718e0b82f3.tar.xz |
filetype: add fat filesystem support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
-rw-r--r-- | common/filetype.c | 20 | ||||
-rw-r--r-- | include/filetype.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/common/filetype.c b/common/filetype.c index 1a5b82da47..e736d43efe 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -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; } diff --git a/include/filetype.h b/include/filetype.h index f5de8ed2b5..179ec0f5eb 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -18,6 +18,7 @@ enum filetype { filetype_aimage, filetype_sh, filetype_mips_barebox, + filetype_fat, }; const char *file_type_to_string(enum filetype f); |