summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/filetype.c37
-rw-r--r--fs/fs.c2
-rw-r--r--include/filetype.h1
3 files changed, 39 insertions, 1 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;
+}
diff --git a/fs/fs.c b/fs/fs.c
index 67c78cd111..c041e41bb5 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1201,7 +1201,7 @@ EXPORT_SYMBOL(register_fs_driver);
static const char *detect_fs(const char *filename)
{
- enum filetype type = file_name_detect_type(filename);
+ enum filetype type = cdev_detect_type(filename);
struct driver_d *drv;
struct fs_driver_d *fdrv;
diff --git a/include/filetype.h b/include/filetype.h
index e452b7ac9d..cde543e5b0 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -45,6 +45,7 @@ const char *file_type_to_short_string(enum filetype f);
enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
enum filetype file_detect_type(const void *_buf, size_t bufsize);
enum filetype file_name_detect_type(const char *filename);
+enum filetype cdev_detect_type(const char *name);
enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
int is_fat_boot_sector(const void *_buf);