diff options
author | Markus Pargmann <mpa@pengutronix.de> | 2016-03-10 08:42:55 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-08 13:34:45 +0200 |
commit | 38eae8b2ca2304356cfbadec9c99985e7cf81b2c (patch) | |
tree | bee448f4bac673a18bb816ec2e5c5e75e575b5ee /fs | |
parent | 0a3795dd0ea3c950eae0309b3feafe9087e54f0e (diff) | |
download | barebox-38eae8b2ca2304356cfbadec9c99985e7cf81b2c.tar.gz barebox-38eae8b2ca2304356cfbadec9c99985e7cf81b2c.tar.xz |
fs: umount based on device path and mount path
umount on Linux can be used on a mount pathes and device pathes. This
patch adds this functionality to barebox.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.c | 48 |
1 files changed, 45 insertions, 3 deletions
@@ -1317,6 +1317,40 @@ err_free_path: } EXPORT_SYMBOL(mount); +static int fsdev_umount(struct fs_device_d *fsdev) +{ + return unregister_device(&fsdev->dev); +} + +/** + * umount_by_cdev Use a cdev struct to umount all mounted filesystems + * @param cdev cdev to the according device + * @return 0 on success or if cdev was not mounted, -errno otherwise + */ +int umount_by_cdev(struct cdev *cdev) +{ + struct fs_device_d *fs; + struct fs_device_d *fs_tmp; + int first_error = 0; + + for_each_fs_device_safe(fs_tmp, fs) { + int ret; + + if (fs->cdev == cdev) { + ret = fsdev_umount(fs); + if (ret) { + pr_err("Failed umounting %s, %d, continuing anyway\n", + fs->path, ret); + if (!first_error) + first_error = ret; + } + } + } + + return first_error; +} +EXPORT_SYMBOL(umount_by_cdev); + int umount(const char *pathname) { struct fs_device_d *fsdev = NULL, *f; @@ -1329,6 +1363,16 @@ int umount(const char *pathname) } } + if (!fsdev) { + struct cdev *cdev = cdev_open(p, O_RDWR); + + if (cdev) { + free(p); + cdev_close(cdev); + return umount_by_cdev(cdev); + } + } + free(p); if (f == fs_dev_root && !list_is_singular(&fs_device_list)) { @@ -1341,9 +1385,7 @@ int umount(const char *pathname) return -EFAULT; } - unregister_device(&fsdev->dev); - - return 0; + return fsdev_umount(fsdev); } EXPORT_SYMBOL(umount); |