Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

c - How to get the file's meta data in kernel space - linux 3.5

Given a file path, how can I get its meta data. Here is my problem: I have to truly hide a file (even with ls -a it should not show up anywhere) and I donot need to gaurentee that it will have the same state when it comes back. Now I though if can just copy the meta data and store it somewhere, only to write it back when I need to, It would solve my problem

  1. I have to create a copy of that meta data and store it in another place.
  2. I have to be able to copy back that meta data when ever I want it to.

So How can I get the meta-data of a file? If there is a better way to fully hide the file how can I?

This is a personal project and I wont have any code up-stream.

I am working in linux kernel 3.5.4v

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I thought about the question some more.

There are filesystem-specific ways to create the possibility of truly hidden files, of course, but I'm not at all interested in exploring those. However, there is a different approach, a variant, that might suit your needs.

You could achieve a similar effect by intercepting only the open syscall (extending the existing one, to be precise). If the opened file resolves to a nonexisting file, but the directory and the file name match, instead of failing you construct a special path to the "hidden" file, and open that instead.

The existing file would then be a perfectly normal file, just actually somewhere else. Of course, you can put it in a root-only accessible directory (drwx------ root:root), and omit the access security check when opening it, to make it "hidden".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...