Skip to content

Commit

Permalink
修复一些小bug
Browse files Browse the repository at this point in the history
  • Loading branch information
min0911Y committed Nov 2, 2024
1 parent 7611c62 commit 683603b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/fs/iso9660.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This code is released under the MIT License

#include <fs.h>

#define L9660_SEEK_END -1
#define L9660_SEEK_SET 0
#define L9660_SEEK_CUR +1
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/kernel/hal/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/kernel/task/basetask.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 683603b

Please sign in to comment.