mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Cc: "Uwe Kleine-König" <uwe@kleine-koenig.org>
Subject: [PATCH 7/9] mount: support filesystem options passed via -o
Date: Thu,  6 Feb 2014 17:40:52 +0100	[thread overview]
Message-ID: <1391704854-3141-8-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <1391704854-3141-1-git-send-email-u.kleine-koenig@pengutronix.de>

From: Uwe Kleine-König <uwe@kleine-koenig.org>

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

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

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-02-06 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-06 16:40 [PATCH 0/9] nfs3 support Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 1/9] net: net_read_uint32: assert that only 32 bit are read Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 2/9] nfs: skip over stale rpc packets Uwe Kleine-König
2014-02-07  8:20   ` Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 3/9] nfs: shorten and simplify rpc_add_credentials a bit Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 4/9] nfs: simplify rpc_lookup_req Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 5/9] nfs: drop an unneeded variable from nfs_do_open() Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 6/9] net: new function net_read_uint64 Uwe Kleine-König
2014-02-07  8:17   ` Uwe Kleine-König
2014-02-06 16:40 ` Uwe Kleine-König [this message]
2014-02-06 16:40 ` [PATCH 8/9] nfs: switch to nfs3 Uwe Kleine-König
2014-02-07  6:48   ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07  8:52     ` Uwe Kleine-König
2014-02-07  9:50       ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 10:23         ` Uwe Kleine-König
2014-02-06 16:40 ` [PATCH 9/9] nfs: parse nfsport and mount port from file system options Uwe Kleine-König
2014-02-07  6:50   ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07  8:22     ` Uwe Kleine-König
2014-02-07  8:45       ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 10:06         ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391704854-3141-8-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=uwe@kleine-koenig.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox