All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yiyang Wu via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: [RFC PATCH 10/24] erofs: add device_infos implementation in Rust
Date: Mon, 16 Sep 2024 21:55:27 +0800	[thread overview]
Message-ID: <20240916135541.98096-11-toolmanp@tlmp.cc> (raw)
In-Reply-To: <20240916135541.98096-1-toolmanp@tlmp.cc>

Add device_infos implementation in rust. It will later be used
to be put inside the SuperblockInfo. This mask and spec can later
be used to chunk-based image file block mapping.

Signed-off-by: Yiyang Wu <toolmanp@tlmp.cc>
---
 fs/erofs/rust/erofs_sys/devices.rs | 47 ++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/fs/erofs/rust/erofs_sys/devices.rs b/fs/erofs/rust/erofs_sys/devices.rs
index 097676ee8720..7495164c7bd0 100644
--- a/fs/erofs/rust/erofs_sys/devices.rs
+++ b/fs/erofs/rust/erofs_sys/devices.rs
@@ -1,6 +1,10 @@
 // Copyright 2024 Yiyang Wu
 // SPDX-License-Identifier: MIT or GPL-2.0-or-later
 
+use super::alloc_helper::*;
+use super::data::raw_iters::*;
+use super::data::*;
+use super::*;
 use alloc::vec::Vec;
 
 /// Device specification.
@@ -21,8 +25,51 @@ pub(crate) struct DeviceSlot {
     reserved: [u8; 56],
 }
 
+impl From<[u8; 128]> for DeviceSlot {
+    fn from(data: [u8; 128]) -> Self {
+        Self {
+            tags: data[0..64].try_into().unwrap(),
+            blocks: u32::from_le_bytes([data[64], data[65], data[66], data[67]]),
+            mapped_blocks: u32::from_le_bytes([data[68], data[69], data[70], data[71]]),
+            reserved: data[72..128].try_into().unwrap(),
+        }
+    }
+}
+
 /// Device information.
 pub(crate) struct DeviceInfo {
     pub(crate) mask: u16,
     pub(crate) specs: Vec<DeviceSpec>,
 }
+
+pub(crate) fn get_device_infos<'a>(
+    iter: &mut (dyn ContinuousBufferIter<'a> + 'a),
+) -> PosixResult<DeviceInfo> {
+    let mut specs = Vec::new();
+    for data in iter {
+        let buffer = data?;
+        let mut cur: usize = 0;
+        let len = buffer.content().len();
+        while cur + 128 <= len {
+            let slot_data: [u8; 128] = buffer.content()[cur..cur + 128].try_into().unwrap();
+            let slot = DeviceSlot::from(slot_data);
+            cur += 128;
+            push_vec(
+                &mut specs,
+                DeviceSpec {
+                    tags: slot.tags,
+                    blocks: slot.blocks,
+                    mapped_blocks: slot.mapped_blocks,
+                },
+            )?;
+        }
+    }
+
+    let mask = if specs.is_empty() {
+        0
+    } else {
+        (1 << (specs.len().ilog2() + 1)) - 1
+    };
+
+    Ok(DeviceInfo { mask, specs })
+}
-- 
2.46.0


WARNING: multiple messages have this Message-ID (diff)
From: Yiyang Wu <toolmanp@tlmp.cc>
To: linux-erofs@lists.ozlabs.org
Cc: rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 10/24] erofs: add device_infos implementation in Rust
Date: Mon, 16 Sep 2024 21:55:27 +0800	[thread overview]
Message-ID: <20240916135541.98096-11-toolmanp@tlmp.cc> (raw)
In-Reply-To: <20240916135541.98096-1-toolmanp@tlmp.cc>

Add device_infos implementation in rust. It will later be used
to be put inside the SuperblockInfo. This mask and spec can later
be used to chunk-based image file block mapping.

Signed-off-by: Yiyang Wu <toolmanp@tlmp.cc>
---
 fs/erofs/rust/erofs_sys/devices.rs | 47 ++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/fs/erofs/rust/erofs_sys/devices.rs b/fs/erofs/rust/erofs_sys/devices.rs
index 097676ee8720..7495164c7bd0 100644
--- a/fs/erofs/rust/erofs_sys/devices.rs
+++ b/fs/erofs/rust/erofs_sys/devices.rs
@@ -1,6 +1,10 @@
 // Copyright 2024 Yiyang Wu
 // SPDX-License-Identifier: MIT or GPL-2.0-or-later
 
+use super::alloc_helper::*;
+use super::data::raw_iters::*;
+use super::data::*;
+use super::*;
 use alloc::vec::Vec;
 
 /// Device specification.
@@ -21,8 +25,51 @@ pub(crate) struct DeviceSlot {
     reserved: [u8; 56],
 }
 
+impl From<[u8; 128]> for DeviceSlot {
+    fn from(data: [u8; 128]) -> Self {
+        Self {
+            tags: data[0..64].try_into().unwrap(),
+            blocks: u32::from_le_bytes([data[64], data[65], data[66], data[67]]),
+            mapped_blocks: u32::from_le_bytes([data[68], data[69], data[70], data[71]]),
+            reserved: data[72..128].try_into().unwrap(),
+        }
+    }
+}
+
 /// Device information.
 pub(crate) struct DeviceInfo {
     pub(crate) mask: u16,
     pub(crate) specs: Vec<DeviceSpec>,
 }
+
+pub(crate) fn get_device_infos<'a>(
+    iter: &mut (dyn ContinuousBufferIter<'a> + 'a),
+) -> PosixResult<DeviceInfo> {
+    let mut specs = Vec::new();
+    for data in iter {
+        let buffer = data?;
+        let mut cur: usize = 0;
+        let len = buffer.content().len();
+        while cur + 128 <= len {
+            let slot_data: [u8; 128] = buffer.content()[cur..cur + 128].try_into().unwrap();
+            let slot = DeviceSlot::from(slot_data);
+            cur += 128;
+            push_vec(
+                &mut specs,
+                DeviceSpec {
+                    tags: slot.tags,
+                    blocks: slot.blocks,
+                    mapped_blocks: slot.mapped_blocks,
+                },
+            )?;
+        }
+    }
+
+    let mask = if specs.is_empty() {
+        0
+    } else {
+        (1 << (specs.len().ilog2() + 1)) - 1
+    };
+
+    Ok(DeviceInfo { mask, specs })
+}
-- 
2.46.0


  parent reply	other threads:[~2024-09-16 13:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 13:55 [RFC PATCH 00/24] erofs: introduce Rust implementation Yiyang Wu via Linux-erofs
2024-09-16 13:55 ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 01/24] erofs: lift up erofs_fill_inode to global Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 02/24] erofs: add superblock data structure in Rust Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 03/24] erofs: add Errno " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 04/24] erofs: add xattrs data structure " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 05/24] erofs: add inode " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 06/24] erofs: add alloc_helper " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 07/24] erofs: add data abstraction " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 08/24] erofs: add device data structure " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` [RFC PATCH 09/24] erofs: add continuous iterators " Yiyang Wu via Linux-erofs
2024-09-16 13:55   ` Yiyang Wu
2024-09-16 13:55 ` Yiyang Wu via Linux-erofs [this message]
2024-09-16 13:55   ` [RFC PATCH 10/24] erofs: add device_infos implementation " Yiyang Wu
2024-09-16 14:04 ` [RFC PATCH 00/24] erofs: introduce Rust implementation Yiyang Wu via Linux-erofs
2024-09-16 14:04   ` Yiyang Wu
  -- strict thread matches above, loose matches on Subject: below --
2024-09-16 13:56 Yiyang Wu via Linux-erofs
2024-09-16 13:56 ` [RFC PATCH 10/24] erofs: add device_infos implementation in Rust Yiyang Wu via Linux-erofs
2024-09-16 13:56   ` Yiyang Wu
2024-09-21  9:44   ` Jianan Huang
2024-09-21  9:44     ` Jianan Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240916135541.98096-11-toolmanp@tlmp.cc \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=toolmanp@tlmp.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.