Reading a symbolic link in kernel-space
Asked Answered
A

1

9

I'm writing a LKM and need to find out where a specific symlink is pointing to. Basically I need the functionality of the syscall readlinkat (or readlink) but in kernel-space. Is there an easy way to do this?

Using readlinkat directly is not working for me, I'm always getting EFAULT (I guess this is because my buffer is obviously in kernel memory space and not in user-space).

Amaranthine answered 9/11, 2014 at 16:3 Comment(2)
possible duplicate of allocate user-space memory from kernelBaggott
Possibly not a duplicate, but might be relevant.Baggott
P
4

Firstly, you can't use user space system calls(readlinkat() or readlink()) directly in your kernel module. Rather you need to use exported function / symbol within the kernel space.

Next, may want to look into the struct inode_operations specific to the file system which you are using. Also look into generic_readlink() which internally call vfs_readlink().

Plutonium answered 9/11, 2014 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.