From 29df764e189c26bc285053e385b91a367fd68710 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Tue, 4 Jul 2023 07:41:48 +0000 Subject: [PATCH] add ioctl Signed-off-by: liuzerun --- fs/hmdfs/file_merge.c | 40 ++++++++++++++++++++++++++++++++++++++++ fs/hmdfs/hmdfs.h | 8 ++++++++ 2 files changed, 48 insertions(+) diff --git a/fs/hmdfs/file_merge.c b/fs/hmdfs/file_merge.c index 8048a203a8e6..962185a92995 100644 --- a/fs/hmdfs/file_merge.c +++ b/fs/hmdfs/file_merge.c @@ -582,11 +582,50 @@ static long hmdfs_ioc_get_writeopen_cnt(struct file *filp, unsigned long arg) return put_user(wo_cnt, (int __user *)arg); } +static long hmdfs_ioc_get_drag_path(struct file *filp, unsigned long arg) +{ + int error = 0; + char localPath[NAME_MAX]; + char cloudPath[NAME_MAX]; + struct dentry *dentry; + struct path path; + struct hmdfs_drag_info hdi; + + if (!access_ok((struct hmdfs_drag_info __user *)arg, + sizeof(struct hmdfs_drag_info))) + return -EFAULT; + + if (copy_from_user(&hdi, (struct hmdfs_drag_info __user *)arg, + sizeof(hdi))) + return -EFAULT; + + if (!access_ok((char *)hdi.localPath, hdi.localLen)) + return -EFAULT; + if (!access_ok((char *)hdi.cloudPath, hdi.cloudLen)) + return -EFAULT; + if (copy_from_user(localPath, (char __user *)hdi.localPath, + hdi.localLen)) + return -EFAULT; + if (copy_from_user(cloudPath, (char __user *)hdi.cloudPath, + hdi.cloudLen)) + return -EFAULT; + + dentry = kern_path_create(AT_FDCWD, cloudPath, &path, 0); + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + error = vfs_symlink(path.dentry->d_inode, dentry, localPath); + done_path_create(&path, dentry); + hmdfs_info("error: %d", error); + return error; +} + static long hmdfs_file_ioctl_merge(struct file *filp, unsigned int cmd, unsigned long arg) { switch (cmd) { case HMDFS_IOC_GET_WRITEOPEN_CNT: return hmdfs_ioc_get_writeopen_cnt(filp, arg); + case HMDFS_IOC_GET_DRAG_PATH: + return hmdfs_ioc_get_drag_path(filp, arg); default: return -ENOTTY; } @@ -606,6 +645,7 @@ const struct file_operations hmdfs_file_fops_merge = { .release = hmdfs_file_release_local, .fsync = hmdfs_fsync_local, .unlocked_ioctl = hmdfs_file_ioctl_merge, + .compat_ioctl = hmdfs_file_ioctl_merge, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, }; diff --git a/fs/hmdfs/hmdfs.h b/fs/hmdfs/hmdfs.h index 14adb4fac1b7..181ba0a39ab2 100644 --- a/fs/hmdfs/hmdfs.h +++ b/fs/hmdfs/hmdfs.h @@ -30,6 +30,7 @@ #define HMDFS_IOC 0xf2 #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct hmdfs_share_control) #define HMDFS_IOC_GET_WRITEOPEN_CNT _IOR(HMDFS_IOC, 2, __u32) +#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, __u32) #define HMDFS_PAGE_SIZE 4096 #define HMDFS_PAGE_OFFSET 12 @@ -222,6 +223,13 @@ static inline bool hmdfs_is_stash_enabled(const struct hmdfs_sb_info *sbi) return sbi->s_offline_stash; } +struct hmdfs_drag_info{ + uint64_t localLen; + uint64_t localPath; + uint64_t cloudLen; + uint64_t cloudPath; +}; + struct setattr_info { loff_t size; unsigned int valid; -- Gitee