* @brief Mount a filesystem. * * This function mounts a filesystem onto a specified directory. It allows for mounting various * types of filesystems, including but not limited to `ext4`, `nfs`, and `tmpfs`. The function * allows the specification of the source device, the target mount point, and additional parameters * such as filesystem type, mount flags, and extra data. * * @param[in] so
| 9785 | * location. Make sure the target directory is empty before mounting to avoid any conflicts. |
| 9786 | */ |
| 9787 | sysret_t sys_mount(char *source, char *target, char *filesystemtype, |
| 9788 | unsigned long mountflags, void *data) |
| 9789 | { |
| 9790 | char *kbuffer, *ksource, *ktarget, *kfs; |
| 9791 | size_t len_source, len_target, len_fs; |
| 9792 | char *tmp = NULL; |
| 9793 | int ret = 0; |
| 9794 | struct stat buf = {0}; |
| 9795 | char *dev_fullpath = RT_NULL; |
| 9796 | |
| 9797 | len_source = source ? lwp_user_strlen(source) : 0; |
| 9798 | if (len_source < 0) |
| 9799 | return -EINVAL; |
| 9800 | |
| 9801 | len_target = target ? lwp_user_strlen(target) : 0; |
| 9802 | if (len_target <= 0) |
| 9803 | return -EINVAL; |
| 9804 | |
| 9805 | len_fs = filesystemtype ? lwp_user_strlen(filesystemtype) : 0; |
| 9806 | if (len_fs < 0) |
| 9807 | return -EINVAL; |
| 9808 | |
| 9809 | kbuffer = (char *)rt_malloc(len_source + 1 + len_target + 1 + len_fs + 1); |
| 9810 | if (!kbuffer) |
| 9811 | { |
| 9812 | return -ENOMEM; |
| 9813 | } |
| 9814 | |
| 9815 | /* get parameters from user space */ |
| 9816 | ksource = kbuffer; |
| 9817 | ktarget = ksource + len_source + 1; |
| 9818 | kfs = ktarget + len_target + 1; |
| 9819 | ksource = _cp_from_usr_string(ksource, source, len_source); |
| 9820 | ktarget = _cp_from_usr_string(ktarget, target, len_target); |
| 9821 | kfs = _cp_from_usr_string(kfs, filesystemtype, len_fs); |
| 9822 | |
| 9823 | if (mountflags & MS_REMOUNT) |
| 9824 | { |
| 9825 | ret = dfs_remount(ktarget, mountflags, data); |
| 9826 | } |
| 9827 | else |
| 9828 | { |
| 9829 | if (strcmp(kfs, "nfs") == 0) |
| 9830 | { |
| 9831 | tmp = ksource; |
| 9832 | ksource = NULL; |
| 9833 | } |
| 9834 | if (strcmp(kfs, "tmp") == 0) |
| 9835 | { |
| 9836 | ksource = NULL; |
| 9837 | } |
| 9838 | |
| 9839 | if (ksource && !dfs_file_stat(ksource, &buf) && S_ISBLK(buf.st_mode)) |
| 9840 | { |
| 9841 | dev_fullpath = dfs_normalize_path(RT_NULL, ksource); |
| 9842 | RT_ASSERT(rt_strncmp(dev_fullpath, "/dev/", sizeof("/dev/") - 1) == 0); |
| 9843 | ret = dfs_mount(dev_fullpath + sizeof("/dev/") - 1, ktarget, kfs, 0, tmp); |
| 9844 | } |
nothing calls this directly
no test coverage detected