Skip to content

Commit 7a87f5c

Browse files
committed
kernel: compat: inline iterate_dir -> vfs_readdir compat
I'll just copy what I put in comments: this is backported on msm-3.10 though SO YEAH WE STILL USE IT IF ITS THERE !! (ref: Makefile) but we have to try to follow what upstream linux is, and it is only added on 3.11 need to inline struct dir_context since this doesnt exist pre-iterate_dir era! ref: torvalds/linux@5c0ba4e analysis: int kernel_iterate_dir(struct file *file, struct dir_context *ctx) -> res = readdir(file, ctx, ctx->actor); ++++ file, struct -> file, struct, struct->member int vfs_readdir(struct file *file, filldir_t filler, void *buf) -> res = readdir(file, buf, filler); file, ??, ?? +++ 1 3 2 Signed-off-by: backslashxx <[email protected]>
1 parent 3995985 commit 7a87f5c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

kernel/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ $(info -- KernelSU Manager signature hash: $(KSU_EXPECTED_HASH))
5656
ccflags-y += -DEXPECTED_SIZE=$(KSU_EXPECTED_SIZE)
5757
ccflags-y += -DEXPECTED_HASH=\"$(KSU_EXPECTED_HASH)\"
5858

59+
# UL, look for iterate_dir on ‎fs/readdir.c
60+
ifeq ($(shell grep -q "^int iterate_dir" $(srctree)/fs/readdir.c 2>/dev/null; echo $$?),0)
61+
$(info -- KernelSU/compat: iterate_dir found!)
62+
ccflags-y += -DKSU_HAS_ITERATE_DIR
63+
endif
64+
5965
# UL, look for read_iter on f_op struct
6066
ifeq ($(shell grep -q "read_iter" $(srctree)/include/linux/fs.h 2>/dev/null; echo $$?),0)
6167
$(info -- KernelSU/compat: f_op->read_iter found!)

kernel/kernel_compat.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ extern ssize_t ksu_kernel_write_compat(struct file *p, const void *buf,
2424

2525
extern int ksu_access_ok(const void *addr, unsigned long size);
2626

27+
// this is backported on msm-3.10 though SO YEAH WE STILL USE IT IF ITS THERE !! (ref: Makefile)
28+
// but we have to try to follow what upstream linux is, and it is only added on 3.11
29+
// need to inline struct dir_context since this doesnt exist pre-iterate_dir era!
30+
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) && !defined(KSU_HAS_ITERATE_DIR)
31+
struct dir_context {
32+
const filldir_t actor;
33+
loff_t pos;
34+
};
35+
36+
// ref: https://github.com/torvalds/linux/commit/5c0ba4e0762e6dabd14a5c276652e2defec38de7
37+
// analysis:
38+
// int kernel_iterate_dir(struct file *file, struct dir_context *ctx) -> res = readdir(file, ctx, ctx->actor); ++++ file, struct -> file, struct, struct->member
39+
// int vfs_readdir(struct file *file, filldir_t filler, void *buf) -> res = readdir(file, buf, filler); file, ??, ?? +++ 1 3 2
40+
static int iterate_dir(struct file *file, struct dir_context *ctx)
41+
{
42+
return vfs_readdir(file, ctx->actor, ctx);
43+
}
44+
#endif // CONFIG_KSU_HAS_ITERATE_DIR
45+
2746
#endif

0 commit comments

Comments
 (0)