From 7c74a49c6bfb90b137e00b2105be310f755a31a8 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Sun, 2 Jul 2023 09:14:31 +0000 Subject: [PATCH] add ioctl hmdfs_get_drag_path Signed-off-by: liuzerun Change-Id: Ia53abfbdb3277d0a982a5a7567aa856f3bdbcea5 --- fs/hmdfs/file_merge.c | 64 ++++++++++++++++++++++++++++++++++++++++++ fs/hmdfs/hmdfs.h | 8 ++++++ fs/hmdfs/inode_local.c | 1 + 3 files changed, 73 insertions(+) diff --git a/fs/hmdfs/file_merge.c b/fs/hmdfs/file_merge.c index 8048a203a8e6..ed805645f574 100644 --- a/fs/hmdfs/file_merge.c +++ b/fs/hmdfs/file_merge.c @@ -8,6 +8,7 @@ #include "hmdfs_merge_view.h" #include +#include #include "hmdfs.h" #include "hmdfs_trace.h" @@ -582,12 +583,74 @@ 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))) { + hmdfs_info("hmdfs_ioc_get_drag_path: struct is not OK, error: -EFAULT"); + return -EFAULT; + } + + if (copy_from_user(&hdi, (struct hmdfs_drag_info __user *)arg, + sizeof(hdi))) { + hmdfs_info("hmdfs_ioc_get_drag_path: copy_from_user failed, error: -EFAULT"); + return -EFAULT; + } + + hmdfs_info("localLen: %llu", hdi.localLen); + hmdfs_info("localLen: %llx", hdi.localPath); + hmdfs_info("localLen: %llu", hdi.cloudLen); + hmdfs_info("localLen: %llx", hdi.cloudPath); + + if (!access_ok((char *)hdi.localPath, hdi.localLen)) { + hmdfs_info("hmdfs_ioc_get_drag_path: localPath is not OK, error: -EFAULT"); + return -EFAULT; + } + if (!access_ok((char *)hdi.cloudPath, hdi.cloudLen)) { + hmdfs_info("hmdfs_ioc_get_drag_path: cloudPath is not OK, error: -EFAULT"); + return -EFAULT; + } + if (copy_from_user(localPath, (char __user *)hdi.localPath, + hdi.localLen)) { + hmdfs_info("hmdfs_ioc_get_drag_path: localPath failed, error: -EFAULT"); + return -EFAULT; + } + if (copy_from_user(cloudPath, (char __user *)hdi.cloudPath, + hdi.cloudLen)) { + hmdfs_info("hmdfs_ioc_get_drag_path: cloudPath failed, error: -EFAULT"); + return -EFAULT; + } + hmdfs_info("localPath: %s", localPath); + hmdfs_info("localPath: %s", cloudPath); + + dentry = kern_path_create(AT_FDCWD, cloudPath, &path, 0); + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + hmdfs_info("dentry finish"); + 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) { + hmdfs_info("hmdfs_file_ioctl_merge"); switch (cmd) { case HMDFS_IOC_GET_WRITEOPEN_CNT: return hmdfs_ioc_get_writeopen_cnt(filp, arg); + case HMDFS_IOC_GET_DRAG_PATH: + hmdfs_info("HMDFS_IOC_GET_WRITEOPEN_CNT"); + return hmdfs_ioc_get_drag_path(filp, arg); default: + hmdfs_info("Case does not hit! error:-%d", ENOTTY); return -ENOTTY; } } @@ -606,6 +669,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; diff --git a/fs/hmdfs/inode_local.c b/fs/hmdfs/inode_local.c index 5d26f6dbbd02..76f7a4bfe833 100644 --- a/fs/hmdfs/inode_local.c +++ b/fs/hmdfs/inode_local.c @@ -779,6 +779,7 @@ static int hmdfs_getattr_local(const struct path *path, struct kstat *stat, stat->gid = d_inode(path->dentry)->i_gid; hmdfs_put_lower_path(&lower_path); + hmdfs_info("hmdfs_getattr_local, ret: %d", ret); return ret; } -- Gitee