inode_storage.php 613 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. $prog = <<<EOT
  3. #include <linux/fs.h>
  4. BPF_INODE_STORAGE(inode_storage_map, int);
  5. LSM_PROBE(inode_rename, struct inode *old_dir, struct dentry *old_dentry,
  6. struct inode *new_dir, struct dentry *new_dentry, unsigned int flags)
  7. {
  8. int *value;
  9. value = inode_storage_map.inode_storage_get(old_dentry->d_inode, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
  10. if (!value)
  11. return 0;
  12. bpf_trace_printk("%d", *value);
  13. return 0;
  14. }
  15. EOT;
  16. # load BPF program
  17. $ebpf = new Bpf(["text" => $prog]);
  18. # format output
  19. while (true) {
  20. try {
  21. $ebpf->trace_print();
  22. } catch (Exception $e) {
  23. continue;
  24. }
  25. }