Re: struct fanotify_event_metadata

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Paris
Date: Friday, August 20, 2010 - 8:19 am

On Fri, 2010-08-20 at 15:27 +0200, Andreas Schwab wrote:

Andreas suggested (I accidentally dropped the list when I ask him) I use
natural alignment and explicit padding rather than ((packed))

I'm open to the idea but I want to make it idiot proof (aka I won't
screw it up later)  My best offhand idea would be to do something like
so:

Expose this to userspace:
struct fanotify_event_metadata {
        __u32 event_len;
        __u32 vers;
        __s32 fd;
        __u64 mask;
        __s64 pid;
};

Wrap this in #ifdef KERNEL
struct fanotify_event_metadata_packed {
        __u32 event_len;
        __u32 vers;
        __s32 fd;
        __u64 mask;
        __s64 pid;
} __attribute__ ((packed));

Then add:
BUILD_BUG_ON(sizeof(struct fanotify_event_metadata) != 
             sizeof(struct fanotify_event_metadata_packed);

Is that a good way to make the actual object non-packed but keep myself
from ever letting it fail alignment and padding requirements?

-Eric

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
struct fanotify_event_metadata, Andreas Schwab, (Sat Aug 14, 10:44 am)
Re: struct fanotify_event_metadata, Tvrtko Ursulin, (Thu Aug 19, 8:44 am)
Re: struct fanotify_event_metadata, Andreas Gruenbacher, (Thu Aug 19, 9:07 am)
Re: struct fanotify_event_metadata, Tvrtko Ursulin, (Thu Aug 19, 9:35 am)
Re: struct fanotify_event_metadata, Eric Paris, (Thu Aug 19, 10:53 am)
Re: struct fanotify_event_metadata, Tvrtko Ursulin, (Fri Aug 20, 2:02 am)
Re: struct fanotify_event_metadata, Andreas Schwab, (Fri Aug 20, 2:16 am)
Re: struct fanotify_event_metadata, Tvrtko Ursulin, (Fri Aug 20, 2:23 am)
Re: struct fanotify_event_metadata, Eric Paris, (Fri Aug 20, 6:13 am)
Re: struct fanotify_event_metadata, Andreas Schwab, (Fri Aug 20, 6:27 am)
Re: struct fanotify_event_metadata, Eric Paris, (Fri Aug 20, 8:19 am)
Re: struct fanotify_event_metadata, Eric Paris, (Fri Aug 20, 10:47 am)