fuse_backend_rs/passthrough/
os_compat.rs

1// Copyright (C) 2020-2022 Alibaba Cloud. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE-BSD-3-Clause file.
4// SPDX-License-Identifier: Apache-2.0
5
6use vm_memory::ByteValued;
7
8#[repr(C, packed)]
9#[derive(Clone, Copy, Debug, Default)]
10pub struct LinuxDirent64 {
11    pub d_ino: libc::ino64_t,
12    pub d_off: libc::off64_t,
13    pub d_reclen: libc::c_ushort,
14    pub d_ty: libc::c_uchar,
15}
16unsafe impl ByteValued for LinuxDirent64 {}
17
18#[cfg(target_env = "gnu")]
19pub use libc::statx as statx_st;
20
21#[cfg(target_env = "gnu")]
22pub use libc::{STATX_BASIC_STATS, STATX_MNT_ID};
23
24// musl provides the 'struct statx', but without stx_mnt_id.
25// However, the libc crate does not provide libc::statx
26// if musl is used. So we add just the required struct and
27// constants to make it works.
28#[cfg(not(target_env = "gnu"))]
29#[repr(C)]
30pub struct statx_st_timestamp {
31    pub tv_sec: i64,
32    pub tv_nsec: u32,
33    pub __statx_timestamp_pad1: [i32; 1],
34}
35
36#[cfg(not(target_env = "gnu"))]
37#[repr(C)]
38pub struct statx_st {
39    pub stx_mask: u32,
40    pub stx_blksize: u32,
41    pub stx_attributes: u64,
42    pub stx_nlink: u32,
43    pub stx_uid: u32,
44    pub stx_gid: u32,
45    pub stx_mode: u16,
46    __statx_pad1: [u16; 1],
47    pub stx_ino: u64,
48    pub stx_size: u64,
49    pub stx_blocks: u64,
50    pub stx_attributes_mask: u64,
51    pub stx_atime: statx_st_timestamp,
52    pub stx_btime: statx_st_timestamp,
53    pub stx_ctime: statx_st_timestamp,
54    pub stx_mtime: statx_st_timestamp,
55    pub stx_rdev_major: u32,
56    pub stx_rdev_minor: u32,
57    pub stx_dev_major: u32,
58    pub stx_dev_minor: u32,
59    pub stx_mnt_id: u64,
60    __statx_pad2: u64,
61    __statx_pad3: [u64; 12],
62}
63
64#[cfg(not(target_env = "gnu"))]
65pub const STATX_BASIC_STATS: libc::c_uint = 0x07ff;
66
67#[cfg(not(target_env = "gnu"))]
68pub const STATX_MNT_ID: libc::c_uint = 0x1000;