2个版本

0.0.2 2022年5月28日
0.0.1 2022年5月28日

#815 in Unix API

MIT/Apache

11KB
182

本基于https://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#appendix_tag_reference。请提交pull request以补充缺失的标签。

要开始使用此crate,创建一个带有给定内存位置的Atags结构。使用iter()方法将返回一个迭代器,该迭代器返回Atag条目。

use atags::{Atag, Atags};

let mut buffer = [
    // Core tag
    0x00, 0x00, 0x00, 0x05, // size
    0x54, 0x41, 0x00, 0x01, // tag
    0x00, 0x00, 0x00, 0x01, //  flags
    0x00, 0x00, 0x10, 0x00, //  page_size
    0x12, 0x34, 0x56, 0x78, //  root_device_number

    // Empty tag
    0x0, 0x0, 0x0, 0x0, // size
    0x0, 0x0, 0x0, 0x0, // tag
];
let ptr = core::ptr::NonNull::new(buffer.as_mut_ptr()).unwrap();
let tags = unsafe { Atags::new(ptr.cast()) };

for tag in tags.iter() {
    // first tag is a core tag
    match tag {
        Atag::Core(core) => {
            assert_eq!(core.flags, 1);
            assert_eq!(core.page_size, 0x1000);
            assert_eq!(core.root_device_number, 0x12345678);
        },
        // Do something with the other tags
        // In this example we only get 1 core tag and nothing else
        _ => panic!("Unknown tag {:?}", tag),
    }
}

功能

nightly

将在此crate中启用nightly strict_provenance功能。

依赖关系

~1.5MB
~37K SLoC