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 3/3] fs: add support loop mount offset
Date: Thu,  1 Feb 2018 11:37:17 +0100	[thread overview]
Message-ID: <20180201103717.17429-3-p.zabel@pengutronix.de> (raw)
In-Reply-To: <20180201103717.17429-1-p.zabel@pengutronix.de>

When loop mounting, allow to specify an offset into the file, similarly
to the losetup offset option. Multiplicative suffixes are supported.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 fs/devfs-core.c  |  8 ++++----
 fs/fs.c          | 12 +++++++++---
 include/driver.h |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index be56edd18d..ea5887c720 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -464,7 +464,7 @@ static const struct file_operations loop_ops = {
 	.lseek = dev_lseek_default,
 };
 
-struct cdev *cdev_create_loop(const char *path, ulong flags)
+struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset)
 {
 	struct cdev *new;
 	struct loop_priv *priv;
@@ -486,15 +486,15 @@ struct cdev *cdev_create_loop(const char *path, ulong flags)
 	new->priv = priv;
 
 	ofs = lseek(priv->fd, 0, SEEK_END);
-	if (ofs < 0) {
+	if (ofs < 0 || ofs <= offset) {
 		free(new);
 		free(priv);
 		return NULL;
 	}
-	lseek(priv->fd, 0, SEEK_SET);
+	lseek(priv->fd, offset, SEEK_SET);
 
 	new->size = ofs;
-	new->offset = 0;
+	new->offset = offset;
 	new->dev = NULL;
 	new->flags = 0;
 
diff --git a/fs/fs.c b/fs/fs.c
index 6f15e93ba9..56e67aac2a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1279,11 +1279,13 @@ static const char *detect_fs(const char *filename, const char *fsoptions)
 	enum filetype type;
 	struct driver_d *drv;
 	struct fs_driver_d *fdrv;
-	bool loop;
+	bool loop = false;
+	unsigned long long offset = 0;
 
 	parseopt_b(fsoptions, "loop", &loop);
+	parseopt_llu_suffix(fsoptions, "offset", &offset);
 	if (loop)
-		type = file_name_detect_type(filename);
+		type = file_name_detect_type_offset(filename, offset);
 	else
 		type = cdev_detect_type(filename);
 
@@ -1302,9 +1304,13 @@ static const char *detect_fs(const char *filename, const char *fsoptions)
 
 int fsdev_open_cdev(struct fs_device_d *fsdev)
 {
+	unsigned long long offset = 0;
+
 	parseopt_b(fsdev->options, "loop", &fsdev->loop);
+	parseopt_llu_suffix(fsdev->options, "offset", &offset);
 	if (fsdev->loop)
-		fsdev->cdev = cdev_create_loop(fsdev->backingstore, O_RDWR);
+		fsdev->cdev = cdev_create_loop(fsdev->backingstore, O_RDWR,
+					       offset);
 	else
 		fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR);
 	if (!fsdev->cdev)
diff --git a/include/driver.h b/include/driver.h
index e571fbbec5..f37805db17 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -475,7 +475,7 @@ struct cdev *cdev_readlink(struct cdev *cdev);
 struct cdev *cdev_by_device_node(struct device_node *node);
 struct cdev *cdev_by_partuuid(const char *partuuid);
 struct cdev *cdev_open(const char *name, unsigned long flags);
-struct cdev *cdev_create_loop(const char *path, ulong flags);
+struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset);
 void cdev_remove_loop(struct cdev *cdev);
 int cdev_do_open(struct cdev *, unsigned long flags);
 void cdev_close(struct cdev *cdev);
-- 
2.15.1


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

  parent 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 ` [PATCH 2/3] filetype: Add type detection at an offset Philipp Zabel
2018-02-01 10:37 ` Philipp Zabel [this message]
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-3-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