aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2021-01-08 23:51:37 +0100
committerMarvin Borner2021-01-08 23:51:37 +0100
commitca466dbbecd387481fbde95e1e3d9b6ff279c169 (patch)
tree75eb11cee96b006aec1b5f63218d87d48522acdb /kernel
parent45a9df836accd39cf2dbfbb2453496b0e4d93fa5 (diff)
Cleanup
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/ide.c16
-rw-r--r--kernel/features/fs.c21
-rw-r--r--kernel/inc/fs.h2
-rw-r--r--kernel/inc/ide.h1
4 files changed, 17 insertions, 23 deletions
diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c
index 6f73b13..f3d0f6e 100644
--- a/kernel/drivers/ide.c
+++ b/kernel/drivers/ide.c
@@ -55,7 +55,7 @@ u8 ide_find(u8 bus, u8 drive)
return 0;
} while ((status & ATA_SR_DRQ) == 0);
- for (int i = 0; i < 256; i++)
+ for (int i = 0; i < BLOCK_COUNT; i++)
*(u16 *)(ide_buf + i * 2) = inw(io + ATA_REG_DATA);
return 1;
@@ -98,7 +98,7 @@ u8 ata_read_one(u8 *buf, u32 lba, struct device *dev)
outb(io + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
ide_poll(io);
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < BLOCK_COUNT; i++) {
u16 data = inw(io + ATA_REG_DATA);
*(u16 *)(buf + i * 2) = data;
}
@@ -106,14 +106,14 @@ u8 ata_read_one(u8 *buf, u32 lba, struct device *dev)
return 1;
}
-u32 ata_read(void *buf, u32 lba, u32 numsects, struct device *dev)
+u32 ata_read(void *buf, u32 lba, u32 sector_count, struct device *dev)
{
u8 *b = buf; // I love bytes, yk
- for (u32 i = 0; i < numsects; i++) {
+ for (u32 i = 0; i < sector_count; i++) {
ata_read_one(b, lba + i, dev);
- b += 512;
+ b += SECTOR_SIZE;
}
- return numsects;
+ return sector_count;
}
int ata_pm = 0, ata_ps = 0, ata_sm = 0, ata_ss = 0;
@@ -140,7 +140,7 @@ void ata_probe(void)
dev->type = DEV_BLOCK;
dev->read = ata_read;
device_add(dev);
- if (vfs_path_mounted("/"))
+ if (vfs_mounted(dev, "/"))
continue;
// TODO: Check if ext2 first
@@ -155,6 +155,6 @@ void ata_probe(void)
void ata_install(void)
{
- ide_buf = malloc(512);
+ ide_buf = malloc(SECTOR_SIZE);
ata_probe();
}
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 6278d50..14e6a9c 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -24,11 +24,12 @@ char *vfs_normalize_path(const char *path)
return fixed;
}
-u32 vfs_path_mounted(const char *path)
+u32 vfs_mounted(struct device *dev, const char *path)
{
struct node *iterator = mount_points->head;
while (iterator) {
- if (!strcmp(((struct mount_info *)iterator->data)->path, path))
+ if (((struct mount_info *)iterator->data)->dev->id == dev->id ||
+ !strcmp(((struct mount_info *)iterator->data)->path, path))
return 1;
iterator = iterator->next;
}
@@ -102,7 +103,7 @@ void vfs_list_mounts()
u32 vfs_mount(struct device *dev, const char *path)
{
// TODO: Check if already mounted
- if (!dev || !dev->id)
+ if (!dev || !dev->id || vfs_mounted(dev, path))
return 0;
char *fixed = vfs_normalize_path(path);
@@ -206,7 +207,7 @@ void device_install(void)
void *buffer_read(u32 block, struct device *dev)
{
void *buf = malloc(BLOCK_SIZE);
- dev->read(buf, block << 1, 2, dev);
+ dev->read(buf, block * SECTOR_COUNT, SECTOR_COUNT, dev);
return buf;
}
@@ -251,16 +252,14 @@ u32 read_indirect(u32 indirect, u32 block_num, struct device *dev)
u32 read_inode(struct ext2_inode *in, void *buf, u32 offset, u32 count, struct device *dev)
{
- // TODO: Support all read parameters
+ // TODO: Support read offset
(void)offset;
- assert(in);
- if (!in)
+ if (!in || !buf)
return 0;
u32 num_blocks = in->blocks / (BLOCK_SIZE / SECTOR_SIZE);
- assert(num_blocks);
if (!num_blocks)
return 0;
@@ -268,12 +267,6 @@ u32 read_inode(struct ext2_inode *in, void *buf, u32 offset, u32 count, struct d
while (BLOCK_SIZE * num_blocks > count)
num_blocks--;
- /* u32 sz = BLOCK_SIZE * num_blocks; */
- /* u32 sz = in->size; */
- /* void *buf = malloc(sz); */
- /* printf("Loading %dKiB\n", sz >> 10); */
- assert(buf);
-
u32 indirect = 0;
u32 blocknum = 0;
char *data = 0;
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 75cb49f..ff14361 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -47,7 +47,7 @@ struct mount_info {
void vfs_install(void);
-u32 vfs_path_mounted(const char *path);
+u32 vfs_mounted(struct device *dev, const char *path);
u32 vfs_mount(struct device *dev, const char *path);
u32 vfs_read(const char *path, void *buf, u32 offset, u32 count);
diff --git a/kernel/inc/ide.h b/kernel/inc/ide.h
index 6e43ece..dbe0652 100644
--- a/kernel/inc/ide.h
+++ b/kernel/inc/ide.h
@@ -8,6 +8,7 @@
#define BLOCK_SIZE 1024
#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32)
#define SECTOR_SIZE 512
+#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE)
#define ATA_PRIMARY_IO 0x1f0
#define ATA_SECONDARY_IO 0x170