mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 21:06:48 +00:00
Fix clippy warnings in kernel crate
This commit is contained in:
parent
81ba3b645b
commit
f0957d2f54
@ -50,7 +50,7 @@ pub struct CurrentUserSpace<'a>(Ref<'a, Option<Vmar<Full>>>);
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! current_userspace {
|
macro_rules! current_userspace {
|
||||||
() => {{
|
() => {{
|
||||||
use crate::context::CurrentUserSpace;
|
use $crate::context::CurrentUserSpace;
|
||||||
CurrentUserSpace::new(&ostd::task::Task::current().unwrap())
|
CurrentUserSpace::new(&ostd::task::Task::current().unwrap())
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@ impl<E: Events> EventsFilter<E> for () {
|
|||||||
|
|
||||||
impl<E: Events, F: EventsFilter<E>> EventsFilter<E> for Option<F> {
|
impl<E: Events, F: EventsFilter<E>> EventsFilter<E> for Option<F> {
|
||||||
fn filter(&self, events: &E) -> bool {
|
fn filter(&self, events: &E) -> bool {
|
||||||
self.as_ref().map_or(true, |f| f.filter(events))
|
self.as_ref().is_none_or(|f| f.filter(events))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,9 @@ impl DeviceId {
|
|||||||
let major = major as u64;
|
let major = major as u64;
|
||||||
let minor = minor as u64;
|
let minor = minor as u64;
|
||||||
Self(
|
Self(
|
||||||
(major & 0xffff_f000) << 32
|
((major & 0xffff_f000) << 32)
|
||||||
| (major & 0x0000_0fff) << 8
|
| ((major & 0x0000_0fff) << 8)
|
||||||
| (minor & 0xffff_ff00) << 12
|
| ((minor & 0xffff_ff00) << 12)
|
||||||
| (minor & 0x0000_00ff),
|
| (minor & 0x0000_00ff),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ impl Iterator for ReadySetPopIter<'_> {
|
|||||||
let weak_entry = entries.pop_front().unwrap();
|
let weak_entry = entries.pop_front().unwrap();
|
||||||
|
|
||||||
// Clear the epoll file's events if there are no ready entries.
|
// Clear the epoll file's events if there are no ready entries.
|
||||||
if entries.len() == 0 {
|
if entries.is_empty() {
|
||||||
self.ready_set.pollee.invalidate();
|
self.ready_set.pollee.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,8 @@ impl TryFrom<RawExfatDentry> for ExfatDentry {
|
|||||||
type Error = crate::error::Error;
|
type Error = crate::error::Error;
|
||||||
fn try_from(dentry: RawExfatDentry) -> Result<Self> {
|
fn try_from(dentry: RawExfatDentry) -> Result<Self> {
|
||||||
let dentry_bytes = dentry.as_bytes();
|
let dentry_bytes = dentry.as_bytes();
|
||||||
|
#[expect(clippy::match_overlapping_arm)]
|
||||||
|
// FIXME: `EXFAT_STREAM` and `0xC0..=0xFF` overlap. Is the overlapping case expected?
|
||||||
match dentry.dentry_type {
|
match dentry.dentry_type {
|
||||||
EXFAT_FILE => Ok(ExfatDentry::File(ExfatFileDentry::from_bytes(dentry_bytes))),
|
EXFAT_FILE => Ok(ExfatDentry::File(ExfatFileDentry::from_bytes(dentry_bytes))),
|
||||||
EXFAT_STREAM => Ok(ExfatDentry::Stream(ExfatStreamDentry::from_bytes(
|
EXFAT_STREAM => Ok(ExfatDentry::Stream(ExfatStreamDentry::from_bytes(
|
||||||
|
@ -85,7 +85,7 @@ mod test {
|
|||||||
BioType::Read => seg
|
BioType::Read => seg
|
||||||
.inner_segment()
|
.inner_segment()
|
||||||
.writer()
|
.writer()
|
||||||
.write(&mut self.queue.0.reader().skip(cur_device_ofs)),
|
.write(self.queue.0.reader().skip(cur_device_ofs)),
|
||||||
BioType::Write => self
|
BioType::Write => self
|
||||||
.queue
|
.queue
|
||||||
.0
|
.0
|
||||||
|
@ -8,7 +8,7 @@ use super::fat::ClusterID;
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub fn make_hash_index(cluster: ClusterID, offset: u32) -> usize {
|
pub fn make_hash_index(cluster: ClusterID, offset: u32) -> usize {
|
||||||
(cluster as usize) << 32usize | (offset as usize & 0xffffffffusize)
|
((cluster as usize) << 32usize) | (offset as usize & 0xffffffffusize)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calc_checksum_32(data: &[u8]) -> u32 {
|
pub fn calc_checksum_32(data: &[u8]) -> u32 {
|
||||||
|
@ -2133,10 +2133,10 @@ impl TryFrom<RawInode> for InodeDesc {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
type_: inode_type,
|
type_: inode_type,
|
||||||
perm: FilePerm::from_raw_mode(inode.mode)?,
|
perm: FilePerm::from_raw_mode(inode.mode)?,
|
||||||
uid: (inode.os_dependent_2.uid_high as u32) << 16 | inode.uid as u32,
|
uid: ((inode.os_dependent_2.uid_high as u32) << 16) | inode.uid as u32,
|
||||||
gid: (inode.os_dependent_2.gid_high as u32) << 16 | inode.gid as u32,
|
gid: ((inode.os_dependent_2.gid_high as u32) << 16) | inode.gid as u32,
|
||||||
size: if inode_type == InodeType::File {
|
size: if inode_type == InodeType::File {
|
||||||
(inode.size_high as usize) << 32 | inode.size_low as usize
|
((inode.size_high as usize) << 32) | inode.size_low as usize
|
||||||
} else {
|
} else {
|
||||||
inode.size_low as usize
|
inode.size_low as usize
|
||||||
},
|
},
|
||||||
|
@ -247,8 +247,7 @@ impl Xattr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value_writer.write_fallible(
|
value_writer.write_fallible(
|
||||||
&mut self
|
self.blocks_buf
|
||||||
.blocks_buf
|
|
||||||
.reader()
|
.reader()
|
||||||
.to_fallible()
|
.to_fallible()
|
||||||
.skip(entry.value_offset as usize)
|
.skip(entry.value_offset as usize)
|
||||||
|
@ -510,7 +510,7 @@ pub fn split_path(path: &str) -> (&str, &str) {
|
|||||||
let file_name = path
|
let file_name = path
|
||||||
.split_inclusive('/')
|
.split_inclusive('/')
|
||||||
.filter(|&x| x != "/")
|
.filter(|&x| x != "/")
|
||||||
.last()
|
.next_back()
|
||||||
.unwrap_or(".");
|
.unwrap_or(".");
|
||||||
|
|
||||||
let mut split = path.trim_end_matches('/').rsplitn(2, '/');
|
let mut split = path.trim_end_matches('/').rsplitn(2, '/');
|
||||||
|
@ -516,9 +516,7 @@ impl OverlayInode {
|
|||||||
return upper;
|
return upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_top_valid_lower_inode()
|
self.get_top_valid_lower_inode().cloned().unwrap()
|
||||||
.map(|lower| lower.clone())
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the top valid lower inode.
|
/// Returns the top valid lower inode.
|
||||||
@ -725,7 +723,7 @@ impl OverlayInode {
|
|||||||
return Ok(upper.clone());
|
return Ok(upper.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert!(!self.parent.is_none());
|
debug_assert!(self.parent.is_some());
|
||||||
// FIXME: Should we hold every upper locks from lower to upper
|
// FIXME: Should we hold every upper locks from lower to upper
|
||||||
// for such a long period?
|
// for such a long period?
|
||||||
let parent_upper = self
|
let parent_upper = self
|
||||||
@ -859,17 +857,16 @@ fn is_opaque_dir(inode: &Arc<dyn Inode>) -> Result<bool> {
|
|||||||
|
|
||||||
let name = XattrName::try_from_full_name(OPAQUE_DIR_XATTR_NAME).unwrap();
|
let name = XattrName::try_from_full_name(OPAQUE_DIR_XATTR_NAME).unwrap();
|
||||||
let mut value = [0u8];
|
let mut value = [0u8];
|
||||||
match inode.get_xattr(
|
if let Err(e) = inode.get_xattr(
|
||||||
name,
|
name,
|
||||||
&mut VmWriter::from(value.as_mut_slice()).to_fallible(),
|
&mut VmWriter::from(value.as_mut_slice()).to_fallible(),
|
||||||
) {
|
) {
|
||||||
Err(e) => match e.error() {
|
match e.error() {
|
||||||
Errno::E2BIG | Errno::ENODATA | Errno::EOPNOTSUPP | Errno::ERANGE => {
|
Errno::E2BIG | Errno::ENODATA | Errno::EOPNOTSUPP | Errno::ERANGE => {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
_ => return Err(e),
|
_ => return Err(e),
|
||||||
},
|
}
|
||||||
Ok(_) => {}
|
|
||||||
};
|
};
|
||||||
Ok(value == WHITEOUT_AND_OPAQUE_XATTR_VALUE)
|
Ok(value == WHITEOUT_AND_OPAQUE_XATTR_VALUE)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ impl SysFsInode {
|
|||||||
InnerNode::Branch(child_branch),
|
InnerNode::Branch(child_branch),
|
||||||
Arc::downgrade(&self.this()),
|
Arc::downgrade(&self.this()),
|
||||||
);
|
);
|
||||||
return Ok(inode);
|
Ok(inode)
|
||||||
}
|
}
|
||||||
SysNodeType::Leaf => {
|
SysNodeType::Leaf => {
|
||||||
let child_leaf_node =
|
let child_leaf_node =
|
||||||
@ -208,7 +208,7 @@ impl SysFsInode {
|
|||||||
InnerNode::Leaf(child_leaf_node),
|
InnerNode::Leaf(child_leaf_node),
|
||||||
Arc::downgrade(&self.this()),
|
Arc::downgrade(&self.this()),
|
||||||
);
|
);
|
||||||
return Ok(inode);
|
Ok(inode)
|
||||||
}
|
}
|
||||||
SysNodeType::Symlink => {
|
SysNodeType::Symlink => {
|
||||||
let child_symlink = child_sysnode
|
let child_symlink = child_sysnode
|
||||||
@ -219,7 +219,7 @@ impl SysFsInode {
|
|||||||
child_symlink,
|
child_symlink,
|
||||||
Arc::downgrade(&self.this()),
|
Arc::downgrade(&self.this()),
|
||||||
);
|
);
|
||||||
return Ok(inode);
|
Ok(inode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -245,7 +245,7 @@ impl SysFsInode {
|
|||||||
parent_node_arc,
|
parent_node_arc,
|
||||||
Arc::downgrade(&self.this()),
|
Arc::downgrade(&self.this()),
|
||||||
);
|
);
|
||||||
return Ok(inode);
|
Ok(inode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,9 +481,9 @@ impl Inode for SysFsInode {
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut last_ino = start_ino;
|
let mut last_ino = start_ino;
|
||||||
|
|
||||||
let mut iter = self.new_dentry_iter(start_ino + 1);
|
let iter = self.new_dentry_iter(start_ino + 1);
|
||||||
|
|
||||||
while let Some(dentry) = iter.next() {
|
for dentry in iter {
|
||||||
// The offset reported back to the caller should be the absolute position
|
// The offset reported back to the caller should be the absolute position
|
||||||
let next_offset = (dentry.ino + 1) as usize;
|
let next_offset = (dentry.ino + 1) as usize;
|
||||||
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, next_offset);
|
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, next_offset);
|
||||||
@ -657,7 +657,7 @@ impl<'a> ThisAndParentDentryIter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for ThisAndParentDentryIter<'a> {
|
impl Iterator for ThisAndParentDentryIter<'_> {
|
||||||
type Item = Dentry;
|
type Item = Dentry;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Dentry> {
|
fn next(&mut self) -> Option<Dentry> {
|
||||||
|
@ -23,5 +23,5 @@ pub fn singleton() -> &'static Arc<SysFs> {
|
|||||||
/// Should be called during kernel filesystem initialization, *after* aster_systree::init().
|
/// Should be called during kernel filesystem initialization, *after* aster_systree::init().
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
// Ensure systree is initialized first. This should be handled by the kernel's init order.
|
// Ensure systree is initialized first. This should be handled by the kernel's init order.
|
||||||
SYSFS_SINGLETON.call_once(|| SysFs::new());
|
SYSFS_SINGLETON.call_once(SysFs::new);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ impl SysNode for MockLeafNode {
|
|||||||
let value = data.get(name).ok_or(SysTreeError::AttributeError)?; // Should exist if in attrs
|
let value = data.get(name).ok_or(SysTreeError::AttributeError)?; // Should exist if in attrs
|
||||||
let bytes = value.as_bytes();
|
let bytes = value.as_bytes();
|
||||||
writer
|
writer
|
||||||
.write_fallible(&mut (&bytes[..]).into())
|
.write_fallible(&mut bytes.into())
|
||||||
.map_err(|_| SysTreeError::AttributeError)
|
.map_err(|_| SysTreeError::AttributeError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ impl SysNode for MockBranchNode {
|
|||||||
};
|
};
|
||||||
let bytes = value.as_bytes();
|
let bytes = value.as_bytes();
|
||||||
writer
|
writer
|
||||||
.write_fallible(&mut (&bytes[..]).into())
|
.write_fallible(&mut bytes.into())
|
||||||
.map_err(|_| SysTreeError::AttributeError)
|
.map_err(|_| SysTreeError::AttributeError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ fn create_mock_systree_instance() -> &'static Arc<SysTree> {
|
|||||||
let symlink1 = MockSymlinkNode::new("link1", "../branch1/leaf1");
|
let symlink1 = MockSymlinkNode::new("link1", "../branch1/leaf1");
|
||||||
|
|
||||||
// Build hierarchy - ignore Result since this is test setup
|
// Build hierarchy - ignore Result since this is test setup
|
||||||
let _ = branch1.add_child(leaf1.clone() as Arc<dyn SysObj>);
|
branch1.add_child(leaf1.clone() as Arc<dyn SysObj>);
|
||||||
let _ = root.add_child(branch1.clone() as Arc<dyn SysObj>);
|
let _ = root.add_child(branch1.clone() as Arc<dyn SysObj>);
|
||||||
let _ = root.add_child(leaf2.clone() as Arc<dyn SysObj>);
|
let _ = root.add_child(leaf2.clone() as Arc<dyn SysObj>);
|
||||||
let _ = root.add_child(symlink1.clone() as Arc<dyn SysObj>);
|
let _ = root.add_child(symlink1.clone() as Arc<dyn SysObj>);
|
||||||
|
@ -59,7 +59,7 @@ impl<P: SupportedNetlinkProtocol> datagram_common::Unbound for UnboundNetlink<P>
|
|||||||
|
|
||||||
let bound_handle = {
|
let bound_handle = {
|
||||||
let endpoint = {
|
let endpoint = {
|
||||||
let mut endpoint = endpoint.clone();
|
let mut endpoint = *endpoint;
|
||||||
endpoint.add_groups(self.groups);
|
endpoint.add_groups(self.groups);
|
||||||
endpoint
|
endpoint
|
||||||
};
|
};
|
||||||
|
@ -81,7 +81,7 @@ impl datagram_common::Bound for BoundNetlinkUevent {
|
|||||||
|
|
||||||
response.write_to(writer)?;
|
response.write_to(writer)?;
|
||||||
|
|
||||||
let remote = response.src_addr().clone();
|
let remote = *response.src_addr();
|
||||||
|
|
||||||
if !flags.contains(SendRecvFlags::MSG_PEEK) {
|
if !flags.contains(SendRecvFlags::MSG_PEEK) {
|
||||||
receive_queue.pop_front().unwrap();
|
receive_queue.pop_front().unwrap();
|
||||||
|
@ -40,7 +40,7 @@ impl FromStr for SyntheticUevent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut envs = Vec::new();
|
let mut envs = Vec::new();
|
||||||
for env_str in split.into_iter() {
|
for env_str in split {
|
||||||
let (key, value) = {
|
let (key, value) = {
|
||||||
// Each string should be in the `KEY=VALUE` format.
|
// Each string should be in the `KEY=VALUE` format.
|
||||||
match env_str.split_once('=') {
|
match env_str.split_once('=') {
|
||||||
@ -87,10 +87,9 @@ impl FromStr for Uuid {
|
|||||||
return_errno_with_message!(Errno::EINVAL, "the UUID length is invalid");
|
return_errno_with_message!(Errno::EINVAL, "the UUID length is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (byte, pattern) in bytes.into_iter().zip(UUID_PATTERN.as_bytes()) {
|
for (byte, pattern) in bytes.iter().zip(UUID_PATTERN.as_bytes()) {
|
||||||
if *pattern == b'x' && byte.is_ascii_hexdigit() {
|
if (*pattern == b'x' && byte.is_ascii_hexdigit()) || (*pattern == b'-' && *byte == b'-')
|
||||||
continue;
|
{
|
||||||
} else if *pattern == b'-' && *byte == b'-' {
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return_errno_with_message!(Errno::EINVAL, "the UUID content is invalid");
|
return_errno_with_message!(Errno::EINVAL, "the UUID content is invalid");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use alloc::format;
|
|
||||||
use core::{
|
use core::{
|
||||||
|
fmt::Display,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::atomic::{AtomicU64, Ordering},
|
sync::atomic::{AtomicU64, Ordering},
|
||||||
};
|
};
|
||||||
@ -142,8 +142,8 @@ impl Uevent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Uevent {
|
impl Display for Uevent {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
let mut env_string = {
|
let mut env_string = {
|
||||||
let len = self
|
let len = self
|
||||||
.envs
|
.envs
|
||||||
@ -160,7 +160,8 @@ impl ToString for Uevent {
|
|||||||
env_string.push('\0');
|
env_string.push('\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
format!(
|
write!(
|
||||||
|
f,
|
||||||
"{}@{}\0ACTION={}\0DEVPATH={}\0SUBSYSTEM={}\0{}SEQNUM={}\0",
|
"{}@{}\0ACTION={}\0DEVPATH={}\0SUBSYSTEM={}\0{}SEQNUM={}\0",
|
||||||
self.action.as_str(),
|
self.action.as_str(),
|
||||||
self.devpath,
|
self.devpath,
|
||||||
|
@ -89,6 +89,7 @@ pub trait SegmentBody: Sized + Clone + Copy {
|
|||||||
|
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[derive(Debug, Clone, Copy, TryFromInt, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, TryFromInt, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
#[expect(clippy::upper_case_acronyms)]
|
||||||
pub enum CSegmentType {
|
pub enum CSegmentType {
|
||||||
// Standard netlink message types
|
// Standard netlink message types
|
||||||
NOOP = 1,
|
NOOP = 1,
|
||||||
|
@ -29,7 +29,7 @@ fn append_done_segment(request_header: &CMsgSegHdr, response_segments: &mut Vec<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the `MULTI` flag to all segments in `segments`.
|
/// Adds the `MULTI` flag to all segments in `segments`.
|
||||||
fn add_multi_flag(response_segments: &mut Vec<RtnlSegment>) {
|
fn add_multi_flag(response_segments: &mut [RtnlSegment]) {
|
||||||
for segment in response_segments.iter_mut() {
|
for segment in response_segments.iter_mut() {
|
||||||
let header = segment.header_mut();
|
let header = segment.header_mut();
|
||||||
let mut flags = SegHdrCommonFlags::from_bits_truncate(header.flags);
|
let mut flags = SegHdrCommonFlags::from_bits_truncate(header.flags);
|
||||||
|
@ -13,6 +13,7 @@ use crate::{
|
|||||||
#[derive(Debug, Clone, Copy, TryFromInt)]
|
#[derive(Debug, Clone, Copy, TryFromInt)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[expect(non_camel_case_types)]
|
#[expect(non_camel_case_types)]
|
||||||
|
#[expect(clippy::upper_case_acronyms)]
|
||||||
enum AddrAttrClass {
|
enum AddrAttrClass {
|
||||||
UNSPEC = 0,
|
UNSPEC = 0,
|
||||||
ADDRESS = 1,
|
ADDRESS = 1,
|
||||||
|
@ -12,7 +12,8 @@ use crate::{
|
|||||||
/// Reference: <https://elixir.bootlin.com/linux/v6.13/source/include/uapi/linux/if_link.h#L297>.
|
/// Reference: <https://elixir.bootlin.com/linux/v6.13/source/include/uapi/linux/if_link.h#L297>.
|
||||||
#[derive(Debug, Clone, Copy, TryFromInt)]
|
#[derive(Debug, Clone, Copy, TryFromInt)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[allow(non_camel_case_types)]
|
#[expect(non_camel_case_types)]
|
||||||
|
#[expect(clippy::upper_case_acronyms)]
|
||||||
enum LinkAttrClass {
|
enum LinkAttrClass {
|
||||||
UNSPEC = 0,
|
UNSPEC = 0,
|
||||||
ADDRESS = 1,
|
ADDRESS = 1,
|
||||||
|
@ -105,6 +105,7 @@ bitflags! {
|
|||||||
/// Reference: <https://elixir.bootlin.com/linux/v6.13/source/include/uapi/linux/rtnetlink.h#L320>.
|
/// Reference: <https://elixir.bootlin.com/linux/v6.13/source/include/uapi/linux/rtnetlink.h#L320>.
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Clone, Copy, TryFromInt)]
|
#[derive(Debug, Clone, Copy, TryFromInt)]
|
||||||
|
#[expect(clippy::upper_case_acronyms)]
|
||||||
pub enum RtScope {
|
pub enum RtScope {
|
||||||
UNIVERSE = 0,
|
UNIVERSE = 0,
|
||||||
// User defined values
|
// User defined values
|
||||||
|
@ -5,18 +5,18 @@
|
|||||||
//!
|
//!
|
||||||
//! Typically, a segment will consist of three parts:
|
//! Typically, a segment will consist of three parts:
|
||||||
//!
|
//!
|
||||||
//! 1. Header: The headers of all segments are of type [`CMessageSegmentHeader`],
|
//! 1. Header: The headers of all segments are of type [`CMegSegHdr`],
|
||||||
//! which indicate the type and total length of the segment.
|
//! which indicate the type and total length of the segment.
|
||||||
//!
|
//!
|
||||||
//! 2. Body: The body is the main component of a segment.
|
//! 2. Body: The body is the main component of a segment.
|
||||||
//! Each segment will have one and only one body.
|
//! Each segment will have one and only one body.
|
||||||
//! The body type is defined by the `type_` field of the header.
|
//! The body type is defined by the `type_` field of the header.
|
||||||
//!
|
//!
|
||||||
//! 3. Attributes: Attributes are optional.
|
//! 3. Attributes: Attributes are optional.
|
||||||
//! A segment can have zero or multiple attributes.
|
//! A segment can have zero or multiple attributes.
|
||||||
//! Attributes belong to different classes,
|
//! Attributes belong to different classes,
|
||||||
//! with the class defined by the `type_` field of the header.
|
//! with the class defined by the `type_` field of the header.
|
||||||
//! The total number of attributes is controlled by the `len` field of the header.
|
//! The total number of attributes is controlled by the `len` field of the header.
|
||||||
//!
|
//!
|
||||||
//! Note that all headers, bodies, and attributes require
|
//! Note that all headers, bodies, and attributes require
|
||||||
//! their starting address in memory to be aligned to [`super::NLMSG_ALIGN`]
|
//! their starting address in memory to be aligned to [`super::NLMSG_ALIGN`]
|
||||||
|
@ -259,7 +259,7 @@ impl<Message: 'static> Drop for BoundHandle<Message> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn init() {
|
pub(super) fn init() {
|
||||||
NETLINK_SOCKET_TABLE.call_once(|| NetlinkSocketTable::new());
|
NETLINK_SOCKET_TABLE.call_once(NetlinkSocketTable::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the `protocol` is valid.
|
/// Returns whether the `protocol` is valid.
|
||||||
@ -270,7 +270,7 @@ pub fn is_valid_protocol(protocol: NetlinkProtocolId) -> bool {
|
|||||||
/// Netlink protocols that are assigned for specific usage.
|
/// Netlink protocols that are assigned for specific usage.
|
||||||
///
|
///
|
||||||
/// Reference: <https://elixir.bootlin.com/linux/v6.0.9/source/include/uapi/linux/netlink.h#L9>.
|
/// Reference: <https://elixir.bootlin.com/linux/v6.0.9/source/include/uapi/linux/netlink.h#L9>.
|
||||||
#[allow(non_camel_case_types)]
|
#[expect(non_camel_case_types)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Debug, Clone, Copy, TryFromInt)]
|
#[derive(Debug, Clone, Copy, TryFromInt)]
|
||||||
pub enum StandardNetlinkProtocol {
|
pub enum StandardNetlinkProtocol {
|
||||||
|
@ -515,6 +515,7 @@ fn clone_sysvsem(clone_flags: CloneFlags) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[expect(clippy::too_many_arguments)]
|
||||||
fn create_child_process(
|
fn create_child_process(
|
||||||
pid: Pid,
|
pid: Pid,
|
||||||
parent: Weak<Process>,
|
parent: Weak<Process>,
|
||||||
|
@ -80,7 +80,7 @@ fn move_process_children(
|
|||||||
// Take the lock first to avoid the race when the `reaper_process` is exiting concurrently.
|
// Take the lock first to avoid the race when the `reaper_process` is exiting concurrently.
|
||||||
let mut reaper_process_children = reaper_process.children().lock();
|
let mut reaper_process_children = reaper_process.children().lock();
|
||||||
|
|
||||||
let is_init = is_init_process(&reaper_process);
|
let is_init = is_init_process(reaper_process);
|
||||||
let is_zombie = reaper_process.status().is_zombie();
|
let is_zombie = reaper_process.status().is_zombie();
|
||||||
if !is_init && is_zombie {
|
if !is_init && is_zombie {
|
||||||
return Err(());
|
return Err(());
|
||||||
|
@ -28,7 +28,7 @@ impl ThreadName {
|
|||||||
let mut thread_name = ThreadName::new();
|
let mut thread_name = ThreadName::new();
|
||||||
let executable_file_name = executable_path
|
let executable_file_name = executable_path
|
||||||
.split('/')
|
.split('/')
|
||||||
.last()
|
.next_back()
|
||||||
.ok_or(Error::with_message(Errno::EINVAL, "invalid elf path"))?;
|
.ok_or(Error::with_message(Errno::EINVAL, "invalid elf path"))?;
|
||||||
let name = CString::new(executable_file_name)?;
|
let name = CString::new(executable_file_name)?;
|
||||||
thread_name.set_name(&name)?;
|
thread_name.set_name(&name)?;
|
||||||
|
@ -108,7 +108,7 @@ impl dyn Terminal {
|
|||||||
let mut session_inner = session.lock();
|
let mut session_inner = session.lock();
|
||||||
|
|
||||||
if let Some(session_terminal) = session_inner.terminal() {
|
if let Some(session_terminal) = session_inner.terminal() {
|
||||||
if Arc::ptr_eq(&session_terminal, &self) {
|
if Arc::ptr_eq(session_terminal, &self) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
return_errno_with_message!(
|
return_errno_with_message!(
|
||||||
@ -195,7 +195,7 @@ impl dyn Terminal {
|
|||||||
|
|
||||||
if !session_inner
|
if !session_inner
|
||||||
.terminal()
|
.terminal()
|
||||||
.is_some_and(|session_terminal| Arc::ptr_eq(session_terminal, &self))
|
.is_some_and(|session_terminal| Arc::ptr_eq(session_terminal, self))
|
||||||
{
|
{
|
||||||
return_errno_with_message!(
|
return_errno_with_message!(
|
||||||
Errno::ENOTTY,
|
Errno::ENOTTY,
|
||||||
|
@ -171,7 +171,7 @@ impl ProcessVm {
|
|||||||
pub fn clear_and_map(&self) {
|
pub fn clear_and_map(&self) {
|
||||||
let root_vmar = self.lock_root_vmar();
|
let root_vmar = self.lock_root_vmar();
|
||||||
root_vmar.unwrap().clear().unwrap();
|
root_vmar.unwrap().clear().unwrap();
|
||||||
self.heap.alloc_and_map_vm(&root_vmar.unwrap()).unwrap();
|
self.heap.alloc_and_map_vm(root_vmar.unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ pub trait Pause: WaitTimeout {
|
|||||||
/// [`ETIME`]: crate::error::Errno::ETIME
|
/// [`ETIME`]: crate::error::Errno::ETIME
|
||||||
/// [`EINTR`]: crate::error::Errno::EINTR
|
/// [`EINTR`]: crate::error::Errno::EINTR
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn pause_timeout<'a>(&self, timeout: &TimeoutExt<'a>) -> Result<()>;
|
fn pause_timeout(&self, timeout: &TimeoutExt<'_>) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pause for Waiter {
|
impl Pause for Waiter {
|
||||||
@ -136,7 +136,7 @@ impl Pause for Waiter {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause_timeout<'a>(&self, timeout: &TimeoutExt<'a>) -> Result<()> {
|
fn pause_timeout(&self, timeout: &TimeoutExt<'_>) -> Result<()> {
|
||||||
let timer = timeout.check_expired()?.map(|timeout| {
|
let timer = timeout.check_expired()?.map(|timeout| {
|
||||||
let waker = self.waker();
|
let waker = self.waker();
|
||||||
timeout.create_timer(move || {
|
timeout.create_timer(move || {
|
||||||
@ -201,7 +201,7 @@ impl Pause for WaitQueue {
|
|||||||
waiter.pause_until_or_timeout_impl(cond, timeout)
|
waiter.pause_until_or_timeout_impl(cond, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pause_timeout<'a>(&self, _timeout: &TimeoutExt<'a>) -> Result<()> {
|
fn pause_timeout(&self, _timeout: &TimeoutExt<'_>) -> Result<()> {
|
||||||
panic!("`pause_timeout` can only be used on `Waiter`");
|
panic!("`pause_timeout` can only be used on `Waiter`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,6 @@ impl SchedPolicyState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update<T>(&self, update: impl FnOnce(&mut SchedPolicy) -> T) -> T {
|
pub fn update<T>(&self, update: impl FnOnce(&mut SchedPolicy) -> T) -> T {
|
||||||
update(&mut *self.policy.disable_irq().lock())
|
update(&mut self.policy.disable_irq().lock())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ struct Dirent {
|
|||||||
name: CString,
|
name: CString,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(C, packed)]
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct DirentInner {
|
struct DirentInner {
|
||||||
d_ino: u64,
|
d_ino: u64,
|
||||||
@ -172,7 +172,7 @@ struct Dirent64 {
|
|||||||
name: CString,
|
name: CString,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(C, packed)]
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Dirent64Inner {
|
struct Dirent64Inner {
|
||||||
d_ino: u64,
|
d_ino: u64,
|
||||||
|
@ -183,9 +183,9 @@ pub(super) fn access_sched_attr_with<T>(
|
|||||||
f: impl FnOnce(&SchedAttr) -> Result<T>,
|
f: impl FnOnce(&SchedAttr) -> Result<T>,
|
||||||
) -> Result<T> {
|
) -> Result<T> {
|
||||||
match tid {
|
match tid {
|
||||||
0 => f(&ctx.thread.sched_attr()),
|
0 => f(ctx.thread.sched_attr()),
|
||||||
_ if tid > (i32::MAX as u32) => Err(Error::with_message(Errno::EINVAL, "invalid tid")),
|
_ if tid > (i32::MAX as u32) => Err(Error::with_message(Errno::EINVAL, "invalid tid")),
|
||||||
_ => f(&thread_table::get_thread(tid)
|
_ => f(thread_table::get_thread(tid)
|
||||||
.ok_or_else(|| Error::with_message(Errno::ESRCH, "thread does not exist"))?
|
.ok_or_else(|| Error::with_message(Errno::ESRCH, "thread does not exist"))?
|
||||||
.sched_attr()),
|
.sched_attr()),
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ pub(super) fn lookup_dentry_for_xattr<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn read_xattr_name_cstr_from_user<'a>(
|
pub(super) fn read_xattr_name_cstr_from_user(
|
||||||
name_ptr: Vaddr,
|
name_ptr: Vaddr,
|
||||||
user_space: &CurrentUserSpace,
|
user_space: &CurrentUserSpace,
|
||||||
) -> Result<CString> {
|
) -> Result<CString> {
|
||||||
@ -170,9 +170,10 @@ pub(super) fn parse_xattr_name(name_str: &str) -> Result<XattrName> {
|
|||||||
return_errno_with_message!(Errno::ERANGE, "xattr name empty or too long");
|
return_errno_with_message!(Errno::ERANGE, "xattr name empty or too long");
|
||||||
}
|
}
|
||||||
|
|
||||||
let xattr_name = XattrName::try_from_full_name(name_str.as_ref()).ok_or(
|
let xattr_name = XattrName::try_from_full_name(name_str).ok_or(Error::with_message(
|
||||||
Error::with_message(Errno::EOPNOTSUPP, "invalid xattr namespace"),
|
Errno::EOPNOTSUPP,
|
||||||
)?;
|
"invalid xattr namespace",
|
||||||
|
))?;
|
||||||
Ok(xattr_name)
|
Ok(xattr_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,18 +182,14 @@ pub(super) fn check_xattr_namespace(namespace: XattrNamespace, ctx: &Context) ->
|
|||||||
let permitted_capset = credentials.permitted_capset();
|
let permitted_capset = credentials.permitted_capset();
|
||||||
let effective_capset = credentials.effective_capset();
|
let effective_capset = credentials.effective_capset();
|
||||||
|
|
||||||
match namespace {
|
if namespace == XattrNamespace::Trusted
|
||||||
XattrNamespace::Trusted => {
|
&& (!permitted_capset.contains(CapSet::SYS_ADMIN)
|
||||||
if !permitted_capset.contains(CapSet::SYS_ADMIN)
|
|| !effective_capset.contains(CapSet::SYS_ADMIN))
|
||||||
|| !effective_capset.contains(CapSet::SYS_ADMIN)
|
{
|
||||||
{
|
return_errno_with_message!(
|
||||||
return_errno_with_message!(
|
Errno::EPERM,
|
||||||
Errno::EPERM,
|
"try to access trusted xattr without CAP_SYS_ADMIN"
|
||||||
"try to access trusted xattr without CAP_SYS_ADMIN"
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ impl From<Duration> for StatxTimestamp {
|
|||||||
fn from(duration: Duration) -> Self {
|
fn from(duration: Duration) -> Self {
|
||||||
Self {
|
Self {
|
||||||
tv_sec: duration.as_secs() as i64,
|
tv_sec: duration.as_secs() as i64,
|
||||||
tv_nsec: duration.subsec_nanos() as u32,
|
tv_nsec: duration.subsec_nanos(),
|
||||||
__reserved: 0,
|
__reserved: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ impl TimerManager {
|
|||||||
pub fn process_expired_timers(&self) {
|
pub fn process_expired_timers(&self) {
|
||||||
let callbacks = {
|
let callbacks = {
|
||||||
let mut timeout_list = self.timer_callbacks.disable_irq().lock();
|
let mut timeout_list = self.timer_callbacks.disable_irq().lock();
|
||||||
if timeout_list.len() == 0 {
|
if timeout_list.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ use alloc::{boxed::Box, vec, vec::Vec};
|
|||||||
use aster_softirq::{softirq_id::TIMER_SOFTIRQ_ID, SoftIrqLine};
|
use aster_softirq::{softirq_id::TIMER_SOFTIRQ_ID, SoftIrqLine};
|
||||||
use ostd::{sync::RcuOption, timer};
|
use ostd::{sync::RcuOption, timer};
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[expect(clippy::type_complexity)]
|
||||||
#[allow(clippy::box_collection)]
|
|
||||||
static TIMER_SOFTIRQ_CALLBACKS: RcuOption<Box<Vec<fn()>>> = RcuOption::new_none();
|
static TIMER_SOFTIRQ_CALLBACKS: RcuOption<Box<Vec<fn()>>> = RcuOption::new_none();
|
||||||
|
|
||||||
pub(super) fn init() {
|
pub(super) fn init() {
|
||||||
|
@ -268,13 +268,13 @@ pub fn write_socket_addr_with_max_len(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Utility function to write a C socket address to user space.
|
// Utility function to write a C socket address to user space.
|
||||||
fn write_c_socket_address_util<TCSockAddr: Pod, TSockAddr>(
|
fn write_c_socket_address_util<TCSockAddr, TSockAddr>(
|
||||||
addr: TSockAddr,
|
addr: TSockAddr,
|
||||||
dest: Vaddr,
|
dest: Vaddr,
|
||||||
max_len: usize,
|
max_len: usize,
|
||||||
) -> Result<usize>
|
) -> Result<usize>
|
||||||
where
|
where
|
||||||
TCSockAddr: From<TSockAddr>,
|
TCSockAddr: Pod + From<TSockAddr>,
|
||||||
{
|
{
|
||||||
let c_socket_addr = TCSockAddr::from(addr);
|
let c_socket_addr = TCSockAddr::from(addr);
|
||||||
let actual_len = size_of::<TCSockAddr>();
|
let actual_len = size_of::<TCSockAddr>();
|
||||||
|
@ -673,7 +673,7 @@ impl<'a, R1, R2> VmarMapOptions<'a, R1, R2> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R1, R2> VmarMapOptions<'a, R1, R2>
|
impl<R1, R2> VmarMapOptions<'_, R1, R2>
|
||||||
where
|
where
|
||||||
Vmo<R2>: VmoRightsOp,
|
Vmo<R2>: VmoRightsOp,
|
||||||
{
|
{
|
||||||
|
@ -459,7 +459,6 @@ impl Vmo_ {
|
|||||||
cursor.next();
|
cursor.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(cursor);
|
|
||||||
drop(locked_pages);
|
drop(locked_pages);
|
||||||
|
|
||||||
for page_idx in removed_page_idx {
|
for page_idx in removed_page_idx {
|
||||||
|
@ -143,7 +143,6 @@ fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result<XArray<
|
|||||||
cursor.store(frame);
|
cursor.store(frame);
|
||||||
cursor.next();
|
cursor.next();
|
||||||
}
|
}
|
||||||
drop(cursor);
|
|
||||||
drop(locked_pages);
|
drop(locked_pages);
|
||||||
Ok(committed_pages)
|
Ok(committed_pages)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user