9
0
Fork 0

mount: support filesystem options passed via -o

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@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Uwe Kleine-König 2014-02-07 22:28:12 +01:00 committed by Sascha Hauer
parent f43f827bb4
commit f97f4b6571
11 changed files with 39 additions and 25 deletions

View File

@ -126,7 +126,7 @@ static int rpi_env_init(void)
} }
mkdir("/boot", 0666); mkdir("/boot", 0666);
ret = mount(diskdev, "fat", "/boot"); ret = mount(diskdev, "fat", "/boot", NULL);
if (ret) { if (ret) {
printf("failed to mount %s\n", diskdev); printf("failed to mount %s\n", diskdev);
return 0; return 0;

View File

@ -136,7 +136,7 @@ static int omap_env_init(void)
} }
mkdir("/boot", 0666); mkdir("/boot", 0666);
ret = mount(diskdev, "fat", "/boot"); ret = mount(diskdev, "fat", "/boot", NULL);
if (ret) { if (ret) {
printf("failed to mount %s\n", diskdev); printf("failed to mount %s\n", diskdev);
return 0; return 0;

View File

@ -110,7 +110,7 @@ static void *omap_xload_boot_mmc(void)
partname = asprintf("%s.0", diskdev); partname = asprintf("%s.0", diskdev);
ret = mount(partname, "fat", "/"); ret = mount(partname, "fat", "/", NULL);
free(partname); free(partname);
@ -170,7 +170,7 @@ static void *omap4_xload_boot_usb(void){
void *buf; void *buf;
int len; int len;
ret = mount("omap4_usbboot", "omap4_usbbootfs", "/"); ret = mount("omap4_usbboot", "omap4_usbbootfs", "/", NULL);
if (ret) { if (ret) {
printf("Unable to mount omap4_usbbootfs (%d)\n", ret); printf("Unable to mount omap4_usbbootfs (%d)\n", ret);
return NULL; return NULL;

View File

@ -97,7 +97,7 @@ static int socfpga_env_init(void)
} }
mkdir("/boot", 0666); mkdir("/boot", 0666);
ret = mount(partname, "fat", "/boot"); ret = mount(partname, "fat", "/boot", NULL);
if (ret) { if (ret) {
printf("failed to mount %s\n", diskdev); printf("failed to mount %s\n", diskdev);
goto out_free; goto out_free;

View File

@ -33,26 +33,31 @@ static int do_mount(int argc, char *argv[])
{ {
int opt; int opt;
int ret = 0, verbose = 0; int ret = 0, verbose = 0;
struct fs_device_d *fsdev;
struct driver_d *drv; struct driver_d *drv;
const char *type = NULL; const char *type = NULL;
const char *mountpoint, *dev; 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) { switch (opt) {
case 'a':
mount_all();
break;
case 't': case 't':
type = optarg; type = optarg;
break; break;
case 'o':
fsoptions = optarg;
break;
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'a':
mount_all();
break;
} }
} }
if (argc == optind) { if (argc == optind) {
struct fs_device_d *fsdev;
for_each_fs_device(fsdev) { for_each_fs_device(fsdev) {
printf("%s on %s type %s\n", printf("%s on %s type %s\n",
fsdev->backingstore ? fsdev->backingstore : "none", fsdev->backingstore ? fsdev->backingstore : "none",
@ -84,7 +89,7 @@ static int do_mount(int argc, char *argv[])
if (!cdev) if (!cdev)
return -ENOENT; return -ENOENT;
path = cdev_mount_default(cdev); path = cdev_mount_default(cdev, fsoptions);
if (IS_ERR(path)) if (IS_ERR(path))
return PTR_ERR(path); return PTR_ERR(path);
@ -108,7 +113,7 @@ static int do_mount(int argc, char *argv[])
mountpoint = argv[optind + 1]; mountpoint = argv[optind + 1];
} }
if ((ret = mount(dev, type, mountpoint))) { if ((ret = mount(dev, type, mountpoint, fsoptions))) {
perror("mount"); perror("mount");
return 1; return 1;
} }

View File

@ -72,7 +72,7 @@ static int do_tftpb(int argc, char *argv[])
goto err_free; goto err_free;
ip = net_get_serverip(); 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) if (ret)
goto err_rmdir; goto err_rmdir;

View File

@ -276,7 +276,7 @@ static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
if (type == filetype_mbr || type == filetype_gpt) if (type == filetype_mbr || type == filetype_gpt)
return -EINVAL; return -EINVAL;
rootpath = cdev_mount_default(cdev); rootpath = cdev_mount_default(cdev, NULL);
if (IS_ERR(rootpath)) if (IS_ERR(rootpath))
return PTR_ERR(rootpath); return PTR_ERR(rootpath);

View File

@ -89,9 +89,9 @@ device_initcall(register_default_env);
#if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS #if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
static int mount_root(void) static int mount_root(void)
{ {
mount("none", "ramfs", "/"); mount("none", "ramfs", "/", NULL);
mkdir("/dev", 0); mkdir("/dev", 0);
mount("none", "devfs", "/dev"); mount("none", "devfs", "/dev", NULL);
return 0; return 0;
} }
fs_initcall(mount_root); fs_initcall(mount_root);

19
fs/fs.c
View File

@ -1242,6 +1242,7 @@ static void fs_remove(struct device_d *dev)
} }
free(fsdev->path); free(fsdev->path);
free(fsdev->options);
if (fsdev == fs_dev_root) if (fsdev == fs_dev_root)
fs_dev_root = NULL; 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 * We do this by registering a new device on which the filesystem
* driver will match. * 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; struct fs_device_d *fsdev;
int ret; int ret;
char *path = normalise_path(_path); 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) { if (fs_dev_root) {
fsdev = get_fsdevice_by_path(path); 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->dev.id = get_free_deviceid(fsdev->dev.name);
fsdev->path = xstrdup(path); fsdev->path = xstrdup(path);
fsdev->dev.bus = &fs_bus; fsdev->dev.bus = &fs_bus;
fsdev->options = xstrdup(fsoptions);
ret = register_device(&fsdev->dev); ret = register_device(&fsdev->dev);
if (ret) 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 * mount it to /mnt/<cdevname> and return the path. Returns an error pointer
* on failure. * on failure.
*/ */
const char *cdev_mount_default(struct cdev *cdev) const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions)
{ {
const char *path; const char *path;
char *newpath, *devpath; 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 * If this cdev is already mounted somewhere use this path
* instead of mounting it again to avoid corruption on the * instead of mounting it again to avoid corruption on the
* filesystem. * filesystem. Note this ignores eventual fsoptions though.
*/ */
path = cdev_get_mount_path(cdev); path = cdev_get_mount_path(cdev);
if (path) if (path)
@ -1731,7 +1738,7 @@ const char *cdev_mount_default(struct cdev *cdev)
devpath = asprintf("/dev/%s", cdev->name); devpath = asprintf("/dev/%s", cdev->name);
ret = mount(devpath, NULL, newpath); ret = mount(devpath, NULL, newpath, fsoptions);
free(devpath); free(devpath);
@ -1761,6 +1768,6 @@ void mount_all(void)
struct cdev *cdev = &bdev->cdev; struct cdev *cdev = &bdev->cdev;
list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list) list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list)
cdev_mount_default(cdev); cdev_mount_default(cdev, NULL);
} }
} }

View File

@ -99,6 +99,7 @@ struct fs_device_d {
char *path; char *path;
struct device_d *parent_device; struct device_d *parent_device;
struct list_head list; struct list_head list;
char *options;
}; };
#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv) #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 symlink(const char *pathname, const char *newpath);
int readlink(const char *path, char *buf, size_t bufsiz); 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); int umount(const char *pathname);
/* not-so-standard functions */ /* 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); int fsdev_open_cdev(struct fs_device_d *fsdev);
const char *cdev_get_mount_path(struct cdev *cdev); 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); void mount_all(void);
#endif /* __FS_H */ #endif /* __FS_H */

View File

@ -20,7 +20,7 @@ void* bootstrap_read_disk(char *dev, char *fstype)
int len; int len;
char *path = "/"; char *path = "/";
ret = mount(dev, fstype, path); ret = mount(dev, fstype, path, NULL);
if (ret) { if (ret) {
bootstrap_err("mounting %s failed with %d\n", dev, ret); bootstrap_err("mounting %s failed with %d\n", dev, ret);
return NULL; return NULL;