Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 0ff6534

Browse files
committed
add cat command and upd fs
1 parent 918ee91 commit 0ff6534

9 files changed

Lines changed: 31 additions & 20 deletions

File tree

Makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ BOOT = $(OUT_DIR)/boot.bin
2525
KERNEL_ELF = $(OUT_DIR)/kernel.elf
2626
KERNEL = $(OUT_DIR)/kernel.bin
2727
IMG = $(OUT_DIR)/disk.img
28+
LITECORE_IMG = $(OUT_DIR)/LiteCore.img
2829
LINKER = $(SRC_DIR)/kernel.ld
2930

3031
CALC_SCRIPT = $(SRC_BOOT)/config.inc
3132

32-
.PHONY: calculate-sectors
33+
.PHONY: all run run-console run-serial clean calculate-sectors
34+
.DEFAULT_GOAL := all
35+
3336
calculate-sectors: $(KERNEL)
3437
@echo "Generating $(SRC_BOOT)/config.inc (based on $(KERNEL) size)"
3538
@size=$$(wc -c < $(KERNEL)); sectors=$$(( (size + 511) / 512 )); \
3639
printf "KERNEL_OFFSET EQU 0x10000 ; カーネルをロードするアドレス\nSECTOR_COUNT EQU %s ; 読み込むセクタの数\nSTART_SECTOR EQU 2 ; 開始するセクタ番号\nCYLINDER_NUM EQU 0 ; シリンダ番号\nHEAD_NUM EQU 0 ; ヘッド番号\nCODE_SEGMENT EQU 0x08 ; コードセグメント\nDATA_SEGMENT EQU 0x10 ; データセメント\n" "$$sectors" > $(SRC_BOOT)/config.inc
3740

3841

39-
all: $(OUT_DIR) $(IMG)
42+
all: $(OUT_DIR) $(IMG) $(LITECORE_IMG)
4043

4144
$(OUT_DIR):
4245
mkdir -p $(OUT_DIR)
@@ -62,22 +65,21 @@ $(OUT_DIR)/%.o: $(SRC_KERNEL)/%.asm
6265
mkdir -p $(dir $@)
6366
$(NASM) -f elf32 $< -o $@
6467

65-
src/ext2.img:
66-
@echo "Creating ext2.img (2MB)..."
67-
@python3 tools/mk_ext2_image.py src/ext2.img 2048 example/
68+
$(LITECORE_IMG):
69+
@echo "Creating LiteCore.img (2MB ext2 filesystem)..."
70+
@python3 tools/mk_ext2_image.py $(LITECORE_IMG) 2048 tree
6871

69-
run: $(IMG) src/ext2.img
72+
run: $(IMG) $(LITECORE_IMG)
7073
make all
71-
$(QEMU) $(QEMU_FLAGS) -drive file=$(IMG),format=raw,if=floppy -drive file=src/ext2.img,format=raw,if=ide
74+
$(QEMU) $(QEMU_FLAGS) -drive file=$(IMG),format=raw,if=floppy -drive file=$(LITECORE_IMG),format=raw,if=ide
7275

73-
run-console: $(IMG) src/ext2.img
76+
run-console: $(IMG) $(LITECORE_IMG)
7477
make all
75-
$(QEMU) $(CONSOLE) -drive file=$(IMG),format=raw,if=floppy -drive file=src/ext2.img,format=raw,if=ide
76-
run-serial: $(IMG) src/ext2.img
78+
$(QEMU) $(CONSOLE) -drive file=$(IMG),format=raw,if=floppy -drive file=$(LITECORE_IMG),format=raw,if=ide
79+
80+
run-serial: $(IMG) $(LITECORE_IMG)
7781
make all
78-
$(QEMU) $(QEMU_SERIAL) -drive file=$(IMG),format=raw,if=floppy -drive file=src/ext2.img,format=raw,if=ide
82+
$(QEMU) $(QEMU_SERIAL) -drive file=$(IMG),format=raw,if=floppy -drive file=$(LITECORE_IMG),format=raw,if=ide
7983

8084
clean:
8185
rm -rf $(OUT_DIR)
82-
83-
.PHONY: all run clean

example/ext2.img

-1.41 MB
Binary file not shown.

example/readme.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/ext2.img

-2 MB
Binary file not shown.

src/kernel/fs/ext/ext2.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,21 @@ int ext2_read_file(struct ext2_super *sb, const char *name, void *buf,
412412
file_inode.i_block[block_idx] != 0;
413413
block_idx++) {
414414
uint32_t block_num = file_inode.i_block[block_idx];
415-
uint32_t block_offset = block_num * sb->block_size;
416415

417-
if (block_offset + sb->block_size > sb->image_size)
418-
break;
416+
/* ブロックデータを読み込む */
417+
uint8_t block_data[4096];
418+
if (sb->cache) {
419+
if (block_cache_read(sb->cache, block_num,
420+
block_data) != 0)
421+
break;
422+
} else {
423+
uint32_t block_offset = block_num * sb->block_size;
424+
if (block_offset + sb->block_size > sb->image_size)
425+
break;
426+
mem_copy(block_data, sb->image + block_offset,
427+
sb->block_size);
428+
}
419429

420-
const uint8_t *block_data = sb->image + block_offset;
421430
uint32_t copy_size = sb->block_size;
422431
if (bytes_read + copy_size > bytes_to_read)
423432
copy_size = bytes_to_read - bytes_read;

src/kernel/util/extended_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static int cmd_ver(int argc, char **argv) {
9999
(void)argc;
100100
(void)argv;
101101

102-
printk("LiteCore Operating System\n");
102+
printk("LiteCore Kernel\n");
103103
printk("Version: %s\n", VERSION);
104104
printk("Build: %s %s\n", __DATE__, __TIME__);
105105
printk("Author: nekogakure\n");

tree/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# LiteCore Kernel
2+
LiteCore Kernel is a simple and lightweight kernel designed for educational purposes. It targets the x86_64 architecture and provides basic features such as memory management, file system, device drivers, and a command system.
File renamed without changes.

0 commit comments

Comments
 (0)