0

I'm going to use struct solaris_x86_slice from linux kernel header in user space. Struct is defined as:

struct solaris_x86_slice {
    __le16 s_tag;       /* ID tag of partition */
    __le16 s_flag;      /* permission flags */
    __le32 s_start;     /* start sector no of partition */
    __le32 s_size;      /* # of blocks in partition */
};

Should I use as byte order fixed types these kernel space specific types __le16, __le32 (via <linux/types.h>) or is there anything user space specific which major libc implementations (glibc, uclibc, musl) implement?

I don't see any type in <endian.h>, there are only conversion functions, so I incline to use __le16, __le32 .

red0ct
  • 4,840
  • 3
  • 17
  • 44
pevik
  • 4,523
  • 3
  • 33
  • 44
  • 1
    There is nothing magic about the types. E.g. `__le16` is equivalent to `uint16_t`. The kernel uses the special types for type-checking by the "sparse" checker to make sure that conversions between host byte order data and endian-specific data have been accounted for by the developer. You can think of the types as documentation, and an indication that you should use the user-space functions from `` to convert the values to and from host byte order. – Ian Abbott Oct 08 '19 at 11:42
  • 1
    @IanAbbott: You should submit that as an answer. – caf Oct 08 '19 at 23:56
  • @IanAbbott would it really work the same on both little and big endian architectures? We've find quite a few bugs for s390 kernel, which is big endian (code is usually written for intel, which is little endian). – pevik Oct 09 '19 at 05:24
  • @pevik Bugs can be fixed, but it is up to the programmer to take big/little-endian differences into account. In user space, the functions in `` provide the facilities to allow the code to correct for endian differences, but it is up to the programmer to use them. – Ian Abbott Oct 09 '19 at 11:13

0 Answers0