fs: add cdev mount helpers
Introduce helpers to iterate over cdevs and mount them to a known path. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
4dda27ce49
commit
cd16227383
80
fs/fs.c
80
fs/fs.c
|
@ -32,6 +32,7 @@
|
||||||
#include <magicvar.h>
|
#include <magicvar.h>
|
||||||
#include <environment.h>
|
#include <environment.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include <block.h>
|
||||||
|
|
||||||
void *read_file(const char *filename, size_t *size)
|
void *read_file(const char *filename, size_t *size)
|
||||||
{
|
{
|
||||||
|
@ -1670,3 +1671,82 @@ ssize_t mem_write(struct cdev *cdev, const void *buf, size_t count, loff_t offse
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(mem_write);
|
EXPORT_SYMBOL(mem_write);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cdev_get_mount_path - return the path a cdev is mounted on
|
||||||
|
*
|
||||||
|
* If a cdev is mounted return the path it's mounted on, NULL
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
const char *cdev_get_mount_path(struct cdev *cdev)
|
||||||
|
{
|
||||||
|
struct fs_device_d *fsdev;
|
||||||
|
|
||||||
|
for_each_fs_device(fsdev) {
|
||||||
|
if (fsdev->cdev && fsdev->cdev == cdev)
|
||||||
|
return fsdev->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cdev_mount_default - mount a cdev to the default path
|
||||||
|
*
|
||||||
|
* If a cdev is already mounted return the path it's mounted on, otherwise
|
||||||
|
* mount it to /mnt/<cdevname> and return the path. Returns an error pointer
|
||||||
|
* on failure.
|
||||||
|
*/
|
||||||
|
const char *cdev_mount_default(struct cdev *cdev)
|
||||||
|
{
|
||||||
|
const char *path;
|
||||||
|
char *newpath, *devpath;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this cdev is already mounted somewhere use this path
|
||||||
|
* instead of mounting it again to avoid corruption on the
|
||||||
|
* filesystem.
|
||||||
|
*/
|
||||||
|
path = cdev_get_mount_path(cdev);
|
||||||
|
if (path)
|
||||||
|
return path;
|
||||||
|
|
||||||
|
newpath = asprintf("/mnt/%s", cdev->name);
|
||||||
|
make_directory(newpath);
|
||||||
|
|
||||||
|
devpath = asprintf("/dev/%s", cdev->name);
|
||||||
|
|
||||||
|
ret = mount(devpath, NULL, newpath);
|
||||||
|
|
||||||
|
free(devpath);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
free(newpath);
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cdev_get_mount_path(cdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* mount_all - iterate over block devices and mount all devices we are able to
|
||||||
|
*/
|
||||||
|
void mount_all(void)
|
||||||
|
{
|
||||||
|
struct device_d *dev;
|
||||||
|
struct block_device *bdev;
|
||||||
|
|
||||||
|
if (!IS_ENABLED(CONFIG_BLOCK))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for_each_device(dev)
|
||||||
|
device_detect(dev);
|
||||||
|
|
||||||
|
for_each_block_device(bdev) {
|
||||||
|
struct cdev *cdev = &bdev->cdev;
|
||||||
|
|
||||||
|
list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list)
|
||||||
|
cdev_mount_default(cdev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -194,5 +194,8 @@ 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);
|
int fsdev_open_cdev(struct fs_device_d *fsdev);
|
||||||
|
const char *cdev_get_mount_path(struct cdev *cdev);
|
||||||
|
const char *cdev_mount_default(struct cdev *cdev);
|
||||||
|
void mount_all(void);
|
||||||
|
|
||||||
#endif /* __FS_H */
|
#endif /* __FS_H */
|
||||||
|
|
Loading…
Reference in New Issue