1

I have this doubt: ¿Wich are the differences between: open a file and access a file?

I'm working with fanotify, and I'm only interested on FAN_ACCESS events. I start my program and when I try to edit some file, the program does what it has to do.

Said that, I have wrote some tests, and some of test cases uses code like this:

filesystem::ofstream acces_to_file;
acces_to_file.open('/tmp/test_file.txt');
acces_to_file <<  "Some text" << endl;
acces_to_file.close();

but surprisingly, this access is no detected by my program. I access the same file from nano (even without restart the so mentioned program) and all works again.

Thats why I think it has to be some difference between access and open a file.

The program is always executed by root user.

I set the flags as following:

fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS | FAN_EVENT_ON_CHILD, AT_FDCWD, MONITOR_ROOT_PATH);
Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60

2 Answers2

1

In general, opening a file tells the OS you want to operate with the file.

In general, file access is how you operate with the file: read only, write only, read & write. Some access permission also include sequential or random.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
  • So when I'm writing to a file, I'm accessing an already opened file? It's that what you mean? Of course that's what you mean, What i'm thinking?? ;p – Raydel Miranda Nov 25 '13 at 22:03
  • And [this](http://www.xypron.de/projects/fanotify-manpages/man2/fanotify_mark.2.html) says that `FAN_ACCESS` means the file was read from (which your example doesn't do) – nos Nov 25 '13 at 23:09
-1

What exactly are you asking? If you are asking about being able to Access the text file which you want to write to, where are you storing the text file? If you are storing the text file in a location that is read only, then writing to the text file will fail. It may still open the file and close it, but no writing will take place. For example, if your text file is located in the program file of your PC, you only have Read Access to items stored there. If you want Read/Write access to the file, store it in C:\Users\Default\AppData