diff --git a/src/fs/iso9660.c b/src/fs/iso9660.c index 555f8ab5..d8641078 100755 --- a/src/fs/iso9660.c +++ b/src/fs/iso9660.c @@ -1,7 +1,6 @@ // This code is released under the MIT License #include - #define L9660_SEEK_END -1 #define L9660_SEEK_SET 0 #define L9660_SEEK_CUR +1 @@ -438,7 +437,14 @@ int iso9660_readfile(file_t file, void *addr, size_t offset, size_t size) { l9660_status st; st = l9660_seek(fp, SEEK_SET, offset); if (st != L9660_OK) return -1; - st = l9660_read(fp, addr, size, null); + size_t read = 0; + size_t total_read = 0; + while (total_read < size) { + st = l9660_read(fp, (char *)addr + total_read, size - total_read, &read); + if (st != L9660_OK) return -1; + total_read += read; + if (read == 0) break; + } if (st != L9660_OK) return -1; return 0; } diff --git a/src/kernel/hal/dev.c b/src/kernel/hal/dev.c index 39792d2a..cf56d2a9 100755 --- a/src/kernel/hal/dev.c +++ b/src/kernel/hal/dev.c @@ -17,10 +17,9 @@ static int devfs_mkdir(void *parent, cstr name, vfs_node_t node) { node->fsid = 0; // 交给vfs处理 return 0; } -static void dummy() { -} +static void dummy() {} // offset 必须能被扇区大小整除 -static int devfs_read(void *file, void *addr, size_t offset, size_t size) { +static int devfs_read(void *file, void *addr, size_t offset, size_t size) { int dev_id = (int)file; int sector_size; if (vdisk_ctl[dev_id].flag == 0) return -1; diff --git a/src/kernel/task/basetask.c b/src/kernel/task/basetask.c index ffb3cf42..3df138af 100755 --- a/src/kernel/task/basetask.c +++ b/src/kernel/task/basetask.c @@ -231,6 +231,26 @@ void shell() { buf[size] = '\0'; printf("%s\n", buf); free(buf); + } else if (strneq(ch, "readhex ", 8)) { + char *s = ch + 8; + vfs_node_t p = vfs_open(s); + if (!p) { + printf("open %s failed\n", s); + continue; + } + if (p->type == file_dir) { + printf("not a file\n"); + continue; + } + size_t size = p->size; + byte *buf = malloc(size); + memset(buf, 0, size); + vfs_read(p, buf, 0, size); + for (size_t i = 0; i < size; i++) { + printf("%02x ", buf[i]); + } + printf("\n"); + free(buf); } else if (strneq(ch, "mkdir ", 6)) { vfs_mkdir(ch + 6); } else if (strneq(ch, "mount ", 6)) {