[PATCH v2 050/113] filetype: have cdev_detect_type take a cdev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



cdev_detect_type reads as if it would take a cdev argument, but instead
it takes the adev's path. Fix it, so it takes a cdev and change the
only user. A new user will be added later that will pass in an already
open cdev.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 common/filetype.c  | 12 ++----------
 fs/fs.c            | 14 +++++++++++---
 include/filetype.h |  4 +++-
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 7f1ce20d0094..ba0f61e5d87e 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -456,20 +456,14 @@ int file_name_detect_type(const char *filename, enum filetype *type)
 	return file_name_detect_type_offset(filename, 0, type);
 }
 
-int cdev_detect_type(const char *name, enum filetype *type)
+int cdev_detect_type(struct cdev *cdev, enum filetype *type)
 {
 	int ret;
-	struct cdev *cdev;
 	void *buf;
 
-	cdev = cdev_open_by_name(name, O_RDONLY);
-	if (!cdev)
-		return -ENOENT;
-
 	if (cdev->filetype != filetype_unknown) {
 		*type = cdev->filetype;
-		ret = 0;
-		goto cdev_close;
+		return 0;
 	}
 
 	buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
@@ -482,8 +476,6 @@ int cdev_detect_type(const char *name, enum filetype *type)
 
 err_out:
 	free(buf);
-cdev_close:
-	cdev_close(cdev);
 	return ret;
 }
 
diff --git a/fs/fs.c b/fs/fs.c
index 3bd476713595..341cf62bbca7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -890,10 +890,18 @@ const char *fs_detect(const char *filename, const char *fsoptions)
 
 	parseopt_b(fsoptions, "loop", &loop);
 	parseopt_llu_suffix(fsoptions, "offset", &offset);
-	if (loop)
+
+	if (loop) {
 		ret = file_name_detect_type_offset(filename, offset, &type);
-	else
-		ret = cdev_detect_type(filename, &type);
+	} else {
+		struct cdev *cdev = cdev_open_by_name(filename, O_RDONLY);
+		if (cdev) {
+			ret = cdev_detect_type(cdev, &type);
+			cdev_close(cdev);
+		} else {
+			ret = -ENOENT;
+		}
+	}
 
 	if (ret || type == filetype_unknown)
 		return NULL;
diff --git a/include/filetype.h b/include/filetype.h
index a1f98f2a983a..f73b2da61f5a 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -66,13 +66,15 @@ enum filetype {
 
 #define FILE_TYPE_SAFE_BUFSIZE		2048
 
+struct cdev;
+
 const char *file_type_to_string(enum filetype f);
 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);
 int file_name_detect_type(const char *filename, enum filetype *type);
 int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
-int cdev_detect_type(const char *name, enum filetype *type);
+int cdev_detect_type(struct cdev *cdev, enum filetype *type);
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
 int is_fat_boot_sector(const void *_buf);
 bool filetype_is_barebox_image(enum filetype ft);
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux