- 用户态共享网络协议栈 CODE/tools/net_stack.h(eth/ARP/IPv4/ICMP/UDP-DNS/TCP static inline,轮询模型) - shell 内建 ping/curl/run 命令;ping.elf/curl.elf 对齐 net_stack.h 真实协议栈 - shell dev_mode 串口镜像(g_serial_mirror)便于自动化验证 - DSK 启动流程:firstInit.txt 双行格式(firstInit + dev_mode),dev_mode=1 触发 shell 自动回归测试 - FirstInit 完成→持久化 USER.CONF + 翻转 firstInit 0->1(保留 dev_mode) - firstInit=1 时 DSK 加载 login.elf 进行用户选择 + 密码校验后再进 desktop - 新增 CODE/login/ 登录应用、CODE/DKM/dkm_shared.h、Logo.png - ahci/e1000/virtio_net/fat32/console_fb 驱动更新;utsm serial/block/dsk_loader 调整 - build.ps1 打包 ping.elf/curl.elf 进 SATA FAT32 根目录 - 移除 CODE/tools/bash(与 shell.elf 重复)
74 lines
2.2 KiB
C
74 lines
2.2 KiB
C
#include <utsm/block.h>
|
|
#include <utsm/log.h>
|
|
|
|
static dkm_block_device_desc g_devices[DKM_BLOCK_MAX_DEVICES];
|
|
static u32 g_device_count;
|
|
|
|
void block_init(void) {
|
|
g_device_count = 0;
|
|
log_info("[BLOCK] registry init");
|
|
}
|
|
|
|
static int block_register_device_impl(const dkm_block_device_desc *desc) {
|
|
if (!desc || !desc->read || !desc->sector_size) return -1;
|
|
if (g_device_count >= DKM_BLOCK_MAX_DEVICES) return -2;
|
|
|
|
u32 index = g_device_count++;
|
|
g_devices[index] = *desc;
|
|
|
|
log_info("[BLOCK] device registered");
|
|
if (desc->name) log_info(desc->name);
|
|
log_hex64("[BLOCK] index=", index);
|
|
log_hex64("[BLOCK] sector_size=", desc->sector_size);
|
|
log_hex64("[BLOCK] sector_count=", desc->sector_count);
|
|
return (int)index;
|
|
}
|
|
|
|
static u32 block_device_count_impl(void) {
|
|
return g_device_count;
|
|
}
|
|
|
|
static int block_read_impl(u32 index, u64 lba, u32 count, void *buffer) {
|
|
if (index >= g_device_count || !buffer || count == 0) return -1;
|
|
dkm_block_device_desc *dev = &g_devices[index];
|
|
if (!dev->read) return -2;
|
|
return dev->read(dev->ctx, lba, count, buffer);
|
|
}
|
|
|
|
static int block_write_impl(u32 index, u64 lba, u32 count, const void *buffer) {
|
|
if (index >= g_device_count || !buffer || count == 0) return -1;
|
|
dkm_block_device_desc *dev = &g_devices[index];
|
|
if (!dev->write) return -2;
|
|
return dev->write(dev->ctx, lba, count, buffer);
|
|
}
|
|
|
|
static u64 block_sector_size_impl(u32 index) {
|
|
if (index >= g_device_count) return 0;
|
|
return g_devices[index].sector_size;
|
|
}
|
|
|
|
static const char *block_device_name_impl(u32 index) {
|
|
if (index >= g_device_count) return 0;
|
|
return g_devices[index].name;
|
|
}
|
|
|
|
static int block_set_write_fn_impl(u32 index, dkm_block_write_fn fn) {
|
|
if (index >= g_device_count) return -1;
|
|
g_devices[index].write = fn;
|
|
return 0;
|
|
}
|
|
|
|
static const dkm_block_api g_block_api = {
|
|
.register_device = block_register_device_impl,
|
|
.device_count = block_device_count_impl,
|
|
.read = block_read_impl,
|
|
.write = block_write_impl,
|
|
.sector_size = block_sector_size_impl,
|
|
.device_name = block_device_name_impl,
|
|
.set_write_fn = block_set_write_fn_impl
|
|
};
|
|
|
|
const dkm_block_api *block_get_api(void) {
|
|
return &g_block_api;
|
|
}
|