Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1bbc817)
raw | patch | inline | side by side (parent: 1bbc817)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 11 Oct 2024 15:02:56 +0000 (23:02 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 11 Oct 2024 15:02:56 +0000 (23:02 +0800) |
| fs/read.c | patch | blob | history | |
| fs/write.c | patch | blob | history |
diff --git a/fs/read.c b/fs/read.c
--- a/fs/read.c
+++ b/fs/read.c
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) {
// 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
--- a/fs/write.c
+++ b/fs/write.c
// ...
// 写入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
// ...