summaryrefslogtreecommitdiffstats
path: root/common/filetype.c
diff options
context:
space:
mode:
authorVicente Bergas <vicencb@gmail.com>2015-10-02 00:08:38 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-10-02 09:10:16 +0200
commite89f1a1f188c196eade0d2ad05b662326d870be3 (patch)
tree6b7fe46d3a75db2d8862c34244c6f02d3142fdfc /common/filetype.c
parentbdb26b1727e1e20f03021fc2f25afc9b3011813e (diff)
downloadbarebox-e89f1a1f188c196eade0d2ad05b662326d870be3.tar.gz
detect_fs: use device instead of file
detect_fs would usually mount a device on a directory, so, use a device-specific type detection. Signed-off-by: Vicente Bergas <vicencb@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/filetype.c')
-rw-r--r--common/filetype.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/filetype.c b/common/filetype.c
index 28a4b2c..dc2ff3f 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;
+}