Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux kernel: how to remove a file in kernel space

I know this is strongly not recommended. But does is possible to do this in kernel space.

Given the file path, can we remove the corresponding file in kernel space?

like image 847
Van Yu Avatar asked Mar 05 '26 06:03

Van Yu


1 Answers

Maybe it's too late, I'll try to reply. As Tsyvarev said in his comment probably you are looking for the vfs_unlink function that you can find here namei.c. Before the implementation there is a description, but a simple example can be this one /* fcheck's prototype is in linux/fdtable.h and returns a file pointer given a given a file descriptor */

struct file *filp= fcheck(fd);
struct inode *parent_inode = filp->f_path.dentry->d_parent->d_inode;
inode_lock(parent_inode);
vfs_unlink(parent_inode, filp->f_path.dentry, NULL);    
inode_unlock(parent_inode);

I hope it's can be useful to someone.

like image 111
Federico A. Avatar answered Mar 06 '26 21:03

Federico A.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!