From fa082df2da6b3be52c66ce0d48c209a3df38115d Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 14 Aug 2022 21:18:01 +0200 Subject: kernel/ata: "proper" read support --- src/kernel/arch/amd64/driver/pata.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/kernel/arch/amd64/driver/pata.c') diff --git a/src/kernel/arch/amd64/driver/pata.c b/src/kernel/arch/amd64/driver/pata.c index b4ec46c..1193add 100644 --- a/src/kernel/arch/amd64/driver/pata.c +++ b/src/kernel/arch/amd64/driver/pata.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -53,22 +54,26 @@ static void accept(struct vfs_request *req) { vfsreq_finish_short(req, req_readcopy(req, list, len)); break; } - // TODO ata size get - if (req->offset < 0) { - vfsreq_finish_short(req, -ENOSYS); - break; - } + fs_normslice(&req->offset, &req->output.len, ata_size(id), false); + char buf[512]; /* stupid */ - uint32_t sector = req->offset / 512; - size_t len = min(req->output.len, 512 - ((size_t)req->offset & 511)); + uint32_t sector = req->offset / ATA_SECTOR; + size_t skip = (size_t)req->offset & (ATA_SECTOR - 1); + size_t len = min(req->output.len, ATA_SECTOR - skip); ata_read(id, sector, buf); - virt_cpy_to(req->caller->pages, req->output.buf, buf, len); + virt_cpy_to(req->caller->pages, req->output.buf, buf + skip, len); vfsreq_finish_short(req, len); break; case VFSOP_WRITE: panic_unimplemented(); + case VFSOP_GETSIZE: + if (id == root_id) + panic_unimplemented(); + vfsreq_finish_short(req, ata_size(id)); + break; + default: vfsreq_finish_short(req, -ENOSYS); break; -- cgit v1.2.3