summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-10-07 08:23:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-10-07 08:23:45 +0200
commitdd4da6d328ebb6e871a5584b3864d8c5cc64af86 (patch)
treee5dbcf1c457411ae2740a055047ec53967605fbd /common
parent181bb315d046da57126b1b93a5d695bb634e3e5f (diff)
parentf54c032120b6e24b622933af7acb8a817395eb34 (diff)
downloadbarebox-dd4da6d328ebb6e871a5584b3864d8c5cc64af86.tar.gz
barebox-dd4da6d328ebb6e871a5584b3864d8c5cc64af86.tar.xz
Merge branch 'for-next/omap'
Diffstat (limited to 'common')
-rw-r--r--common/filetype.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/filetype.c b/common/filetype.c
index 28a4b2ca25..dc2ff3f5f0 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;
+}