@@ -240,27 +240,45 @@ pub const FANOTIFY_METADATA_VERSION: u8 = libc::FANOTIFY_METADATA_VERSION;
240
240
241
241
/// Abstract over [`libc::fanotify_event_info_fid`], which represents an
242
242
/// information record received via [`Fanotify::read_events_with_info_records`].
243
- // Is not Clone due to fd field, to avoid use-after-close scenarios.
244
243
#[ derive( Debug , Eq , Hash , PartialEq ) ]
245
244
#[ repr( transparent) ]
246
245
#[ allow( missing_copy_implementations) ]
247
- pub struct FanotifyFidRecord ( libc:: fanotify_event_info_fid ) ;
246
+ pub struct LibcFanotifyFidRecord ( libc:: fanotify_event_info_fid ) ;
247
+
248
+ /// Extends LibcFanotifyFidRecord to include file_handle bytes.
249
+ /// This allows Rust to move the record around in memory and not lose the file_handle
250
+ /// as the libc::fanotify_event_info_fid does not include any of the file_handle bytes.
251
+ // Is not Clone due to fd field, to avoid use-after-close scenarios.
252
+ #[ derive( Debug , Eq , Hash , PartialEq ) ]
253
+ #[ repr( C ) ]
254
+ #[ allow( missing_copy_implementations) ]
255
+ pub struct FanotifyFidRecord {
256
+ record : LibcFanotifyFidRecord ,
257
+ handle_bytes : * const u8 ,
258
+ }
248
259
249
260
impl FanotifyFidRecord {
250
261
/// The filesystem id where this event occurred. The value this method returns
251
262
/// differs depending on the host system. Please read the statfs(2) documentation
252
263
/// for more information:
253
264
/// <https://man7.org/linux/man-pages/man2/statfs.2.html#VERSIONS>
254
265
pub fn filesystem_id ( & self ) -> libc:: __kernel_fsid_t {
255
- self . 0 . fsid
266
+ self . record . 0 . fsid
256
267
}
257
268
258
269
/// The file handle for the filesystem object where the event occurred. The handle is
259
270
/// represented as a 0-length u8 array, but it actually points to variable-length
260
271
/// file_handle struct.For more information:
261
272
/// <https://man7.org/linux/man-pages/man2/open_by_handle_at.2.html>
262
- pub fn handle ( & self ) -> [ u8 ; 0 ] {
263
- self . 0 . handle
273
+ pub fn handle ( & self ) -> * const u8 {
274
+ self . handle_bytes
275
+ }
276
+
277
+ /// The specific info_type for this Fid Record. Fanotify can return an Fid Record
278
+ /// with many different possible info_types. The info_type is not always necessary
279
+ /// but can be useful for connecting similar events together (like a FAN_RENAME)
280
+ pub fn info_type ( & self ) -> u8 {
281
+ self . record . 0 . hdr . info_type
264
282
}
265
283
}
266
284
@@ -613,7 +631,18 @@ impl Fanotify {
613
631
& buffer,
614
632
current_event_offset,
615
633
) ;
616
- Some ( FanotifyInfoRecord :: Fid ( FanotifyFidRecord ( record) ) )
634
+
635
+ let record_ptr: * const libc:: fanotify_event_info_fid = unsafe {
636
+ buffer. as_ptr ( ) . add ( current_event_offset)
637
+ as * const libc:: fanotify_event_info_fid
638
+ } ;
639
+
640
+ let file_handle_ptr = unsafe { record_ptr. add ( 1 ) as * const u8 } ;
641
+
642
+ Some ( FanotifyInfoRecord :: Fid ( FanotifyFidRecord {
643
+ record : LibcFanotifyFidRecord ( record) ,
644
+ handle_bytes : file_handle_ptr,
645
+ } ) )
617
646
}
618
647
#[ cfg( target_env = "gnu" ) ]
619
648
libc:: FAN_EVENT_INFO_TYPE_ERROR => {
0 commit comments