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>
This commit is contained in:
parent
d4f5bb1e01
commit
ecb3aaa23b
|
@ -422,29 +422,33 @@ static int cramfs_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev;
|
struct fs_device_d *fsdev;
|
||||||
struct cramfs_priv *priv;
|
struct cramfs_priv *priv;
|
||||||
|
int ret;
|
||||||
|
|
||||||
fsdev = dev_to_fs_device(dev);
|
fsdev = dev_to_fs_device(dev);
|
||||||
|
|
||||||
priv = xmalloc(sizeof(struct cramfs_priv));
|
priv = xmalloc(sizeof(struct cramfs_priv));
|
||||||
dev->priv = priv;
|
dev->priv = priv;
|
||||||
|
|
||||||
if (strncmp(fsdev->backingstore, "/dev/", 5))
|
ret = fsdev_open_cdev(fsdev);
|
||||||
return -ENODEV;
|
if (ret)
|
||||||
|
goto err_out;
|
||||||
|
|
||||||
priv->cdev = cdev_by_name(fsdev->backingstore + 5);
|
priv->cdev = fsdev->cdev;
|
||||||
if (!priv->cdev)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (cramfs_read_super(priv)) {
|
if (cramfs_read_super(priv)) {
|
||||||
dev_info(dev, "no valid cramfs found\n");
|
dev_info(dev, "no valid cramfs found\n");
|
||||||
free(priv);
|
ret = -EINVAL;
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->curr_base = -1;
|
priv->curr_base = -1;
|
||||||
|
|
||||||
cramfs_uncompress_init ();
|
cramfs_uncompress_init ();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_out:
|
||||||
|
free(priv);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cramfs_remove(struct device_d *dev)
|
static void cramfs_remove(struct device_d *dev)
|
||||||
|
|
|
@ -225,7 +225,6 @@ static int ext_readlink(struct device_d *dev, const char *pathname,
|
||||||
static int ext_probe(struct device_d *dev)
|
static int ext_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
||||||
char *backingstore = fsdev->backingstore;
|
|
||||||
int ret;
|
int ret;
|
||||||
struct ext_filesystem *fs;
|
struct ext_filesystem *fs;
|
||||||
|
|
||||||
|
@ -234,14 +233,11 @@ static int ext_probe(struct device_d *dev)
|
||||||
dev->priv = fs;
|
dev->priv = fs;
|
||||||
fs->dev = dev;
|
fs->dev = dev;
|
||||||
|
|
||||||
if (!strncmp(backingstore , "/dev/", 5))
|
ret = fsdev_open_cdev(fsdev);
|
||||||
backingstore += 5;
|
if (ret)
|
||||||
|
|
||||||
fs->cdev = cdev_open(backingstore, O_RDWR);
|
|
||||||
if (!fs->cdev) {
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto err_open;
|
goto err_open;
|
||||||
}
|
|
||||||
|
fs->cdev = fsdev->cdev;
|
||||||
|
|
||||||
ret = ext4fs_mount(fs);
|
ret = ext4fs_mount(fs);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -250,7 +246,6 @@ static int ext_probe(struct device_d *dev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_mount:
|
err_mount:
|
||||||
cdev_close(fs->cdev);
|
|
||||||
err_open:
|
err_open:
|
||||||
free(fs);
|
free(fs);
|
||||||
|
|
||||||
|
@ -262,7 +257,6 @@ static void ext_remove(struct device_d *dev)
|
||||||
struct ext_filesystem *fs = dev->priv;
|
struct ext_filesystem *fs = dev->priv;
|
||||||
|
|
||||||
ext4fs_umount(fs);
|
ext4fs_umount(fs);
|
||||||
cdev_close(fs->cdev);
|
|
||||||
free(fs);
|
free(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
fs/fat/fat.c
17
fs/fat/fat.c
|
@ -373,19 +373,15 @@ static int fat_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
||||||
struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
|
struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
|
||||||
char *backingstore = fsdev->backingstore;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev->priv = priv;
|
dev->priv = priv;
|
||||||
|
|
||||||
if (!strncmp(backingstore , "/dev/", 5))
|
ret = fsdev_open_cdev(fsdev);
|
||||||
backingstore += 5;
|
if (ret)
|
||||||
|
|
||||||
priv->cdev = cdev_open(backingstore, O_RDWR);
|
|
||||||
if (!priv->cdev) {
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto err_open;
|
goto err_open;
|
||||||
}
|
|
||||||
|
priv->cdev = fsdev->cdev;
|
||||||
|
|
||||||
priv->fat.userdata = priv;
|
priv->fat.userdata = priv;
|
||||||
ret = f_mount(&priv->fat);
|
ret = f_mount(&priv->fat);
|
||||||
|
@ -395,7 +391,6 @@ static int fat_probe(struct device_d *dev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_mount:
|
err_mount:
|
||||||
cdev_close(priv->cdev);
|
|
||||||
err_open:
|
err_open:
|
||||||
free(priv);
|
free(priv);
|
||||||
|
|
||||||
|
@ -404,10 +399,6 @@ err_open:
|
||||||
|
|
||||||
static void fat_remove(struct device_d *dev)
|
static void fat_remove(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fat_priv *priv = dev->priv;
|
|
||||||
|
|
||||||
cdev_close(priv->cdev);
|
|
||||||
|
|
||||||
free(dev->priv);
|
free(dev->priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
fs/fs.c
28
fs/fs.c
|
@ -1231,6 +1231,9 @@ static void fs_remove(struct device_d *dev)
|
||||||
if (fsdev == fs_dev_root)
|
if (fsdev == fs_dev_root)
|
||||||
fs_dev_root = NULL;
|
fs_dev_root = NULL;
|
||||||
|
|
||||||
|
if (fsdev->cdev)
|
||||||
|
cdev_close(fsdev->cdev);
|
||||||
|
|
||||||
free(fsdev->backingstore);
|
free(fsdev->backingstore);
|
||||||
free(fsdev);
|
free(fsdev);
|
||||||
}
|
}
|
||||||
|
@ -1279,6 +1282,23 @@ static const char *detect_fs(const char *filename)
|
||||||
return NULL;
|
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.
|
* Mount a device to a directory.
|
||||||
* We do this by registering a new device on which the filesystem
|
* 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->path = xstrdup(path);
|
||||||
fsdev->dev.bus = &fs_bus;
|
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);
|
ret = register_device(&fsdev->dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_register;
|
goto err_register;
|
||||||
|
|
|
@ -553,25 +553,22 @@ static int ubifs_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
struct fs_device_d *fsdev = dev_to_fs_device(dev);
|
||||||
struct ubifs_priv *priv = xzalloc(sizeof(struct ubifs_priv));
|
struct ubifs_priv *priv = xzalloc(sizeof(struct ubifs_priv));
|
||||||
char *backingstore = fsdev->backingstore;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev->priv = priv;
|
dev->priv = priv;
|
||||||
|
|
||||||
if (!strncmp(backingstore , "/dev/", 5))
|
ret = fsdev_open_cdev(fsdev);
|
||||||
backingstore += 5;
|
if (ret)
|
||||||
|
|
||||||
priv->cdev = cdev_open(backingstore, O_RDONLY);
|
|
||||||
if (!priv->cdev) {
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto err_free;
|
goto err_free;
|
||||||
}
|
|
||||||
|
priv->cdev = fsdev->cdev;
|
||||||
|
|
||||||
priv->ubi = ubi_open_volume_cdev(priv->cdev, UBI_READONLY);
|
priv->ubi = ubi_open_volume_cdev(priv->cdev, UBI_READONLY);
|
||||||
if (IS_ERR(priv->ubi)) {
|
if (IS_ERR(priv->ubi)) {
|
||||||
dev_err(dev, "failed to open ubi volume: %s\n",
|
dev_err(dev, "failed to open ubi volume: %s\n",
|
||||||
strerror(-PTR_ERR(priv->ubi)));
|
strerror(-PTR_ERR(priv->ubi)));
|
||||||
return PTR_ERR(priv->ubi);
|
ret = PTR_ERR(priv->ubi);
|
||||||
|
goto err_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->sb = ubifs_get_super(priv->ubi, 0);
|
priv->sb = ubifs_get_super(priv->ubi, 0);
|
||||||
|
@ -596,7 +593,6 @@ static void ubifs_remove(struct device_d *dev)
|
||||||
|
|
||||||
ubifs_umount(c);
|
ubifs_umount(c);
|
||||||
ubi_close_volume(priv->ubi);
|
ubi_close_volume(priv->ubi);
|
||||||
cdev_close(priv->cdev);
|
|
||||||
|
|
||||||
free(c);
|
free(c);
|
||||||
free(sb);
|
free(sb);
|
||||||
|
|
|
@ -193,4 +193,6 @@ void automount_print(void);
|
||||||
|
|
||||||
int unlink_recursive(const char *path, char **failedpath);
|
int unlink_recursive(const char *path, char **failedpath);
|
||||||
|
|
||||||
|
int fsdev_open_cdev(struct fs_device_d *fsdev);
|
||||||
|
|
||||||
#endif /* __FS_H */
|
#endif /* __FS_H */
|
||||||
|
|
Loading…
Reference in New Issue