summaryrefslogtreecommitdiffstats
path: root/fs/fs.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-09-27 22:47:10 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-09-29 12:11:14 +0200
commitecb3aaa23b09c41f2ac8364f5ca72779467762e3 (patch)
treeab76b31d8736050aed1a150c5ec7525dd0836e2b /fs/fs.c
parentd4f5bb1e011ac653a167031554f0ac9e028e9e36 (diff)
downloadbarebox-ecb3aaa23b09c41f2ac8364f5ca72779467762e3.tar.gz
barebox-ecb3aaa23b09c41f2ac8364f5ca72779467762e3.tar.xz
fs: cleanup backingstore handling
All filesystem drivers which need a backingstore device do the same ignoring of '/dev/' in the backingstore followed by a cdev_open. Add a helper function for it and let the core handle the cdev. As a side effect this makes sure that fsdev->cdev is also set when a device is mounted without the leading '/dev/' which was previously ignored by the mount code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs/fs.c')
-rw-r--r--fs/fs.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/fs/fs.c b/fs/fs.c
index d913a503f2..4618b4fdcc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1231,6 +1231,9 @@ static void fs_remove(struct device_d *dev)
if (fsdev == fs_dev_root)
fs_dev_root = NULL;
+ if (fsdev->cdev)
+ cdev_close(fsdev->cdev);
+
free(fsdev->backingstore);
free(fsdev);
}
@@ -1279,6 +1282,23 @@ static const char *detect_fs(const char *filename)
return NULL;
}
+int fsdev_open_cdev(struct fs_device_d *fsdev)
+{
+ const char *backingstore = fsdev->backingstore;
+
+ if (!strncmp(backingstore , "/dev/", 5))
+ backingstore += 5;
+
+ fsdev->cdev = cdev_open(backingstore, O_RDWR);
+ if (!fsdev->cdev)
+ return -EINVAL;
+
+ fsdev->dev.parent = fsdev->cdev->dev;
+ fsdev->parent_device = fsdev->cdev->dev;
+
+ return 0;
+}
+
/*
* Mount a device to a directory.
* We do this by registering a new device on which the filesystem
@@ -1323,14 +1343,6 @@ int mount(const char *device, const char *fsname, const char *_path)
fsdev->path = xstrdup(path);
fsdev->dev.bus = &fs_bus;
- if (!strncmp(device, "/dev/", 5))
- fsdev->cdev = cdev_by_name(device + 5);
-
- if (fsdev->cdev) {
- fsdev->dev.parent = fsdev->cdev->dev;
- fsdev->parent_device = fsdev->cdev->dev;
- }
-
ret = register_device(&fsdev->dev);
if (ret)
goto err_register;