mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
2
user/apps/test_statx/.gitignore
vendored
Normal file
2
user/apps/test_statx/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
Cargo.lock
|
||||
/target
|
8
user/apps/test_statx/Cargo.toml
Normal file
8
user/apps/test_statx/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "test_statx"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.153"
|
||||
sc = "0.2.7"
|
56
user/apps/test_statx/Makefile
Normal file
56
user/apps/test_statx/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu"
|
||||
# RUSTFLAGS+="-C target-feature=+crt-static -C link-arg=-no-pie"
|
||||
|
||||
ifdef DADK_CURRENT_BUILD_DIR
|
||||
# 如果是在dadk中编译,那么安装到dadk的安装目录中
|
||||
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
|
||||
else
|
||||
# 如果是在本地编译,那么安装到当前目录下的install目录中
|
||||
INSTALL_DIR = ./install
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
export RUST_TARGET=riscv64gc-unknown-linux-gnu
|
||||
else
|
||||
# 默认为x86_86,用于本地编译
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
endif
|
||||
|
||||
run:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET)
|
||||
|
||||
build:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
|
||||
|
||||
clean:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET)
|
||||
|
||||
test:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET)
|
||||
|
||||
doc:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc --target $(RUST_TARGET)
|
||||
|
||||
fmt:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
|
||||
|
||||
fmt-check:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check
|
||||
|
||||
run-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --release
|
||||
|
||||
build-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release
|
||||
|
||||
clean-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release
|
||||
|
||||
test-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET) --release
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force
|
63
user/apps/test_statx/src/main.rs
Normal file
63
user/apps/test_statx/src/main.rs
Normal file
@ -0,0 +1,63 @@
|
||||
use libc::syscall;
|
||||
use libc::AT_FDCWD;
|
||||
use std::ffi::CString;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct Statx {
|
||||
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: StatxTimestamp,
|
||||
pub stx_btime: StatxTimestamp,
|
||||
pub stx_ctime: StatxTimestamp,
|
||||
pub stx_mtime: StatxTimestamp,
|
||||
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,
|
||||
pub stx_dio_mem_align: u32,
|
||||
pub stx_dio_offset_align: u32,
|
||||
__statx_pad3: [u64; 12],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct StatxTimestamp {
|
||||
pub tv_sec: i64,
|
||||
pub tv_nsec: u32,
|
||||
pub __statx_timestamp_pad1: [i32; 1],
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let path = CString::new("/bin/about.elf").expect("Failed to create CString");
|
||||
let mut statxbuf: Statx = unsafe { std::mem::zeroed() };
|
||||
let x = sc::nr::STATX as i64;
|
||||
|
||||
let result = unsafe {
|
||||
syscall(
|
||||
x,
|
||||
AT_FDCWD,
|
||||
path.as_ptr(),
|
||||
libc::AT_SYMLINK_NOFOLLOW,
|
||||
0x7ff,
|
||||
&mut statxbuf,
|
||||
)
|
||||
};
|
||||
|
||||
if result != -1 {
|
||||
println!("statx succeeded: {:?}", statxbuf);
|
||||
} else {
|
||||
eprintln!("statx failed");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user