Skip to content

android: use proper types for dirent.d_ino, dirent.d_off, stat.st_mode and stat64.st_mode #4216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/unix/linux_like/android/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::prelude::*;

pub type c_long = i32;
pub type c_ulong = u32;
pub type mode_t = u16;
pub type mode_t = c_ushort;
pub type ino_t = u64;
pub type off_t = i32;
pub type off64_t = c_longlong;
pub type sigset_t = c_ulong;
pub type socklen_t = i32;
Expand All @@ -30,7 +32,7 @@ s! {
pub st_dev: c_ulonglong,
__pad0: [c_uchar; 4],
__st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in fact an unsigned int and not a mode_t.

Note that stat and stat64 are actually the same on Android.

pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand All @@ -52,7 +54,7 @@ s! {
pub st_dev: c_ulonglong,
__pad0: [c_uchar; 4],
__st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be unsigned int, not mode_t.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this mode_t to allow code using rust libc to just use the time mode_t to store the type like on other *nix platforms instead of having to deal with Android in other way.

pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand Down
4 changes: 2 additions & 2 deletions src/unix/linux_like/android/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ s! {
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand All @@ -32,7 +32,7 @@ s! {
pub struct stat64 {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/android/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::prelude::*;
pub type c_long = i64;
pub type c_ulong = u64;
pub type mode_t = u32;
pub type ino_t = c_ulong;
pub type off_t = i64;
pub type off64_t = i64;
pub type socklen_t = u32;

Expand Down
4 changes: 2 additions & 2 deletions src/unix/linux_like/android/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ s! {
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_nlink: c_uint,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand All @@ -33,7 +33,7 @@ s! {
pub struct stat64 {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_nlink: c_uint,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
Expand Down
4 changes: 2 additions & 2 deletions src/unix/linux_like/android/b64/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ s! {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_nlink: c_ulong,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
Expand All @@ -31,7 +31,7 @@ s! {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_nlink: c_ulong,
pub st_mode: c_uint,
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
Expand Down
10 changes: 4 additions & 6 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::prelude::*;
pub type clock_t = c_long;
pub type time_t = c_long;
pub type suseconds_t = c_long;
pub type off_t = c_long;
pub type blkcnt_t = c_ulong;
pub type blksize_t = c_ulong;
pub type nlink_t = u32;
Expand All @@ -21,7 +20,6 @@ pub type fsblkcnt_t = c_ulong;
pub type nfds_t = c_uint;
pub type rlim_t = c_ulong;
pub type dev_t = c_ulong;
pub type ino_t = c_ulong;
pub type ino64_t = u64;
pub type __CPU_BITTYPE = c_ulong;
pub type idtype_t = c_int;
Expand Down Expand Up @@ -528,16 +526,16 @@ s_no_extra_traits! {
}

pub struct dirent {
pub d_ino: u64,
pub d_off: i64,
pub d_ino: crate::ino_t,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, ino_t is only used when LP64 is enabled (int is 32-bit, long int is 64-bit, pointers are 64-bit).

In all other cases (mostly 32-bit CPUs), this is an explicit u64, not an ino_t.

We could split dirent by architecture if we really wanted to use ino_t here, but on LP64 platforms, ino_t happens to be u64 which is why this was working.

pub d_off: crate::off_t,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This either needs to remain unmodified or become off64_t - it is unconditionally 64-bits on android

pub d_reclen: c_ushort,
pub d_type: c_uchar,
pub d_name: [c_char; 256],
}

pub struct dirent64 {
pub d_ino: u64,
pub d_off: i64,
pub d_ino: crate::ino64_t,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies here - dirent64 and dirent are the same struct on Android.

pub d_off: crate::off_t,
pub d_reclen: c_ushort,
pub d_type: c_uchar,
pub d_name: [c_char; 256],
Expand Down
Loading