Skip to content

Commit a1ad825

Browse files
committed
Auto merge of rust-lang#3408 - ad0:fanotify-new-constants, r=JohnTitor
feat: add new constants from fanotify linux api Since it's introduction in Linux and in this repo (rust-lang#1699), several new features have been introduced in the fanotify API. In the original fanotify API, only a limited set of events was supported. In particular, there was no support for create, delete, and move events. The support for those events was added in Linux 5.1. This PR adds missing constants from `fanotify.h` to support the newest features.
2 parents 2dcc239 + c7e481e commit a1ad825

File tree

6 files changed

+118
-17
lines changed

6 files changed

+118
-17
lines changed

libc-test/build.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -3739,8 +3739,6 @@ fn test_linux(target: &str) {
37393739

37403740
// kernel constants not available in uclibc 1.0.34
37413741
| "EXTPROC"
3742-
| "FAN_MARK_FILESYSTEM"
3743-
| "FAN_MARK_INODE"
37443742
| "IPPROTO_BEETPH"
37453743
| "IPPROTO_MPLS"
37463744
| "IPV6_HDRINCL"
@@ -3879,6 +3877,36 @@ fn test_linux(target: &str) {
38793877
// FIXME: Requires linux 6.1
38803878
"ALG_SET_KEY_BY_KEY_SERIAL" | "ALG_SET_DRBG_ENTROPY" => true,
38813879

3880+
// FIXME: Requires more recent kernel headers
3881+
| "FAN_FS_ERROR" // linux v5.16+
3882+
| "FAN_RENAME" // linux v5.17+
3883+
| "FAN_REPORT_TARGET_FID" // linux v5.17+
3884+
| "FAN_REPORT_DFID_NAME_TARGET" // linux v5.17+
3885+
| "FAN_MARK_EVICTABLE" // linux v5.19+
3886+
| "FAN_MARK_IGNORE" // linux v6.0+
3887+
| "FAN_MARK_IGNORE_SURV" // linux v6.0+
3888+
| "FAN_EVENT_INFO_TYPE_ERROR" // linux v5.16+
3889+
| "FAN_EVENT_INFO_TYPE_OLD_DFID_NAME" // linux v5.17+
3890+
| "FAN_EVENT_INFO_TYPE_NEW_DFID_NAME" // linux v5.17+
3891+
| "FAN_RESPONSE_INFO_NONE" // linux v5.16+
3892+
| "FAN_RESPONSE_INFO_AUDIT_RULE" // linux v5.16+
3893+
| "FAN_INFO" // linux v5.16+
3894+
=> true,
3895+
3896+
// FIXME: Requires linux 5.15+
3897+
"FAN_REPORT_PIDFD" if musl => true,
3898+
3899+
// FIXME: Requires linux 5.9+
3900+
| "FAN_REPORT_DIR_FID"
3901+
| "FAN_REPORT_NAME"
3902+
| "FAN_REPORT_DFID_NAME"
3903+
| "FAN_EVENT_INFO_TYPE_DFID_NAME"
3904+
| "FAN_EVENT_INFO_TYPE_DFID"
3905+
| "FAN_EVENT_INFO_TYPE_PIDFD"
3906+
| "FAN_NOPIDFD"
3907+
| "FAN_EPIDFD"
3908+
if musl => true,
3909+
38823910
_ => false,
38833911
}
38843912
});

libc-test/semver/linux.txt

+37
Original file line numberDiff line numberDiff line change
@@ -719,32 +719,69 @@ FANOTIFY_METADATA_VERSION
719719
FAN_ACCESS
720720
FAN_ACCESS_PERM
721721
FAN_ALLOW
722+
FAN_ATTRIB
723+
FAN_AUDIT
722724
FAN_CLASS_CONTENT
723725
FAN_CLASS_NOTIF
724726
FAN_CLASS_PRE_CONTENT
725727
FAN_CLOEXEC
726728
FAN_CLOSE
727729
FAN_CLOSE_NOWRITE
728730
FAN_CLOSE_WRITE
731+
FAN_CREATE
732+
FAN_DELETE
733+
FAN_DELETE_SELF
729734
FAN_DENY
735+
FAN_ENABLE_AUDIT
736+
FAN_EPIDFD
737+
FAN_EVENT_INFO_TYPE_DFID
738+
FAN_EVENT_INFO_TYPE_DFID_NAME
739+
FAN_EVENT_INFO_TYPE_ERROR
740+
FAN_EVENT_INFO_TYPE_FID
741+
FAN_EVENT_INFO_TYPE_NEW_DFID_NAME
742+
FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
743+
FAN_EVENT_INFO_TYPE_PIDFD
730744
FAN_EVENT_ON_CHILD
745+
FAN_FS_ERROR
746+
FAN_INFO
731747
FAN_MARK_ADD
732748
FAN_MARK_DONT_FOLLOW
749+
FAN_MARK_EVICTABLE
733750
FAN_MARK_FILESYSTEM
734751
FAN_MARK_FLUSH
752+
FAN_MARK_IGNORE
735753
FAN_MARK_IGNORED_MASK
736754
FAN_MARK_IGNORED_SURV_MODIFY
755+
FAN_MARK_IGNORE_SURV
737756
FAN_MARK_INODE
738757
FAN_MARK_MOUNT
739758
FAN_MARK_ONLYDIR
740759
FAN_MARK_REMOVE
741760
FAN_MODIFY
761+
FAN_MOVE
762+
FAN_MOVED_FROM
763+
FAN_MOVED_TO
764+
FAN_MOVE_SELF
742765
FAN_NOFD
743766
FAN_NONBLOCK
767+
FAN_NOPIDFD
744768
FAN_ONDIR
745769
FAN_OPEN
770+
FAN_OPEN_EXEC
771+
FAN_OPEN_EXEC_PERM
746772
FAN_OPEN_PERM
747773
FAN_Q_OVERFLOW
774+
FAN_RENAME
775+
FAN_REPORT_DFID_NAME
776+
FAN_REPORT_DFID_NAME_TARGET
777+
FAN_REPORT_DIR_FID
778+
FAN_REPORT_FID
779+
FAN_REPORT_NAME
780+
FAN_REPORT_PIDFD
781+
FAN_REPORT_TARGET_FID
782+
FAN_REPORT_TID
783+
FAN_RESPONSE_INFO_AUDIT_RULE
784+
FAN_RESPONSE_INFO_NONE
748785
FAN_UNLIMITED_MARKS
749786
FAN_UNLIMITED_QUEUE
750787
FF0

src/unix/linux_like/linux/gnu/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,6 @@ pub const SOCK_SEQPACKET: ::c_int = 5;
718718
pub const SOCK_DCCP: ::c_int = 6;
719719
pub const SOCK_PACKET: ::c_int = 10;
720720

721-
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
722-
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
723-
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
724-
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
725-
726721
pub const AF_IB: ::c_int = 27;
727722
pub const AF_MPLS: ::c_int = 28;
728723
pub const AF_NFC: ::c_int = 39;

src/unix/linux_like/linux/mod.rs

+51-2
Original file line numberDiff line numberDiff line change
@@ -3568,20 +3568,33 @@ pub const UINPUT_MAX_NAME_SIZE: usize = 80;
35683568
// uapi/linux/fanotify.h
35693569
pub const FAN_ACCESS: u64 = 0x0000_0001;
35703570
pub const FAN_MODIFY: u64 = 0x0000_0002;
3571+
pub const FAN_ATTRIB: u64 = 0x0000_0004;
35713572
pub const FAN_CLOSE_WRITE: u64 = 0x0000_0008;
35723573
pub const FAN_CLOSE_NOWRITE: u64 = 0x0000_0010;
35733574
pub const FAN_OPEN: u64 = 0x0000_0020;
3575+
pub const FAN_MOVED_FROM: u64 = 0x0000_0040;
3576+
pub const FAN_MOVED_TO: u64 = 0x0000_0080;
3577+
pub const FAN_CREATE: u64 = 0x0000_0100;
3578+
pub const FAN_DELETE: u64 = 0x0000_0200;
3579+
pub const FAN_DELETE_SELF: u64 = 0x0000_0400;
3580+
pub const FAN_MOVE_SELF: u64 = 0x0000_0800;
3581+
pub const FAN_OPEN_EXEC: u64 = 0x0000_1000;
35743582

35753583
pub const FAN_Q_OVERFLOW: u64 = 0x0000_4000;
3584+
pub const FAN_FS_ERROR: u64 = 0x0000_8000;
35763585

35773586
pub const FAN_OPEN_PERM: u64 = 0x0001_0000;
35783587
pub const FAN_ACCESS_PERM: u64 = 0x0002_0000;
3579-
3580-
pub const FAN_ONDIR: u64 = 0x4000_0000;
3588+
pub const FAN_OPEN_EXEC_PERM: u64 = 0x0004_0000;
35813589

35823590
pub const FAN_EVENT_ON_CHILD: u64 = 0x0800_0000;
35833591

3592+
pub const FAN_RENAME: u64 = 0x1000_0000;
3593+
3594+
pub const FAN_ONDIR: u64 = 0x4000_0000;
3595+
35843596
pub const FAN_CLOSE: u64 = FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE;
3597+
pub const FAN_MOVE: u64 = FAN_MOVED_FROM | FAN_MOVED_TO;
35853598

35863599
pub const FAN_CLOEXEC: ::c_uint = 0x0000_0001;
35873600
pub const FAN_NONBLOCK: ::c_uint = 0x0000_0002;
@@ -3592,6 +3605,18 @@ pub const FAN_CLASS_PRE_CONTENT: ::c_uint = 0x0000_0008;
35923605

35933606
pub const FAN_UNLIMITED_QUEUE: ::c_uint = 0x0000_0010;
35943607
pub const FAN_UNLIMITED_MARKS: ::c_uint = 0x0000_0020;
3608+
pub const FAN_ENABLE_AUDIT: ::c_uint = 0x0000_0040;
3609+
3610+
pub const FAN_REPORT_PIDFD: ::c_uint = 0x0000_0080;
3611+
pub const FAN_REPORT_TID: ::c_uint = 0x0000_0100;
3612+
pub const FAN_REPORT_FID: ::c_uint = 0x0000_0200;
3613+
pub const FAN_REPORT_DIR_FID: ::c_uint = 0x0000_0400;
3614+
pub const FAN_REPORT_NAME: ::c_uint = 0x0000_0800;
3615+
pub const FAN_REPORT_TARGET_FID: ::c_uint = 0x0000_1000;
3616+
3617+
pub const FAN_REPORT_DFID_NAME: ::c_uint = FAN_REPORT_DIR_FID | FAN_REPORT_NAME;
3618+
pub const FAN_REPORT_DFID_NAME_TARGET: ::c_uint =
3619+
FAN_REPORT_DFID_NAME | FAN_REPORT_FID | FAN_REPORT_TARGET_FID;
35953620

35963621
pub const FAN_MARK_ADD: ::c_uint = 0x0000_0001;
35973622
pub const FAN_MARK_REMOVE: ::c_uint = 0x0000_0002;
@@ -3600,13 +3625,37 @@ pub const FAN_MARK_ONLYDIR: ::c_uint = 0x0000_0008;
36003625
pub const FAN_MARK_IGNORED_MASK: ::c_uint = 0x0000_0020;
36013626
pub const FAN_MARK_IGNORED_SURV_MODIFY: ::c_uint = 0x0000_0040;
36023627
pub const FAN_MARK_FLUSH: ::c_uint = 0x0000_0080;
3628+
pub const FAN_MARK_EVICTABLE: ::c_uint = 0x0000_0200;
3629+
pub const FAN_MARK_IGNORE: ::c_uint = 0x0000_0100;
3630+
3631+
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
3632+
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
3633+
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
3634+
3635+
pub const FAN_MARK_IGNORE_SURV: ::c_uint = FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY;
36033636

36043637
pub const FANOTIFY_METADATA_VERSION: u8 = 3;
36053638

3639+
pub const FAN_EVENT_INFO_TYPE_FID: u8 = 1;
3640+
pub const FAN_EVENT_INFO_TYPE_DFID_NAME: u8 = 2;
3641+
pub const FAN_EVENT_INFO_TYPE_DFID: u8 = 3;
3642+
pub const FAN_EVENT_INFO_TYPE_PIDFD: u8 = 4;
3643+
pub const FAN_EVENT_INFO_TYPE_ERROR: u8 = 5;
3644+
3645+
pub const FAN_EVENT_INFO_TYPE_OLD_DFID_NAME: u8 = 10;
3646+
pub const FAN_EVENT_INFO_TYPE_NEW_DFID_NAME: u8 = 12;
3647+
3648+
pub const FAN_RESPONSE_INFO_NONE: u8 = 0;
3649+
pub const FAN_RESPONSE_INFO_AUDIT_RULE: u8 = 1;
3650+
36063651
pub const FAN_ALLOW: u32 = 0x01;
36073652
pub const FAN_DENY: u32 = 0x02;
3653+
pub const FAN_AUDIT: u32 = 0x10;
3654+
pub const FAN_INFO: u32 = 0x20;
36083655

36093656
pub const FAN_NOFD: ::c_int = -1;
3657+
pub const FAN_NOPIDFD: ::c_int = FAN_NOFD;
3658+
pub const FAN_EPIDFD: ::c_int = -2;
36103659

36113660
pub const FUTEX_WAIT: ::c_int = 0;
36123661
pub const FUTEX_WAKE: ::c_int = 1;

src/unix/linux_like/linux/musl/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,6 @@ pub const PTRACE_INTERRUPT: ::c_int = 0x4207;
592592
pub const PTRACE_LISTEN: ::c_int = 0x4208;
593593
pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209;
594594

595-
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
596-
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
597-
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
598-
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
599-
600595
pub const AF_IB: ::c_int = 27;
601596
pub const AF_MPLS: ::c_int = 28;
602597
pub const AF_NFC: ::c_int = 39;

src/unix/linux_like/linux/uclibc/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ pub const EDEADLOCK: ::c_int = EDEADLK;
246246
pub const EXTA: ::c_uint = B19200;
247247
pub const EXTB: ::c_uint = B38400;
248248
pub const EXTPROC: ::tcflag_t = 0200000;
249-
pub const FAN_MARK_FILESYSTEM: ::c_int = 0x00000100;
250-
pub const FAN_MARK_INODE: ::c_int = 0x00000000;
251-
pub const FAN_MARK_MOUNT: ::c_int = 0x10;
252249
pub const FOPEN_MAX: ::c_int = 16;
253250
pub const F_GETOWN: ::c_int = 9;
254251
pub const F_OFD_GETLK: ::c_int = 36;

0 commit comments

Comments
 (0)