Question

I want to delete a file or folder by implementing my own system call such that after giving command 'ls -a' it must not be visible to me.

So basically I want to hide a file from commands like 'ls'or 'ls -a'. And then unhide it from the same.

It means I don't want it to completely delete it. Just hide it from user.

I am thinking it has to do some thing with

struct file_operations *f_op;

From where we can actually hide the file by manipulating 'readdir()'.

But I don't know how to manipulate it.

Any help?

P.S:- Linux Kernel version 3.5.x x86 64bit. I am doing changes in /linux/fs/namei.c

Was it helpful?

Solution

There is no way to do this - and even if there is, you shouldn't.

Instead, if you want to be able to "undelete" a file, you should have a folder somewhere on the file system (eg, ".Trash"), and instead of deleting the file using unlink or the like, just move the file into the trash directory. On "undelete", just move the file back. On "empty trash" or whatever, actually unlink the file from the hard drive.

This will have the effect of "hiding" the file from commands like ls -a because the file no longer exists in that folder; it's been moved to some Trash folder or Recycling Bin somewhere else on the hard drive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top