|
@@ -5743,79 +5743,94 @@ sysret_t sys_fstatfs64(int fd, size_t sz, struct statfs *buf)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-sysret_t sys_mount(char *source, char *target,
|
|
|
- char *filesystemtype,
|
|
|
- unsigned long mountflags, void *data)
|
|
|
-{
|
|
|
- char *copy_source;
|
|
|
- char *copy_target;
|
|
|
- char *copy_filesystemtype;
|
|
|
- size_t len_source, copy_len_source;
|
|
|
- size_t len_target, copy_len_target;
|
|
|
- size_t len_filesystemtype, copy_len_filesystemtype;
|
|
|
+static char *_cp_from_usr_string(char *dst, char *src, size_t length)
|
|
|
+{
|
|
|
+ char *rc;
|
|
|
+ size_t copied_bytes;
|
|
|
+ if (length)
|
|
|
+ {
|
|
|
+ copied_bytes = lwp_get_from_user(dst, src, length);
|
|
|
+ dst[copied_bytes] = '\0';
|
|
|
+ rc = dst;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rc = RT_NULL;
|
|
|
+ }
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+sysret_t sys_mount(char *source, char *target, char *filesystemtype,
|
|
|
+ unsigned long mountflags, void *data)
|
|
|
+{
|
|
|
+ char *kbuffer, *ksource, *ktarget, *kfs;
|
|
|
+ size_t len_source, len_target, len_fs;
|
|
|
char *tmp = NULL;
|
|
|
int ret = 0;
|
|
|
struct stat buf = {0};
|
|
|
+ char *dev_fullpath = RT_NULL;
|
|
|
|
|
|
- len_source = lwp_user_strlen(source);
|
|
|
- if (len_source <= 0)
|
|
|
+ len_source = source ? lwp_user_strlen(source) : 0;
|
|
|
+ if (len_source < 0)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- len_target = lwp_user_strlen(target);
|
|
|
+ len_target = target ? lwp_user_strlen(target) : 0;
|
|
|
if (len_target <= 0)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- len_filesystemtype = lwp_user_strlen(filesystemtype);
|
|
|
- if (len_filesystemtype <= 0)
|
|
|
+ len_fs = filesystemtype ? lwp_user_strlen(filesystemtype) : 0;
|
|
|
+ if (len_fs < 0)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- copy_source = (char*)rt_malloc(len_source + 1 + len_target + 1 + len_filesystemtype + 1);
|
|
|
- if (!copy_source)
|
|
|
+ kbuffer = (char *)rt_malloc(len_source + 1 + len_target + 1 + len_fs + 1);
|
|
|
+ if (!kbuffer)
|
|
|
{
|
|
|
return -ENOMEM;
|
|
|
}
|
|
|
- copy_target = copy_source + len_source + 1;
|
|
|
- copy_filesystemtype = copy_target + len_target + 1;
|
|
|
|
|
|
- copy_len_source = lwp_get_from_user(copy_source, source, len_source);
|
|
|
- copy_source[copy_len_source] = '\0';
|
|
|
- copy_len_target = lwp_get_from_user(copy_target, target, len_target);
|
|
|
- copy_target[copy_len_target] = '\0';
|
|
|
- copy_len_filesystemtype = lwp_get_from_user(copy_filesystemtype, filesystemtype, len_filesystemtype);
|
|
|
- copy_filesystemtype[copy_len_filesystemtype] = '\0';
|
|
|
+ /* get parameters from user space */
|
|
|
+ ksource = kbuffer;
|
|
|
+ ktarget = ksource + len_source + 1;
|
|
|
+ kfs = ktarget + len_target + 1;
|
|
|
+ ksource = _cp_from_usr_string(ksource, source, len_source);
|
|
|
+ ktarget = _cp_from_usr_string(ktarget, target, len_target);
|
|
|
+ kfs = _cp_from_usr_string(kfs, filesystemtype, len_fs);
|
|
|
|
|
|
- if (strcmp(copy_filesystemtype, "nfs") == 0)
|
|
|
+ if (mountflags & MS_REMOUNT)
|
|
|
{
|
|
|
- tmp = copy_source;
|
|
|
- copy_source = NULL;
|
|
|
+ ret = dfs_remount(ktarget, mountflags, data);
|
|
|
}
|
|
|
- if (strcmp(copy_filesystemtype, "tmp") == 0)
|
|
|
+ else
|
|
|
{
|
|
|
- copy_source = NULL;
|
|
|
- }
|
|
|
+ if (strcmp(kfs, "nfs") == 0)
|
|
|
+ {
|
|
|
+ tmp = ksource;
|
|
|
+ ksource = NULL;
|
|
|
+ }
|
|
|
+ if (strcmp(kfs, "tmp") == 0)
|
|
|
+ {
|
|
|
+ ksource = NULL;
|
|
|
+ }
|
|
|
|
|
|
- if (copy_source && stat(copy_source, &buf) && S_ISBLK(buf.st_mode))
|
|
|
- {
|
|
|
- char *dev_fullpath = dfs_normalize_path(RT_NULL, copy_source);
|
|
|
- RT_ASSERT(rt_strncmp(dev_fullpath, "/dev/", sizeof("/dev/") - 1) == 0);
|
|
|
- ret = dfs_mount(dev_fullpath + sizeof("/dev/") - 1, copy_target, copy_filesystemtype, 0, tmp);
|
|
|
- if (ret < 0)
|
|
|
+ if (ksource && !dfs_file_stat(ksource, &buf) && S_ISBLK(buf.st_mode))
|
|
|
{
|
|
|
- ret = -rt_get_errno();
|
|
|
+ dev_fullpath = dfs_normalize_path(RT_NULL, ksource);
|
|
|
+ RT_ASSERT(rt_strncmp(dev_fullpath, "/dev/", sizeof("/dev/") - 1) == 0);
|
|
|
+ ret = dfs_mount(dev_fullpath + sizeof("/dev/") - 1, ktarget, kfs, 0, tmp);
|
|
|
}
|
|
|
- rt_free(copy_source);
|
|
|
- rt_free(dev_fullpath);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ret = dfs_mount(copy_source, copy_target, copy_filesystemtype, 0, tmp);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = dfs_mount(ksource, ktarget, kfs, 0, tmp);
|
|
|
+ }
|
|
|
+
|
|
|
if (ret < 0)
|
|
|
{
|
|
|
ret = -rt_get_errno();
|
|
|
}
|
|
|
- rt_free(copy_source);
|
|
|
}
|
|
|
|
|
|
+ rt_free(kbuffer);
|
|
|
+ rt_free(dev_fullpath);
|
|
|
return ret;
|
|
|
}
|
|
|
|