summaryrefslogtreecommitdiff
path: root/kernel/hd.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/hd.c')
-rw-r--r--kernel/hd.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/kernel/hd.c b/kernel/hd.c
index 3b2aa3c..2f680d1 100644
--- a/kernel/hd.c
+++ b/kernel/hd.c
@@ -102,53 +102,53 @@ static int write_sect(void *buf, uint32_t lba) {
return 0;
}
-size_t hd_read_block(void *buf, size_t block, size_t len) {
+int hd_read_block(void *buf, size_t block) {
int ret;
size_t i;
uint32_t s = SECTS(block);
- uint32_t e = SECTS(block + len);
+ uint32_t e = SECTS(block + 1);
- if(s > nblocks - 1)
- s = nblocks - 1;
- if(e > nblocks - 1)
- e = nblocks - 1;
+ if(nblocks <= s)
+ return -1;
+ if(nblocks <= e)
+ return -1;
for(i = 0; i < (e - s); i++) {
ret = read_sect(buf, i + s);
if(ret < 0)
- return BLOCKS(i);
+ return -1;
buf = ((char*) buf + 512);
}
- return len;
+ return 0;
}
-size_t hd_write_block(void *buf, size_t block, size_t len) {
+int hd_write_block(void *buf, size_t block) {
int ret;
size_t i;
uint32_t s = SECTS(block);
- uint32_t e = SECTS(block + len);
+ uint32_t e = SECTS(block + 1);
- if(s > nblocks - 1)
- s = nblocks - 1;
- if(e > nblocks - 1)
- e = nblocks - 1;
+ if(nblocks <= s)
+ return -1;
+ if(nblocks <= e)
+ return -1;
for(i = 0; i < (e - s); i++) {
ret = write_sect(buf, i + s);
if(ret < 0)
- return BLOCKS(i);
+ return -1;
buf = ((char*) buf + 512);
}
- return len;
+ return 0;
}
-void hd_init(void) {
+int hd_init(void) {
int i;
uint8_t s;
uint16_t *buf = (uint16_t*) sbuf;
@@ -162,13 +162,13 @@ void hd_init(void) {
s = inb(0x1F7);
if(!s) {
printk("[hd] Master drive not detected on primary bus!\n");
- return;
+ return -1;
}
if(s & ST_ERR) {
if(!inb(0x1F4) && !inb(0x1F5))
continue;
printk("[hd] IDENTIFY command error!\n");
- return;
+ return -1;
}
if(s & ST_DRQ && !(s & ST_ERR))
break;
@@ -180,8 +180,9 @@ void hd_init(void) {
nblocks = *((uint32_t*) &buf[60]);
if(!nblocks) {
printk("[hd] Drive does not support LBA28 addressing!\n");
- return;
+ return -1;
}
printk("[hd] Primary bus master drive initialized! (status: 0x%02x, nsects: 0x%01x)\n", s, nblocks);
+ return 0;
}