mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] filetype: add fat filesystem support
Date: Sun, 12 Aug 2012 13:49:37 +0200	[thread overview]
Message-ID: <1344772179-13591-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1344772179-13591-1-git-send-email-plagnioj@jcrosoft.com>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/filetype.c  |   20 ++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 21 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 1a5b82d..e736d43 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 f5de8ed..179ec0f 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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-08-12 11:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-12 11:46 [PATCH 0/4] fs/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 11:49 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 11:49   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-08-12 11:49   ` [PATCH 3/4] fs/fat: add filetype Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 11:49   ` [PATCH 4/4] command/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 12:43     ` Sascha Hauer
2012-08-12 12:46   ` [PATCH 1/4] fs/mount: add autodetection type support Sascha Hauer
2012-08-13  7:08   ` Uwe Kleine-König
2012-08-13  7:30     ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-13  8:16       ` Uwe Kleine-König
2012-08-13 10:56         ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:05 [PATCH 0/4 v2] fs/mount: add autodetection support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10 ` [PATCH 1/4] fs/mount: add autodetection type support Jean-Christophe PLAGNIOL-VILLARD
2012-08-12 18:10   ` [PATCH 2/4] filetype: add fat filesystem support Jean-Christophe PLAGNIOL-VILLARD

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=1344772179-13591-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /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