mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] filetype: Add type detection at an offset
Date: Thu,  1 Feb 2018 11:37:16 +0100	[thread overview]
Message-ID: <20180201103717.17429-2-p.zabel@pengutronix.de> (raw)
In-Reply-To: <20180201103717.17429-1-p.zabel@pengutronix.de>

Add file_name_detect_type_offset to allow file system detection for loop
mounts at an offset.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 common/filetype.c  | 10 ++++++++--
 include/filetype.h |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index f9c034ff2a..71691fd813 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -21,6 +21,7 @@
 #include <asm/unaligned.h>
 #include <fcntl.h>
 #include <fs.h>
+#include <libfile.h>
 #include <malloc.h>
 #include <errno.h>
 #include <envfs.h>
@@ -343,13 +344,13 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
-enum filetype file_name_detect_type(const char *filename)
+enum filetype file_name_detect_type_offset(const char *filename, loff_t pos)
 {
 	int fd, ret;
 	void *buf;
 	enum filetype type = filetype_unknown;
 
-	fd = open(filename, O_RDONLY);
+	fd = open_and_lseek(filename, O_RDONLY, pos);
 	if (fd < 0)
 		return fd;
 
@@ -368,6 +369,11 @@ err_out:
 	return type;
 }
 
+enum filetype file_name_detect_type(const char *filename)
+{
+	return file_name_detect_type_offset(filename, 0);
+}
+
 enum filetype cdev_detect_type(const char *name)
 {
 	enum filetype type = filetype_unknown;
diff --git a/include/filetype.h b/include/filetype.h
index b98dcb5014..ec5aea2635 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -50,6 +50,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 file_name_detect_type_offset(const char *filename, loff_t pos);
 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);
-- 
2.15.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-02-01 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01 10:37 [PATCH 1/3] fs/parseopt: Add parseopt_llu_suffix Philipp Zabel
2018-02-01 10:37 ` Philipp Zabel [this message]
2018-02-01 10:37 ` [PATCH 3/3] fs: add support loop mount offset Philipp Zabel
2018-02-05  7:26 ` [PATCH 1/3] fs/parseopt: Add parseopt_llu_suffix Sascha Hauer

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=20180201103717.17429-2-p.zabel@pengutronix.de \
    --to=p.zabel@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