From: acevest Date: Fri, 11 Oct 2024 15:02:56 +0000 (+0800) Subject: 修复vfs读写位置错误的问题 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=ae3ceb46c16fe156199c67d9d990a1c1e59e82e8;p=kernel.git 修复vfs读写位置错误的问题 --- 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 // ...