Skip to content

Commit

Permalink
修复vfs的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
min0911Y committed Feb 1, 2025
1 parent 3779119 commit 8395357
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
14 changes: 8 additions & 6 deletions apps/filereader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ static bool isprint(char c) {
return c >= 0x20 && c <= 0x7e;
}

static void print_data(const byte *data, usize len) {
static void print_data(const byte *data, usize current, usize len) {
for (usize i = 0; i < len; i += 16) {
printf("\033[1;33m%08x\033[0m ", i);
printf("\033[1;33m%08x\033[0m ", i + current);
for (usize j = 0; j < 16; j++) {
if (i + j < len) {
printf("%02x ", data[i + j]);
Expand All @@ -27,7 +27,7 @@ static void print_data(const byte *data, usize len) {
}
}
int main(int argc, const char **argv) {

if (argc != 2) {
printf("Usage: %s filename\n", argv[0]);
return 1;
Expand All @@ -49,11 +49,13 @@ int main(int argc, const char **argv) {
}
printf(" \033[1;36mCHAR\033[0m\n");

byte *buf = malloc(1024);
byte *buf = malloc(1024);
usize total = 0;
while (true) {
val len = __syscall(SYSCALL_READ,fd, buf, 1024);
val len = __syscall(SYSCALL_READ, fd, buf, 1024);
if (len == 0) break;
print_data(buf, len);
print_data(buf, total, len);
total += len;
}
free(buf);
__syscall(SYSCALL_CLOSE, fd);
Expand Down
4 changes: 2 additions & 2 deletions src/fs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ ssize_t vfs_read(vfs_node_t file, void *addr, size_t offset, size_t size) {
assert(file != null);
assert(addr != null);
do_update(file);
if (file->type != file_block) return -1;
if (file->type == file_dir) return -1;
return callbackof(file, read)(file->handle, addr, offset, size);
}

ssize_t vfs_write(vfs_node_t file, const void *addr, size_t offset, size_t size) {
assert(file != null);
assert(addr != null);
do_update(file);
if (file->type != file_block) return -1;
if (file->type == file_dir) return -1;
ssize_t write_bytes = callbackof(file, write)(file->handle, addr, offset, size);
if (write_bytes > 0) { file->size = max(file->size, offset + write_bytes); }
return write_bytes;
Expand Down
1 change: 1 addition & 0 deletions src/kernel/drivers/general/vmtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static inthandler_f inthandler2c;
static void *ps2_mouse_handler = null;

static void vmware_mouse_init() {
return;
// 取消鼠标捕获
vmware_send(41, 0x45414552);
vmware_send(40, 0);
Expand Down
1 change: 1 addition & 0 deletions src/kernel/hal/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static int devfs_mkdir(void *parent, cstr name, vfs_node_t node) {
static void dummy() {}
// offset 必须能被扇区大小整除
static ssize_t devfs_read(void *file, void *addr, size_t offset, size_t size) {
// klogd("devfs_read");
int dev_id = (int)file;
size_t sector_size;
size_t sectors_to_do;
Expand Down
6 changes: 5 additions & 1 deletion src/kernel/syscall/read-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ isize syscall_read(int fd, void *addr, usize size) {
if (file->fd->node == null) return -1;
if (file->fd->node->type == file_dir) return -1;

isize read_bytes = vfs_read(file->fd->node, addr, file->offset, size);
klogd("read %s\n", file->fd->node->name);
klogd("read %p\n", file->fd->node->handle);
klogd("read %d\n", file->fd->node->fsid);

isize read_bytes = vfs_read(file->fd->node, addr, file->offset, size);
klogd("read_bytes %d\n", read_bytes);
// 这里offset必不可能超过文件大小
file->offset += read_bytes;

Expand Down

0 comments on commit 8395357

Please sign in to comment.