0

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

suraj_fale
  • 978
  • 2
  • 21
  • 53

1 Answers1

2

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.

cegfault
  • 6,442
  • 3
  • 27
  • 49
  • Thank you for you answer. Could you tell me then what is this : I mean is this on same path? http://www.codeproject.com/Articles/444995/Driver-to-hide-files-in-Linux-OS# – suraj_fale Oct 27 '12 at 07:11
  • 3
    @SRJ - me pisses myself laughing. As soon as I saw a link to CodeProject I suspected who the article's author would be. I was not incorrect. Have a look at their other system-programming articles - all they ever seem to publish are hacky/back-door methods for effing-with things that the os should maintain exclusive rights to. For reference: http://www.codeproject.com/Articles/Apriorit-Inc#articles – enhzflep Oct 27 '12 at 07:22
  • 2
    @SRJ: the article you linked to is, in my opinion, bad programming practice and should NEVER be used. It is, per se, a hack. It violates security principles and undermines good faith efforts of general computing. Please never implement such a program, nor pursue such programming tactics. – cegfault Oct 27 '12 at 07:38