diff options
author | Philipp Zabel <p.zabel@pengutronix.de> | 2017-06-01 12:37:29 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-06-06 09:16:23 +0200 |
commit | f3cd5b1bbcb27108496eb572ae2ff7cd526ddc55 (patch) | |
tree | 4a0e5586df03dd50f6190525c5cb71db34128113 /fs/fs.c | |
parent | 7bcbc91a5eb2c3fbb3a6d67103ca0ff8fc8e4412 (diff) | |
download | barebox-f3cd5b1bbcb27108496eb572ae2ff7cd526ddc55.tar.gz barebox-f3cd5b1bbcb27108496eb572ae2ff7cd526ddc55.tar.xz |
fs: add cdev_create_loop and cdev_remove_loop for loop mount option
Allow to create a loopback cdev from a file.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Fixed up with:
fs: Makefile: Add parseopt to all builds
parseopt.h was included to fs.c with commit 9248b, but parseopt.o has a
dependency to CONFIG_FS_NFS.
Moved parseopt.o to the default build to eliminate build failures.
Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs/fs.c')
-rw-r--r-- | fs/fs.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -36,6 +36,8 @@ #include <block.h> #include <libfile.h> +#include "parseopt.h" + char *mkmodestr(unsigned long mode, char *str) { static const char *l = "xwr"; @@ -1210,6 +1212,9 @@ static void fs_remove(struct device_d *dev) if (fsdev->cdev) cdev_close(fsdev->cdev); + if (fsdev->loop) + cdev_remove_loop(fsdev->cdev); + free(fsdev->backingstore); free(fsdev); } @@ -1236,13 +1241,18 @@ int register_fs_driver(struct fs_driver_d *fsdrv) } EXPORT_SYMBOL(register_fs_driver); -static const char *detect_fs(const char *filename) +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; - type = cdev_detect_type(filename); + parseopt_b(fsoptions, "loop", &loop); + if (loop) + type = file_name_detect_type(filename); + else + type = cdev_detect_type(filename); if (type == filetype_unknown) return NULL; @@ -1259,7 +1269,11 @@ static const char *detect_fs(const char *filename) int fsdev_open_cdev(struct fs_device_d *fsdev) { - fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR); + parseopt_b(fsdev->options, "loop", &fsdev->loop); + if (fsdev->loop) + fsdev->cdev = cdev_create_loop(fsdev->backingstore, O_RDWR); + else + fsdev->cdev = cdev_open(fsdev->backingstore, O_RDWR); if (!fsdev->cdev) return -EINVAL; @@ -1306,7 +1320,7 @@ int mount(const char *device, const char *fsname, const char *_path, } if (!fsname) - fsname = detect_fs(device); + fsname = detect_fs(device, fsoptions); if (!fsname) return -ENOENT; |