From 7c50b03a92f638824455b06b5ae1afdf88d110cb Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Fri, 27 Dec 2024 17:34:14 +0800 Subject: [PATCH] libconfig: split cmd_error helper --- libconfig/src/sd_reader.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libconfig/src/sd_reader.rs b/libconfig/src/sd_reader.rs index 5254a07..03a9763 100644 --- a/libconfig/src/sd_reader.rs +++ b/libconfig/src/sd_reader.rs @@ -1,6 +1,6 @@ use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFrom, Write}; use fatfs; -use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError}; +use libboard_zynq::sdio::sd_card::SdCard; use log::debug; use alloc::vec::Vec; @@ -12,10 +12,6 @@ const PARTID_FAT32: u8 = 0x0B; const PARTID_FAT32_LBA: u8 = 0x0C; const PARTID_FAT16_LBA: u8 = 0x0E; -fn cmd_error_to_io_error(_: CmdTransferError) -> Error { - Error::new(ErrorKind::Other, "Command transfer error") -} - const BLOCK_SIZE: usize = 512; /// SdReader struct implementing `Read + BufRead + Write + Seek` traits for `core_io`. @@ -221,7 +217,7 @@ impl BufRead for SdReader { // reload buffer self.sd .read_block(self.byte_addr / (BLOCK_SIZE as u32), 1, &mut self.buffer) - .map_err(cmd_error_to_io_error)?; + .map_err(|_| Error::new(ErrorKind::Other, "Command transfer error"))?; self.index = (self.byte_addr as usize) % BLOCK_SIZE; } Ok(&self.buffer[self.index..]) @@ -260,7 +256,7 @@ impl Write for SdReader { let block_addr = (self.byte_addr - self.index as u32) / (BLOCK_SIZE as u32); self.sd .write_block(block_addr, 1, &self.buffer) - .map_err(cmd_error_to_io_error)?; + .map_err(|_| Error::new(ErrorKind::Other, "Command transfer error"))?; self.dirty = false; } Ok(())