fix(clippy): make clippy = host libs + riscv programs (shared PROGRAMS); libkos alloc spinlock (was unlocked across threads); keystore Account; gpu Rect; factory Entry; Default impls, let-chains, div_ceil, iter loops
This commit is contained in:
@@ -44,16 +44,21 @@ impl MockFileSystem {
|
||||
|
||||
fn find_by_name(&self, path: &[u8]) -> Option<usize> {
|
||||
for i in 0..MAX_FILES {
|
||||
if let Some(entry) = &self.files[i] {
|
||||
if entry.name == *path {
|
||||
if let Some(entry) = &self.files[i]
|
||||
&& entry.name == *path {
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MockFileSystem {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystem for MockFileSystem {
|
||||
fn writable(&self) -> bool {
|
||||
!self.read_only
|
||||
|
||||
@@ -39,6 +39,10 @@ impl FileName {
|
||||
pub fn len(&self) -> usize {
|
||||
self.len as usize
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<[u8]> for FileName {
|
||||
|
||||
@@ -37,11 +37,10 @@ pub fn find_entry<B: BlockDevice>(
|
||||
let name_len = block_buf[pos + 6] as usize;
|
||||
|
||||
if rec_len == 0 { break; }
|
||||
if entry_inode != 0 && name_len == name.len() {
|
||||
if &block_buf[pos + 8..pos + 8 + name_len] == name {
|
||||
if entry_inode != 0 && name_len == name.len()
|
||||
&& &block_buf[pos + 8..pos + 8 + name_len] == name {
|
||||
return Some(entry_inode);
|
||||
}
|
||||
}
|
||||
pos += rec_len;
|
||||
}
|
||||
}
|
||||
@@ -147,8 +146,8 @@ pub fn remove_entry<B: BlockDevice>(
|
||||
let name_len = block_buf[pos + 6] as usize;
|
||||
|
||||
if rec_len == 0 { break; }
|
||||
if entry_inode != 0 && name_len == name.len() {
|
||||
if &block_buf[pos + 8..pos + 8 + name_len] == name {
|
||||
if entry_inode != 0 && name_len == name.len()
|
||||
&& &block_buf[pos + 8..pos + 8 + name_len] == name {
|
||||
if let Some(pp) = prev_pos {
|
||||
let prev_rec = read_u16(&block_buf, pp + 4) as usize;
|
||||
write_u16(&mut block_buf, pp + 4, (prev_rec + rec_len) as u16);
|
||||
@@ -158,7 +157,6 @@ pub fn remove_entry<B: BlockDevice>(
|
||||
write_block(device, phys, spb, &block_buf);
|
||||
return Some(entry_inode);
|
||||
}
|
||||
}
|
||||
prev_pos = Some(pos);
|
||||
pos += rec_len;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,9 @@ impl<B: BlockDevice> FileSystem for Ext4<B> {
|
||||
done += chunk;
|
||||
}
|
||||
|
||||
self.open_files[handle.raw() as usize].as_mut().map(|f| f.offset += done);
|
||||
if let Some(f) = self.open_files[handle.raw() as usize].as_mut() {
|
||||
f.offset += done;
|
||||
}
|
||||
Some(done)
|
||||
}
|
||||
|
||||
@@ -204,13 +206,12 @@ impl<B: BlockDevice> FileSystem for Ext4<B> {
|
||||
|
||||
fn close(&mut self, handle: FileHandle) {
|
||||
if handle.raw() as usize >= MAX_OPEN_FILES { return; }
|
||||
if let Some(file) = self.open_files[handle.raw() as usize].take() {
|
||||
if let Some(mut inode) = self.read_inode(file.inode_num) {
|
||||
if let Some(file) = self.open_files[handle.raw() as usize].take()
|
||||
&& let Some(mut inode) = self.read_inode(file.inode_num) {
|
||||
inode.size = file.size as u64;
|
||||
inode.block_data = file.block_data;
|
||||
self.write_inode(file.inode_num, &inode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn list_dir(&mut self, path: &[u8], entries: &mut [DirEntry]) -> Option<usize> {
|
||||
@@ -222,14 +223,13 @@ impl<B: BlockDevice> FileSystem for Ext4<B> {
|
||||
|
||||
let inode = self.read_inode(dir_inode_num)?;
|
||||
let count = dir::list_entries(&mut self.device, &self.sb, &inode, entries)?;
|
||||
for i in 0..count {
|
||||
if !entries[i].is_dir {
|
||||
let name = entries[i].name;
|
||||
if let Some(child_ino) = dir::find_entry(&mut self.device, &self.sb, &inode, name.as_bytes()) {
|
||||
if let Some(child) = self.read_inode(child_ino) {
|
||||
entries[i].size = child.size as usize;
|
||||
for entry in entries.iter_mut().take(count) {
|
||||
if !entry.is_dir {
|
||||
let name = entry.name;
|
||||
if let Some(child_ino) = dir::find_entry(&mut self.device, &self.sb, &inode, name.as_bytes())
|
||||
&& let Some(child) = self.read_inode(child_ino) {
|
||||
entry.size = child.size as usize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(count)
|
||||
@@ -279,11 +279,10 @@ impl<B: BlockDevice> FileSystem for Ext4<B> {
|
||||
None => return false,
|
||||
};
|
||||
|
||||
if let Some(child_inode) = self.read_inode(child_inode_num) {
|
||||
if child_inode.is_dir() {
|
||||
if let Some(child_inode) = self.read_inode(child_inode_num)
|
||||
&& child_inode.is_dir() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let parent_inode = match self.read_inode(parent_inode_num) {
|
||||
Some(i) => i,
|
||||
@@ -299,11 +298,10 @@ impl<B: BlockDevice> FileSystem for Ext4<B> {
|
||||
self.clear_inode(child_inode_num);
|
||||
self.free_inode(child_inode_num);
|
||||
for slot in self.open_files.iter_mut() {
|
||||
if let Some(f) = slot {
|
||||
if f.inode_num == child_inode_num {
|
||||
if let Some(f) = slot
|
||||
&& f.inode_num == child_inode_num {
|
||||
*slot = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -102,3 +102,9 @@ impl Grants {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Grants {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user