Skip to content

Commit d302a0d

Browse files
committed
Merge branch 'dev' into main
2 parents a43dbc4 + 3554e20 commit d302a0d

File tree

5 files changed

+27
-73
lines changed

5 files changed

+27
-73
lines changed

easy-fs/src/efs.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ impl EasyFileSystem {
119119
)
120120
}
121121

122-
/*
123-
fn get_super_block(&self) -> Dirty<SuperBlock> {
124-
Dirty::new(0, 0, self.block_device.clone())
125-
}
126-
*/
127-
128122
pub fn get_disk_inode_pos(&self, inode_id: u32) -> (u32, usize) {
129123
let inode_size = core::mem::size_of::<DiskInode>();
130124
let inodes_per_block = (BLOCK_SZ / inode_size) as u32;
@@ -136,16 +130,6 @@ impl EasyFileSystem {
136130
self.data_area_start_block + data_block_id
137131
}
138132

139-
/*
140-
fn get_block(&self, block_id: u32) -> Dirty<DataBlock> {
141-
Dirty::new(
142-
block_id as usize,
143-
0,
144-
self.block_device.clone(),
145-
)
146-
}
147-
*/
148-
149133
pub fn alloc_inode(&mut self) -> u32 {
150134
self.inode_bitmap.alloc(&self.block_device).unwrap() as u32
151135
}

easy-fs/src/layout.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ type IndirectBlock = [u32; BLOCK_SZ / 4];
7272
type DataBlock = [u8; BLOCK_SZ];
7373

7474
#[repr(C)]
75-
/// Only support level-1 indirect now, **indirect2** field is always 0.
7675
pub struct DiskInode {
7776
pub size: u32,
7877
pub direct: [u32; INODE_DIRECT_COUNT],
@@ -235,32 +234,6 @@ impl DiskInode {
235234
}
236235
});
237236
}
238-
239-
/*
240-
pub fn clear_size(&mut self, block_device: &Arc<dyn BlockDevice>) -> Vec<u32> {
241-
let mut v: Vec<u32> = Vec::new();
242-
let blocks = self.blocks() as usize;
243-
self.size = 0;
244-
for i in 0..blocks.min(INODE_DIRECT_COUNT) {
245-
v.push(self.direct[i]);
246-
self.direct[i] = 0;
247-
}
248-
if blocks > INODE_DIRECT_COUNT {
249-
get_block_cache(
250-
self.indirect1 as usize,
251-
Arc::clone(block_device),
252-
)
253-
.lock()
254-
.modify(0, |indirect_block: &mut IndirectBlock| {
255-
for i in 0..blocks - INODE_DIRECT_COUNT {
256-
v.push(indirect_block[i]);
257-
indirect_block[i] = 0;
258-
}
259-
});
260-
}
261-
v
262-
}
263-
*/
264237

265238
/// Clear size to zero and return blocks that should be deallocated.
266239
///
@@ -434,10 +407,13 @@ pub struct DirEntry {
434407

435408
pub const DIRENT_SZ: usize = 32;
436409

437-
//pub type DirentBlock = [DirEntry; BLOCK_SZ / DIRENT_SZ];
438-
pub type DirentBytes = [u8; DIRENT_SZ];
439-
440410
impl DirEntry {
411+
pub fn empty() -> Self {
412+
Self {
413+
name: [0u8; NAME_LENGTH_LIMIT + 1],
414+
inode_number: 0,
415+
}
416+
}
441417
pub fn new(name: &str, inode_number: u32) -> Self {
442418
let mut bytes = [0u8; NAME_LENGTH_LIMIT + 1];
443419
&mut bytes[..name.len()].copy_from_slice(name.as_bytes());
@@ -446,18 +422,20 @@ impl DirEntry {
446422
inode_number,
447423
}
448424
}
449-
pub fn into_bytes(&self) -> &DirentBytes {
425+
pub fn as_bytes(&self) -> &[u8] {
450426
unsafe {
451-
&*(self as *const Self as usize as *const DirentBytes)
427+
core::slice::from_raw_parts(
428+
self as *const _ as usize as *const u8,
429+
DIRENT_SZ,
430+
)
452431
}
453432
}
454-
pub fn from_bytes(bytes: &DirentBytes) -> &Self {
455-
unsafe { &*(bytes.as_ptr() as usize as *const Self) }
456-
}
457-
#[allow(unused)]
458-
pub fn from_bytes_mut(bytes: &mut DirentBytes) -> &mut Self {
433+
pub fn as_bytes_mut(&mut self) -> &mut [u8] {
459434
unsafe {
460-
&mut *(bytes.as_mut_ptr() as usize as *mut Self)
435+
core::slice::from_raw_parts_mut(
436+
self as *mut _ as usize as *mut u8,
437+
DIRENT_SZ,
438+
)
461439
}
462440
}
463441
pub fn name(&self) -> &str {

easy-fs/src/vfs.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::{
33
DiskInode,
44
DiskInodeType,
55
DirEntry,
6-
DirentBytes,
76
EasyFileSystem,
87
DIRENT_SZ,
98
get_block_cache,
@@ -49,12 +48,6 @@ impl Inode {
4948
).lock().modify(self.block_offset, f)
5049
}
5150

52-
/*
53-
fn get_disk_inode(&self, fs: &mut MutexGuard<EasyFileSystem>) -> Dirty<DiskInode> {
54-
fs.get_disk_inode(self.inode_id)
55-
}
56-
*/
57-
5851
fn find_inode_id(
5952
&self,
6053
name: &str,
@@ -63,17 +56,16 @@ impl Inode {
6356
// assert it is a directory
6457
assert!(disk_inode.is_dir());
6558
let file_count = (disk_inode.size as usize) / DIRENT_SZ;
66-
let mut dirent_space: DirentBytes = Default::default();
59+
let mut dirent = DirEntry::empty();
6760
for i in 0..file_count {
6861
assert_eq!(
6962
disk_inode.read_at(
7063
DIRENT_SZ * i,
71-
&mut dirent_space,
64+
dirent.as_bytes_mut(),
7265
&self.block_device,
7366
),
7467
DIRENT_SZ,
7568
);
76-
let dirent = DirEntry::from_bytes(&dirent_space);
7769
if dirent.name() == name {
7870
return Some(dirent.inode_number() as u32);
7971
}
@@ -144,7 +136,7 @@ impl Inode {
144136
let dirent = DirEntry::new(name, new_inode_id);
145137
root_inode.write_at(
146138
file_count * DIRENT_SZ,
147-
dirent.into_bytes(),
139+
dirent.as_bytes(),
148140
&self.block_device,
149141
);
150142
});
@@ -164,16 +156,16 @@ impl Inode {
164156
let file_count = (disk_inode.size as usize) / DIRENT_SZ;
165157
let mut v: Vec<String> = Vec::new();
166158
for i in 0..file_count {
167-
let mut dirent_bytes: DirentBytes = Default::default();
159+
let mut dirent = DirEntry::empty();
168160
assert_eq!(
169161
disk_inode.read_at(
170162
i * DIRENT_SZ,
171-
&mut dirent_bytes,
163+
dirent.as_bytes_mut(),
172164
&self.block_device,
173165
),
174166
DIRENT_SZ,
175167
);
176-
v.push(String::from(DirEntry::from_bytes(&dirent_bytes).name()));
168+
v.push(String::from(dirent.name()));
177169
}
178170
v
179171
})

os/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ disasm-vim: kernel
7171
@vim $(DISASM_TMP)
7272
@rm $(DISASM_TMP)
7373

74-
run: tools run-inner
74+
run: run-inner
7575

76-
tools:
77-
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)
76+
7877

7978
run-inner: build
8079
ifeq ($(BOARD),qemu)
@@ -86,6 +85,7 @@ ifeq ($(BOARD),qemu)
8685
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
8786
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
8887
else
88+
(which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools)
8989
@cp $(BOOTLOADER) $(BOOTLOADER).copy
9090
@dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(K210_BOOTLOADER_SIZE) seek=1
9191
@mv $(BOOTLOADER).copy $(KERNEL_BIN)
@@ -100,4 +100,4 @@ debug: build
100100
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
101101
tmux -2 attach-session -d
102102

103-
.PHONY: build env kernel clean disasm disasm-vim run-inner tools
103+
.PHONY: build env kernel clean disasm disasm-vim run-inner

os/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub const CLOCK_FREQ: usize = 12500000;
1818

1919
#[cfg(feature = "board_qemu")]
2020
pub const MMIO: &[(usize, usize)] = &[
21-
(0x10000000, 0x10000),
21+
(0x10001000, 0x1000),
2222
];
2323

2424
#[cfg(feature = "board_k210")]

0 commit comments

Comments
 (0)