1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

fanotifyによる削除検出について調べてみた

Posted at

概要

  • 元々fanotify(ファイルシステムイベントの監視)で削除ができなかった。
  • Linux 5.1より削除が検出できるようになった。
  • 具体的な実装方法を探してみた。

結果

--- fanotify_example.c.org      2021-05-01 20:55:37.356846871 +0000
+++ fanotify_example.c  2021-05-01 20:57:37.118257631 +0000
@@ -40,7 +40,7 @@
     }

     int ret = fanotify_mark(fan,
-                            FAN_MARK_ADD,
+                            FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
                             FAN_CREATE | FAN_DELETE | FAN_MODIFY | FAN_EVENT_ON_CHILD,
                             AT_FDCWD,
                             argv[1]
  • rm /tmp/a/a.txtを実行したときの出力は以下となる。
$ gcc -Wall fanotify_example.c
$ sudo ./a.out /
FAN_DELETE/tmp/a
  • fanotify(7) - Linux manual page下部にfanotify_fid.cがあるが、FAN_REPORT_DFID_NAMEがLinux 5.9 以降でないと動かない。(現在最新ubuntu 21.04はLinux 5.8.0だったのでここまで)

fanotify(7)めも - φ(・・*)ゞ ウーン カーネルとか弄ったりのメモ
ファイルを監視して、将来どのプロセスがファイルを書き込みまたは削除するかを確認する方法 - Javaer101
fanotify(7) - Linux manual page

Man page of FANOTIFY_INIT

dmacvicar/fanotify_example: Example of fanotify API including the new FAN_DELETE in kernel 5.1

c ++-fanotify-カーネル5.1で導入された新しいフラグの問題-スタックオーバーフロー

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?