[PATCH v2 10/11] mount: support filesystem options passed via -o

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Fri Feb 7 16:28:12 EST 2014


Similar to mount(8) the barebox command mount now supports passing a string
to the file system driver via -o.

This is used in the next commit to let the user specify port numbers for
nfs mounts.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi.c |  2 +-
 arch/arm/mach-omap/omap_generic.c  |  2 +-
 arch/arm/mach-omap/xload.c         |  4 ++--
 arch/arm/mach-socfpga/generic.c    |  2 +-
 commands/mount.c                   | 19 ++++++++++++-------
 commands/tftp.c                    |  2 +-
 common/blspec.c                    |  2 +-
 common/startup.c                   |  4 ++--
 fs/fs.c                            | 19 +++++++++++++------
 include/fs.h                       |  6 ++++--
 lib/bootstrap/disk.c               |  2 +-
 11 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
index 0997124c01ec..03a16d75619d 100644
--- a/arch/arm/boards/raspberry-pi/rpi.c
+++ b/arch/arm/boards/raspberry-pi/rpi.c
@@ -126,7 +126,7 @@ static int rpi_env_init(void)
 	}
 
 	mkdir("/boot", 0666);
-	ret = mount(diskdev, "fat", "/boot");
+	ret = mount(diskdev, "fat", "/boot", NULL);
 	if (ret) {
 		printf("failed to mount %s\n", diskdev);
 		return 0;
diff --git a/arch/arm/mach-omap/omap_generic.c b/arch/arm/mach-omap/omap_generic.c
index bedb4d8d2618..060c59277f4e 100644
--- a/arch/arm/mach-omap/omap_generic.c
+++ b/arch/arm/mach-omap/omap_generic.c
@@ -136,7 +136,7 @@ static int omap_env_init(void)
 	}
 
 	mkdir("/boot", 0666);
-	ret = mount(diskdev, "fat", "/boot");
+	ret = mount(diskdev, "fat", "/boot", NULL);
 	if (ret) {
 		printf("failed to mount %s\n", diskdev);
 		return 0;
diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
index 69e3e42df69d..a30945010990 100644
--- a/arch/arm/mach-omap/xload.c
+++ b/arch/arm/mach-omap/xload.c
@@ -110,7 +110,7 @@ static void *omap_xload_boot_mmc(void)
 
 	partname = asprintf("%s.0", diskdev);
 
-	ret = mount(partname, "fat", "/");
+	ret = mount(partname, "fat", "/", NULL);
 
 	free(partname);
 
@@ -170,7 +170,7 @@ static void *omap4_xload_boot_usb(void){
 	void *buf;
 	int len;
 
-	ret = mount("omap4_usbboot", "omap4_usbbootfs", "/");
+	ret = mount("omap4_usbboot", "omap4_usbbootfs", "/", NULL);
 	if (ret) {
 		printf("Unable to mount omap4_usbbootfs (%d)\n", ret);
 		return NULL;
diff --git a/arch/arm/mach-socfpga/generic.c b/arch/arm/mach-socfpga/generic.c
index 0d958d23af60..62593549d6e4 100644
--- a/arch/arm/mach-socfpga/generic.c
+++ b/arch/arm/mach-socfpga/generic.c
@@ -97,7 +97,7 @@ static int socfpga_env_init(void)
 	}
 
 	mkdir("/boot", 0666);
-	ret = mount(partname, "fat", "/boot");
+	ret = mount(partname, "fat", "/boot", NULL);
 	if (ret) {
 		printf("failed to mount %s\n", diskdev);
 		goto out_free;
diff --git a/commands/mount.c b/commands/mount.c
index 2e9d4bef5e3f..691bc2911e8f 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -33,26 +33,31 @@ static int do_mount(int argc, char *argv[])
 {
 	int opt;
 	int ret = 0, verbose = 0;
-	struct fs_device_d *fsdev;
 	struct driver_d *drv;
 	const char *type = NULL;
 	const char *mountpoint, *dev;
+	const char *fsoptions = NULL;
 
-	while ((opt = getopt(argc, argv, "t:va")) > 0) {
+	while ((opt = getopt(argc, argv, "ao:t:v")) > 0) {
 		switch (opt) {
+		case 'a':
+			mount_all();
+			break;
 		case 't':
 			type = optarg;
 			break;
+		case 'o':
+			fsoptions = optarg;
+			break;
 		case 'v':
 			verbose++;
 			break;
-		case 'a':
-			mount_all();
-			break;
 		}
 	}
 
 	if (argc == optind) {
+		struct fs_device_d *fsdev;
+
 		for_each_fs_device(fsdev) {
 			printf("%s on %s type %s\n",
 				fsdev->backingstore ? fsdev->backingstore : "none",
@@ -84,7 +89,7 @@ static int do_mount(int argc, char *argv[])
 		if (!cdev)
 			return -ENOENT;
 
-		path = cdev_mount_default(cdev);
+		path = cdev_mount_default(cdev, fsoptions);
 		if (IS_ERR(path))
 			return PTR_ERR(path);
 
@@ -108,7 +113,7 @@ static int do_mount(int argc, char *argv[])
 		mountpoint = argv[optind + 1];
 	}
 
-	if ((ret = mount(dev, type, mountpoint))) {
+	if ((ret = mount(dev, type, mountpoint, fsoptions))) {
 		perror("mount");
 		return 1;
 	}
diff --git a/commands/tftp.c b/commands/tftp.c
index c83d1740e2f0..64cab2f0451d 100644
--- a/commands/tftp.c
+++ b/commands/tftp.c
@@ -72,7 +72,7 @@ static int do_tftpb(int argc, char *argv[])
 		goto err_free;
 
 	ip = net_get_serverip();
-	ret = mount(ip_to_string(ip), "tftp", TFTP_MOUNT_PATH);
+	ret = mount(ip_to_string(ip), "tftp", TFTP_MOUNT_PATH, NULL);
 	if (ret)
 		goto err_rmdir;
 
diff --git a/common/blspec.c b/common/blspec.c
index 2244d5a8a868..df3c9c3c65da 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -276,7 +276,7 @@ static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
 	if (type == filetype_mbr || type == filetype_gpt)
 		return -EINVAL;
 
-	rootpath = cdev_mount_default(cdev);
+	rootpath = cdev_mount_default(cdev, NULL);
 	if (IS_ERR(rootpath))
 		return PTR_ERR(rootpath);
 
diff --git a/common/startup.c b/common/startup.c
index e8b9ea0216fe..0b5fe46adb50 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -89,9 +89,9 @@ device_initcall(register_default_env);
 #if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
 static int mount_root(void)
 {
-	mount("none", "ramfs", "/");
+	mount("none", "ramfs", "/", NULL);
 	mkdir("/dev", 0);
-	mount("none", "devfs", "/dev");
+	mount("none", "devfs", "/dev", NULL);
 	return 0;
 }
 fs_initcall(mount_root);
diff --git a/fs/fs.c b/fs/fs.c
index 32dba8cf0abe..7a57bc0670bc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1242,6 +1242,7 @@ static void fs_remove(struct device_d *dev)
 	}
 
 	free(fsdev->path);
+	free(fsdev->options);
 
 	if (fsdev == fs_dev_root)
 		fs_dev_root = NULL;
@@ -1316,13 +1317,18 @@ int fsdev_open_cdev(struct fs_device_d *fsdev)
  * We do this by registering a new device on which the filesystem
  * driver will match.
  */
-int mount(const char *device, const char *fsname, const char *_path)
+int mount(const char *device, const char *fsname, const char *_path,
+		const char *fsoptions)
 {
 	struct fs_device_d *fsdev;
 	int ret;
 	char *path = normalise_path(_path);
 
-	debug("mount: %s on %s type %s\n", device, path, fsname);
+	if (!fsoptions)
+		fsoptions = "";
+
+	debug("mount: %s on %s type %s, options=%s\n",
+			device, path, fsname, fsoptions);
 
 	if (fs_dev_root) {
 		fsdev = get_fsdevice_by_path(path);
@@ -1354,6 +1360,7 @@ int mount(const char *device, const char *fsname, const char *_path)
 	fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
 	fsdev->path = xstrdup(path);
 	fsdev->dev.bus = &fs_bus;
+	fsdev->options = xstrdup(fsoptions);
 
 	ret = register_device(&fsdev->dev);
 	if (ret)
@@ -1711,7 +1718,7 @@ const char *cdev_get_mount_path(struct cdev *cdev)
  * 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 *cdev_mount_default(struct cdev *cdev, const char *fsoptions)
 {
 	const char *path;
 	char *newpath, *devpath;
@@ -1720,7 +1727,7 @@ const char *cdev_mount_default(struct cdev *cdev)
 	/*
 	 * If this cdev is already mounted somewhere use this path
 	 * instead of mounting it again to avoid corruption on the
-	 * filesystem.
+	 * filesystem. Note this ignores eventual fsoptions though.
 	 */
 	path = cdev_get_mount_path(cdev);
 	if (path)
@@ -1731,7 +1738,7 @@ const char *cdev_mount_default(struct cdev *cdev)
 
 	devpath = asprintf("/dev/%s", cdev->name);
 
-	ret = mount(devpath, NULL, newpath);
+	ret = mount(devpath, NULL, newpath, fsoptions);
 
 	free(devpath);
 
@@ -1761,6 +1768,6 @@ void mount_all(void)
 		struct cdev *cdev = &bdev->cdev;
 
 		list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list)
-			cdev_mount_default(cdev);
+			cdev_mount_default(cdev, NULL);
 	}
 }
diff --git a/include/fs.h b/include/fs.h
index 856e00abb043..073641c74746 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -99,6 +99,7 @@ struct fs_device_d {
 	char *path;
 	struct device_d *parent_device;
 	struct list_head list;
+	char *options;
 };
 
 #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
@@ -140,7 +141,8 @@ int closedir(DIR *dir);
 int symlink(const char *pathname, const char *newpath);
 int readlink(const char *path, char *buf, size_t bufsiz);
 
-int mount (const char *device, const char *fsname, const char *path);
+int mount (const char *device, const char *fsname, const char *path,
+		const char *fsoptions);
 int umount(const char *pathname);
 
 /* not-so-standard functions */
@@ -197,7 +199,7 @@ int unlink_recursive(const char *path, char **failedpath);
 
 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);
+const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions);
 void mount_all(void);
 
 #endif /* __FS_H */
diff --git a/lib/bootstrap/disk.c b/lib/bootstrap/disk.c
index 879d3315e8e3..527e4308979c 100644
--- a/lib/bootstrap/disk.c
+++ b/lib/bootstrap/disk.c
@@ -20,7 +20,7 @@ void* bootstrap_read_disk(char *dev, char *fstype)
 	int len;
 	char *path = "/";
 
-	ret = mount(dev, fstype, path);
+	ret = mount(dev, fstype, path, NULL);
 	if (ret) {
 		bootstrap_err("mounting %s failed with %d\n", dev, ret);
 		return NULL;
-- 
1.8.5.2




More information about the barebox mailing list