1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (C) 2020-2022 Alibaba Cloud. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
// SPDX-License-Identifier: Apache-2.0

use vm_memory::ByteValued;

#[repr(C, packed)]
#[derive(Clone, Copy, Debug, Default)]
pub struct LinuxDirent64 {
    pub d_ino: libc::ino64_t,
    pub d_off: libc::off64_t,
    pub d_reclen: libc::c_ushort,
    pub d_ty: libc::c_uchar,
}
unsafe impl ByteValued for LinuxDirent64 {}

#[cfg(target_env = "gnu")]
pub use libc::statx as statx_st;

#[cfg(target_env = "gnu")]
pub use libc::{STATX_BASIC_STATS, STATX_MNT_ID};

// musl provides the 'struct statx', but without stx_mnt_id.
// However, the libc crate does not provide libc::statx
// if musl is used. So we add just the required struct and
// constants to make it works.
#[cfg(not(target_env = "gnu"))]
#[repr(C)]
pub struct statx_st_timestamp {
    pub tv_sec: i64,
    pub tv_nsec: u32,
    pub __statx_timestamp_pad1: [i32; 1],
}

#[cfg(not(target_env = "gnu"))]
#[repr(C)]
pub struct statx_st {
    pub stx_mask: u32,
    pub stx_blksize: u32,
    pub stx_attributes: u64,
    pub stx_nlink: u32,
    pub stx_uid: u32,
    pub stx_gid: u32,
    pub stx_mode: u16,
    __statx_pad1: [u16; 1],
    pub stx_ino: u64,
    pub stx_size: u64,
    pub stx_blocks: u64,
    pub stx_attributes_mask: u64,
    pub stx_atime: statx_st_timestamp,
    pub stx_btime: statx_st_timestamp,
    pub stx_ctime: statx_st_timestamp,
    pub stx_mtime: statx_st_timestamp,
    pub stx_rdev_major: u32,
    pub stx_rdev_minor: u32,
    pub stx_dev_major: u32,
    pub stx_dev_minor: u32,
    pub stx_mnt_id: u64,
    __statx_pad2: u64,
    __statx_pad3: [u64; 12],
}

#[cfg(not(target_env = "gnu"))]
pub const STATX_BASIC_STATS: libc::c_uint = 0x07ff;

#[cfg(not(target_env = "gnu"))]
pub const STATX_MNT_ID: libc::c_uint = 0x1000;