From ae3ceb46c16fe156199c67d9d990a1c1e59e82e8 Mon Sep 17 00:00:00 2001 From: acevest Date: Fri, 11 Oct 2024 23:02:56 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Dvfs=E8=AF=BB=E5=86=99=E4=BD=8D?= =?utf8?q?=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- fs/read.c | 6 +++++- fs/write.c | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/read.c b/fs/read.c index 743be3f..6d3e071 100644 --- a/fs/read.c +++ b/fs/read.c @@ -29,7 +29,7 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po uint32_t offset = pos & (PAGE_SIZE - 1); size_t left = size; - while (true) { + while (left > 0) { page_t *page = NULL; uint32_t end_index = inode->i_size >> PAGE_SHIFT; if (index > end_index) { @@ -57,9 +57,13 @@ ssize_t vfs_generic_file_read(file_t *file, char *buf, size_t size, loff_t *p_po // TODO 增加page引用计数 // copy data + bytes = bytes < left ? bytes : left; void *addr = page2va(page); + // printk("memcpy bytes %u index %u\n", bytes, index); + // printk("read addr %x bytes %u index %u offset %u\n", addr, bytes, index, offset); memcpy(buf, addr, bytes); + buf += bytes; offset += bytes; index += offset >> PAGE_SHIFT; offset &= (PAGE_SIZE - 1); diff --git a/fs/write.c b/fs/write.c index d29ca9a..d3e70f1 100644 --- a/fs/write.c +++ b/fs/write.c @@ -68,7 +68,8 @@ ssize_t vfs_generic_file_write(file_t *file, const char *buf, size_t size, loff_ // ... // 写入page - memcpy(addr, buf, bytes); + memcpy(addr, buf + pos, bytes); + // printk("write addr %x bytes %u index %u offset %u\n", addr, bytes, index, offset); // TODO // ... -- 2.44.0