[PATCH 049/112] filetype: have cdev_detect_type take a cdev
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Jan 3 10:12:09 PST 2024
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 at pengutronix.de>
---
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 43d292c27baf..f726a933d245 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -450,20 +450,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);
@@ -476,8 +470,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 fc9e56168c9c..9b177911efba 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 e5aa050ebc27..4e646aec9d6f 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -65,13 +65,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
More information about the barebox
mailing list