mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 3/7] filetype: add function pointer to file_name_detect_type_offset()
Date: Tue, 18 Mar 2025 15:41:44 +0100	[thread overview]
Message-ID: <20250318-filetype-size-reduction-v1-3-4f463ffae7d0@pengutronix.de> (raw)
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>

file_name_detect_type_offset() calls file_detect_type() which is quite
a big function. Add a function pointer argument so the caller can
decide which file detection function shall be called. This allows
callers to depend on a function with a smaller binary size impact.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c  | 8 +++++---
 fs/fs.c            | 3 ++-
 include/filetype.h | 3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 2a55d5f4ea..1e2d4ed0e3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -476,7 +476,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
-int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type)
+int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize))
 {
 	int fd, ret;
 	void *buf;
@@ -491,7 +492,7 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 	if (ret < 0)
 		goto err_out;
 
-	*type = file_detect_type(buf, ret);
+	*type = detect(buf, ret);
 
 	ret = 0;
 err_out:
@@ -503,7 +504,8 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 
 int file_name_detect_type(const char *filename, enum filetype *type)
 {
-	return file_name_detect_type_offset(filename, 0, type);
+	return file_name_detect_type_offset(filename, 0, type,
+					    file_detect_type);
 }
 
 int cdev_detect_type(struct cdev *cdev, enum filetype *type)
diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341e..9924709424 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -903,7 +903,8 @@ const char *fs_detect(const char *filename, const char *fsoptions)
 	parseopt_llu_suffix(fsoptions, "offset", &offset);
 
 	if (loop) {
-		ret = file_name_detect_type_offset(filename, offset, &type);
+		ret = file_name_detect_type_offset(filename, offset, &type,
+						   file_detect_fs_type);
 	} else {
 		struct cdev *cdev = cdev_open_by_name(filename, O_RDONLY);
 		if (cdev) {
diff --git a/include/filetype.h b/include/filetype.h
index 329ebc9e8b..03d1f1595d 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -78,7 +78,8 @@ enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_fs_type(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 file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize));
 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);

-- 
2.39.5




  parent reply	other threads:[~2025-03-18 14:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18 14:41 [PATCH 0/7] filetype: Some size reduction patches Sascha Hauer
2025-03-18 14:41 ` [PATCH 1/7] filetype: add file_detect_compression_type() Sascha Hauer
2025-03-18 14:41 ` [PATCH 2/7] filetype: add file_detect_fs_type() Sascha Hauer
2025-03-18 14:51   ` Ahmad Fatoum
2025-03-18 15:06     ` Sascha Hauer
2025-03-18 14:41 ` Sascha Hauer [this message]
2025-03-18 14:41 ` [PATCH 4/7] filetype: let cdev_detect_type() only detect filesystems Sascha Hauer
2025-03-18 14:41 ` [PATCH 5/7] filetype: make file type strings optional Sascha Hauer
2025-03-18 14:41 ` [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree Sascha Hauer
2025-03-18 14:41 ` [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings Sascha Hauer
2025-03-18 15:01 ` [PATCH 0/7] filetype: Some size reduction patches Alexander Shiyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250318-filetype-size-reduction-v1-3-4f463ffae7d0@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox