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:
parent
f43f827bb4
commit
f97f4b6571
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
19
fs/fs.c
19
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue