[PATCH 3/4] add ext fs detection support

Sascha Hauer s.hauer at pengutronix.de
Mon Dec 3 05:27:47 EST 2012


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c  |    8 ++++++++
 include/filetype.h |    1 +
 2 files changed, 9 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index c1bd11d..748e364 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -47,6 +47,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_mbr] = { "MBR sector", "mbr" },
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
+	[filetype_ext] = { "ext filesystem", "ext" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -110,6 +111,7 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
 	u32 *buf = _buf;
 	u64 *buf64 = _buf;
 	u8 *buf8 = _buf;
+	u16 *buf16 = _buf;
 	enum filetype type;
 
 	if (bufsize < 9)
@@ -161,6 +163,12 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
 	if (type != filetype_unknown)
 		return type;
 
+	if (bufsize < 1536)
+		return filetype_unknown;
+
+	if (buf16[512 + 28] == le16_to_cpu(0xef53))
+		return filetype_ext;
+
 	return filetype_unknown;
 }
 
diff --git a/include/filetype.h b/include/filetype.h
index 5fac531..91139db 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -22,6 +22,7 @@ enum filetype {
 	filetype_mbr,
 	filetype_bmp,
 	filetype_png,
+	filetype_ext,
 	filetype_max,
 };
 
-- 
1.7.10.4




More information about the barebox mailing list