summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2018-02-01 11:37:17 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-02-05 08:26:22 +0100
commit87aa4832f7f3587a65ee92ffa24f528652684c1b (patch)
tree164be1aaaf4c24e45aa6b78605c9b4f69ee96800 /fs
parent119147ebfd2827558b6d27e525c2d8da6bf2865a (diff)
downloadbarebox-87aa4832f7f3587a65ee92ffa24f528652684c1b.tar.gz
barebox-87aa4832f7f3587a65ee92ffa24f528652684c1b.tar.xz
fs: add support loop mount offset
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/devfs-core.c8
-rw-r--r--fs/fs.c12
2 files changed, 13 insertions, 7 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 7d0d97906d..d188fa995f 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)